create word document(.doc) using apache poi-scratchpad 3.7 jar Please help me i have to finish this job today itself.
it throws this exception
java.lang.ArrayIndexOutOfBoundsException: 23
at org.apache.poi.util.LittleEndian.getShort(LittleEndian.java:225)
at org.apache.poi.hwpf.model.types.FibBaseAbstractType.fillFields(FibBaseAbstractType.java:101)
at org.apache.poi.hwpf.model.FibBase.<init>(FibBase.java:43)
at org.apache.poi.hwpf.model.FileInformationBlock.<init>(FileInformationBlock.java:71)
at org.apache.poi.hwpf.HWPFDocumentCore.<init>(HWPFDocumentCore.java:155)
at org.apache.poi.hwpf.HWPFDocument.<init>(HWPFDocument.java:218)
at org.apache.poi.hwpf.HWPFDocument.<init>(HWPFDocument.java:186)
at newPackage.OneMore.main(OneMore.java:28)[color=#444444]
I have added code tags to your code, and you can see how much better it looks. Why are you not closing the file output stream in a finally block? Why are you calling flush(); I thought you did not need that.
Don’t know about the Exception; there are no obvious arrays in your code, unless there is an array in the insertAfter method. Are you sure it is the code you posted which is causing that Exception? Unless insertAfter requires an array, which has 23 elements or fewer, I can’t see where the Exception came from.
Thank you for your Precious and quick reply Ritchie.
Actually my requirement is to create word 2003 format document using apache poi.Please let me know what changes need to be done in the above code.Also post your suggestions for creating word 2003 document.I have to create table in the document.
velMurugan vasu wrote:Actually my requirement is to create word 2003 format document using apache poi.Please let me know what changes need to be done in the above code.Also post your suggestions for creating word 2003 document.I have to create table in the document.
Well your exception appears to be occurring in the constructor itself.
Why, I don't know - I'm no POI expert - but one possibility is that the file doesn't exist. Have you checked this?
It also seems an odd way to create a document (ie, from a class that appears to refer to a file system, rather than a file or stream). Have you tried creating it directly from the input stream itself? HWPFDocument seems to allow you to do that but, as I say, I'm no expert.
This is the new program i tried and i got the word document with the given word.But how to
display table inside word.I know how to create table using XWPFDocument but that will not work
in MSWord 2003.so i want yours help.
I doubt that this is the correct approach to create documents. I think it's more likely that DirectoryEntry and its methods deal with content inside of a file, rather than files inside of a file system. Your first approach looks better to me. This may help: https://coderanch.com/how-to/java/CreateWordDocument
I comment the code from 46 to 51 then the program runs successfully but i got the empty document as output.
you have any sample code to generate table.
POI's API is complex, and not much documentation is available. You need to be prepared to spend time with the javadocs and for some experimentation. Here's some code you could try:
Once you figure out how to add tables, that would be a good addition for you to add to that example code