1

I've been searching from hours how to generate from scratch an Open Office document (but a .doc would be glad, no docx) with a Java API (I'm using Grails). Anyway it seems that every method require a preexisting document to work correctly. I've looked on javaranch (http://www.coderanch.com/how-to/java/AccessingFileFormats) and nothing I've seen meets my desires.

So I ask you the question : is it actually possible to generate a .doc or .odt file from scratch ? Because I find that creating a document outside the code is pretty ugly.

Cheers

JackRackham
  • 61
  • 1
  • 5
  • 1
    Duplicate of http://stackoverflow.com/questions/4791389/how-to-create-an-odt-file-programmatically-with-java ? – Tony Apr 27 '12 at 14:31
  • `.doc` is *not* an open office document, it's a microsoft word document. As is docx. As for odt, see duplicate. – Brian Roach Apr 27 '12 at 14:34

2 Answers2

0

First, decide which "open office" you are talking about. Either it is "Office Open XML" which is the Microsoft branding of their XML document, or it is "OpenOffice" which is the native document format of "Libre Office/Open Office/Star Office" suites (and about 50 others).

Also, if you are searching for tutorials on how to access the internals of a document, odds are excellent that you will find instructions that require a document exist (to be accessed).

Perhaps searching for programmatic document creation would help, but if that doesn't land you what you need, you could note the libraries used to modify a document, and see if any of them provide APIs for "clean" document generation. Odds are good that one of them does, even if it is incomplete.

Sorry for the general answer, but it has to be general, as from the tag list, it is not even clear in which document format you intend to write.

Edwin Buck
  • 69,361
  • 7
  • 100
  • 138
  • Hello. In fact I don't really care about the format, I don't have any preference between .odt or .doc if I can do what I want :D As you said, I've watched the examples and tried to see if it was possible to generate a "clean" document. For the moment I haven't seen it. That's why I'm asking here ;) – JackRackham Apr 27 '12 at 14:35
  • If you don't care, then flip a coin and pick one. I have personally written software that generated .odf files, so I can say they are pretty easy to write. Back then they were just .zip files containing a structured set of XML files, and one of the XML files is the "content" file (others are for styling, page format, etc). You could use any XML library to write all of the contents from scratch, providing you wrote the code to emit the minimal "sensible" expected XML documents. That said, if you can use the ODF toolkit, it will save you a lot of boilerplate code. – Edwin Buck Apr 27 '12 at 15:09
0

OpenOffice.org's Universal Network Objects (UNO), allow you to generate .doc,.PDF, as well as OpenOffice documents. It supports several programming languages like: Java, C++, Visual Basic, etcc..

Some good things is that: its free, open source and plataform-independent

You can build documents, spreadsheets, presentations, etc. Start from scratch or using a template and fill the gaps..

In order to use it you will need to include some libraries that comes with the OpenOffice suite.

Useful links:

German Attanasio
  • 22,217
  • 7
  • 47
  • 63