失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > java word 颜色设置_如何为Word文档在Java中的背景颜色

java word 颜色设置_如何为Word文档在Java中的背景颜色

时间:2022-04-04 12:38:30

相关推荐

java word 颜色设置_如何为Word文档在Java中的背景颜色

展开全部

用第三方吧,比较方便,参考下Free Spire.Doc for Java的方法,这个是免费版,直接用可以了。62616964757a686964616fe58685e5aeb931333431373261纯色背景色importcom.spire.doc.*;

importcom.spire.doc.documents.BackgroundType;

importjava.awt.*;

importjava.io.IOException;

publicclassBackgroundColor_Doc{

publicstaticvoidmain(String[]args)throwsIOException{

//加载测试文

Stringinput="test.docx";

Stringoutput="backgroundcolor.docx";

Documentdoc=newDocument(input);

//设置单色背景

doc.getBackground().setType(BackgroundType.Color);

doc.getBackground().setColor(Color.PINK);

//保存文档

doc.saveToFile(output,FileFormat.Docx_);

}

}

2. 渐变背景色importcom.spire.doc.*;

importcom.spire.doc.documents.BackgroundType;

importcom.spire.doc.documents.GradientShadingStyle;

importcom.spire.doc.documents.GradientShadingVariant;

importjava.awt.*;

importjava.io.IOException;

publicclassGradientBackground_Doc{

publicstaticvoidmain(String[]arg)throwsIOException{

//加载测试文档

Stringinput="test.docx";

Stringoutput="GradientBackgound.docx";

Documentdoc=newDocument(input);

//设置渐变色

doc.getBackground().setType(BackgroundType.Gradient);

doc.getBackground().getGradient().setColor1(Color.white);

doc.getBackground().getGradient().setColor2(Color.green);

doc.getBackground().getGradient().setShadingVariant(GradientShadingVariant.Shading_Middle);

doc.getBackground().getGradient().setShadingStyle(GradientShadingStyle.Horizontal);

//保存文档

doc.saveToFile(output,FileFormat.Docx_);

}

}

3. 图片背景importcom.spire.doc.*;

importcom.spire.doc.documents.BackgroundType;

importjava.io.IOException;

publicclassImgBackground_Doc{

publicstaticvoidmain(String[]arg)throwsIOException{

//加载文件

Stringinput="test.docx";

Stringoutput="ImgBackgound.docx";

Stringimg="lye.png";

Documentdoc=newDocument(input);

//设置图片背景

doc.getBackground().setType(BackgroundType.Picture);

doc.getBackground().setPicture(img);

//保存文档

doc.saveToFile(output,FileFormat.Docx);

}

}

如果觉得《java word 颜色设置_如何为Word文档在Java中的背景颜色》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。