Ask Your Question

Can attributes such as background color be encoded in a raw .csv file?

asked 2016-12-02 01:12:39 +0100

I know about conditional formatting, where field attributes can depend on contents of the field or other fields. What I'd like to do is colorize certain fields as determined programmatically while generating a raw separator-separated list, so that when importing into LibreOffice, those fields will be colorized.

Of course, I can add a new column with a flag indicating whether the field should be colorized, but this still requires me to do the conditional formatting after importing the .csv file. I want the .csv file to be portable so that anyone who just imports it will see the colorized fields.

I'm envisioning syntax something like this to cause the third column in this row to be red:
data 1~data 2~<red>data3</red>~data4~

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted

answered 2016-12-02 17:51:47 +0100

Lupp gravatar image

Working with Calc it is bad practise to code relevant information using attributes only. Creating explicit data to give this information would also allow to save it in a csv, a "B(111,222,333)" e.g. telling there is a BckColor described by the specific RGB triple.

To do so will require using custom code. It's a complication - but not a prohibitive one. I can provide an approptiate function if you are interested.

(Irrelevant information needn't be transmitted.)

edit flag offensive delete link more

answered 2016-12-02 16:48:58 +0100

updated 2016-12-02 17:16:04 +0100

By definition, a CSV file doesn't support text formatting. See, for example, and

So... Nope. At least anything along those lines wouldn't be portable.

You can, however, write your program to do this using HTML. For example, if you save the following in a .html file and open it in Calc, three items will be colored as indicated.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<tr><td><font color="red">data1</font></td><td>data1</td><td>data1</td></tr>
<tr><td>data4</td><td><font color="green">data5</font></td><td>data6</td></tr>
<tr><td>data7</td><td>data8</td><td><font color="blue">data9</font></td></tr>

You can also save a Calc document in HTML, and it'll retain font formatting in the same way.

If you want to set the background color of a cell instead of the font color, you'd use <td bgcolor="red">data1</td> rather than using font tags as above.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower


Asked: 2016-12-02 01:12:39 +0100

Seen: 678 times

Last updated: Dec 02 '16