How to create docx file using java?
Solution 1
Tried multiple libraries
This one is free. http://www.docx4java.org/trac/docx4j
Also check aspose (is not free) http://www.aspose.com/categories/java-components/aspose.total-for-java/default.aspx
Solution 2
you may use http://poi.apache.org/ to create such files.
Solution 3
Microsoft Word's docx files are zip files with specific content inside them. Simply creating a file in Java and writing some text to them isn't going to create a valid docx file that Word will recognize, even if you give it a .docx extension.
To create them from Java you can use the Apache POI XWPF library. That will give you some Java classes that'll create and write contents to docx files that will work with Word.
Vighanesh Gursale
Updated on June 11, 2020Comments
-
Vighanesh Gursale almost 4 years
I am trying to create a .docx file using java but for some reason I can't open the file. The error comes "Problem with the content of file". Does anyone knows how to fix this problem?
-
Vighanesh Gursale over 11 yearsThanx Stanis the docx4j liberary works. I was just creating the word file using normal file system but it won't work but this library work efficiently. Please any one can give me a example of adding external jar files in the manifest file. I want to add synthetica look and feel into my project but for some reason the look and feel can't be load. Bunch of exception comes like NoClassFoundException or you have to pass Style Factory etc
-
StanislavL over 11 yearsJust include all the .jar files in your classpath. java -cp "all the jars"