Added support for worksheet tables.

Feature request #33
This commit is contained in:
John McNamara 2021-08-16 21:29:27 +01:00
parent 6524326300
commit 6d6d99eeaf
78 changed files with 3279 additions and 9 deletions

View file

@ -0,0 +1,22 @@
/*****************************************************************************
* Test cases for libxlsxwriter.
*
* Test to compare output against Excel files.
*
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
*
*/
#include "xlsxwriter.h"
int main() {
lxw_workbook *workbook = workbook_new("test_table01.xlsx");
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
worksheet_set_column(worksheet, COLS("C:F"), 10.288, NULL);
worksheet_add_table(worksheet, RANGE("C3:F13"), NULL);
return workbook_close(workbook);
}

View file

@ -0,0 +1,29 @@
/*****************************************************************************
* Test cases for libxlsxwriter.
*
* Test to compare output against Excel files.
*
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
*
*/
#include "xlsxwriter.h"
int main() {
lxw_workbook *workbook = workbook_new("test_table02.xlsx");
lxw_worksheet *worksheet1 = workbook_add_worksheet(workbook, NULL);
lxw_worksheet *worksheet2 = workbook_add_worksheet(workbook, NULL);
worksheet_set_column(worksheet1, COLS("B:J"), 10.288, NULL);
worksheet_set_column(worksheet2, COLS("C:L"), 10.288, NULL);
worksheet_add_table(worksheet1, RANGE("B3:E11"), NULL);
worksheet_add_table(worksheet1, RANGE("G10:J16"), NULL);
worksheet_add_table(worksheet1, RANGE("C18:F25"), NULL);
worksheet_add_table(worksheet2, RANGE("I4:L11"), NULL);
worksheet_add_table(worksheet2, RANGE("C16:H23"), NULL);
return workbook_close(workbook);
}

View file

@ -0,0 +1,26 @@
/*****************************************************************************
* Test cases for libxlsxwriter.
*
* Test to compare output against Excel files.
*
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
*
*/
#include "xlsxwriter.h"
int main() {
lxw_workbook *workbook = workbook_new("test_table03.xlsx");
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
worksheet_set_column(worksheet, COLS("C:F"), 10.288, NULL);
worksheet_add_table(worksheet, RANGE("C3:F13"), NULL);
/* Add other objects to check rId handling. */
workbook_unset_default_url_format(workbook);
worksheet_write_url(worksheet, CELL("A1"), "http://perl.com/", NULL);
return workbook_close(workbook);
}

View file

@ -0,0 +1,30 @@
/*****************************************************************************
* Test cases for libxlsxwriter.
*
* Test to compare output against Excel files.
*
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
*
*/
#include "xlsxwriter.h"
int main() {
lxw_workbook *workbook = workbook_new("test_table04.xlsx");
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
worksheet_set_column(worksheet, COLS("C:F"), 10.288, NULL);
worksheet_add_table(worksheet, RANGE("C3:F13"), NULL);
/* Add other objects to check rId handling. */
workbook_unset_default_url_format(workbook);
worksheet_write_url(worksheet, CELL("A1"), "http://perl.com/", NULL);
worksheet_set_comments_author(worksheet, "John");
worksheet_write_comment(worksheet, CELL("H1"), "Test1");
worksheet_write_comment(worksheet, CELL("J1"), "Test2");
return workbook_close(workbook);
}

View file

@ -0,0 +1,32 @@
/*****************************************************************************
* Test cases for libxlsxwriter.
*
* Test to compare output against Excel files.
*
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
*
*/
#include "xlsxwriter.h"
int main() {
lxw_workbook *workbook = workbook_new("test_table05.xlsx");
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
worksheet_set_column(worksheet, COLS("C:F"), 10.288, NULL);
worksheet_add_table(worksheet, RANGE("C3:F13"), NULL);
/* Add other objects to check rId handling. */
workbook_unset_default_url_format(workbook);
worksheet_write_url(worksheet, CELL("A1"), "http://perl.com/", NULL);
worksheet_set_comments_author(worksheet, "John");
worksheet_write_comment(worksheet, CELL("H1"), "Test1");
worksheet_write_comment(worksheet, CELL("J1"), "Test2");
worksheet_insert_image(worksheet, CELL("A4"), "images/blue.png");
return workbook_close(workbook);
}

View file

@ -0,0 +1,35 @@
/*****************************************************************************
* Test cases for libxlsxwriter.
*
* Test to compare output against Excel files.
*
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
*
*/
#include "xlsxwriter.h"
int main() {
lxw_workbook *workbook = workbook_new("test_table06.xlsx");
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
worksheet_set_column(worksheet, COLS("C:H"), 10.288, NULL);
worksheet_add_table(worksheet, RANGE("C3:F13"), NULL);
worksheet_add_table(worksheet, RANGE("F15:H20"), NULL);
worksheet_add_table(worksheet, RANGE("C23:D30"), NULL);
/* Add other objects to check rId handling. */
workbook_unset_default_url_format(workbook);
worksheet_write_url(worksheet, CELL("A1"), "http://perl.com/", NULL);
worksheet_write_url(worksheet, CELL("C1"), "http://perl.com/", NULL);
worksheet_set_comments_author(worksheet, "John");
worksheet_write_comment(worksheet, CELL("H1"), "Test1");
worksheet_write_comment(worksheet, CELL("J1"), "Test2");
worksheet_insert_image(worksheet, CELL("A4"), "images/blue.png");
return workbook_close(workbook);
}

View file

@ -0,0 +1,25 @@
/*****************************************************************************
* Test cases for libxlsxwriter.
*
* Test to compare output against Excel files.
*
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
*
*/
#include "xlsxwriter.h"
int main() {
lxw_workbook *workbook = workbook_new("test_table07.xlsx");
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
worksheet_set_column(worksheet, COLS("C:F"), 10.288, NULL);
worksheet_write_string(worksheet, CELL("A1"), "Foo", NULL);
lxw_table_options options = {.no_header_row = LXW_TRUE};
worksheet_add_table(worksheet, RANGE("C3:F13"), &options);
return workbook_close(workbook);
}

View file

@ -0,0 +1,36 @@
/*****************************************************************************
* Test cases for libxlsxwriter.
*
* Test to compare output against Excel files.
*
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
*
*/
#include "xlsxwriter.h"
int main() {
lxw_workbook *workbook = workbook_new("test_table08.xlsx");
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
worksheet_set_column(worksheet, COLS("C:F"), 10.288, NULL);
worksheet_write_string(worksheet, CELL("A1"), "Column1", NULL);
worksheet_write_string(worksheet, CELL("B1"), "Column2", NULL);
worksheet_write_string(worksheet, CELL("C1"), "Column3", NULL);
worksheet_write_string(worksheet, CELL("D1"), "Column4", NULL);
worksheet_write_string(worksheet, CELL("E1"), "Total", NULL);
lxw_table_column col1 = {.total_string = "Total"};
lxw_table_column col2 = {0};
lxw_table_column col3 = {0};
lxw_table_column col4 = {.total_function = LXW_TABLE_FUNCTION_COUNT};
lxw_table_column *columns[] = {&col1, &col2, &col3, &col4, NULL};
lxw_table_options options = {.total_row = LXW_TRUE, .columns = columns};
worksheet_add_table(worksheet, RANGE("C3:F14"), &options);
return workbook_close(workbook);
}

View file

