• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
velMurugan vasu
Greenhorn
Posts: 13
Java MySQL Database Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48652
56
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13
Java MySQL Database Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 10277
60
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
velMurugan vasu
Greenhorn
Posts: 13
Java MySQL Database Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 859
Chrome IBM DB2 Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is this line:


Start there ...

WP
 
velMurugan vasu
Greenhorn
Posts: 13
Java MySQL Database Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Bartender
Posts: 2756
38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13
Java MySQL Database Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Bartender
Posts: 2756
38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13
Java MySQL Database Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Bartender
Posts: 2756
38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13
Java MySQL Database Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tim Moores Thanks alot for your example code and i fixed the issue thanks again for your code.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic