This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
I'm looking for some pointers on the HWPFDocument class in Jakarta's POI library. What I want to ultimately do is open an existing .doc file, change part of the header, and then write the file back to hard drive.
So I created a .doc file with Word 2003 and called it test.doc, I can open it in my source code and do lots of fun stuff with the ranges and paragraphs, but: I can't save it back to disk properly. The following code executes, but when I try opening the output document in Word, the program will hang and not react anymore.
The .doc-file contains a single page: a header region with some test words and a main body containing "hello world".
Martijn Verburg wrote:Hi there and welcome to Javranch! What version of POI are you using?
Hi Martijn, thanks for the welcome!
I downloaded the current POI version, 3.7. Running Java 1.6 I believe (not at my work computer right now).
I have to mention this funny thing: When I create a Word 2003 document with OpenOffice instead of MS Word, it can be read and saved with no problems (but it loses the page header). Again, both MS & OO documents can be read fine.
What happens when you try to open it again in OO? Also have you got the latest updates for MS Office 2003 installed? BTW, I'm not a POI user, hopefully an actual expert will be able to assist
Joined: Jan 12, 2011
Martijn Verburg wrote:What happens when you try to open it again in OO? Also have you got the latest updates for MS Office 2003 installed? BTW, I'm not a POI user, hopefully an actual expert will be able to assist
Martijn, thanks again. I'm not at my workplace today, but I will try the things you mentioned tomorrow morning. Talk to you then
Joined: Jan 12, 2011
Ok, here's what I found out: There seems to be a problem with the Word 2003 .doc format in general.
Whatever I do, if I take .doc-files and re-save them with the above code, trying to open them in my Word 2003 leads to a Word crash. I installed the latest Word 2003 Service Pack (#3), that didn't help. If anyone knows a solution to that problem, I'd be so thankful.
However, since Word 2003 seems to be able to deal with the docx format, I tried the XWPF class and that seems to work. Now all I need to do is convince the customer to use the docx-format
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
subject: Jakarta POI: Please help me get started with doc files