本文概述
- Apache POI字样式示例
让我们看一个示例,其中我们创建一个段落并将其设置为粗体和斜体。
Apache POI字样式示例
package poiexample;
import java.io.FileOutputStream;
import java.io.OutputStream;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XW.PFParagraph;
import org.apache.poi.xwpf.usermodel.XWPFRun;
public class StyleExample {
public static void main(String[] args) {
XWPFDocument doc = new XWPFDocument();
try(OutputStream os = new FileOutputStream("srcmini.docx")) {
XWPFParagraph paragraph = doc.createParagraph();
//Set Bold an Italic
XWPFRun xr = paragraph.createRun();
xr.setBold(true);
xr.setItalic(true);
xr.setText("This text is Bold and have Italic style");
xr.addBreak();
doc.write(os);
}catch(Exception e) {
System.out.println(e);
}
}
}
【apache poi word风格】输出:
文章图片
推荐阅读
- apache poi word对齐
- apache poi word提取文本
- apache poi word提取段落
- apache poi和powerpoint
- apache poi创建ms word文档
- apache poi microsoft word文档
- apache poi的注释
- apache poi样式化形状
- apache poi重写