Added docs for conditional formatting.

Feature request #302
This commit is contained in:
John McNamara 2020-09-05 21:17:39 +01:00
parent 5d4a571105
commit e3d4bcaf7c
27 changed files with 1868 additions and 133 deletions

View file

@ -0,0 +1,55 @@
/*
* An a simple example of how to add conditional formatting to an
* libxlsxwriter file.
*
* See conditional_format.c for a more comprehensive example.
*
* Copyright 2014-2020, John McNamara, jmcnamara@cpan.org
*
*/
#include "xlsxwriter.h"
int main() {
lxw_workbook *workbook = workbook_new("conditional_format_simple.xlsx");
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
/* Write some sample data. */
worksheet_write_number(worksheet, CELL("B1"), 34, NULL);
worksheet_write_number(worksheet, CELL("B2"), 32, NULL);
worksheet_write_number(worksheet, CELL("B3"), 31, NULL);
worksheet_write_number(worksheet, CELL("B4"), 35, NULL);
worksheet_write_number(worksheet, CELL("B5"), 36, NULL);
worksheet_write_number(worksheet, CELL("B6"), 30, NULL);
worksheet_write_number(worksheet, CELL("B7"), 38, NULL);
worksheet_write_number(worksheet, CELL("B8"), 38, NULL);
worksheet_write_number(worksheet, CELL("B9"), 32, NULL);
/* Add a format with red text. */
lxw_format *custom_format = workbook_add_format(workbook);
format_set_font_color(custom_format, LXW_COLOR_RED);
/* Create a conditional format object. A static object would also work. */
lxw_conditional_format *conditional_format = calloc(1, sizeof(lxw_conditional_format));
/* Set the format type: a cell conditional: */
conditional_format->type = LXW_CONDITIONAL_TYPE_CELL;
/* Set the criteria to use: */
conditional_format->criteria = LXW_CONDITIONAL_CRITERIA_LESS_THAN;
/* Set the value to which the criteria will be applied: */
conditional_format->value = 33;
/* Set the format to use if the criteria/value applies: */
conditional_format->format = custom_format;
/* Now apply the format to data range. */
worksheet_conditional_format_range(worksheet, RANGE("B1:B9"), conditional_format);
/* Free the object and close the file. */
free(conditional_format);
return workbook_close(workbook);
}

View file

@ -1,5 +1,5 @@
/*
* An example how to add conditional formatting to an XlsxWriter file.
* An 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.
@ -358,34 +358,34 @@ int main() {
conditional_format->type = LXW_CONDITIONAL_TYPE_ICON_SETS;
conditional_format->icon_style = LXW_CONDITIONAL_ICONS_3_TRAFFIC_LIGHTS;
conditional_format->icon_style = LXW_CONDITIONAL_ICONS_3_TRAFFIC_LIGHTS_UNRIMMED;
worksheet_conditional_format_range(worksheet9, RANGE("B3:D3"), conditional_format);
reset_conditional_format(conditional_format);
conditional_format->type = LXW_CONDITIONAL_TYPE_ICON_SETS;
conditional_format->icon_style = LXW_CONDITIONAL_ICONS_3_TRAFFIC_LIGHTS;
conditional_format->icon_style = LXW_CONDITIONAL_ICONS_3_TRAFFIC_LIGHTS_UNRIMMED;
conditional_format->reverse_icons = LXW_TRUE;
worksheet_conditional_format_range(worksheet9, RANGE("B4:D4"), conditional_format);
reset_conditional_format(conditional_format);
conditional_format->type = LXW_CONDITIONAL_TYPE_ICON_SETS;
conditional_format->icon_style = LXW_CONDITIONAL_ICONS_3_TRAFFIC_LIGHTS;
conditional_format->icon_style = LXW_CONDITIONAL_ICONS_3_TRAFFIC_LIGHTS_UNRIMMED;
conditional_format->icons_only = LXW_TRUE;
worksheet_conditional_format_range(worksheet9, RANGE("B5:D5"), conditional_format);
reset_conditional_format(conditional_format);
conditional_format->type = LXW_CONDITIONAL_TYPE_ICON_SETS;
conditional_format->icon_style = LXW_CONDITIONAL_ICONS_3_ARROWS;
conditional_format->icon_style = LXW_CONDITIONAL_ICONS_3_ARROWS_COLORED;
worksheet_conditional_format_range(worksheet9, RANGE("B6:D6"), conditional_format);
reset_conditional_format(conditional_format);
conditional_format->type = LXW_CONDITIONAL_TYPE_ICON_SETS;
conditional_format->icon_style = LXW_CONDITIONAL_ICONS_4_ARROWS;
conditional_format->icon_style = LXW_CONDITIONAL_ICONS_4_ARROWS_COLORED;
worksheet_conditional_format_range(worksheet9, RANGE("B7:E7"), conditional_format);
reset_conditional_format(conditional_format);
conditional_format->type = LXW_CONDITIONAL_TYPE_ICON_SETS;
conditional_format->icon_style = LXW_CONDITIONAL_ICONS_5_ARROWS;
conditional_format->icon_style = LXW_CONDITIONAL_ICONS_5_ARROWS_COLORED;
worksheet_conditional_format_range(worksheet9, RANGE("B8:F8"), conditional_format);
reset_conditional_format(conditional_format);