format bold in flatfile for both odt and docx

Context of question is flat file generated on unix system; I need to encode a sentence in bold; the file may subsequently be rendered by OpenOffice but more likely virtually any version of Microsoft Word - I have no control over this.

How best to encode such bold text?


What do you mean by a FLAT FILE? I quote
‘A flat file typically consists of a text file, from which all word processing or other structure characters or markup have been removed’ Sometime punctuation such as ;., are used in .csv delimiters. Making a sentence bold would not keep the file flat as it would be adding direct formatting information.

Peter, Very good point - this file will no longer be the flatfile it was.
The extent of the formatting required is limited, getting this consistent across the many different versions of Word is outside my experience - which is why I asked the question. I’ve looked briefly at RTF (on wikipedia) but concluded I’d be better off asking some expert here.

How would you suggest a single sentence be made bold in a world with many versions of Microsoft Word?

As I commented previously, the FLAT FILE does not have word processing formatting, hence it would NOT have bold sentences, nor a font change. You could save as a .txt file which would be flat but not have bold sentences. Or you could save as a .odt file which would not be flat but would be able to have bold sentences.

I am not certain what you are trying to do and why you need a flat file. LibreOffice and Word do not use flat files.

My description of the file as FLAT reflects its origins on a unix system; it has no formatting.
A user has asked for some formatting - a single sentence in bold. which perforce means that the once flat file is flat no more. The systems that handle the file generate a .txt file; if this is supplemented with (for example) RTF coding and then imported into LibreOffice Writer then the outcome is a happy one. My concern was whether this outcome would be consistent - many recipients are likely instead to use Microsoft Word, and I have no knowledge of much less control over the version used.

I consequently posted the query here in the hope that someone’s prior experience could be brought to bear on the conundrum.

Suggestion: Might the subject probably better be:
How to format parts of text from flatfile bold and store the result to both .odt and .docx
(Subjects are editable.)

This may not be the answer you want.
You mention OpenOffice and Word for processing your files, but not how you actually create them. If you are using Unix you will not be using Word and I assume from the question that you are encoding your files in Eng-US and using 7bit characters. If you need a consistent formatting and you cannot avoid the font change to bold you cannot use a flat file. If you use .rtf, be aware that it is of 2007 and prior vintage, and ‘Will generally work’ when processed by other users.(Not my words).

If I were you and you need consistent processing you should use the International Standard Open Document Format to create the document. Then you can send the document as a .pdf file if the user needs to read/view/print the file but not change it. Otherwise send it as a .odt document and suggest the users use LibreOffice or other readers to manage the file.

For advice on Word or OpenOffice you may well be given other advice on their respective sites…

Your purpose is rather obscure. Here’s how I understand it.

You have a source (meaning “at the origin of the work flow”) file containing your document as a sequence of characters (usually a .txt file). In this basic document, you want to add some markup for turning runs of chars bold, italic or other formatting. This is equivalent to AskLibO markup where double asterisks ** mean “make next run bold until another marker”.

You can imagine many variants of such a markup, but as it becomes more sophisticated, more and more characters are removed from common use for the “in-band signalling” of the markup unless they are escaped.

The first real difficulty arises when you try to import such a file into Writer or Word: you need a filter to interpret the markup and translate it into the document processor internals.

You can opt for an XML markup. The advantage is “out-of-band signalling”: only < needs to be escaped in text. This is precisely what ODF is based upon and you can have a look at it when saving documents as .fodt.

Writer uses natively this format (.odt is a zip-compressed variant of it) and has the filter to handle it. Word claims it can process ODF but does not implement the whole standard and adds divergent features to it.

The answer to your question might be a .fodt file. It is a text file with XML markup, consequently it is transportable to any platform, albeit a bit fat because of no compression. However, the destination processor needs to have an input filter for it.
In the end, an .odt file is likely to be the best trade-off.

Unfortunately, FODT wouldn’t fit the requirement to be openable in Word and/or AOO…

yes, as you mentioned.

Assuming your “flat” source file simply is “plain text”, and the question is not related to database use of such a file.
Further assuming you have a working install of LibO and your default Writer template has the wanted and no unwanted settings.

I would use a Calc document as a kind of batch file prepared to perform by user code iterations of
-1- Open the plain-text file in Writer.
-2- FindAll the text portions needing to be set bold with the help of a SearchDescriptor.
-3- Set all found TexRange(s) to bold (CharWeight = 150)
-4- The so edited document StoreTo whatever URL(s) and with whatever filter(s) you want.
-5- Close the document under work.

The SearchDescriptor doesn’t use regular expressions by default, but you can change that.

Attached are a raw and simplified demo .ods and a related plain-text .txt file which I had to rename to a fake extension to get it through the security check. Re-rename it to plain.txt again. Best put the files into a common empty folder and don’t miss to enter the correct absolute paths into the respective cells of the sheet. Then run the BASIC Sub ‘doIT()’ contained in the .ods to see exactly what I meant by my explanations above.