@ -0,0 +1,69 @@
/*****************************************************************************
* Test cases for libxlsxwriter.
*
* Test to compare output against Excel files.
*
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
*
*/
#include "xlsxwriter.h"
int main() {
lxw_workbook *workbook = workbook_new("test_table09.xlsx");
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
worksheet_set_column(worksheet, COLS("B:K"), 10.288, NULL);
worksheet_write_string(worksheet, CELL("A1"), "Column1", NULL);
worksheet_write_string(worksheet, CELL("B1"), "Column2", NULL);
worksheet_write_string(worksheet, CELL("C1"), "Column3", NULL);
worksheet_write_string(worksheet, CELL("D1"), "Column4", NULL);
worksheet_write_string(worksheet, CELL("E1"), "Column5", NULL);
worksheet_write_string(worksheet, CELL("F1"), "Column6", NULL);
worksheet_write_string(worksheet, CELL("G1"), "Column7", NULL);
worksheet_write_string(worksheet, CELL("H1"), "Column8", NULL);
worksheet_write_string(worksheet, CELL("I1"), "Column9", NULL);
worksheet_write_string(worksheet, CELL("J1"), "Column10", NULL);
worksheet_write_string(worksheet, CELL("K1"), "Total", NULL);
worksheet_write_number(worksheet, 3, 1, 0, NULL);
worksheet_write_number(worksheet, 3, 2, 0, NULL);
worksheet_write_number(worksheet, 3, 3, 0, NULL);
worksheet_write_number(worksheet, 3, 6, 0, NULL);
worksheet_write_number(worksheet, 3, 7, 0, NULL);
worksheet_write_number(worksheet, 3, 8, 0, NULL);
worksheet_write_number(worksheet, 3, 9, 0, NULL);
worksheet_write_number(worksheet, 3, 10, 0, NULL);
worksheet_write_number(worksheet, 4, 1, 0, NULL);
worksheet_write_number(worksheet, 4, 2, 0, NULL);
worksheet_write_number(worksheet, 4, 3, 0, NULL);
worksheet_write_number(worksheet, 4, 6, 0, NULL);
worksheet_write_number(worksheet, 4, 7, 0, NULL);
worksheet_write_number(worksheet, 4, 8, 0, NULL);
worksheet_write_number(worksheet, 4, 9, 0, NULL);
worksheet_write_number(worksheet, 4, 10, 0, NULL);
lxw_table_column col1 = {.total_string = "Total"};
lxw_table_column col2 = {0};
lxw_table_column col3 = {.total_function = LXW_TABLE_FUNCTION_AVERAGE};
lxw_table_column col4 = {.total_function = LXW_TABLE_FUNCTION_COUNT};
lxw_table_column col5 = {.total_function = LXW_TABLE_FUNCTION_COUNT_NUMS};
lxw_table_column col6 = {.total_function = LXW_TABLE_FUNCTION_MAX};
lxw_table_column col7 = {.total_function = LXW_TABLE_FUNCTION_MIN};
lxw_table_column col8 = {.total_function = LXW_TABLE_FUNCTION_SUM};
lxw_table_column col9 = {.total_function = LXW_TABLE_FUNCTION_STD_DEV};
lxw_table_column col10 = {.total_function = LXW_TABLE_FUNCTION_VAR};
lxw_table_column *columns[] = {&col1, &col2, &col3, &col4, &col5, &col6, &col7, &col8, &col9, &col10, NULL};
lxw_table_options options = {.total_row = LXW_TRUE, .columns = columns};
worksheet_add_table(worksheet, RANGE("B3:K6"), &options);
return workbook_close(workbook);
}

View file

@ -0,0 +1,74 @@
/*****************************************************************************
* Test cases for libxlsxwriter.
*
* Test to compare output against Excel files.
*
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
*
*/
#include "xlsxwriter.h"
int main() {
lxw_workbook *workbook = workbook_new("test_table10.xlsx");
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
lxw_format *format = workbook_add_format(workbook);
format_set_num_format_index(format, 2);
worksheet_set_column(worksheet, COLS("B:K"), 10.288, NULL);
worksheet_write_string(worksheet, CELL("A1"), "Column1", NULL);
worksheet_write_string(worksheet, CELL("B1"), "Column2", NULL);
worksheet_write_string(worksheet, CELL("C1"), "Column3", NULL);
worksheet_write_string(worksheet, CELL("D1"), "Column4", NULL);
worksheet_write_string(worksheet, CELL("E1"), "Column5", NULL);
worksheet_write_string(worksheet, CELL("F1"), "Column6", NULL);
worksheet_write_string(worksheet, CELL("G1"), "Column7", NULL);
worksheet_write_string(worksheet, CELL("H1"), "Column8", NULL);
worksheet_write_string(worksheet, CELL("I1"), "Column9", NULL);
worksheet_write_string(worksheet, CELL("J1"), "Column10", NULL);
worksheet_write_string(worksheet, CELL("K1"), "Total", NULL);
worksheet_write_number(worksheet, 3, 1, 0, NULL);
worksheet_write_number(worksheet, 3, 2, 0, NULL);
worksheet_write_number(worksheet, 3, 3, 0, NULL);
worksheet_write_number(worksheet, 3, 6, 0, NULL);
worksheet_write_number(worksheet, 3, 7, 0, NULL);
worksheet_write_number(worksheet, 3, 8, 0, NULL);
worksheet_write_number(worksheet, 3, 9, 0, NULL);
worksheet_write_number(worksheet, 3, 10, 0, NULL);
worksheet_write_number(worksheet, 4, 1, 0, NULL);
worksheet_write_number(worksheet, 4, 2, 0, NULL);
worksheet_write_number(worksheet, 4, 3, 0, NULL);
worksheet_write_number(worksheet, 4, 6, 0, NULL);
worksheet_write_number(worksheet, 4, 7, 0, NULL);
worksheet_write_number(worksheet, 4, 8, 0, NULL);
worksheet_write_number(worksheet, 4, 9, 0, NULL);
worksheet_write_number(worksheet, 4, 10, 0, NULL);
lxw_table_column col1 = {.total_string = "Total"};
lxw_table_column col2 = {0};
lxw_table_column col3 = {.total_function = LXW_TABLE_FUNCTION_AVERAGE};
lxw_table_column col4 = {.total_function = LXW_TABLE_FUNCTION_COUNT};
lxw_table_column col5 = {.total_function = LXW_TABLE_FUNCTION_COUNT_NUMS};
lxw_table_column col6 = {.total_function = LXW_TABLE_FUNCTION_MAX};
lxw_table_column col7 = {.total_function = LXW_TABLE_FUNCTION_MIN};
lxw_table_column col8 = {.total_function = LXW_TABLE_FUNCTION_SUM};
lxw_table_column col9 = {.total_function = LXW_TABLE_FUNCTION_STD_DEV};
lxw_table_column col10 = {.total_function = LXW_TABLE_FUNCTION_VAR,
.formula = "SUM(Table1[[#This Row],[Column1]:[Column3]])",
.format = format};
lxw_table_column *columns[] = {&col1, &col2, &col3, &col4, &col5, &col6, &col7, &col8, &col9, &col10, NULL};
lxw_table_options options = {.total_row = LXW_TRUE, .columns = columns};
worksheet_add_table(worksheet, RANGE("B3:K6"), &options);
return workbook_close(workbook);
}

View file

@ -0,0 +1,42 @@
/*****************************************************************************
* Test cases for libxlsxwriter.
*
* Test to compare output against Excel files.
*
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
*
*/
#include "xlsxwriter.h"
int main() {
lxw_workbook *workbook = workbook_new("test_table11.xlsx");
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
worksheet_set_column(worksheet, COLS("C:F"), 10.288, NULL);
worksheet_add_table(worksheet, RANGE("C2:F6"), NULL);
worksheet_write_string(worksheet, 2, 2, "Foo", NULL);
worksheet_write_string(worksheet, 3, 2, "Bar", NULL);
worksheet_write_string(worksheet, 4, 2, "Baz", NULL);
worksheet_write_string(worksheet, 5, 2, "Bop", NULL);
worksheet_write_number(worksheet, 2, 3, 1234, NULL);
worksheet_write_number(worksheet, 3, 3, 1256, NULL);
worksheet_write_number(worksheet, 4, 3, 2234, NULL);
worksheet_write_number(worksheet, 5, 3, 1324, NULL);
worksheet_write_number(worksheet, 2, 4, 2000, NULL);
worksheet_write_number(worksheet, 3, 4, 4000, NULL);
worksheet_write_number(worksheet, 4, 4, 3000, NULL);
worksheet_write_number(worksheet, 5, 4, 1000, NULL);
worksheet_write_number(worksheet, 2, 5, 4321, NULL);
worksheet_write_number(worksheet, 3, 5, 4320, NULL);
worksheet_write_number(worksheet, 4, 5, 4332, NULL);
worksheet_write_number(worksheet, 5, 5, 4333, NULL);
return workbook_close(workbook);
}

View file

@ -0,0 +1,34 @@
/*****************************************************************************
* Test cases for libxlsxwriter.
*
* Test to compare output against Excel files.
*
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
*
*/
#include "xlsxwriter.h"
int main() {
lxw_workbook *workbook = workbook_new("test_table12.xlsx");
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
worksheet_set_column(worksheet, COLS("C:F"), 10.288, NULL);
worksheet_add_table(worksheet, RANGE("C2:F6"), NULL);
worksheet_write_string(worksheet, 2, 2, "Foo", NULL);
worksheet_write_string(worksheet, 3, 2, "Bar", NULL);
worksheet_write_string(worksheet, 4, 2, "Baz", NULL);
worksheet_write_number(worksheet, 2, 3, 1234, NULL);
worksheet_write_number(worksheet, 3, 3, 1256, NULL);
worksheet_write_number(worksheet, 4, 3, 2234, NULL);
worksheet_write_number(worksheet, 2, 4, 2000, NULL);
worksheet_write_number(worksheet, 3, 4, 4000, NULL);
worksheet_write_number(worksheet, 4, 4, 3000, NULL);
return workbook_close(workbook);
}

View file

