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

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 close merge delete

Sort by » oldest newest most voted

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.)

more

By definition, a CSV file doesn't support text formatting. See, for example, http://www.computerhope.com/jargon/c/... and http://www.computerhope.com/jargon/p/....

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">
<html>
<body>
<table>
<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>
</table>
</body>
</html>


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.

more