This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
HWPF - Errors when inserting text into a word document
Bawa Nathan
Greenhorn
Joined: Nov 01, 2009
Posts: 7
posted
0
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!
manoj r patil
Ranch Hand
Joined: Jun 06, 2002
Posts: 180
posted
0
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.
love your job and not your company;
...because you never know when your company will stop loving you!
Bawa Nathan
Greenhorn
Joined: Nov 01, 2009
Posts: 7
posted
0
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
Joined: Jun 06, 2002
Posts: 180
posted
0
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.
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35247
7
posted
0
Are you by any chance doing something with tables? There's at least one bug that produces this message; there may be more.