libxlsxwriter multiple formats on a cell

132 Views Asked by At

First time poster, long time reader! I am using libxlsxwriter in C.

I want to color rows either green or red and give the columns a different format each (which is either a date, a 2 decimal number or a 7 decimal number, or default.

the problem is that only the later is applied to each sell. so if do:

    worksheet_set_column(bla, bla, bla, date_format)
    //later in a loop:
    worksheet_set_row(bla, bla, bla, green_format).

the cells will only have the green_format but the the date_format

is there a way to apply both? I have a very messy solution where i just make red and green variation of each format, i.e. date_green_format/date_red_format. but that is really messy and i would like to avoid it aat all cost.

Is there a better way? Thanks!

2

There are 2 best solutions below

0
On

First use worksheet_set_row() and then use worksheet_set_column().

As per the documentation,

The format parameter will be applied to any cells in the row that don't have a format. As with Excel the row format is overridden by an explicit cell format.

Refer: worksheet_set_row()

0
On

is there a way to apply both? I have a very messy solution where i just make red and green variation of each format, i.e. date_green_format/date_red_format. but that is really messy and i would like to avoid it aat all cost.

Unfortunately that is the only possible solution. In Excel a cell that is at the intersection of a row and column format has a separate cell format that is a combination of both. As such, with libxlsxwriter you will also need to create and add a cell format that is a combination of the row and column formats.