CBennett
CBennett

Reputation: 39

How to edit existing word file using POI API

Using:

XWPFDocument document = new XWPFDocument();

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

Upvotes: 2

Views: 4370

Answers (1)

Gagravarr
Gagravarr

Reputation: 48376

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);

Upvotes: 5

Related Questions