worksheet: add extra tests for sheet name quoting

This commit is contained in:
John McNamara 2024-06-22 21:00:48 +01:00
parent f483e65f2e
commit f2084bcf78
15 changed files with 383 additions and 0 deletions

View File

@ -0,0 +1,51 @@
/*****************************************************************************
* Test cases for libxlsxwriter.
*
* Test to compare output against Excel files.
*
* Copyright 2014-2024, John McNamara, jmcnamara@cpan.org
*
*/
#include "xlsxwriter.h"
int main()
{
lxw_workbook *workbook = workbook_new("test_quote_name01.xlsx");
uint8_t data[5][3] = {
{1, 2, 3},
{2, 4, 6},
{3, 6, 9},
{4, 8, 12},
{5, 10, 15}};
char *sheetnames[] = {
"Sheet 1",
"Sheet 2",
"Sheet!3",
"Sheet\"4",
"Sheet#5",
"Sheet$6",
"Sheet%7",
"Sheet&8",
};
for (int i = 0; i < 8; i++)
{
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, sheetnames[i]);
for (int row = 0; row < 5; row++)
for (int col = 0; col < 3; col++)
worksheet_write_number(worksheet, row, col, data[row][col], NULL);
lxw_chart *chart = workbook_add_chart(workbook, LXW_CHART_PIE);
lxw_chart_series *series = chart_add_series(chart, NULL, NULL);
chart_series_set_values(series, sheetnames[i], 0, 0, 4, 0);
lxw_chart_options options = {.x_offset = 26, .y_offset = 17};
worksheet_insert_chart_opt(worksheet, CELL("E6"), chart, &options);
}
return workbook_close(workbook);
}

View File

@ -0,0 +1,51 @@
/*****************************************************************************
* Test cases for libxlsxwriter.
*
* Test to compare output against Excel files.
*
* Copyright 2014-2024, John McNamara, jmcnamara@cpan.org
*
*/
#include "xlsxwriter.h"
int main()
{
lxw_workbook *workbook = workbook_new("test_quote_name02.xlsx");
uint8_t data[5][3] = {
{1, 2, 3},
{2, 4, 6},
{3, 6, 9},
{4, 8, 12},
{5, 10, 15}};
char *sheetnames[] = {
"Sheet'1",
"S'heet'2",
"Sheet(3",
"Sheet)4",
"Sheet+5",
"Sheet,6",
"Sheet-7",
"Sheet;8",
};
for (int i = 0; i < 8; i++)
{
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, sheetnames[i]);
for (int row = 0; row < 5; row++)
for (int col = 0; col < 3; col++)
worksheet_write_number(worksheet, row, col, data[row][col], NULL);
lxw_chart *chart = workbook_add_chart(workbook, LXW_CHART_PIE);
lxw_chart_series *series = chart_add_series(chart, NULL, NULL);
chart_series_set_values(series, sheetnames[i], 0, 0, 4, 0);
lxw_chart_options options = {.x_offset = 26, .y_offset = 17};
worksheet_insert_chart_opt(worksheet, CELL("E6"), chart, &options);
}
return workbook_close(workbook);
}

View File

@ -0,0 +1,51 @@
/*****************************************************************************
* Test cases for libxlsxwriter.
*
* Test to compare output against Excel files.
*
* Copyright 2014-2024, John McNamara, jmcnamara@cpan.org
*
*/
#include "xlsxwriter.h"
int main()
{
lxw_workbook *workbook = workbook_new("test_quote_name03.xlsx");
uint8_t data[5][3] = {
{1, 2, 3},
{2, 4, 6},
{3, 6, 9},
{4, 8, 12},
{5, 10, 15}};
char *sheetnames[] = {
"Sheet<1",
"Sheet>2",
"Sheet=3",
"Sheet@4",
"Sheet^5",
"Sheet`6",
"Sheet_7",
"Sheet~8",
};
for (int i = 0; i < 8; i++)
{
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, sheetnames[i]);
for (int row = 0; row < 5; row++) for (int col = 0; col < 3; col++)
worksheet_write_number(worksheet, row, col, data[row][col], NULL);
lxw_chart *chart = workbook_add_chart(workbook, LXW_CHART_PIE);
lxw_chart_series *series = chart_add_series(chart, NULL, NULL);
chart_series_set_values(series, sheetnames[i], 0, 0, 4, 0);
lxw_chart_options options = {.x_offset = 26, .y_offset = 17};
worksheet_insert_chart_opt(worksheet, CELL("E6"), chart, &options);
}
return workbook_close(workbook);
}