@ -0,0 +1,63 @@
/*****************************************************************************
* Test cases for libxlsxwriter.
*
* Test to compare output against Excel files.
*
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
*
*/
#include "xlsxwriter.h"
int main() {
lxw_workbook *workbook = workbook_new("test_table14.xlsx");
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
lxw_format *format1 = workbook_add_format(workbook);
lxw_format *format2 = workbook_add_format(workbook);
lxw_format *format3 = workbook_add_format(workbook);
format_set_num_format(format1, "0.00;[Red]0.00");
format_set_num_format(format2, "0.00_ ;\\-0.00\\ ");
format_set_num_format(format3, "0.00_ ;[Red]\\-0.00\\ ");
/* We manually set the indices to get the same order as the target file. */
lxw_format_get_dxf_index(format3);
lxw_format_get_dxf_index(format2);
lxw_format_get_dxf_index(format1);
worksheet_set_column(worksheet, COLS("C:F"), 10.288, NULL);
lxw_table_column col1 = {0};
lxw_table_column col2 = {.format = format1};
lxw_table_column col3 = {.format = format2};
lxw_table_column col4 = {.format = format3};
lxw_table_column *columns[] = {&col1, &col2, &col3, &col4, NULL};
lxw_table_options options = {.columns = columns};
worksheet_add_table(worksheet, RANGE("C2:F6"), &options);
worksheet_write_string(worksheet, 2, 2, "Foo", NULL);
worksheet_write_string(worksheet, 3, 2, "Bar", NULL);
worksheet_write_string(worksheet, 4, 2, "Baz", NULL);
worksheet_write_string(worksheet, 5, 2, "Bop", NULL);
worksheet_write_number(worksheet, 2, 3, 1234, format1);
worksheet_write_number(worksheet, 3, 3, 1256, format1);
worksheet_write_number(worksheet, 4, 3, 2234, format1);
worksheet_write_number(worksheet, 5, 3, 1324, format1);
worksheet_write_number(worksheet, 2, 4, 2000, format2);
worksheet_write_number(worksheet, 3, 4, 4000, format2);
worksheet_write_number(worksheet, 4, 4, 3000, format2);
worksheet_write_number(worksheet, 5, 4, 1000, format2);
worksheet_write_number(worksheet, 2, 5, 4321, format3);
worksheet_write_number(worksheet, 3, 5, 4320, format3);
worksheet_write_number(worksheet, 4, 5, 4332, format3);
worksheet_write_number(worksheet, 5, 5, 4333, format3);
return workbook_close(workbook);
}

View file

@ -0,0 +1,42 @@
/*****************************************************************************
* Test cases for libxlsxwriter.
*
* Test to compare output against Excel files.
*
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
*
*/
#include "xlsxwriter.h"
int main() {
lxw_workbook *workbook = workbook_new("test_table15.xlsx");
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
worksheet_set_column(worksheet, COLS("C:F"), 10.288, NULL);
worksheet_add_table(worksheet, RANGE("C2:F6"), NULL);
worksheet_write_string(worksheet, 2, 2, "Foo", NULL);
worksheet_write_string(worksheet, 3, 2, "Bar", NULL);
worksheet_write_string(worksheet, 4, 2, "Baz", NULL);
worksheet_write_string(worksheet, 5, 2, "Bop", NULL);
worksheet_write_number(worksheet, 2, 3, 1234, NULL);
worksheet_write_number(worksheet, 3, 3, 1256, NULL);
worksheet_write_number(worksheet, 4, 3, 2234, NULL);
worksheet_write_number(worksheet, 5, 3, 1324, NULL);
worksheet_write_number(worksheet, 2, 4, 2000, NULL);
worksheet_write_number(worksheet, 3, 4, 0, NULL);
worksheet_write_number(worksheet, 4, 4, 3000, NULL);
worksheet_write_number(worksheet, 5, 4, 1000, NULL);
worksheet_write_number(worksheet, 2, 5, 4321, NULL);
worksheet_write_number(worksheet, 3, 5, 4320, NULL);
worksheet_write_number(worksheet, 4, 5, 4332, NULL);
worksheet_write_number(worksheet, 5, 5, 4333, NULL);
return workbook_close(workbook);
}

View file

@ -0,0 +1,31 @@
/*****************************************************************************
* Test cases for libxlsxwriter.
*
* Test to compare output against Excel files.
*
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
*
*/
#include "xlsxwriter.h"
int main() {
lxw_workbook *workbook = workbook_new("test_table16.xlsx");
lxw_worksheet *worksheet1 = workbook_add_worksheet(workbook, NULL);
lxw_worksheet *worksheet2 = workbook_add_worksheet(workbook, NULL);
worksheet_set_column(worksheet1, COLS("B:J"), 10.288, NULL);
worksheet_set_column(worksheet2, COLS("C:L"), 10.288, NULL);
/* Add the tables in reverse worksheet order to test_table02.c */
worksheet_add_table(worksheet2, RANGE("I4:L11"), NULL);
worksheet_add_table(worksheet2, RANGE("C16:H23"), NULL);
worksheet_add_table(worksheet1, RANGE("B3:E11"), NULL);
worksheet_add_table(worksheet1, RANGE("G10:J16"), NULL);
worksheet_add_table(worksheet1, RANGE("C18:F25"), NULL);
return workbook_close(workbook);
}

View file

@ -0,0 +1,69 @@
/*****************************************************************************
* Test cases for libxlsxwriter.
*
* Test to compare output against Excel files.
*
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
*
*/
#include "xlsxwriter.h"
int main() {
lxw_workbook *workbook = workbook_new("test_table17.xlsx");
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
worksheet_set_column(worksheet, COLS("B:K"), 10.288, NULL);
worksheet_write_string(worksheet, CELL("A1"), "Column1", NULL);
worksheet_write_string(worksheet, CELL("B1"), "Column2", NULL);
worksheet_write_string(worksheet, CELL("C1"), "Column3", NULL);
worksheet_write_string(worksheet, CELL("D1"), "Column4", NULL);
worksheet_write_string(worksheet, CELL("E1"), "Column5", NULL);
worksheet_write_string(worksheet, CELL("F1"), "Column6", NULL);
worksheet_write_string(worksheet, CELL("G1"), "Column7", NULL);
worksheet_write_string(worksheet, CELL("H1"), "Column8", NULL);
worksheet_write_string(worksheet, CELL("I1"), "Column9", NULL);
worksheet_write_string(worksheet, CELL("J1"), "Column10", NULL);
worksheet_write_string(worksheet, CELL("K1"), "Total", NULL);
worksheet_write_number(worksheet, 3, 1, 0, NULL);
worksheet_write_number(worksheet, 3, 2, 0, NULL);
worksheet_write_number(worksheet, 3, 3, 0, NULL);
worksheet_write_number(worksheet, 3, 6, 4, NULL);
worksheet_write_number(worksheet, 3, 7, 0, NULL);
worksheet_write_number(worksheet, 3, 8, 1, NULL);
worksheet_write_number(worksheet, 3, 9, 0, NULL);
worksheet_write_number(worksheet, 3, 10, 0, NULL);
worksheet_write_number(worksheet, 4, 1, 0, NULL);
worksheet_write_number(worksheet, 4, 2, 0, NULL);
worksheet_write_number(worksheet, 4, 3, 0, NULL);
worksheet_write_number(worksheet, 4, 6, 5, NULL);
worksheet_write_number(worksheet, 4, 7, 0, NULL);
worksheet_write_number(worksheet, 4, 8, 2, NULL);
worksheet_write_number(worksheet, 4, 9, 0, NULL);
worksheet_write_number(worksheet, 4, 10, 0, NULL);
lxw_table_column col1 = {.total_string = "Total"};
lxw_table_column col2 = {0};
lxw_table_column col3 = {.total_function = LXW_TABLE_FUNCTION_AVERAGE};
lxw_table_column col4 = {.total_function = LXW_TABLE_FUNCTION_COUNT};
lxw_table_column col5 = {.total_function = LXW_TABLE_FUNCTION_COUNT_NUMS};
lxw_table_column col6 = {.total_function = LXW_TABLE_FUNCTION_MAX, .total_value = 5};
lxw_table_column col7 = {.total_function = LXW_TABLE_FUNCTION_MIN};
lxw_table_column col8 = {.total_function = LXW_TABLE_FUNCTION_SUM, .total_value = 3};
lxw_table_column col9 = {.total_function = LXW_TABLE_FUNCTION_STD_DEV};
lxw_table_column col10 = {.total_function = LXW_TABLE_FUNCTION_VAR};
lxw_table_column *columns[] = {&col1, &col2, &col3, &col4, &col5, &col6, &col7, &col8, &col9, &col10, NULL};
lxw_table_options options = {.total_row = LXW_TRUE, .columns = columns};
worksheet_add_table(worksheet, RANGE("B3:K6"), &options);
return workbook_close(workbook);
}

View file

