【发布时间】:2016-10-29 02:37:42
【问题描述】:
我一直在尝试根据预定义的标准将一个 docx 文档分割成多个文档。以下是我将其切成段落的方法
try {
FileInputStream in = new FileInputStream(file);
XWPFDocument doc = new XWPFDocument(in);
List<XWPFParagraph> paragraphs = doc.getParagraphs();
for (int idx = 0; idx < paragraphs.size(); idx++) {
XWPFDocument outputDocument = new XWPFDocument();
createParagraphInAnotherDocument(outputDocument, paragraphs.get(idx).getText());
String fullPath = String.format("./content/output/%1$s_%2$s_%3$04d.docx", FileUtils.getFileName(file), getName(), idx);
FileOutputStream outputStream = new FileOutputStream(fullPath);
outputDocument.write(outputStream);
outputDocument.close();
doc.close();
}
} catch (IOException e) {
e.printStackTrace();
}
虽然我可以使用上面的代码提取段落,但我找不到提取页面的方法。我的理解是 word 中的页面是渲染问题,它发生在 word 应用程序的运行时。
【问题讨论】:
-
希望这对你有用click here@DenisFLASH 回答
-
谢谢@yash,这是我发现的线程之一,仍然只是逐段而不是逐页分段,即使这样它也不会生成样式或完整的段落
标签: java apache-poi docx xwpf