View File

@ -0,0 +1,41 @@
/*****************************************************************************
* Test cases for libxlsxwriter.
*
* Test to compare output against Excel files.
*
* Copyright 2014-2024, John McNamara, jmcnamara@cpan.org
*
*/
#include "xlsxwriter.h"
int main()
{
lxw_workbook *workbook = workbook_new("test_quote_name04.xlsx");
uint8_t data[5][3] = {
{1, 2, 3},
{2, 4, 6},
{3, 6, 9},
{4, 8, 12},
{5, 10, 15}};
char *sheetname = "Sheet 1";
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, sheetname);
for (int row = 0; row < 5; row++)
for (int col = 0; col < 3; col++)
worksheet_write_number(worksheet, row, col, data[row][col], NULL);
lxw_chart *chart = workbook_add_chart(workbook, LXW_CHART_PIE);
lxw_chart_series *series = chart_add_series(chart, NULL, NULL);
chart_series_set_values(series, sheetname, 0, 0, 4, 0);
chart_series_set_name_range(series, sheetname, 0, 0);
chart_title_set_name(chart, "Foo");
worksheet_insert_chart(worksheet, CELL("E9"), chart);
return workbook_close(workbook);
}

View File

@ -0,0 +1,51 @@
/*****************************************************************************
* Test cases for libxlsxwriter.
*
* Test to compare output against Excel files.
*
* Copyright 2014-2024, John McNamara, jmcnamara@cpan.org
*
*/
#include "xlsxwriter.h"
int main()
{
lxw_workbook *workbook = workbook_new("test_quote_name05.xlsx");
char *sheetname = "Sheet1";
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, sheetname);
lxw_chart *chart = workbook_add_chart(workbook, LXW_CHART_COLUMN);
/* For testing, copy the randomly generated axis ids in the target file. */
chart->axis_id_1 = 54437760;
chart->axis_id_2 = 59195776;
uint8_t data[5][3] = {
{1, 2, 3},
{2, 4, 6},
{3, 6, 9},
{4, 8, 12},
{5, 10, 15}};
int row, col;
for (row = 0; row < 5; row++)
for (col = 0; col < 3; col++)
worksheet_write_number(worksheet, row, col, data[row][col], NULL);
worksheet_repeat_rows(worksheet, 0, 1);
worksheet_set_portrait(worksheet);
worksheet->vertical_dpi = 200;
lxw_chart_series *series1 = chart_add_series(chart, NULL, NULL);
lxw_chart_series *series2 = chart_add_series(chart, NULL, NULL);
lxw_chart_series *series3 = chart_add_series(chart, NULL, NULL);
chart_series_set_values(series1, sheetname, 0, 0, 4, 0);
chart_series_set_values(series2, sheetname, 0, 1, 4, 1);
chart_series_set_values(series3, sheetname, 0, 2, 4, 2);
worksheet_insert_chart(worksheet, CELL("E9"), chart);
return workbook_close(workbook);
}

View File

