- Apache POI Word 教程
- Apache POI Word - 首页
- Apache POI Word - 概览
- Apache POI Word - 安装
- Apache POI Word - 核心类
- Apache POI Word - 文档
- Apache POI Word - 段落
- Apache POI Word - 边框
- Apache POI Word - 表格
- Apache POI Word - 字体和对齐方式
- Apache POI Word - 文本提取
- Apache POI Word 资源
- Apache POI Word - 快速指南
- Apache POI Word - 有用资源
- Apache POI Word - 讨论
Apache POI Word - 边框
在本章中,您将学习如何使用 Java 编程为段落应用边框。
应用边框
以下代码用于在文档中应用边框 −
import java.io.File;
import java.io.FileOutputStream;
import org.apache.poi.xwpf.usermodel.Borders;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.poi.xwpf.usermodel.XWPFRun;
public class ApplyingBorder {
public static void main(String[] args)throws Exception {
//Blank Document
XWPFDocument document = new XWPFDocument();
//Write the Document in file system
FileOutputStream out = new FileOutputStream(new File("applyingborder.docx"));
//create paragraph
XWPFParagraph paragraph = document.createParagraph();
//Set bottom border to paragraph
paragraph.setBorderBottom(Borders.BASIC_BLACK_DASHES);
//Set left border to paragraph
paragraph.setBorderLeft(Borders.BASIC_BLACK_DASHES);
//Set right border to paragraph
paragraph.setBorderRight(Borders.BASIC_BLACK_DASHES);
//Set top border to paragraph
paragraph.setBorderTop(Borders.BASIC_BLACK_DASHES);
XWPFRun run = paragraph.createRun();
run.setText("At tutorialspoint.com, we strive hard to " +
"provide quality tutorials for self-learning " +
"purpose in the domains of Academics, Information " +
"Technology, Management and Computer Programming " +
"Languages.");
document.write(out);
out.close();
System.out.println("applyingborder.docx written successully");
}
}
将上述代码另存为名为 ApplyingBorder.java 的文件,并通过命令提示符按以下方式编译和执行 −
$javac ApplyingBorder.java $java ApplyingBorder
如果您的系统已配置 POI 库,则它将进行编译和执行,从而在当前目录中生成名为 applyingborder.docx 的 Word 文档,并显示以下输出 −
applyingborder.docx written successfully
applyingborder.docx 文件如下所示 −
广告