@ -0,0 +1,37 @@
/*****************************************************************************
* Test cases for libxlsxwriter.
*
* Test to compare output against Excel files.
*
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
*
*/
#include "xlsxwriter.h"
int main() {
lxw_workbook *workbook = workbook_new("test_table18.xlsx");
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
lxw_format *wrap = workbook_add_format(workbook);
format_set_text_wrap(wrap);
worksheet_set_column(worksheet, COLS("C:F"), 10.288, NULL);
worksheet_set_row(worksheet, 2, 39, NULL);
lxw_table_column col1 = {0};
lxw_table_column col2 = {0};
lxw_table_column col3 = {0};
lxw_table_column col4 = {.header = "Column\n4", .header_format = wrap};
lxw_table_column *columns[] = {&col1, &col2, &col3, &col4, NULL};
lxw_table_options options = {.columns = columns};
worksheet_add_table(worksheet, RANGE("C3:F13"), &options);
worksheet_write_string(worksheet, CELL("A16"), "hello", NULL);
return workbook_close(workbook);
}

View file

@ -0,0 +1,31 @@
/*****************************************************************************
* Test cases for libxlsxwriter.
*
* Test to compare output against Excel files.
*
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
*
*/
#include "xlsxwriter.h"
int main() {
lxw_workbook *workbook = workbook_new("test_table19.xlsx");
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
worksheet_set_column(worksheet, COLS("C:F"), 10.288, NULL);
lxw_table_column col1 = {0};
lxw_table_column col2 = {0};
lxw_table_column col3 = {0};
lxw_table_column col4 = {.header = " Column4 "};
lxw_table_column *columns[] = {&col1, &col2, &col3, &col4, NULL};
lxw_table_options options = {.columns = columns};
worksheet_add_table(worksheet, RANGE("C3:F13"), &options);
return workbook_close(workbook);
}

View file

@ -0,0 +1,29 @@
/*****************************************************************************
* Test cases for libxlsxwriter.
*
* Test to compare output against Excel files.
*
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
*
*/
#include "xlsxwriter.h"
int main() {
lxw_workbook *workbook = workbook_new("test_table21.xlsx");
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
worksheet_set_column(worksheet, COLS("C:D"), 10.288, NULL);
worksheet_write_string(worksheet, CELL("A1"), "Column", NULL);
lxw_table_column col1 = {.header = "Column"};
lxw_table_column *columns[] = {&col1, NULL};
lxw_table_options options = {.columns = columns};
worksheet_add_table(worksheet, RANGE("C3:D13"), &options);
return workbook_close(workbook);
}

View file

@ -0,0 +1,32 @@
/*****************************************************************************
* Test cases for libxlsxwriter.
*
* Test to compare output against Excel files.
*
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
*
*/
#include "xlsxwriter.h"
int main() {
lxw_workbook *workbook = workbook_new("test_table22.xlsx");
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
worksheet_set_column(worksheet, COLS("B:C"), 10.288, NULL);
worksheet_write_string(worksheet, CELL("B2"), "apple", NULL);
worksheet_write_string(worksheet, CELL("C2"), "pie", NULL);
worksheet_write_string(worksheet, CELL("B3"), "pine", NULL);
worksheet_write_string(worksheet, CELL("C3"), "tree", NULL);
lxw_table_options options = {.no_header_row = LXW_TRUE};
worksheet_add_table(worksheet, RANGE("B2:C3"), &options);
return workbook_close(workbook);
}

View file

@ -0,0 +1,38 @@
/*****************************************************************************
* Test cases for libxlsxwriter.
*
* Test to compare output against Excel files.
*
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
*
*/
#include "xlsxwriter.h"
int main() {
lxw_workbook *workbook = workbook_new("test_table23.xlsx");
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
worksheet_set_column(worksheet, COLS("B:F"), 10.288, NULL);
worksheet_write_string(worksheet, CELL("A1"), "Column1", NULL);
worksheet_write_string(worksheet, CELL("F1"), "Total", NULL);
worksheet_write_string(worksheet, CELL("B1"), "Column'", NULL);
worksheet_write_string(worksheet, CELL("C1"), "Column#", NULL);
worksheet_write_string(worksheet, CELL("D1"), "Column[", NULL);
worksheet_write_string(worksheet, CELL("E1"), "Column]", NULL);
lxw_table_column col1 = {.header = "Column1", .total_string = "Total"};
lxw_table_column col2 = {.header = "Column'", .total_function = LXW_TABLE_FUNCTION_SUM};
lxw_table_column col3 = {.header = "Column#", .total_function = LXW_TABLE_FUNCTION_SUM};
lxw_table_column col4 = {.header = "Column[", .total_function = LXW_TABLE_FUNCTION_SUM};
lxw_table_column col5 = {.header = "Column]", .total_function = LXW_TABLE_FUNCTION_SUM};
lxw_table_column *columns[] = {&col1, &col2, &col3, &col4, &col5, NULL};
lxw_table_options options = {.total_row = LXW_TRUE, .columns = columns};
worksheet_add_table(worksheet, RANGE("B3:F9"), &options);
return workbook_close(workbook);
}

View file

@ -0,0 +1,25 @@
/*****************************************************************************
* Test cases for libxlsxwriter.
*
* Test to compare output against Excel files.
*
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
*
*/
#include "xlsxwriter.h"
int main() {
lxw_workbook *workbook = workbook_new("test_table24.xlsx");
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
worksheet_set_column(worksheet, COLS("C:F"), 10.288, NULL);
lxw_table_options options = {.style_type = LXW_TABLE_STYLE_TYPE_MEDIUM,
.style_type_number = 10};
worksheet_add_table(worksheet, RANGE("C3:F13"), &options);
return workbook_close(workbook);
}

View file

@ -0,0 +1,25 @@
/*****************************************************************************
* Test cases for libxlsxwriter.
*
* Test to compare output against Excel files.
*
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
*
*/
#include "xlsxwriter.h"
int main() {
lxw_workbook *workbook = workbook_new("test_table25.xlsx");
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
worksheet_set_column(worksheet, COLS("C:F"), 10.288, NULL);
lxw_table_options options = {.style_type = LXW_TABLE_STYLE_TYPE_LIGHT,
.style_type_number = 0};
worksheet_add_table(worksheet, RANGE("C3:F13"), &options);
return workbook_close(workbook);
}

View file

@ -0,0 +1,56 @@
/*****************************************************************************
* Test cases for libxlsxwriter.
*
* Test to compare output against Excel files.
*
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
*
*/
#include "xlsxwriter.h"
int main() {
lxw_workbook *workbook = workbook_new("test_table26.xlsx");
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
worksheet_set_column(worksheet, COLS("C:D"), 10.288, NULL);
worksheet_set_column(worksheet, COLS("F:G"), 10.288, NULL);
/* Add some valid tables. */
worksheet_add_table(worksheet, RANGE("C2:D3"), NULL);
lxw_table_options options1 = {.name = "Table2", .no_header_row = LXW_TRUE};
worksheet_add_table(worksheet, RANGE("F3:G3"), &options1);
/*
* Test incorrect tables. These should be ignored with a warning.
* */
/* Add a table with an incorrect range. */
worksheet_add_table(worksheet, RANGE("I2:J2"), NULL);
/* Check incorrect table names. */
lxw_table_options options2 = {.name = "Has space"};
worksheet_add_table(worksheet, RANGE("F3:G33"), &options2);
lxw_table_options options3 = {.name = "Table["};
worksheet_add_table(worksheet, RANGE("F3:G33"), &options3);
lxw_table_options options4 = {.name = "This_is_a_long_table_name_that_exceeds_a_limit_of_255_characters_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"};
worksheet_add_table(worksheet, RANGE("F3:G33"), &options4);
lxw_table_options options5 = {.name = "c"};
worksheet_add_table(worksheet, RANGE("F3:G33"), &options5);
lxw_table_options options6 = {.name = "R"};
worksheet_add_table(worksheet, RANGE("F3:G33"), &options6);
lxw_table_options options7 = {.name = ".Table"};
worksheet_add_table(worksheet, RANGE("F3:G33"), &options7);
lxw_table_options options8 = {.name = "1Table"};
worksheet_add_table(worksheet, RANGE("F3:G33"), &options8);
return workbook_close(workbook);
}

View file

