apache poi word文档段落

本文概述

  • Apache POI Word段落示例
为了在MS Word文件中创建一个段落,Apache POI提供了XWPFParagraph类。此类使用XWPFRun将该段落的setText()方法使用。
让我们看一个示例,其中我们创建段落并将其写入Word文件。
Apache POI Word段落示例
package poiexample; import java.io.FileOutputStream; import java.io.OutputStream; import org.apache.poi.xwpf.usermodel.XWPFDocument; import org.apache.poi.xwpf.usermodel.XWPFParagraph; import org.apache.poi.xwpf.usermodel.XWPFRun; public class ParagraphExample { public static void main(String[] args) { XWPFDocument doc = new XWPFDocument(); try(OutputStream os = new FileOutputStream("srcmini.doc")) { XWPFParagraph paragraph = doc.createParagraph(); XWPFRun run = paragraph.createRun(); run.setText("Hello, This is srcmini. This paragraph is written "+ "by using XWPFParagrah."); doc.write(os); }catch(Exception e) { System.out.println(e.getMessage()); } } }

【apache poi word文档段落】输出:
apache poi word文档段落

文章图片

    推荐阅读