Forums Register Login

create word document(.doc) using apache poi 3.7 jar

+Pie Number of slices to send: Send
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]



1
+Pie Number of slices to send: Send
Welcome to the Ranch

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.
+Pie Number of slices to send: Send
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.

+Pie Number of slices to send: Send
 

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.

Winston
+Pie Number of slices to send: Send
Thank you winston.

I verified and confirmed file existance.Is there anybody know poi very well please help to come out of the error.Its very urgent.
+Pie Number of slices to send: Send
What is this line:


Start there ...

WP
+Pie Number of slices to send: Send
Thank you WP for your reply.

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.


+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send


Thank you for your reply.

I got this exception

Exception in thread "main" java.lang.NullPointerException
at com.vel.Threads.NewSample.main(NewSample.java:47)




+Pie Number of slices to send: Send
So you have a NPE to track down and fix. You can remove anything related to document properties from this example if it's not relevant to your code.
+Pie Number of slices to send: Send
Thank you for your reply

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.
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
Hi Tim Moores Thanks alot for your example code and i fixed the issue thanks again for your code.
I'm gonna teach you a lesson! Start by looking at this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 18854 times.
Similar Threads
java.io.FileNotFoundException
Mearging two word documents using POI
Facing issue with org.apache.poi.POIDocument: method init()V not found
Reading text in a table from word document
Reading word Documents Using JAVA
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 14:02:48.