@ -0,0 +1,106 @@
###############################################################################
#
# Tests for libxlsxwriter.
#
# Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
#
import base_test_class
class TestCompareXLSXFiles(base_test_class.XLSXBaseTest):
"""
Test file created with libxlsxwriter against a file created by Excel.
"""
def test_table01(self):
self.run_exe_test('test_table01')
def test_table02(self):
self.run_exe_test('test_table02')
def test_table03(self):
self.run_exe_test('test_table03')
def test_table04(self):
self.run_exe_test('test_table04')
def test_table05(self):
self.run_exe_test('test_table05')
def test_table06(self):
self.run_exe_test('test_table06')
def test_table07(self):
self.run_exe_test('test_table07')
def test_table08(self):
self.ignore_files = ['xl/calcChain.xml',
'[Content_Types].xml',
'xl/_rels/workbook.xml.rels']
self.run_exe_test('test_table08')
def test_table09(self):
self.ignore_files = ['xl/calcChain.xml',
'[Content_Types].xml',
'xl/_rels/workbook.xml.rels']
self.run_exe_test('test_table09')
def test_table10(self):
self.ignore_files = ['xl/calcChain.xml',
'[Content_Types].xml',
'xl/_rels/workbook.xml.rels']
self.run_exe_test('test_table10')
def test_table11(self):
self.run_exe_test('test_table11')
def test_table12(self):
self.run_exe_test('test_table12')
# Skip test_table13 since we can't set the dxf index for
# format_set_num_format_index() formats with C hash struct.
def test_table14(self):
self.run_exe_test('test_table14')
def test_table15(self):
self.run_exe_test('test_table15')
def test_table16(self):
self.run_exe_test('test_table16', 'table02.xlsx')
def test_table17(self):
self.ignore_files = ['xl/calcChain.xml',
'[Content_Types].xml',
'xl/_rels/workbook.xml.rels']
self.run_exe_test('test_table17')
def test_table18(self):
self.run_exe_test('test_table18')
def test_table19(self):
self.run_exe_test('test_table19')
# TODO. Duplicate names.
def test_table21(self):
self.run_exe_test('test_table21')
def test_table22(self):
self.run_exe_test('test_table22')
def test_table23(self):
self.ignore_files = ['xl/calcChain.xml',
'[Content_Types].xml',
'xl/_rels/workbook.xml.rels']
self.run_exe_test('test_table23')
def test_table24(self):
self.run_exe_test('test_table24')
def test_table25(self):
self.run_exe_test('test_table25')
def test_table26(self):
self.run_exe_test('test_table26')

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -41,6 +41,7 @@ SRCS += $(wildcard chartsheet/test*.c)
SRCS += $(wildcard vml/test*.c)
SRCS += $(wildcard comment/test*.c)
SRCS += $(wildcard metadata/test*.c)
SRCS += $(wildcard table/test*.c)
# End of SRCS
OBJS = $(patsubst %.c,%.o,$(SRCS))
@ -77,6 +78,7 @@ all :
$(Q)$(MAKE) -C vml
$(Q)$(MAKE) -C comment
$(Q)$(MAKE) -C metadata
$(Q)$(MAKE) -C table
# END make all
clean :
@ -98,6 +100,7 @@ clean :
$(Q)$(MAKE) clean -C vml
$(Q)$(MAKE) clean -C comment
$(Q)$(MAKE) clean -C metadata
$(Q)$(MAKE) clean -C table
# END make clean

8
test/unit/table/Makefile Normal file
View file

@ -0,0 +1,8 @@
###############################################################################
#
# Makefile for libxlsxwriter library.
#
# Copyright 2014-2015, John McNamara, jmcnamara@cpan.org
#
include ../Makefile.unit

15
test/unit/table/main.c Normal file
View file

@ -0,0 +1,15 @@
/*
* Test runner for xmlwriter using ctest.
*
* Copyright 2014-2021 John McNamara, jmcnamara@cpan.org
*
*/
#define CTEST_MAIN
#include "../ctest.h"
int main(int argc, const char *argv[])
{
return ctest_main(argc, argv);
}

View file

@ -0,0 +1,54 @@
/*
* Tests for the libxlsxwriter library.
*
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
*
*/
#include "../ctest.h"
#include "../helper.h"
#include "../../../include/xlsxwriter/worksheet.h"
#include "../../../include/xlsxwriter/table.h"
// Test assembling a complete Table file.
CTEST(worksheet, worksheet_table01) {
char* got;
char exp[] =
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
"<table xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" id=\"1\" name=\"Table1\" displayName=\"Table1\" ref=\"C3:F13\" totalsRowShown=\"0\">"
"<autoFilter ref=\"C3:F13\"/>"
"<tableColumns count=\"4\">"
"<tableColumn id=\"1\" name=\"Column1\"/>"
"<tableColumn id=\"2\" name=\"Column2\"/>"
"<tableColumn id=\"3\" name=\"Column3\"/>"
"<tableColumn id=\"4\" name=\"Column4\"/>"
"</tableColumns>"
"<tableStyleInfo name=\"TableStyleMedium9\" showFirstColumn=\"0\" showLastColumn=\"0\" showRowStripes=\"1\" showColumnStripes=\"0\"/>"
"</table>";
FILE* testfile = lxw_tmpfile(NULL);
FILE* testfile2 = lxw_tmpfile(NULL);
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
worksheet->file = testfile2;
worksheet->sst = lxw_sst_new();
lxw_table *table = lxw_table_new();
table->file = testfile;
worksheet_add_table(worksheet, RANGE("C3:F13"), NULL);
table->table_obj = STAILQ_FIRST(worksheet->table_objs);
table->table_obj->id = 1;
lxw_table_assemble_xml_file(table);
RUN_XLSX_STREQ_SHORT(exp, got);
lxw_worksheet_free(worksheet);
lxw_table_free(table);
}

View file

@ -0,0 +1,58 @@
/*
* Tests for the libxlsxwriter library.
*
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
*
*/
#include "../ctest.h"
#include "../helper.h"
#include "../../../include/xlsxwriter/worksheet.h"
#include "../../../include/xlsxwriter/table.h"
// Test assembling a complete Table file.
CTEST(worksheet, worksheet_table02) {
char* got;
char exp[] =
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
"<table xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" id=\"1\" name=\"Table1\" displayName=\"Table1\" ref=\"D4:I15\" totalsRowShown=\"0\">"
"<autoFilter ref=\"D4:I15\"/>"
"<tableColumns count=\"6\">"
"<tableColumn id=\"1\" name=\"Column1\"/>"
"<tableColumn id=\"2\" name=\"Column2\"/>"
"<tableColumn id=\"3\" name=\"Column3\"/>"
"<tableColumn id=\"4\" name=\"Column4\"/>"
"<tableColumn id=\"5\" name=\"Column5\"/>"
"<tableColumn id=\"6\" name=\"Column6\"/>"
"</tableColumns>"
"<tableStyleInfo name=\"TableStyleLight17\" showFirstColumn=\"0\" showLastColumn=\"0\" showRowStripes=\"1\" showColumnStripes=\"0\"/>"
"</table>";
FILE* testfile = lxw_tmpfile(NULL);
FILE* testfile2 = lxw_tmpfile(NULL);
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
worksheet->file = testfile2;
worksheet->sst = lxw_sst_new();
lxw_table *table = lxw_table_new();
table->file = testfile;
lxw_table_options options = {.style_type = LXW_TABLE_STYLE_TYPE_LIGHT, .style_type_number = 17};
worksheet_add_table(worksheet, RANGE("D4:I15"), &options);
table->table_obj = STAILQ_FIRST(worksheet->table_objs);
table->table_obj->id = 1;
lxw_table_assemble_xml_file(table);
RUN_XLSX_STREQ_SHORT(exp, got);
lxw_worksheet_free(worksheet);
lxw_table_free(table);
}

View file

@ -0,0 +1,54 @@
/*
* Tests for the libxlsxwriter library.
*
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
*
*/
#include "../ctest.h"
#include "../helper.h"
#include "../../../include/xlsxwriter/worksheet.h"
#include "../../../include/xlsxwriter/table.h"
// Test assembling a complete Table file.
CTEST(worksheet, worksheet_table03) {
char* got;
char exp[] =
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
"<table xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" id=\"1\" name=\"Table1\" displayName=\"Table1\" ref=\"C5:D16\" totalsRowShown=\"0\">"
"<autoFilter ref=\"C5:D16\"/>"
"<tableColumns count=\"2\">"
"<tableColumn id=\"1\" name=\"Column1\"/>"
"<tableColumn id=\"2\" name=\"Column2\"/>"
"</tableColumns>"
"<tableStyleInfo name=\"TableStyleMedium9\" showFirstColumn=\"1\" showLastColumn=\"1\" showRowStripes=\"0\" showColumnStripes=\"1\"/>"
"</table>";
FILE* testfile = lxw_tmpfile(NULL);
FILE* testfile2 = lxw_tmpfile(NULL);
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
worksheet->file = testfile2;
worksheet->sst = lxw_sst_new();
lxw_table *table = lxw_table_new();
table->file = testfile;
lxw_table_options options = {.first_column = LXW_TRUE, .last_column = LXW_TRUE, .no_banded_rows = LXW_TRUE, .banded_columns = LXW_TRUE};
worksheet_add_table(worksheet, RANGE("C5:D16"), &options);
table->table_obj = STAILQ_FIRST(worksheet->table_objs);
table->table_obj->id = 1;
lxw_table_assemble_xml_file(table);
RUN_XLSX_STREQ_SHORT(exp, got);
lxw_worksheet_free(worksheet);
lxw_table_free(table);
}

View file

