Spire.Doc for Java支持按节来拆分Word文档,其中包含了如何遍历获取文档中的节。代码示例如下:import com.spire.doc.Document; public class SplitWordBySection { public static void main(String[] args) { //创建Document对象 Document document = new Document(); //加载要拆分的文档 document.loadFromFile("C:UsersAdministratorDesktopsections.docx"); //声明新的Document对象 Document newWord; //遍历源文档中的节 for (int i = 0; i < document.getSections().getCount(); i++) { //初始化新的Document对象 newWord = new Document(); //将源文档中的指定节复制到新文档 newWord.getSections().add(document.getSections().get(i).deepClone()); //保存新文档到指定文件夹 newWord.saveToFile(String.format("C:UsersAdministratorDesktopOutputresult-%d.docx", i)); } } }
Spire.Doc for Java支持按节来拆分Word文档,其中包含了如何遍历获取文档中的节。代码示例如下: