A more comprehensive example of how to add conditional formatting to an libxlsxwriter file. Conditional formatting allows you to apply a format to a cell or a range of cells based on certain criteria.
#include "xlsxwriter.h"
uint8_t data[10][10] = {
{34, 72, 38, 30, 75, 48, 75, 66, 84, 86},
{6, 24, 1, 84, 54, 62, 60, 3, 26, 59},
{28, 79, 97, 13, 85, 93, 93, 22, 5, 14},
{27, 71, 40, 17, 18, 79, 90, 93, 29, 47},
{88, 25, 33, 23, 67, 1, 59, 79, 47, 36},
{24, 100, 20, 88, 29, 33, 38, 54, 54, 88},
{6, 57, 88, 28, 10, 26, 37, 7, 41, 48},
{52, 78, 1, 96, 26, 45, 47, 33, 96, 36},
{60, 54, 81, 66, 81, 90, 80, 93, 12, 55},
{70, 5, 46, 14, 71, 19, 66, 36, 41, 21},
};
int row, col;
for (row = 0; row < 10; row++)
for (col = 0; col < 10; col++)
}
}
int main() {
write_worksheet_data(worksheet1);
"Cells with values >= 50 are in light red. "
"Values < 50 are in light green.",
NULL);
conditional_format->
value = 50;
conditional_format->
format = format1;
conditional_format->
value = 50;
conditional_format->
format = format2;
write_worksheet_data(worksheet2);
"Values between 30 and 70 are in light red. "
"Values outside that range are in light green.",
NULL);
conditional_format->
format = format1;
conditional_format->
format = format2;
write_worksheet_data(worksheet3);
"Duplicate values are in light red. "
"Unique values are in light green.",
NULL);
conditional_format->
format = format1;
conditional_format->
format = format2;
write_worksheet_data(worksheet4);
"Above average values are in light red. "
"Below average values are in light green.",
NULL);
conditional_format->
format = format1;
conditional_format->
format = format2;
write_worksheet_data(worksheet5);
"Top 10 values are in light red. "
"Bottom 10 values are in light green.",
NULL);
conditional_format->
value = 10;
conditional_format->
format = format1;
conditional_format->
value = 10;
conditional_format->
format = format2;
write_worksheet_data(worksheet6);
"Cells with values >= 50 are in light red."
"Values < 50 are in light green. Non-contiguous ranges.",
NULL);
conditional_format->
value = 50;
conditional_format->
format = format1;
conditional_format->
value = 50;
conditional_format->
format = format2;
reset_conditional_format(conditional_format);
for (int i = 1; i <= 12; i++) {
}
"Examples of color scales with default and user colors.",
NULL);
reset_conditional_format(conditional_format);
reset_conditional_format(conditional_format);
for (int i = 1; i <= 12; i++) {
}
int data[] = {-1, -2, -3, -2, -1, 0, 1, 2, 3, 2, 1, 0};
for (int i = 1; i <= 12; i++) {
}
"Examples of data bars.",
NULL);
reset_conditional_format(conditional_format);
reset_conditional_format(conditional_format);
reset_conditional_format(conditional_format);
reset_conditional_format(conditional_format);
reset_conditional_format(conditional_format);
reset_conditional_format(conditional_format);
reset_conditional_format(conditional_format);
for (int i = 1; i <= 3; i++) {
}
for (int i = 1; i <= 4; i++) {
}
for (int i = 1; i <= 5; i++) {
}
"Examples of conditional formats with icon sets.",
NULL);
reset_conditional_format(conditional_format);
reset_conditional_format(conditional_format);
reset_conditional_format(conditional_format);
reset_conditional_format(conditional_format);
reset_conditional_format(conditional_format);
reset_conditional_format(conditional_format);
reset_conditional_format(conditional_format);
free(conditional_format);
}