@ -0,0 +1,55 @@
/*
* Tests for the libxlsxwriter library.
*
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
*
*/
#include "../ctest.h"
#include "../helper.h"
#include "../../../include/xlsxwriter/worksheet.h"
#include "../../../include/xlsxwriter/table.h"
// Test assembling a complete Table file.
CTEST(worksheet, worksheet_table04) {
char* got;
char exp[] =
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
"<table xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" id=\"1\" name=\"Table1\" displayName=\"Table1\" ref=\"C3:F13\" totalsRowShown=\"0\">"
"<tableColumns count=\"4\">"
"<tableColumn id=\"1\" name=\"Column1\"/>"
"<tableColumn id=\"2\" name=\"Column2\"/>"
"<tableColumn id=\"3\" name=\"Column3\"/>"
"<tableColumn id=\"4\" name=\"Column4\"/>"
"</tableColumns>"
"<tableStyleInfo name=\"TableStyleMedium9\" showFirstColumn=\"0\" showLastColumn=\"0\" showRowStripes=\"1\" showColumnStripes=\"0\"/>"
"</table>";
FILE* testfile = lxw_tmpfile(NULL);
FILE* testfile2 = lxw_tmpfile(NULL);
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
worksheet->file = testfile2;
worksheet->sst = lxw_sst_new();
lxw_table *table = lxw_table_new();
table->file = testfile;
lxw_table_options options = {.no_autofilter = LXW_TRUE};
worksheet_add_table(worksheet, RANGE("C3:F13"), &options);
table->table_obj = STAILQ_FIRST(worksheet->table_objs);
table->table_obj->id = 1;
lxw_table_assemble_xml_file(table);
RUN_XLSX_STREQ_SHORT(exp, got);
lxw_worksheet_free(worksheet);
lxw_table_free(table);
}

View file

@ -0,0 +1,55 @@
/*
* Tests for the libxlsxwriter library.
*
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
*
*/
#include "../ctest.h"
#include "../helper.h"
#include "../../../include/xlsxwriter/worksheet.h"
#include "../../../include/xlsxwriter/table.h"
// Test assembling a complete Table file.
CTEST(worksheet, worksheet_table05) {
char* got;
char exp[] =
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
"<table xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" id=\"1\" name=\"Table1\" displayName=\"Table1\" ref=\"C4:F13\" headerRowCount=\"0\" totalsRowShown=\"0\">"
"<tableColumns count=\"4\">"
"<tableColumn id=\"1\" name=\"Column1\"/>"
"<tableColumn id=\"2\" name=\"Column2\"/>"
"<tableColumn id=\"3\" name=\"Column3\"/>"
"<tableColumn id=\"4\" name=\"Column4\"/>"
"</tableColumns>"
"<tableStyleInfo name=\"TableStyleMedium9\" showFirstColumn=\"0\" showLastColumn=\"0\" showRowStripes=\"1\" showColumnStripes=\"0\"/>"
"</table>";
FILE* testfile = lxw_tmpfile(NULL);
FILE* testfile2 = lxw_tmpfile(NULL);
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
worksheet->file = testfile2;
worksheet->sst = lxw_sst_new();
lxw_table *table = lxw_table_new();
table->file = testfile;
lxw_table_options options = {.no_header_row = LXW_TRUE};
worksheet_add_table(worksheet, RANGE("C4:F13"), &options);
table->table_obj = STAILQ_FIRST(worksheet->table_objs);
table->table_obj->id = 1;
lxw_table_assemble_xml_file(table);
RUN_XLSX_STREQ_SHORT(exp, got);
lxw_worksheet_free(worksheet);
lxw_table_free(table);
}

View file

@ -0,0 +1,62 @@
/*
* Tests for the libxlsxwriter library.
*
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
*
*/
#include "../ctest.h"
#include "../helper.h"
#include "../../../include/xlsxwriter/worksheet.h"
#include "../../../include/xlsxwriter/table.h"
// Test assembling a complete Table file.
CTEST(worksheet, worksheet_table06) {
char* got;
char exp[] =
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
"<table xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" id=\"1\" name=\"Table1\" displayName=\"Table1\" ref=\"C3:F13\" totalsRowShown=\"0\">"
"<autoFilter ref=\"C3:F13\"/>"
"<tableColumns count=\"4\">"
"<tableColumn id=\"1\" name=\"Foo\"/>"
"<tableColumn id=\"2\" name=\"Column2\"/>"
"<tableColumn id=\"3\" name=\"Column3\"/>"
"<tableColumn id=\"4\" name=\"Baz\"/>"
"</tableColumns>"
"<tableStyleInfo name=\"TableStyleMedium9\" showFirstColumn=\"0\" showLastColumn=\"0\" showRowStripes=\"1\" showColumnStripes=\"0\"/>"
"</table>";
FILE* testfile = lxw_tmpfile(NULL);
FILE* testfile2 = lxw_tmpfile(NULL);
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
worksheet->file = testfile2;
worksheet->sst = lxw_sst_new();
lxw_table *table = lxw_table_new();
table->file = testfile;
lxw_table_column col1 = {.header = "Foo"};
lxw_table_column col2 = {0};
lxw_table_column col3 = {0};
lxw_table_column col4 = {.header = "Baz"};
lxw_table_column *columns[] = {&col1, &col2, &col3, &col4, NULL};
lxw_table_options options = {.columns = columns};
worksheet_add_table(worksheet, RANGE("C3:F13"), &options);
table->table_obj = STAILQ_FIRST(worksheet->table_objs);
table->table_obj->id = 1;
lxw_table_assemble_xml_file(table);
RUN_XLSX_STREQ_SHORT(exp, got);
lxw_worksheet_free(worksheet);
lxw_table_free(table);
}

View file

@ -0,0 +1,56 @@
/*
* Tests for the libxlsxwriter library.
*
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
*
*/
#include "../ctest.h"
#include "../helper.h"
#include "../../../include/xlsxwriter/worksheet.h"
#include "../../../include/xlsxwriter/table.h"
// Test assembling a complete Table file.
CTEST(worksheet, worksheet_table07) {
char* got;
char exp[] =
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
"<table xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" id=\"1\" name=\"Table1\" displayName=\"Table1\" ref=\"C3:F14\" totalsRowCount=\"1\">"
"<autoFilter ref=\"C3:F13\"/>"
"<tableColumns count=\"4\">"
"<tableColumn id=\"1\" name=\"Column1\"/>"
"<tableColumn id=\"2\" name=\"Column2\"/>"
"<tableColumn id=\"3\" name=\"Column3\"/>"
"<tableColumn id=\"4\" name=\"Column4\"/>"
"</tableColumns>"
"<tableStyleInfo name=\"TableStyleMedium9\" showFirstColumn=\"0\" showLastColumn=\"0\" showRowStripes=\"1\" showColumnStripes=\"0\"/>"
"</table>";
FILE* testfile = lxw_tmpfile(NULL);
FILE* testfile2 = lxw_tmpfile(NULL);
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
worksheet->file = testfile2;
worksheet->sst = lxw_sst_new();
lxw_table *table = lxw_table_new();
table->file = testfile;
lxw_table_options options = {.total_row = LXW_TRUE};
worksheet_add_table(worksheet, RANGE("C3:F14"), &options);
table->table_obj = STAILQ_FIRST(worksheet->table_objs);
table->table_obj->id = 1;
lxw_table_assemble_xml_file(table);
RUN_XLSX_STREQ_SHORT(exp, got);
lxw_worksheet_free(worksheet);
lxw_table_free(table);
}

View file

@ -0,0 +1,62 @@
/*
* Tests for the libxlsxwriter library.
*
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
*
*/
#include "../ctest.h"
#include "../helper.h"
#include "../../../include/xlsxwriter/worksheet.h"
#include "../../../include/xlsxwriter/table.h"
// Test assembling a complete Table file.
CTEST(worksheet, worksheet_table08) {
char* got;
char exp[] =
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
"<table xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" id=\"1\" name=\"Table1\" displayName=\"Table1\" ref=\"C3:F14\" totalsRowCount=\"1\">"
"<autoFilter ref=\"C3:F13\"/>"
"<tableColumns count=\"4\">"
"<tableColumn id=\"1\" name=\"Column1\" totalsRowLabel=\"Total\"/>"
"<tableColumn id=\"2\" name=\"Column2\"/>"
"<tableColumn id=\"3\" name=\"Column3\"/>"
"<tableColumn id=\"4\" name=\"Column4\" totalsRowFunction=\"count\"/>"
"</tableColumns>"
"<tableStyleInfo name=\"TableStyleMedium9\" showFirstColumn=\"0\" showLastColumn=\"0\" showRowStripes=\"1\" showColumnStripes=\"0\"/>"
"</table>";
FILE* testfile = lxw_tmpfile(NULL);
FILE* testfile2 = lxw_tmpfile(NULL);
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
worksheet->file = testfile2;
worksheet->sst = lxw_sst_new();
lxw_table *table = lxw_table_new();
table->file = testfile;
lxw_table_column col1 = {.total_string = "Total"};
lxw_table_column col2 = {0};
lxw_table_column col3 = {0};
lxw_table_column col4 = {.total_function = LXW_TABLE_FUNCTION_COUNT};
lxw_table_column *columns[] = {&col1, &col2, &col3, &col4, NULL};
lxw_table_options options = {.total_row = LXW_TRUE, .columns = columns};
worksheet_add_table(worksheet, RANGE("C3:F14"), &options);
table->table_obj = STAILQ_FIRST(worksheet->table_objs);
table->table_obj->id = 1;
lxw_table_assemble_xml_file(table);
RUN_XLSX_STREQ_SHORT(exp, got);
lxw_worksheet_free(worksheet);
lxw_table_free(table);
}

