my dog learned polymorphism*
The moose likes Other Open Source Projects and the fly likes Jakarta POI: Please help me get started with doc files Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "Jakarta POI: Please help me get started with doc files" Watch "Jakarta POI: Please help me get started with doc files" New topic
Author

Jakarta POI: Please help me get started with doc files

Chris Wassermann
Greenhorn

Joined: Jan 12, 2011
Posts: 4
Hey guys, first post

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".

This is the content of my class:


Can anyone help?
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

Hi there and welcome to Javranch! What version of POI are you using?


Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
Chris Wassermann
Greenhorn

Joined: Jan 12, 2011
Posts: 4
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.

Your help is much appreciated.
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

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
Chris Wassermann
Greenhorn

Joined: Jan 12, 2011
Posts: 4
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
Chris Wassermann
Greenhorn

Joined: Jan 12, 2011
Posts: 4
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
 
jQuery in Action, 2nd edition
 
subject: Jakarta POI: Please help me get started with doc files
 
Similar Threads
Word document is crashing after adding custom properties using apache poi HWPF
Mearging two word documents using POI
TIFF. DOC, EXCEL to PDF Converter
problem opening a new word file
problem with updating placeholder with poi