This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Other Open Source Projects and the fly likes How to make downloadable Word Document with Apache POI? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "How to make downloadable Word Document with Apache POI?" Watch "How to make downloadable Word Document with Apache POI?" New topic
Author

How to make downloadable Word Document with Apache POI?

Matti Kiviharju
Greenhorn

Joined: Nov 25, 2012
Posts: 8
How to make downloadable Word Document with Apache POI?

Here is code that makes empty Word Document:

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39547
    
  27
What differentiates a downloadable document from any other document? Is this question about some feature of Confluence (the API of which this code seem to use)?


Ping & DNS - updated with new look and Ping home screen widget
Matti Kiviharju
Greenhorn

Joined: Nov 25, 2012
Posts: 8
Ulf Dittmer wrote:What differentiates a downloadable document from any other document? Is this question about some feature of Confluence (the API of which this code seem to use)?


Confluence API includes a Apache POI for making .doc files but not .docx files.

I just want to make Curriculum Vitae Editor that uses external MySQL datasource configured to ./conf/server.xml and function that generates a .doc file from database (for Confluence as commercial Plugin):

I had to ask this because I don't find working tutorials via Google fo my question.

If you making me a working code I will pay you royalies from sales.


Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39547
    
  27
OK, but what is the actual problem? That Confluence uses an old version of POI that doesn't support the XML formats? If this is your own installation (as opposed to a hosted installation), have you tried upgrading the POI libraries to a newer version (3.8) that does support the XML formats?
Matti Kiviharju
Greenhorn

Joined: Nov 25, 2012
Posts: 8
Ulf Dittmer wrote:OK, but what is the actual problem? That Confluence uses an old version of POI that doesn't support the XML formats? If this is your own installation (as opposed to a hosted installation), have you tried upgrading the POI libraries to a newer version (3.8) that does support the XML formats?


Actual problem is that I do not find any tutorials here: http://poi.apache.org/hwpf/quick-guide.html

Like I find tutorials here for MS Excel: http://poi.apache.org/spreadsheet/examples.html

I am not tried to upgrade to latest POI.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39547
    
  27
Ah, so the problem has nothing to do with Confluence, it is about how to use POI to create Word documents? That is woefully underdocumented; see https://www.coderanch.com/how-to/java/CreateWordDocument for some hints. I'm not sure of HWPF or XWPF is the more powerful API at this point; if I wanted to create something readable by a word processor I'd probably resort to creating RTF.
Matti Kiviharju
Greenhorn

Joined: Nov 25, 2012
Posts: 8
Ulf Dittmer wrote:Ah, so the problem has nothing to do with Confluence, it is about how to use POI to create Word documents? That is woefully underdocumented; see https://www.coderanch.com/how-to/java/CreateWordDocument for some hints. I'm not sure of HWPF or XWPF is the more powerful API at this point; if I wanted to create something readable by a word processor I'd probably resort to creating RTF.


Here is now code:



But it makes security error:

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39547
    
  27
What's it say? During which operation does it happen?

Does the account used to run Confluence have access to /var/vhosts/atlassian/cv.doc and all the directories above it?

Also note that a .doc file is binary data, so "out.toString()" will create garbage.
Matti Kiviharju
Greenhorn

Joined: Nov 25, 2012
Posts: 8
Ulf Dittmer wrote:What's it say? During which operation does it happen?

Does the account used to run Confluence have access to /var/vhosts/atlassian/cv.doc and all the directories above it?

Also note that a .doc file is binary data, so "out.toString()" will create garbage.



Confluence has access to /var/vhosts/atlassian/cv.doc and all subfolders.

I tried to save document into file /var/vhosts/atlassian/admin+Curriculum+Vitae.doc and it makes same security warning message when I open it on word.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39547
    
  27
I see, the creation of the document works fine. I thought that's when the problem occurred. So what does the message say? It looks like Finnish to me, which is unfortunately beyond me (and, I suspect, beyond most people in this forum).
Matti Kiviharju
Greenhorn

Joined: Nov 25, 2012
Posts: 8
Ulf Dittmer wrote:I see, the creation of the document works fine. I thought that's when the problem occurred. So what does the message say? It looks like Finnish to me, which is unfortunately beyond me (and, I suspect, beyond most people in this forum).


I have no English MS Word.

It says: "WARNING! Office file check noticed a problem when Word tries open a file. Opening the file migth be dangerous. You computer will be used unathorized."

Does this is enoung I don't want translate whole error message.
Matti Kiviharju
Greenhorn

Joined: Nov 25, 2012
Posts: 8
Hi,

I want to give up about making Word Document.

Do you have tutorials to this: http://pdfbox.apache.org/

I want generate PDF file.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39547
    
  27
PDFBox, too, is rather underdocumented. Its web site contains the entire docs that I know of, and those have been sufficient for my purposes. Note that it has few ways of creating PDFs, http://pdfbox.apache.org/commandlineutilities/TextToPDF.html is the only documented one I'm aware of, and that is rather limited.

You may want to check out Apache FOP as well as the iText library (with iText, be aware of the licensing differences between version 2 and version 5). Start here: https://www.coderanch.com/how-to/java/ItextExample

As an aside, I would advise not to give up so quickly on things. Few projects are trivial enough that you'll crack them within a day, so you'll encounter disappointments if you don't stick with them.
Matti Kiviharju
Greenhorn

Joined: Nov 25, 2012
Posts: 8
Ulf Dittmer wrote:PDFBox, too, is rather underdocumented. Its web site contains the entire docs that I know of, and those have been sufficient for my purposes. Note that it has few ways of creating PDFs, http://pdfbox.apache.org/commandlineutilities/TextToPDF.html is the only documented one I'm aware of, and that is rather limited.

You may want to check out Apache FOP as well as the iText library (with iText, be aware of the licensing differences between version 2 and version 5). Start here: https://www.coderanch.com/how-to/java/ItextExample

As an aside, I would advise not to give up so quickly on things. Few projects are trivial enough that you'll crack them within a day, so you'll encounter disappointments if you don't stick with them.


How do I making linebreak with drawString function?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to make downloadable Word Document with Apache POI?
 
Similar Threads
Unable to add Image while converting Word doc to PDF using POI and Itext API
TIFF. DOC, EXCEL to PDF Converter
java.io.FileNotFoundException
create word document(.doc) using apache poi 3.7 jar
Reading Microsoft Word Document in JAVA