Example of adding autofilters to a worksheets and adding filter conditions.
#include "xlsxwriter.h"
int main() {
struct row {
char region[16];
char item[16];
int volume;
char month[16];
};
struct row data[] = {
{"East", "Apple", 9000, "July" },
{"East", "Apple", 5000, "July" },
{"South", "Orange", 9000, "September" },
{"North", "Apple", 2000, "November" },
{"West", "Apple", 9000, "November" },
{"South", "Pear", 7000, "October" },
{"North", "Pear", 9000, "August" },
{"West", "Orange", 1000, "December" },
{"West", "Grape", 1000, "November" },
{"South", "Pear", 10000, "April" },
{"West", "Grape", 6000, "January" },
{"South", "Orange", 3000, "May" },
{"North", "Apple", 3000, "December" },
{"South", "Apple", 7000, "February" },
{"West", "Grape", 1000, "December" },
{"East", "Grape", 8000, "February" },
{"South", "Grape", 10000, "June" },
{"West", "Pear", 7000, "December" },
{"South", "Apple", 2000, "October" },
{"East", "Grape", 7000, "December" },
{"North", "Grape", 6000, "April" },
{"East", "Pear", 8000, "February" },
{"North", "Apple", 7000, "August" },
{"North", "Orange", 7000, "July" },
{"North", "Apple", 6000, "June" },
{"South", "Grape", 8000, "September" },
{"West", "Apple", 3000, "October" },
{"South", "Orange", 10000, "November" },
{"West", "Grape", 4000, "July" },
{"North", "Orange", 5000, "August" },
{"East", "Orange", 1000, "November" },
{"East", "Orange", 4000, "October" },
{"North", "Grape", 5000, "August" },
{"East", "Apple", 1000, "December" },
{"South", "Apple", 10000, "March" },
{"East", "Grape", 7000, "October" },
{"West", "Grape", 1000, "September" },
{"East", "Grape", 10000, "October" },
{"South", "Orange", 8000, "March" },
{"North", "Apple", 4000, "July" },
{"South", "Orange", 5000, "July" },
{"West", "Apple", 4000, "June" },
{"East", "Apple", 5000, "April" },
{"North", "Pear", 3000, "August" },
{"East", "Grape", 9000, "November" },
{"North", "Orange", 8000, "October" },
{"East", "Apple", 10000, "June" },
{"South", "Pear", 1000, "December" },
{"North", "Grape", 10000, "July" },
{"East", "Grape", 6000, "February" }
};
uint16_t i;
write_worksheet_header(worksheet1, header);
for (i = 0; i < sizeof(data)/sizeof(struct row); i++) {
}
write_worksheet_header(worksheet2, header);
for (i = 0; i < sizeof(data)/sizeof(struct row); i++) {
if (strcmp(data[i].region, "East") == 0) {
}
else {
}
}
.value_string = "East"};
write_worksheet_header(worksheet3, header);
for (i = 0; i < sizeof(data)/sizeof(struct row); i++) {
if (strcmp(data[i].region, "East") == 0 || strcmp(data[i].region, "South") == 0) {
}
else {
}
}
.value_string = "East"};
.value_string = "South"};
write_worksheet_header(worksheet4, header);
for (i = 0; i < sizeof(data)/sizeof(struct row); i++) {
if (strcmp(data[i].region, "East") == 0 &&
data[i].volume > 3000 && data[i].volume < 8000)
{
}
else {
}
}
.value_string = "East"};
.value = 3000};
.value = 8000};
write_worksheet_header(worksheet5, header);
for (i = 0; i < sizeof(data)/sizeof(struct row); i++) {
if (strcmp(data[i].region, "East") == 0 ||
strcmp(data[i].region, "North") == 0 ||
strcmp(data[i].region, "South") == 0)
{
}
else {
}
}
const char* list[] = {"East", "North", "South", NULL};
write_worksheet_header(worksheet6, header);
data[5].region[0] = '\0';
for (i = 0; i < sizeof(data)/sizeof(struct row); i++) {
if (strcmp(data[i].region, "") == 0) {
}
else {
}
}
write_worksheet_header(worksheet7, header);
for (i = 0; i < sizeof(data)/sizeof(struct row); i++) {
if (strcmp(data[i].region, "") != 0) {
}
else {
}
}
}
}
@ LXW_TRUE
Definition: common.h:54
Options for autofilter rules.
Definition: worksheet.h:1666
uint8_t criteria
Definition: worksheet.h:1669
Options for rows and columns.
Definition: worksheet.h:842
uint8_t hidden
Definition: worksheet.h:844
Struct to represent an Excel workbook.
Definition: workbook.h:293
Struct to represent an Excel worksheet.
Definition: worksheet.h:2115
lxw_workbook * workbook_new(const char *filename)
Create a new workbook object.
lxw_format * workbook_add_format(lxw_workbook *workbook)
Create a new Format object to formats cells in worksheets.
lxw_error workbook_close(lxw_workbook *workbook)
Close the Workbook object and write the XLSX file.
lxw_worksheet * workbook_add_worksheet(lxw_workbook *workbook, const char *sheetname)
Add a new worksheet to a workbook.
lxw_error worksheet_filter_column2(lxw_worksheet *worksheet, lxw_col_t col, lxw_filter_rule *rule1, lxw_filter_rule *rule2, uint8_t and_or)
Write two filter rules to an autofilter column.
lxw_error worksheet_filter_column(lxw_worksheet *worksheet, lxw_col_t col, lxw_filter_rule *rule)
Write a filter rule to an autofilter column.
lxw_error worksheet_autofilter(lxw_worksheet *worksheet, lxw_row_t first_row, lxw_col_t first_col, lxw_row_t last_row, lxw_col_t last_col)
Set the autofilter area in the worksheet.
lxw_error worksheet_filter_list(lxw_worksheet *worksheet, lxw_col_t col, const char **list)
Write multiple string filters to an autofilter column.
@ LXW_FILTER_OR
Definition: worksheet.h:639
@ LXW_FILTER_AND
Definition: worksheet.h:636
#define LXW_DEF_ROW_HEIGHT
Definition: worksheet.h:77
lxw_error worksheet_set_column(lxw_worksheet *worksheet, lxw_col_t first_col, lxw_col_t last_col, double width, lxw_format *format)
Set the properties for one or more columns of cells.
lxw_error worksheet_set_row(lxw_worksheet *worksheet, lxw_row_t row, double height, lxw_format *format)
Set the properties for a row of cells.
lxw_error worksheet_set_row_opt(lxw_worksheet *worksheet, lxw_row_t row, double height, lxw_format *format, lxw_row_col_options *options)
Set the properties for a row of cells.
lxw_error worksheet_write_string(lxw_worksheet *worksheet, lxw_row_t row, lxw_col_t col, const char *string, lxw_format *format)
Write a string to a worksheet cell.
@ LXW_FILTER_CRITERIA_NON_BLANKS
Definition: worksheet.h:623
@ LXW_FILTER_CRITERIA_BLANKS
Definition: worksheet.h:620
@ LXW_FILTER_CRITERIA_LESS_THAN
Definition: worksheet.h:611
@ LXW_FILTER_CRITERIA_GREATER_THAN
Definition: worksheet.h:608
@ LXW_FILTER_CRITERIA_EQUAL_TO
Definition: worksheet.h:602
lxw_error worksheet_write_number(lxw_worksheet *worksheet, lxw_row_t row, lxw_col_t col, double number, lxw_format *format)
Write a number to a worksheet cell.