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?
-
Are you saying that the generated Word document is invalid when you try to access it (by using Word, for example)? – nickolayratchev Oct 15 '12 at 13:07
-
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 – Vighanesh Gursale Oct 19 '12 at 08:31
4 Answers
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

- 56,971
- 9
- 68
- 98
-
Thanx 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 – Vighanesh Gursale Oct 19 '12 at 08:22
-
Just include all the .jar files in your classpath. java -cp "all the jars" – StanislavL Oct 19 '12 at 11:20
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.

- 587
- 8
- 17
It sounds like you are producing a corrupt document. If it really is DOCX format, then open it with a ZIP tool and examine the contexts of the XML files - there's a reasonable chance you are simply producing invalid XML and so looking at it with a browser or XML editor will help you there.
You probably need to say HOW you are producing the DOCX file so people can make better suggestions.
If you are looking for more options, I would look at docx4j and Docmosis. Please note I work for the company that created Docmosis.

- 6,513
- 2
- 24
- 19