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

展开全部

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

import com.spire.doc.documents.BackgroundType;

import java.awt.*;

import java.io.IOException;

public class BackgroundColor_Doc {

public static void main (String[] args) throws IOException{

//加载测试文

String input="test.docx";

String output="backgroundcolor.docx";

Document doc = new Document(input);

//设置单色背景

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

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

//保存文档

doc.saveToFile(output,FileFormat.Docx_2013);

}

}

2. 渐变背景色import com.spire.doc.*;

import com.spire.doc.documents.BackgroundType;

import com.spire.doc.documents.GradientShadingStyle;

import com.spire.doc.documents.GradientShadingVariant;

import java.awt.*;

import java.io.IOException;

public class GradientBackground_Doc {

public static void main(String[] arg) throws IOException{

//加载测试文档

String input= "test.docx";

String output="GradientBackgound.docx";

Document doc = new Document(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_2010);

}

}

3. 图片背景import com.spire.doc.*;

import com.spire.doc.documents.BackgroundType;

import java.io.IOException;

public class ImgBackground_Doc {

public static void main(String[] arg) throws IOException {

//加载文件

String input= "test.docx";

String output="ImgBackgound.docx";

String img= "lye.png";

Document doc = new Document(input);

//设置图片背景

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

doc.getBackground().setPicture(img);

//保存文档

doc.saveToFile(output, FileFormat.Docx);

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值