View file

@ -0,0 +1,75 @@
/*
* Tests for the libxlsxwriter library.
*
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
*
*/
#include "../ctest.h"
#include "../helper.h"
#include "../../../include/xlsxwriter/worksheet.h"
#include "../../../include/xlsxwriter/table.h"
// Test assembling a complete Table file.
CTEST(worksheet, worksheet_table09) {
char* got;
char exp[] =
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
"<table xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" id=\"1\" name=\"Table1\" displayName=\"Table1\" ref=\"B2:K8\" totalsRowCount=\"1\">"
"<autoFilter ref=\"B2:K7\"/>"
"<tableColumns count=\"10\">"
"<tableColumn id=\"1\" name=\"Column1\" totalsRowLabel=\"Total\"/>"
"<tableColumn id=\"2\" name=\"Column2\"/>"
"<tableColumn id=\"3\" name=\"Column3\" totalsRowFunction=\"average\"/>"
"<tableColumn id=\"4\" name=\"Column4\" totalsRowFunction=\"count\"/>"
"<tableColumn id=\"5\" name=\"Column5\" totalsRowFunction=\"countNums\"/>"
"<tableColumn id=\"6\" name=\"Column6\" totalsRowFunction=\"max\"/>"
"<tableColumn id=\"7\" name=\"Column7\" totalsRowFunction=\"min\"/>"
"<tableColumn id=\"8\" name=\"Column8\" totalsRowFunction=\"sum\"/>"
"<tableColumn id=\"9\" name=\"Column9\" totalsRowFunction=\"stdDev\"/>"
"<tableColumn id=\"10\" name=\"Column10\" totalsRowFunction=\"var\"/>"
"</tableColumns>"
"<tableStyleInfo name=\"TableStyleMedium9\" showFirstColumn=\"0\" showLastColumn=\"0\" showRowStripes=\"1\" showColumnStripes=\"0\"/>"
"</table>";
FILE* testfile = lxw_tmpfile(NULL);
FILE* testfile2 = lxw_tmpfile(NULL);
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
worksheet->file = testfile2;
worksheet->sst = lxw_sst_new();
lxw_table *table = lxw_table_new();
table->file = testfile;
lxw_table_column col1 = {.total_string = "Total"};
lxw_table_column col2 = {0};
lxw_table_column col3 = {.total_function = LXW_TABLE_FUNCTION_AVERAGE};
lxw_table_column col4 = {.total_function = LXW_TABLE_FUNCTION_COUNT};
lxw_table_column col5 = {.total_function = LXW_TABLE_FUNCTION_COUNT_NUMS};
lxw_table_column col6 = {.total_function = LXW_TABLE_FUNCTION_MAX};
lxw_table_column col7 = {.total_function = LXW_TABLE_FUNCTION_MIN};
lxw_table_column col8 = {.total_function = LXW_TABLE_FUNCTION_SUM};
lxw_table_column col9 = {.total_function = LXW_TABLE_FUNCTION_STD_DEV};
lxw_table_column col10 = {.total_function = LXW_TABLE_FUNCTION_VAR};
lxw_table_column *columns[] = {&col1, &col2, &col3, &col4, &col5, &col6, &col7, &col8, &col9, &col10, NULL};
lxw_table_options options = {.total_row = LXW_TRUE, .columns = columns};
worksheet_add_table(worksheet, RANGE("B2:K8"), &options);
table->table_obj = STAILQ_FIRST(worksheet->table_objs);
table->table_obj->id = 1;
lxw_table_assemble_xml_file(table);
RUN_XLSX_STREQ_SHORT(exp, got);
lxw_worksheet_free(worksheet);
lxw_table_free(table);
}

View file

@ -0,0 +1,56 @@
/*
* Tests for the libxlsxwriter library.
*
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
*
*/
#include "../ctest.h"
#include "../helper.h"
#include "../../../include/xlsxwriter/worksheet.h"
#include "../../../include/xlsxwriter/table.h"
// Test assembling a complete Table file.
CTEST(worksheet, worksheet_table10) {
char* got;
char exp[] =
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
"<table xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" id=\"1\" name=\"MyTable\" displayName=\"MyTable\" ref=\"C2:F13\" totalsRowShown=\"0\">"
"<autoFilter ref=\"C2:F13\"/>"
"<tableColumns count=\"4\">"
"<tableColumn id=\"1\" name=\"Column1\"/>"
"<tableColumn id=\"2\" name=\"Column2\"/>"
"<tableColumn id=\"3\" name=\"Column3\"/>"
"<tableColumn id=\"4\" name=\"Column4\"/>"
"</tableColumns>"
"<tableStyleInfo name=\"TableStyleMedium9\" showFirstColumn=\"0\" showLastColumn=\"0\" showRowStripes=\"1\" showColumnStripes=\"0\"/>"
"</table>";
FILE* testfile = lxw_tmpfile(NULL);
FILE* testfile2 = lxw_tmpfile(NULL);
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
worksheet->file = testfile2;
worksheet->sst = lxw_sst_new();
lxw_table *table = lxw_table_new();
table->file = testfile;
lxw_table_options options = {.name = "MyTable"};
worksheet_add_table(worksheet, RANGE("C2:F13"), &options);
table->table_obj = STAILQ_FIRST(worksheet->table_objs);
table->table_obj->id = 1;
lxw_table_assemble_xml_file(table);
RUN_XLSX_STREQ_SHORT(exp, got);
lxw_worksheet_free(worksheet);
lxw_table_free(table);
}

View file

@ -0,0 +1,56 @@
/*
* Tests for the libxlsxwriter library.
*
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
*
*/
#include "../ctest.h"
#include "../helper.h"
#include "../../../include/xlsxwriter/worksheet.h"
#include "../../../include/xlsxwriter/table.h"
// Test assembling a complete Table file.
CTEST(worksheet, worksheet_table11) {
char* got;
char exp[] =
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
"<table xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" id=\"1\" name=\"Table1\" displayName=\"Table1\" ref=\"C3:F13\" totalsRowShown=\"0\">"
"<autoFilter ref=\"C3:F13\"/>"
"<tableColumns count=\"4\">"
"<tableColumn id=\"1\" name=\"Column1\"/>"
"<tableColumn id=\"2\" name=\"Column2\"/>"
"<tableColumn id=\"3\" name=\"Column3\"/>"
"<tableColumn id=\"4\" name=\"Column4\"/>"
"</tableColumns>"
"<tableStyleInfo showFirstColumn=\"0\" showLastColumn=\"0\" showRowStripes=\"1\" showColumnStripes=\"0\"/>"
"</table>";
FILE* testfile = lxw_tmpfile(NULL);
FILE* testfile2 = lxw_tmpfile(NULL);
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
worksheet->file = testfile2;
worksheet->sst = lxw_sst_new();
lxw_table *table = lxw_table_new();
table->file = testfile;
lxw_table_options options = {.style_type = LXW_TABLE_STYLE_TYPE_LIGHT, .style_type_number = 0};
worksheet_add_table(worksheet, RANGE("C3:F13"), &options);
table->table_obj = STAILQ_FIRST(worksheet->table_objs);
table->table_obj->id = 1;
lxw_table_assemble_xml_file(table);
RUN_XLSX_STREQ_SHORT(exp, got);
lxw_worksheet_free(worksheet);
lxw_table_free(table);
}

View file

@ -0,0 +1,56 @@
/*
* Tests for the libxlsxwriter library.
*
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
*
*/
#include "../ctest.h"
#include "../helper.h"
#include "../../../include/xlsxwriter/worksheet.h"
#include "../../../include/xlsxwriter/table.h"
// Test assembling a complete Table file.
CTEST(worksheet, worksheet_table12) {
char* got;
char exp[] =
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
"<table xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" id=\"1\" name=\"Table1\" displayName=\"Table1\" ref=\"C3:F13\" totalsRowShown=\"0\">"
"<autoFilter ref=\"C3:F13\"/>"
"<tableColumns count=\"4\">"
"<tableColumn id=\"1\" name=\"Column1\"/>"
"<tableColumn id=\"2\" name=\"Column2\"/>"
"<tableColumn id=\"3\" name=\"Column3\"/>"
"<tableColumn id=\"4\" name=\"Column4\"/>"
"</tableColumns>"
"<tableStyleInfo name=\"TableStyleMedium1\" showFirstColumn=\"0\" showLastColumn=\"0\" showRowStripes=\"1\" showColumnStripes=\"0\"/>"
"</table>";
FILE* testfile = lxw_tmpfile(NULL);
FILE* testfile2 = lxw_tmpfile(NULL);
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
worksheet->file = testfile2;
worksheet->sst = lxw_sst_new();
lxw_table *table = lxw_table_new();
table->file = testfile;
lxw_table_options options = {.style_type = LXW_TABLE_STYLE_TYPE_MEDIUM, .style_type_number = 1};
worksheet_add_table(worksheet, RANGE("C3:F13"), &options);
table->table_obj = STAILQ_FIRST(worksheet->table_objs);
table->table_obj->id = 1;
lxw_table_assemble_xml_file(table);
RUN_XLSX_STREQ_SHORT(exp, got);
lxw_worksheet_free(worksheet);
lxw_table_free(table);
}

