With Java: replace string in MS Word file -


We require a Java library to replace strings in MS Word files.

Can someone suggest?

Loading and then the most basic when supporting MS Word in

Saveing ​​any file besides formatting might possibly correct the layout. You should try this though, maybe it works for you.

There are also many commercial libraries, but I do not know that none of them is better.

While working on this type of requirement, I was using the format recently to settle the dirty "solution", open the zip container, read the document XML, and then to my markers in the correct texts Was replaced with. It works to change the simple bits of text without paragraphs etc.

  Private static final string WORD_TEMPLATE_PATH = "word / word_template.docx"; Private static final string DOCUMENT_XML = "word / document.xml"; / *** / final processing templatefile = new class text processing (WORD_TEMPLATE_PATH); Final zip inputstream zipin = new zip intstream (template file.zestinputstream ()); Last ZIPOutputStream ZIPOut = new zip outputstream (output); Antivirus in ZIP; While ((InEntry = zipIn.getNextEntry ())! = Null) {last zipantry outline = new zipantry (InEntry.getName ()); ZipOut.putNextEntry (outEntry); If (inEntry.getName (.) Equals (DOCUMENT_XML)) {Final String ContentIn = IOUtils.toString (Zipin, UTF_8); Last String Outsmill = this.processContent (New StringReader (contentIn)); IOUtils.write (out content, zip, UTF_8); } And {IOUtils.copy (zip, zip,); } ZipOut.closeEntry (); } ZipIn.close (); ZipOut.finish ();  

I'm not proud of it, but it works.


Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

jquery - SimpleModal Confirm fails to submit form -

php - Multiple Select with Explode: only returns the word "Array" -