wood burning stoves 2.0*
The moose likes Other Open Source Projects and the fly likes create word document(.doc) using apache poi 3.7 jar Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "create word document(.doc) using apache poi 3.7 jar" Watch "create word document(.doc) using apache poi 3.7 jar" New topic
Author

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

velMurugan vasu
Greenhorn

Joined: May 21, 2012
Posts: 13

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]



Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36486
    
  16
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.
velMurugan vasu
Greenhorn

Joined: May 21, 2012
Posts: 13

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.

Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7052
    
  16

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


Isn't it funny how there's always time and money enough to do it WRONG?
Artlicles by Winston can be found here
velMurugan vasu
Greenhorn

Joined: May 21, 2012
Posts: 13

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.
William P O'Sullivan
Ranch Hand

Joined: Mar 28, 2012
Posts: 860

What is this line:


Start there ...

WP
velMurugan vasu
Greenhorn

Joined: May 21, 2012
Posts: 13

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.


Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
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: http://www.coderanch.com/how-to/java/CreateWordDocument
velMurugan vasu
Greenhorn

Joined: May 21, 2012
Posts: 13



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)




Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
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.
velMurugan vasu
Greenhorn

Joined: May 21, 2012
Posts: 13

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.
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
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
velMurugan vasu
Greenhorn

Joined: May 21, 2012
Posts: 13

Hi Tim Moores Thanks alot for your example code and i fixed the issue thanks again for your code.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: create word document(.doc) using apache poi 3.7 jar
 
Similar Threads
java.io.FileNotFoundException
Mearging two word documents using POI
Facing issue with org.apache.poi.POIDocument: method init()V not found
Reading word Documents Using JAVA
Reading text in a table from word document