• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

HWPF - Errors when inserting text into a word document

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello all

I'm extremely new to POI. I tried one of the examples to insert test into word but I received errors when attempting to run it.

Code:
HWPFDocument doc = new HWPFDocument(new FileInputStream("D:\\temp\\test2.doc"));
Range range = doc.getRange();
CharacterRun run = range.insertAfter("Hello World!!! HAHAHAHAHA I DID IT!!!");
OutputStream out = new FileOutputStream("D:\\temp\\test2.doc");
doc.write(out);
out.flush();
out.close();

Error:
Exception in thread "main" java.lang.IllegalArgumentException: The end (43) must not be before the start (80)
at org.apache.poi.hwpf.usermodel.Range.sanityCheckStartEnd(Range.java:247)
at org.apache.poi.hwpf.usermodel.Range.<init>(Range.java:180)
at org.apache.poi.hwpf.usermodel.CharacterRun.<init>(CharacterRun.java:96)
at org.apache.poi.hwpf.usermodel.Range.getCharacterRun(Range.java:796)
at org.apache.poi.hwpf.usermodel.Range.insertAfter(Range.java:444)
at export.ExportToWord.main(ExportToWord.java:21)

Could anyone help please?

Thanks heaps!
 
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bee, welcome to Javaranch!

can you please use code tags so that your code becomes readable? Also don't forget to mention the line on which its throwing exception. ExportToWord.java:21 in this case.
 
Bawa Nathan
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Manoj

Thanks for your response!

Oops, sorry about that! I didn't see those tab buttons on top as I typed, I just noticed it now! The error line 21 refers to :


Let me know if I need to provide more info on this to make sense.

Thanks once again!
 
manoj r patil
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Probably it has something to do with the way you have initialized Range ... just a guess. Until you post all the relevant code, its difficult to help you out.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you by any chance doing something with tables? There's at least one bug that produces this message; there may be more.

Maybe this code helps: CreateWordDocument
 
Bawa Nathan
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, I'm not using tables. I tried the code you referred to, but I'm getting a NullPointerException for this line:



Thanks.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Bee Sat", please check your private messages for an important administrative matter.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As the comment says, the stuff about custom properties is just showing off extra functionality; you can remove it if you don't use them.
 
reply
    Bookmark Topic Watch Topic
  • New Topic