How to edit existing word file using POI API

痴心易碎 提交于 2019-12-11 05:51:18

问题


Using:

XWPFDocument document = new XWPFDocument();

How do I assign it so it doesn't overwrite the file if it already exists?


回答1:


The following will create a brand new, empty XWPF Word Document to work with:

XWPFDocument document = new XWPFDocument();

Whereas this will open up an existing one for editing:

XWPFDocument document = new XWPFDocument(OPCPackage.open("MyFile.docx"));

Or if you have an InputStream rather than a file:

XWPFDocument document = new XWPFDocument(inputStream);


来源:https://stackoverflow.com/questions/15737169/how-to-edit-existing-word-file-using-poi-api

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!