@ -0,0 +1,51 @@
/*****************************************************************************
* Test cases for libxlsxwriter.
*
* Test to compare output against Excel files.
*
* Copyright 2014-2024, John McNamara, jmcnamara@cpan.org
*
*/
#include "xlsxwriter.h"
int main()
{
lxw_workbook *workbook = workbook_new("test_quote_name06.xlsx");
char *sheetname = "Sheet-1";
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, sheetname);
lxw_chart *chart = workbook_add_chart(workbook, LXW_CHART_COLUMN);
/* For testing, copy the randomly generated axis ids in the target file. */
chart->axis_id_1 = 62284544;
chart->axis_id_2 = 83429248;
uint8_t data[5][3] = {
{1, 2, 3},
{2, 4, 6},
{3, 6, 9},
{4, 8, 12},
{5, 10, 15}};
int row, col;
for (row = 0; row < 5; row++)
for (col = 0; col < 3; col++)
worksheet_write_number(worksheet, row, col, data[row][col], NULL);
worksheet_repeat_rows(worksheet, 0, 1);
worksheet_set_portrait(worksheet);
worksheet->vertical_dpi = 200;
lxw_chart_series *series1 = chart_add_series(chart, NULL, NULL);
lxw_chart_series *series2 = chart_add_series(chart, NULL, NULL);
lxw_chart_series *series3 = chart_add_series(chart, NULL, NULL);
chart_series_set_values(series1, sheetname, 0, 0, 4, 0);
chart_series_set_values(series2, sheetname, 0, 1, 4, 1);
chart_series_set_values(series3, sheetname, 0, 2, 4, 2);
worksheet_insert_chart(worksheet, CELL("E9"), chart);
return workbook_close(workbook);
}

View File

@ -0,0 +1,51 @@
/*****************************************************************************
* Test cases for libxlsxwriter.
*
* Test to compare output against Excel files.
*
* Copyright 2014-2024, John McNamara, jmcnamara@cpan.org
*
*/
#include "xlsxwriter.h"
int main()
{
lxw_workbook *workbook = workbook_new("test_quote_name07.xlsx");
char *sheetname = "Sheet'1";
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, sheetname);
lxw_chart *chart = workbook_add_chart(workbook, LXW_CHART_COLUMN);
/* For testing, copy the randomly generated axis ids in the target file. */
chart->axis_id_1 = 48135552;
chart->axis_id_2 = 54701056;
uint8_t data[5][3] = {
{1, 2, 3},
{2, 4, 6},
{3, 6, 9},
{4, 8, 12},
{5, 10, 15}};
int row, col;
for (row = 0; row < 5; row++)
for (col = 0; col < 3; col++)
worksheet_write_number(worksheet, row, col, data[row][col], NULL);
worksheet_repeat_rows(worksheet, 0, 1);
worksheet_set_portrait(worksheet);
worksheet->vertical_dpi = 200;
lxw_chart_series *series1 = chart_add_series(chart, NULL, NULL);
lxw_chart_series *series2 = chart_add_series(chart, NULL, NULL);
lxw_chart_series *series3 = chart_add_series(chart, NULL, NULL);
chart_series_set_values(series1, sheetname, 0, 0, 4, 0);
chart_series_set_values(series2, sheetname, 0, 1, 4, 1);
chart_series_set_values(series3, sheetname, 0, 2, 4, 2);
worksheet_insert_chart(worksheet, CELL("E9"), chart);
return workbook_close(workbook);
}

View File

@ -0,0 +1,36 @@
###############################################################################
#
# Tests for libxlsxwriter.
#
# SPDX-License-Identifier: BSD-2-Clause
# Copyright 2014-2024, 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_quote_name01(self):
self.run_exe_test('test_quote_name01')
def test_quote_name02(self):
self.run_exe_test('test_quote_name02')
def test_quote_name03(self):
self.run_exe_test('test_quote_name03')
def test_quote_name04(self):
self.run_exe_test('test_quote_name04')
def test_quote_name05(self):
self.run_exe_test('test_quote_name05')
def test_quote_name06(self):
self.run_exe_test('test_quote_name06')
def test_quote_name07(self):
self.run_exe_test('test_quote_name07')

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.