Java 给Word中的指定文本字符串添加边框
1、1.手动引入:下载jar包后,解压到本地路径;在Java程序中打开“Project Structure”界面(快捷键:Ctrl+Shift+Alt+S),按如下步骤执行:
2、2.maven配置jar路径并指定依赖,然后引入。如下:
<repositories>
<repository>
<id>com.e-iceblue</id>
<url>http://repo.e-iceblue.cn/repository/maven-public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId> e-iceblue </groupId>
<artifactId>spire.doc.free</artifactId>
<version>3.9.0</version>
</dependency>
</dependencies>
配置完成后导入。
1、import com.spire.doc.*;
import com.spire.doc.documents.BorderStyle;
import com.spire.doc.documents.TextSelection;
import java.awt.*;
public class TextrangeBoder {
public static void main(String[] args) {
//加载Word文档
Document document = new Document("test.docx");
//查找文本
TextSelection[] textSelections1 = document.findAllString("TALMONT", false, false);
//给文本字符串添加边框
for (TextSelection selection : textSelections1)
{
selection.getAsOneRange().getCharacterFormat().getBorder().setBorderType(BorderStyle.Single);
selection.getAsOneRange().getCharacterFormat().getBorder().setColor(Color.red);
selection.getAsOneRange().getCharacterFormat().getBorder().setLineWidth(2);
}
//保存文档
document.saveToFile("BorderToCharacter.docx", FileFormat.Docx_2013);
}
}
2、完成代码编辑后,执行程序,生成结果文档,如图效果:
声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
阅读量:29
阅读量:20
阅读量:67
阅读量:81
阅读量:21