Win a copy of GANs in ActionE this week in the AI forum
or WebAssembly in Action in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

Jakarta POI: Please help me get started with doc files

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
author
Posts: 3281
8
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there and welcome to Javranch! What version of POI are you using?
 
Chris Wassermann
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 3281
8
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 think I'll just lie down here for a second. And ponder this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!