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!