View file

@ -0,0 +1,56 @@
/*
* Tests for the libxlsxwriter library.
*
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
*
*/
#include "../ctest.h"
#include "../helper.h"
#include "../../../include/xlsxwriter/worksheet.h"
#include "../../../include/xlsxwriter/table.h"
// Test assembling a complete Table file.
CTEST(worksheet, worksheet_table13) {
char* got;
char exp[] =
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
"<table xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" id=\"1\" name=\"Table1\" displayName=\"Table1\" ref=\"C3:F13\" totalsRowShown=\"0\">"
"<autoFilter ref=\"C3:F13\"/>"
"<tableColumns count=\"4\">"
"<tableColumn id=\"1\" name=\"Column1\"/>"
"<tableColumn id=\"2\" name=\"Column2\"/>"
"<tableColumn id=\"3\" name=\"Column3\"/>"
"<tableColumn id=\"4\" name=\"Column4\"/>"
"</tableColumns>"
"<tableStyleInfo name=\"TableStyleDark11\" showFirstColumn=\"0\" showLastColumn=\"0\" showRowStripes=\"1\" showColumnStripes=\"0\"/>"
"</table>";
FILE* testfile = lxw_tmpfile(NULL);
FILE* testfile2 = lxw_tmpfile(NULL);
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
worksheet->file = testfile2;
worksheet->sst = lxw_sst_new();
lxw_table *table = lxw_table_new();
table->file = testfile;
lxw_table_options options = {.style_type = LXW_TABLE_STYLE_TYPE_DARK, .style_type_number = 11};
worksheet_add_table(worksheet, RANGE("C3:F13"), &options);
table->table_obj = STAILQ_FIRST(worksheet->table_objs);
table->table_obj->id = 1;
lxw_table_assemble_xml_file(table);
RUN_XLSX_STREQ_SHORT(exp, got);
lxw_worksheet_free(worksheet);
lxw_table_free(table);
}

View file

@ -0,0 +1,72 @@
/*
* Tests for the libxlsxwriter library.
*
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
*
*/
#include "../ctest.h"
#include "../helper.h"
#include "../../../include/xlsxwriter/worksheet.h"
#include "../../../include/xlsxwriter/table.h"
// Test assembling a complete Table file.
CTEST(worksheet, worksheet_table14) {
char* got;
char exp[] =
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
"<table xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" id=\"1\" name=\"Table1\" displayName=\"Table1\" ref=\"B3:G7\" totalsRowShown=\"0\">"
"<autoFilter ref=\"B3:G7\"/>"
"<tableColumns count=\"6\">"
"<tableColumn id=\"1\" name=\"Product\"/>"
"<tableColumn id=\"2\" name=\"Quarter 1\"/>"
"<tableColumn id=\"3\" name=\"Quarter 2\"/>"
"<tableColumn id=\"4\" name=\"Quarter 3\"/>"
"<tableColumn id=\"5\" name=\"Quarter 4\"/>"
"<tableColumn id=\"6\" name=\"Year\">"
"<calculatedColumnFormula>SUM(Table1[[#This Row],[Quarter 1]:[Quarter 4]])</calculatedColumnFormula>"
"</tableColumn>"
"</tableColumns>"
"<tableStyleInfo name=\"TableStyleMedium9\" showFirstColumn=\"0\" showLastColumn=\"0\" showRowStripes=\"1\" showColumnStripes=\"0\"/>"
"</table>";
FILE* testfile = lxw_tmpfile(NULL);
FILE* testfile2 = lxw_tmpfile(NULL);
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
worksheet->file = testfile2;
worksheet->sst = lxw_sst_new();
lxw_table *table = lxw_table_new();
table->file = testfile;
/* Set the table options. */
lxw_table_column col8_1 = {.header = "Product"};
lxw_table_column col8_2 = {.header = "Quarter 1"};
lxw_table_column col8_3 = {.header = "Quarter 2"};
lxw_table_column col8_4 = {.header = "Quarter 3"};
lxw_table_column col8_5 = {.header = "Quarter 4"};
lxw_table_column col8_6 = {.header = "Year",
.formula = "=SUM(Table1[@[Quarter 1]:[Quarter 4]])"};
lxw_table_column *columns8[] = {&col8_1, &col8_2, &col8_3, &col8_4, &col8_5, &col8_6, NULL};
lxw_table_options options8 = {.columns = columns8};
/* Add a table to the worksheet. */
worksheet_add_table(worksheet, RANGE("B3:G7"), &options8);
table->table_obj = STAILQ_FIRST(worksheet->table_objs);
table->table_obj->id = 1;
lxw_table_assemble_xml_file(table);
RUN_XLSX_STREQ_SHORT(exp, got);
lxw_worksheet_free(worksheet);
lxw_table_free(table);
}

View file

@ -0,0 +1,72 @@
/*
* Tests for the libxlsxwriter library.
*
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
*
*/
#include "../ctest.h"
#include "../helper.h"
#include "../../../include/xlsxwriter/worksheet.h"
#include "../../../include/xlsxwriter/table.h"
// Test assembling a complete Table file.
CTEST(worksheet, worksheet_table15) {
char* got;
char exp[] =
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
"<table xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" id=\"1\" name=\"Table1\" displayName=\"Table1\" ref=\"B3:G7\" totalsRowShown=\"0\">"
"<autoFilter ref=\"B3:G7\"/>"
"<tableColumns count=\"6\">"
"<tableColumn id=\"1\" name=\"Product\"/>"
"<tableColumn id=\"2\" name=\"Quarter 1\"/>"
"<tableColumn id=\"3\" name=\"Quarter 2\"/>"
"<tableColumn id=\"4\" name=\"Quarter 3\"/>"
"<tableColumn id=\"5\" name=\"Quarter 4\"/>"
"<tableColumn id=\"6\" name=\"Year\">"
"<calculatedColumnFormula>[#This Row],[#This Row], [#This Row], [#This Row],[#This Row],</calculatedColumnFormula>"
"</tableColumn>"
"</tableColumns>"
"<tableStyleInfo name=\"TableStyleMedium9\" showFirstColumn=\"0\" showLastColumn=\"0\" showRowStripes=\"1\" showColumnStripes=\"0\"/>"
"</table>";
FILE* testfile = lxw_tmpfile(NULL);
FILE* testfile2 = lxw_tmpfile(NULL);
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
worksheet->file = testfile2;
worksheet->sst = lxw_sst_new();
lxw_table *table = lxw_table_new();
table->file = testfile;
/* Set the table options. */
lxw_table_column col8_1 = {.header = "Product"};
lxw_table_column col8_2 = {.header = "Quarter 1"};
lxw_table_column col8_3 = {.header = "Quarter 2"};
lxw_table_column col8_4 = {.header = "Quarter 3"};
lxw_table_column col8_5 = {.header = "Quarter 4"};
lxw_table_column col8_6 = {.header = "Year",
.formula = "@@ @ @@"};
lxw_table_column *columns8[] = {&col8_1, &col8_2, &col8_3, &col8_4, &col8_5, &col8_6, NULL};
lxw_table_options options8 = {.columns = columns8};
/* Add a table to the worksheet. */
worksheet_add_table(worksheet, RANGE("B3:G7"), &options8);
table->table_obj = STAILQ_FIRST(worksheet->table_objs);
table->table_obj->id = 1;
lxw_table_assemble_xml_file(table);
RUN_XLSX_STREQ_SHORT(exp, got);
lxw_worksheet_free(worksheet);
lxw_table_free(table);
}

View file

@ -0,0 +1,28 @@
/*
* Tests for the libxlsxwriter library.
*
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
*
*/
#include "../ctest.h"
#include "../helper.h"
#include "xlsxwriter/table.h"
// Test _xml_declaration().
CTEST(table, xml_declaration) {
char* got;
char exp[] = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n";
FILE* testfile = tmpfile();
lxw_table *table = lxw_table_new();
table->file = testfile;
_table_xml_declaration(table);
RUN_XLSX_STREQ(exp, got);
lxw_table_free(table);
}