Can an inserted text document include style information?

I have recently inserted plain text files into a Writer document. This is fine for text that is all the same style, but I would like to improve this process if possible by specifying different styles for different text items. Is it possible to generate a text file with added style information? I understand that the content.xml file of the ODF archive contains this information for the parent document and that the style.xml file has the style details but is there any way of telling the parent document to apply an existing style to a given text item as it is being inserted. I’m using LO version on Ubuntu 15.10


Is it not possible to insert ODT documents instead of text files?


In this case it would be possible but a very big task as the text file I’m referring to is generated from a bit of Python. I don’t relish the prospect of generating a “correct” .odt file from a Python program :frowning:

Thinking about it further this leads to a potential further question :- What is the simplest syntactically correct .odt doc archive that can be generated? I suspect it’s still quite a lot of work

Perhaps the first question that should be asked is, “Why are you doing as you describe?” Armed with that information, we may be able to put our heads together and find a way for you to accomplish your real goal.

TXT files by definition are simple text and contain no formatting information. When you insert them into a standard LibO writer file they will assume the current style settings. If you need to include LibO style settings, as I often do, then I suggest you create them as .odt files as @pierre-yves suggests. Otherwise, I regret you will need to change the styles after inserting them…

Sorry this is not the answer you wanted. Regards Peter

See the comment I made to @pierre-yves’ post. It seems there is no easy way to enhance my Python code in the way I wanted to :frowning:

@TrevorRitchie, having read your recent exchange with others, I believe I better understand what you are asking and why. I am going to answer your question with opinion and conjecture, albeit from what I believe is a sound perspective.

First let me state that I have coding background, but not in Python. Second, let me state that I am a power user of MS-Office, but have only recently begun working with LO (and am quite impressed) – however, my answer is based on years of observations and experiences that I believe are valid concerning LO and your question.

Okay, now let’s get to my answer. Since you are a coder, I’d like to answer coder to coder.

You know, as I do, that apps such as LO Writer include in each document file a header reserved for application use which is read by the application when the file is opened. You also know that, in the case of LO Writer, this header contains all of the styles, formatting, etc. peculiar to the specific document in question. It is this header area to which you should direct your attention.

I believe you should research how to construct (or deconstruct) an LO Writer document file. It may be necessary to contact the folks at The Document Foundation for advice, but I suspect you will find the answer already on the web if you search hard enough.

Once you understand how to create the header, simply add the desired styles and other attributes to your Python code as required by LO Writer. Next, you will have to determine whether you have to output from Python as text and import to LO Writer, or whether you can name your Python output with an odt extension and simply open in LO Writer. If I had to guess, I’d bet on the latter choice.

If you believe my response best answers your question, please click the check box next to my post.

Thanks for that answer. I have indeed begun to investigate the structure of .ODT files. They seem however to be an archive of several files, most, if not all, of which contain rather involved XML scripts. I may investigate this further as you suggest but I think the effort involved does not justify it for my current requirements. As I understand it the Python code would be responsible not only for generating the syntactically correct XML files of the archive but also ZIPping these up.

The .odt file is XML, it is not a just header with the attached text, albeit zipped. You would need to include the formatting information in the text itself, Hence, I believe, you have the choice of importing straight unformatted text, and not simply naming your output with an .odt extension…Peter