You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by ph...@bayerbbs.com on 2010/04/07 15:26:20 UTC
How to create a simple instance of XWPFDocument with POI?
Hi user-list,
I'm trying to create a simple docx file with POI but I don't know how and
I don't find much information on the web.
I tried the following code (with a lot of help from the Content Assist,
thanks Eclipse!) but the code does not work correctly:
String tmpPathname = aFilename + ".docx";
File tmpFile = new File(tmpPathname);
ZipPackage tmpPackage = (ZipPackage) OPCPackage.create(tmpPathname);
PackagePartName tmpFirstPartName =
PackagingURIHelper.createPartName("/FirstPart");
PackagePart tmpFirstPart = tmpPackage.createPart(tmpFirstPartName,
"ISO-8859-1");
XWPFDocument tmpDocument = new XWPFDocument(tmpPackage); //Exception
XWPFParagraph tmpParagraph = tmpDocument.createParagraph();
XWPFRun tmpRun = tmpParagraph.createRun();
tmpRun.setText("LALALALAALALAAAA");
tmpRun.setFontSize(18);
tmpPackage.save(tmpFile);
The thrown exception is the following:
Exception in thread "main" java.lang.NullPointerException
at org.apache.poi.POIXMLDocumentPart.read(POIXMLDocumentPart.java:235)
at org.apache.poi.POIXMLDocument.load(POIXMLDocument.java:196)
at
org.apache.poi.xwpf.usermodel.XWPFDocument.<init>(XWPFDocument.java:94)
at DocGenerator.makeDocxWithPoi(DocGenerator.java:64)
at DocGenerator.main(DocGenerator.java:50)
Does anybody can help me with my (really simple) requirements?
Best Regards
Philip Gillißen
_________________________________________
Bayer Business Services GmbH
BBS-S&T-APS-AD
Leverkusen, 4810
Raum 1.02
Phone: 0214/30-49436
Fax:
E-mail: philip.gillissen@bayerbbs.com
Web: http://www.BayerBBS.com
Geschäftsführung: Vorsitzender Daniel Hartert | Arbeitsdirektor
Norbert Fieseler
Vorsitzender des Aufsichtsrats: Klaus Kühn
Sitz der Gesellschaft: Leverkusen | Amtsgericht Köln, HRB 49895
Antwort: Re: How to create a simple instance of XWPFDocument with POI?
Posted by ph...@bayerbbs.com.
It's already solved, I was too stupid...
http://stackoverflow.com/questions/2592579/#2592747
Greetings, Philip
Nick Burch <ni...@alfresco.com> schrieb am 07.04.2010 15:32:47:
> On Wed, 7 Apr 2010, philip.gillissen@bayerbbs.com wrote:
> > I'm trying to create a simple docx file with POI but I don't know how
> > and I don't find much information on the web.
>
> I'm not sure if that's supported yet. You might have more luck with
> creating a template empty file in word, and editing copies of that
through
> POI.
>
> Nick
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org
Re: How to create a simple instance of XWPFDocument with POI?
Posted by Nick Burch <ni...@alfresco.com>.
On Wed, 7 Apr 2010, philip.gillissen@bayerbbs.com wrote:
> I'm trying to create a simple docx file with POI but I don't know how
> and I don't find much information on the web.
I'm not sure if that's supported yet. You might have more luck with
creating a template empty file in word, and editing copies of that through
POI.
Nick
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org