Conditional formatting in Writer, or how to automate a strikethrough

I’m writing a template document that has some fields from a database and the very common Mr./Mrs. text where one is supposed to strike the wrong one out. You may ask me why I don’t just add that as a field from the database too? Because the boss wants it that way. So the way I try to do it now is to print every document as a single document file and then edit them manually.

Is there a way to have a strikeout there applied if the field “gender” in the database is “f” or “m”?

I tried to trick it to do it with hidden texts and with conditional text, but in the conditional text I can’t seem to have the possibility to apply the formatting to only a portion of the text. It seems to be either all or nothing.

An approach to what you want would be using conditional text fields
https://books.libreoffice.org/en/WG252/WG2517-Fields.html#toc24

One possible solution is to somehow “mark” these fields (for example: {{m}}, {{f}}), and then run a macro that will make the necessary replacement.

The linked manual says:
…You also cannot format part of the text (for example, bold one word but not the others), …
which however is exactly what I would like to do (with strikeout instead of bold). I also don’t seem to be able to format all the words, but only when the condition is met, which would give me an option.

You may get suggestions relying on user code. (See post by @Sokol92.)
In this case as for any solution relying on means/tools/settings stored to the user profile, it is essential if you can assure that these helpers are available from the profile when needed.
Only the usage of macros (user code) can in principle store its tools to the template and by that make them available in derived documents. Not recommendable!
Please clarify!
= =
I didn’t explicitly work with databeses for years now, and am not an expert at all.
But: Binary “gender/sex” isn’t state of the art, is it?
Your Boss won’t make the clock run backwards

We can also try the option with 4 hidden fields:
Mr. Mr. / Mrs. Mrs.

1 Like

@sokol92 I thought about that, and also about the version
Mr. / Mrs. Mr. / Mrs.
and I admit I didn’t try it because I was afraid that that would leave the space for the hidden text blank, thereby giving some funny looking space.

But how will we know the truth if we don’t try? :slight_smile:

3 Likes

I tried it on a similar example (see Has Author).

biblio.odt (7.9 KB)