-
Java 设置Word页面背景色
Word中可以针对不同文档排版设计要求来设置背景设置颜色。常见的可设置单一颜色、渐变色或加载指定图片来设置成背景。下面通过Java来设置以上3种Word页面背景色。
使用工具:Spire.Doc for Java v2.2.0
Jar文件导入方法
方法1:通过官网下载。在程序下新建一个directory目录,并命名(本示例中命名为lib);将控件包lib文件夹下的jar(如下图1)直接复制到程序中新建的目录下。复制jar文件后,鼠标右键点击jar文件,选择”Add as Library”。完成导入(如下图2)。
图1:
图2:
方法2:通过maven导入。参考导入方法(https://www.e-iceblue.cn/licensing/install-spirepdf-for-java-from-maven-repository.html)。
Java代码示例(供参考)
【示例1】添加单一颜色的背景色
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); } }
(本文完)
出 处:https://www.cnblogs.com/Yesi/p/10831597.html
最新更新
求1000阶乘的结果末尾有多少个0
详解MyBatis延迟加载是如何实现的
IDEA 控制台中文乱码4种解决方案
SpringBoot中版本兼容性处理的实现示例
Spring的IOC解决程序耦合的实现
详解Spring多数据源如何切换
Java报错:UnsupportedOperationException in Col
使用Spring Batch实现批处理任务的详细教程
java中怎么将多个音频文件拼接合成一个
SpringBoot整合ES多个精确值查询 terms功能实
数据库审计与智能监控:从日志分析到异
SQL Server 中的数据类型隐式转换问题
SQL Server中T-SQL 数据类型转换详解
sqlserver 数据类型转换小实验
SQL Server数据类型转换方法
SQL Server 2017无法连接到服务器的问题解决
SQLServer地址搜索性能优化
Sql Server查询性能优化之不可小觑的书签查
SQL Server数据库的高性能优化经验总结
SQL SERVER性能优化综述(很好的总结,不要错
uniapp/H5 获取手机桌面壁纸 (静态壁纸)
[前端] DNS解析与优化
为什么在js中需要添加addEventListener()?
JS模块化系统
js通过Object.defineProperty() 定义和控制对象
这是目前我见过最好的跨域解决方案!
减少回流与重绘
减少回流与重绘
如何使用KrpanoToolJS在浏览器切图
performance.now() 与 Date.now() 对比