Save and write an odt file

Hi, I would like to write and save a file with open office. Is this feasible ?

You can save any file and give it any extension, however writing to that file so that open office can read it may be challenging.

For writing files you can use the fileWriter class.However someone like you has already had the same ideas and provided libraries we can use to achieve said task.

Here are some links.

At this point however you may be best served for information on a java forum as these are java libraries.

1 Like

Thanks, this seems to be great but java is too hard for me :confused:
Is there a way to get hold of other software. To write directly to LibreOffice as we would have done manually but with processing?

What are you trying to do exactly? Writing an odt file may be more difficult than you think because open office is such a huge codebase. One workaround may be to first output a text file (or markdown if you want formatting) and to use command line such as pandoc to convert to odt

I know java and stack may be a bit daunting, but putting a bit of effort to learn what you need here will ultimately payoff.

please take a look at the third suggestion.

There are a total of 7 lines so shouldnt require too many changes.

Just take it line by line and see what you understand, ie strings for loops etc, things that you should be familiar with. Then ask yourself what is the purpose of this line, and do i need to worry about for now, if not move on to something else.

A complement of previously given solutions would be JODReports, which allows creating office documents and reports in ODT format (from templates, composed using the LibreOffice/ Writer word processor).

DocumentTemplateFactory templateFactory = new DocumentTemplateFactory();
DocumentTemplate template = templateFactory .getTemplate(new File("template.odt"));
Map data = new HashMap();
data.put("title", "Title of my doc");
data.put("picture", new RenderedImageSource( File("/tmp/lena.png"))));
data.put("answer", "42");
template.createDocument(data, new FileOutputStream("output.odt"));
Optionally the documents can then be converted to PDF, Word, RTF, etc. with JODConverter.

This seems to be the most straightforward one to me.

I am trying to fill some data in a large text on a odt file. So your solution may be right one because in the meantime I am doing it on a txt file then i convert it online on But i barely understood how pandoc is working, can i make a link between pandoc and processing to automate everything ?

In general terms, i understand (exept the first and the third line). You open an odt file, you write a title, you put a picture, you write some things then you record it. This is exactly what i need !

I will try your solution and take a closer look at this librarie. But i have a problem apart, when i downloaded Java JDK, how do I open the programming interface ?

First line seems to be creating a instance of class DocumentTemplateFactory. Please look into classes and constructors if you wish to find out more. But for now thats irrelevant. The only thing we care about its that its a requirement, (note you are free to change the name of the var).

Third line again is a class constructor in this instance creating a new HashMap() instance. Hashmaps acts similarly to arrays and arrylists in the sense that they store data, the difference however is a hashmap will store a pair of values rather than a single string or float.

The following line should help you understand, put is used to add data to the hashmap

1 Like

You shouldnt need to download jdk. I might be wrong, but processing is already built on top of java so all java code should work.

Have you made sure to import the library, thats usually the only thing you need to do.

Please check forum solutions for importing libraries or simply drag the library to your sketch window and processing will add it to your project folder.

1 Like