1 /*
2 * Tests for the libxlsxwriter library.
3 *
4 * Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
5 *
6 */
7
8 #include "../ctest.h"
9 #include "../helper.h"
10
11 #include "../../../include/xlsxwriter/worksheet.h"
12 #include "../../../include/xlsxwriter/table.h"
13
14 // Test assembling a complete Table file.
CTEST(worksheet,worksheet_table08)15 CTEST(worksheet, worksheet_table08) {
16
17 char* got;
18 char exp[] =
19 "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
20 "<table xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" id=\"1\" name=\"Table1\" displayName=\"Table1\" ref=\"C3:F14\" totalsRowCount=\"1\">"
21 "<autoFilter ref=\"C3:F13\"/>"
22 "<tableColumns count=\"4\">"
23 "<tableColumn id=\"1\" name=\"Column1\" totalsRowLabel=\"Total\"/>"
24 "<tableColumn id=\"2\" name=\"Column2\"/>"
25 "<tableColumn id=\"3\" name=\"Column3\"/>"
26 "<tableColumn id=\"4\" name=\"Column4\" totalsRowFunction=\"count\"/>"
27 "</tableColumns>"
28 "<tableStyleInfo name=\"TableStyleMedium9\" showFirstColumn=\"0\" showLastColumn=\"0\" showRowStripes=\"1\" showColumnStripes=\"0\"/>"
29 "</table>";
30
31 FILE* testfile = lxw_tmpfile(NULL);
32 FILE* testfile2 = lxw_tmpfile(NULL);
33
34 lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
35 worksheet->file = testfile2;
36 worksheet->sst = lxw_sst_new();
37
38 lxw_table *table = lxw_table_new();
39 table->file = testfile;
40
41 lxw_table_column col1 = {.total_string = "Total"};
42 lxw_table_column col2 = {0};
43 lxw_table_column col3 = {0};
44 lxw_table_column col4 = {.total_function = LXW_TABLE_FUNCTION_COUNT};
45 lxw_table_column *columns[] = {&col1, &col2, &col3, &col4, NULL};
46
47 lxw_table_options options = {.total_row = LXW_TRUE, .columns = columns};
48
49 worksheet_add_table(worksheet, RANGE("C3:F14"), &options);
50
51 table->table_obj = STAILQ_FIRST(worksheet->table_objs);
52 table->table_obj->id = 1;
53
54 lxw_table_assemble_xml_file(table);
55
56 RUN_XLSX_STREQ_SHORT(exp, got);
57
58 lxw_worksheet_free(worksheet);
59 lxw_table_free(table);
60 }
61
62
63