初始化PHP-Xlswrite扩展
This commit is contained in:
15
library/libxlsxwriter/test/unit/worksheet/main.c
Normal file
15
library/libxlsxwriter/test/unit/worksheet/main.c
Normal 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);
|
||||
}
|
||||
|
137
library/libxlsxwriter/test/unit/worksheet/test_worksheet.c
Normal file
137
library/libxlsxwriter/test/unit/worksheet/test_worksheet.c
Normal file
@ -0,0 +1,137 @@
|
||||
/*
|
||||
* Tests for the lib_xlsx_writer library.
|
||||
*
|
||||
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
|
||||
*
|
||||
*/
|
||||
|
||||
#include "../ctest.h"
|
||||
#include "../helper.h"
|
||||
|
||||
#include "../../../include/xlsxwriter/worksheet.h"
|
||||
#include "../../../include/xlsxwriter/shared_strings.h"
|
||||
|
||||
// Test assembling a complete Worksheet file.
|
||||
CTEST(worksheet, worksheet01) {
|
||||
|
||||
char* got;
|
||||
char exp[] =
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
|
||||
"<worksheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\">"
|
||||
"<dimension ref=\"A1\"/>"
|
||||
"<sheetViews>"
|
||||
"<sheetView tabSelected=\"1\" workbookViewId=\"0\"/>"
|
||||
"</sheetViews>"
|
||||
"<sheetFormatPr defaultRowHeight=\"15\"/>"
|
||||
"<sheetData/>"
|
||||
"<pageMargins left=\"0.7\" right=\"0.7\" top=\"0.75\" bottom=\"0.75\" header=\"0.3\" footer=\"0.3\"/>"
|
||||
"</worksheet>";
|
||||
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
worksheet_select(worksheet);
|
||||
|
||||
lxw_worksheet_assemble_xml_file(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ_SHORT(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
// Test assembling a complete Worksheet file.
|
||||
CTEST(worksheet, worksheet02) {
|
||||
|
||||
char* got;
|
||||
char exp[] =
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
|
||||
"<worksheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\">"
|
||||
"<dimension ref=\"A1\"/>"
|
||||
"<sheetViews>"
|
||||
"<sheetView tabSelected=\"1\" workbookViewId=\"0\"/>"
|
||||
"</sheetViews>"
|
||||
"<sheetFormatPr defaultRowHeight=\"15\"/>"
|
||||
"<sheetData>"
|
||||
"<row r=\"1\" spans=\"1:1\">"
|
||||
"<c r=\"A1\">"
|
||||
"<v>123</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"</sheetData>"
|
||||
"<pageMargins left=\"0.7\" right=\"0.7\" top=\"0.75\" bottom=\"0.75\" header=\"0.3\" footer=\"0.3\"/>"
|
||||
"</worksheet>";
|
||||
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
worksheet_select(worksheet);
|
||||
|
||||
worksheet_write_number(worksheet, 0, 0, 123, NULL);
|
||||
|
||||
lxw_worksheet_assemble_xml_file(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ_SHORT(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
// Test assembling a complete Worksheet file.
|
||||
CTEST(worksheet, worksheet03) {
|
||||
|
||||
char* got;
|
||||
char exp[] =
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
|
||||
"<worksheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\">"
|
||||
"<dimension ref=\"A1:E9\"/>"
|
||||
"<sheetViews>"
|
||||
"<sheetView tabSelected=\"1\" workbookViewId=\"0\"/>"
|
||||
"</sheetViews>"
|
||||
"<sheetFormatPr defaultRowHeight=\"15\"/>"
|
||||
"<sheetData>"
|
||||
"<row r=\"1\" spans=\"1:5\">"
|
||||
"<c r=\"A1\" t=\"s\">"
|
||||
"<v>0</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"2\" spans=\"1:5\">"
|
||||
"<c r=\"C2\">"
|
||||
"<v>123</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"4\" spans=\"1:5\">"
|
||||
"<c r=\"B4\" t=\"s\">"
|
||||
"<v>1</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"9\" spans=\"1:5\">"
|
||||
"<c r=\"E9\">"
|
||||
"<v>890</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"</sheetData>"
|
||||
"<pageMargins left=\"0.7\" right=\"0.7\" top=\"0.75\" bottom=\"0.75\" header=\"0.3\" footer=\"0.3\"/>"
|
||||
"</worksheet>";
|
||||
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
worksheet->sst = lxw_sst_new();
|
||||
worksheet_select(worksheet);
|
||||
|
||||
worksheet_write_string(worksheet, 0, 0, "Foo", NULL);
|
||||
worksheet_write_number(worksheet, 1, 2, 123, NULL);
|
||||
worksheet_write_string(worksheet, 3, 1, "Bar", NULL);
|
||||
worksheet_write_number(worksheet, 8, 4, 890, NULL);
|
||||
|
||||
lxw_worksheet_assemble_xml_file(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ_SHORT(exp, got);
|
||||
|
||||
lxw_sst_free(worksheet->sst);
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,121 @@
|
||||
/*
|
||||
* Tests for the lib_xlsx_writer library.
|
||||
*
|
||||
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
|
||||
*
|
||||
*/
|
||||
|
||||
#include "../ctest.h"
|
||||
#include "../helper.h"
|
||||
|
||||
#include "../../../include/xlsxwriter/worksheet.h"
|
||||
#include "../../../include/xlsxwriter/shared_strings.h"
|
||||
|
||||
// Test assembling a complete Worksheet file.
|
||||
CTEST(merged_range, array_formula01) {
|
||||
|
||||
char* got;
|
||||
char exp[] =
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
|
||||
"<worksheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\">"
|
||||
"<dimension ref=\"A1:C7\"/>"
|
||||
"<sheetViews>"
|
||||
"<sheetView tabSelected=\"1\" workbookViewId=\"0\"/>"
|
||||
"</sheetViews>"
|
||||
"<sheetFormatPr defaultRowHeight=\"15\"/>"
|
||||
"<sheetData>"
|
||||
"<row r=\"1\" spans=\"1:3\">"
|
||||
"<c r=\"A1\">"
|
||||
"<f t=\"array\" ref=\"A1\">SUM(B1:C1*B2:C2)</f>"
|
||||
"<v>9500</v>"
|
||||
"</c>"
|
||||
"<c r=\"B1\">"
|
||||
"<v>500</v>"
|
||||
"</c>"
|
||||
"<c r=\"C1\">"
|
||||
"<v>300</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"2\" spans=\"1:3\">"
|
||||
"<c r=\"A2\">"
|
||||
"<f t=\"array\" ref=\"A2\">SUM(B1:C1*B2:C2)</f>"
|
||||
"<v>9500</v>"
|
||||
"</c>"
|
||||
"<c r=\"B2\">"
|
||||
"<v>10</v>"
|
||||
"</c>"
|
||||
"<c r=\"C2\">"
|
||||
"<v>15</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"5\" spans=\"1:3\">"
|
||||
"<c r=\"A5\">"
|
||||
"<f t=\"array\" ref=\"A5:A7\">TREND(C5:C7,B5:B7)</f>"
|
||||
"<v>22196</v>"
|
||||
"</c>"
|
||||
"<c r=\"B5\">"
|
||||
"<v>1</v>"
|
||||
"</c>"
|
||||
"<c r=\"C5\">"
|
||||
"<v>20234</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"6\" spans=\"1:3\">"
|
||||
"<c r=\"A6\">"
|
||||
"<v>0</v>"
|
||||
"</c>"
|
||||
"<c r=\"B6\">"
|
||||
"<v>2</v>"
|
||||
"</c>"
|
||||
"<c r=\"C6\">"
|
||||
"<v>21003</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"7\" spans=\"1:3\">"
|
||||
"<c r=\"A7\">"
|
||||
"<v>0</v>"
|
||||
"</c>"
|
||||
"<c r=\"B7\">"
|
||||
"<v>3</v>"
|
||||
"</c>"
|
||||
"<c r=\"C7\">"
|
||||
"<v>10000</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"</sheetData>"
|
||||
"<pageMargins left=\"0.7\" right=\"0.7\" top=\"0.75\" bottom=\"0.75\" header=\"0.3\" footer=\"0.3\"/>"
|
||||
"</worksheet>";
|
||||
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
//worksheet->sst = _new_sst();
|
||||
worksheet_select(worksheet);
|
||||
|
||||
lxw_format *format = lxw_format_new();
|
||||
format->xf_index = 1;
|
||||
|
||||
worksheet_write_array_formula_num(worksheet, 0, 0, 0, 0, "{=SUM(B1:C1*B2:C2)}", NULL, 9500);
|
||||
worksheet_write_array_formula_num(worksheet, 1, 0, 1, 0, "{=SUM(B1:C1*B2:C2)}", NULL, 9500);
|
||||
worksheet_write_array_formula_num(worksheet, 4, 0, 6, 0, "{=TREND(C5:C7,B5:B7)}", NULL, 22196);
|
||||
|
||||
worksheet_write_number(worksheet, 0, 1, 500, NULL);
|
||||
worksheet_write_number(worksheet, 1, 1, 10, NULL);
|
||||
worksheet_write_number(worksheet, 4, 1, 1, NULL);
|
||||
worksheet_write_number(worksheet, 5, 1, 2, NULL);
|
||||
worksheet_write_number(worksheet, 6, 1, 3, NULL);
|
||||
|
||||
worksheet_write_number(worksheet, 0, 2, 300, NULL);
|
||||
worksheet_write_number(worksheet, 1, 2, 15, NULL);
|
||||
worksheet_write_number(worksheet, 4, 2, 20234, NULL);
|
||||
worksheet_write_number(worksheet, 5, 2, 21003, NULL);
|
||||
worksheet_write_number(worksheet, 6, 2, 10000, NULL);
|
||||
|
||||
lxw_worksheet_assemble_xml_file(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ_SHORT(exp, got);
|
||||
|
||||
//_free_sst(worksheet->sst);
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
@ -0,0 +1,84 @@
|
||||
/*
|
||||
* 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/shared_strings.h"
|
||||
|
||||
// Test assembling a complete Worksheet file.
|
||||
CTEST(worksheet, worksheet_condtional_format01) {
|
||||
|
||||
char* got;
|
||||
char exp[] =
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
|
||||
"<worksheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\">"
|
||||
"<dimension ref=\"A1:A4\"/>"
|
||||
"<sheetViews>"
|
||||
"<sheetView tabSelected=\"1\" workbookViewId=\"0\"/>"
|
||||
"</sheetViews>"
|
||||
"<sheetFormatPr defaultRowHeight=\"15\"/>"
|
||||
"<sheetData>"
|
||||
"<row r=\"1\" spans=\"1:1\">"
|
||||
"<c r=\"A1\">"
|
||||
"<v>10</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"2\" spans=\"1:1\">"
|
||||
"<c r=\"A2\">"
|
||||
"<v>20</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"3\" spans=\"1:1\">"
|
||||
"<c r=\"A3\">"
|
||||
"<v>30</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"4\" spans=\"1:1\">"
|
||||
"<c r=\"A4\">"
|
||||
"<v>40</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"</sheetData>"
|
||||
"<conditionalFormatting sqref=\"A1\">"
|
||||
"<cfRule type=\"cellIs\" priority=\"1\" operator=\"greaterThan\">"
|
||||
"<formula>5</formula>"
|
||||
"</cfRule>"
|
||||
"</conditionalFormatting>"
|
||||
"<pageMargins left=\"0.7\" right=\"0.7\" top=\"0.75\" bottom=\"0.75\" header=\"0.3\" footer=\"0.3\"/>"
|
||||
"</worksheet>";
|
||||
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
worksheet_select(worksheet);
|
||||
|
||||
worksheet_write_number(worksheet, CELL("A1"), 10, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A2"), 20, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A3"), 30, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A4"), 40, NULL);
|
||||
|
||||
lxw_conditional_format *conditional_format = calloc(1, sizeof(lxw_conditional_format));
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_TYPE_CELL;
|
||||
conditional_format->criteria = LXW_CONDITIONAL_CRITERIA_GREATER_THAN;
|
||||
conditional_format->value = 5;
|
||||
conditional_format->format = NULL;
|
||||
worksheet_conditional_format_cell(worksheet, CELL("A1"), conditional_format);
|
||||
|
||||
free(conditional_format);
|
||||
|
||||
lxw_worksheet_assemble_xml_file(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ_SHORT(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,163 @@
|
||||
/*
|
||||
* 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/shared_strings.h"
|
||||
|
||||
// Test assembling a complete Worksheet file.
|
||||
CTEST(worksheet, worksheet_condtional_format02) {
|
||||
|
||||
char* got;
|
||||
char exp[] =
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
|
||||
"<worksheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\">"
|
||||
"<dimension ref=\"A1:B4\"/>"
|
||||
"<sheetViews>"
|
||||
"<sheetView tabSelected=\"1\" workbookViewId=\"0\"/>"
|
||||
"</sheetViews>"
|
||||
"<sheetFormatPr defaultRowHeight=\"15\"/>"
|
||||
"<sheetData>"
|
||||
"<row r=\"1\" spans=\"1:2\">"
|
||||
"<c r=\"A1\">"
|
||||
"<v>10</v>"
|
||||
"</c>"
|
||||
"<c r=\"B1\">"
|
||||
"<v>5</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"2\" spans=\"1:2\">"
|
||||
"<c r=\"A2\">"
|
||||
"<v>20</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"3\" spans=\"1:2\">"
|
||||
"<c r=\"A3\">"
|
||||
"<v>30</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"4\" spans=\"1:2\">"
|
||||
"<c r=\"A4\">"
|
||||
"<v>40</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"</sheetData>"
|
||||
"<conditionalFormatting sqref=\"A1\">"
|
||||
"<cfRule type=\"cellIs\" priority=\"1\" operator=\"greaterThan\">"
|
||||
"<formula>$B$1</formula>"
|
||||
"</cfRule>"
|
||||
"</conditionalFormatting>"
|
||||
"<pageMargins left=\"0.7\" right=\"0.7\" top=\"0.75\" bottom=\"0.75\" header=\"0.3\" footer=\"0.3\"/>"
|
||||
"</worksheet>";
|
||||
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
worksheet_select(worksheet);
|
||||
|
||||
worksheet_write_number(worksheet, CELL("A1"), 10, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A2"), 20, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A3"), 30, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A4"), 40, NULL);
|
||||
|
||||
worksheet_write_number(worksheet, CELL("B1"), 5, NULL);
|
||||
|
||||
lxw_conditional_format *conditional_format = calloc(1, sizeof(lxw_conditional_format));
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_TYPE_CELL;
|
||||
conditional_format->criteria = LXW_CONDITIONAL_CRITERIA_GREATER_THAN;
|
||||
conditional_format->value_string = "$B$1";
|
||||
conditional_format->format = NULL;
|
||||
worksheet_conditional_format_cell(worksheet, CELL("A1"), conditional_format);
|
||||
|
||||
free(conditional_format);
|
||||
|
||||
lxw_worksheet_assemble_xml_file(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ_SHORT(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
// This version uses a range formula "$B$1" -> "=$B$1".
|
||||
CTEST(worksheet, worksheet_condtional_format02b) {
|
||||
|
||||
char* got;
|
||||
char exp[] =
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
|
||||
"<worksheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\">"
|
||||
"<dimension ref=\"A1:B4\"/>"
|
||||
"<sheetViews>"
|
||||
"<sheetView tabSelected=\"1\" workbookViewId=\"0\"/>"
|
||||
"</sheetViews>"
|
||||
"<sheetFormatPr defaultRowHeight=\"15\"/>"
|
||||
"<sheetData>"
|
||||
"<row r=\"1\" spans=\"1:2\">"
|
||||
"<c r=\"A1\">"
|
||||
"<v>10</v>"
|
||||
"</c>"
|
||||
"<c r=\"B1\">"
|
||||
"<v>5</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"2\" spans=\"1:2\">"
|
||||
"<c r=\"A2\">"
|
||||
"<v>20</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"3\" spans=\"1:2\">"
|
||||
"<c r=\"A3\">"
|
||||
"<v>30</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"4\" spans=\"1:2\">"
|
||||
"<c r=\"A4\">"
|
||||
"<v>40</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"</sheetData>"
|
||||
"<conditionalFormatting sqref=\"A1\">"
|
||||
"<cfRule type=\"cellIs\" priority=\"1\" operator=\"greaterThan\">"
|
||||
"<formula>$B$1</formula>"
|
||||
"</cfRule>"
|
||||
"</conditionalFormatting>"
|
||||
"<pageMargins left=\"0.7\" right=\"0.7\" top=\"0.75\" bottom=\"0.75\" header=\"0.3\" footer=\"0.3\"/>"
|
||||
"</worksheet>";
|
||||
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
worksheet_select(worksheet);
|
||||
|
||||
worksheet_write_number(worksheet, CELL("A1"), 10, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A2"), 20, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A3"), 30, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A4"), 40, NULL);
|
||||
|
||||
worksheet_write_number(worksheet, CELL("B1"), 5, NULL);
|
||||
|
||||
lxw_conditional_format *conditional_format = calloc(1, sizeof(lxw_conditional_format));
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_TYPE_CELL;
|
||||
conditional_format->criteria = LXW_CONDITIONAL_CRITERIA_GREATER_THAN;
|
||||
conditional_format->value_string = "=$B$1";
|
||||
conditional_format->format = NULL;
|
||||
worksheet_conditional_format_cell(worksheet, CELL("A1"), conditional_format);
|
||||
|
||||
free(conditional_format);
|
||||
|
||||
lxw_worksheet_assemble_xml_file(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ_SHORT(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
@ -0,0 +1,181 @@
|
||||
/*
|
||||
* 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/shared_strings.h"
|
||||
|
||||
// Test assembling a complete Worksheet file.
|
||||
CTEST(worksheet, worksheet_condtional_format03) {
|
||||
|
||||
char* got;
|
||||
char exp[] =
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
|
||||
"<worksheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\">"
|
||||
"<dimension ref=\"A1:A4\"/>"
|
||||
"<sheetViews>"
|
||||
"<sheetView tabSelected=\"1\" workbookViewId=\"0\"/>"
|
||||
"</sheetViews>"
|
||||
"<sheetFormatPr defaultRowHeight=\"15\"/>"
|
||||
"<sheetData>"
|
||||
"<row r=\"1\" spans=\"1:1\">"
|
||||
"<c r=\"A1\">"
|
||||
"<v>10</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"2\" spans=\"1:1\">"
|
||||
"<c r=\"A2\">"
|
||||
"<v>20</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"3\" spans=\"1:1\">"
|
||||
"<c r=\"A3\">"
|
||||
"<v>30</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"4\" spans=\"1:1\">"
|
||||
"<c r=\"A4\">"
|
||||
"<v>40</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"</sheetData>"
|
||||
"<conditionalFormatting sqref=\"A1:A4\">"
|
||||
"<cfRule type=\"cellIs\" priority=\"1\" operator=\"between\">"
|
||||
"<formula>20</formula>"
|
||||
"<formula>30</formula>"
|
||||
"</cfRule>"
|
||||
"<cfRule type=\"cellIs\" priority=\"2\" operator=\"notBetween\">"
|
||||
"<formula>20</formula>"
|
||||
"<formula>30</formula>"
|
||||
"</cfRule>"
|
||||
"</conditionalFormatting>"
|
||||
"<pageMargins left=\"0.7\" right=\"0.7\" top=\"0.75\" bottom=\"0.75\" header=\"0.3\" footer=\"0.3\"/>"
|
||||
"</worksheet>";
|
||||
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
worksheet_select(worksheet);
|
||||
|
||||
worksheet_write_number(worksheet, CELL("A1"), 10, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A2"), 20, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A3"), 30, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A4"), 40, NULL);
|
||||
|
||||
lxw_conditional_format *conditional_format = calloc(1, sizeof(lxw_conditional_format));
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_TYPE_CELL;
|
||||
conditional_format->criteria = LXW_CONDITIONAL_CRITERIA_BETWEEN;
|
||||
conditional_format->min_value = 20;
|
||||
conditional_format->max_value = 30;
|
||||
|
||||
worksheet_conditional_format_range(worksheet, RANGE("A1:A4"), conditional_format);
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_TYPE_CELL;
|
||||
conditional_format->criteria = LXW_CONDITIONAL_CRITERIA_NOT_BETWEEN;
|
||||
conditional_format->min_value = 20;
|
||||
conditional_format->max_value = 30;
|
||||
|
||||
worksheet_conditional_format_range(worksheet, RANGE("A1:A4"), conditional_format);
|
||||
|
||||
|
||||
free(conditional_format);
|
||||
|
||||
lxw_worksheet_assemble_xml_file(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ_SHORT(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
// Test cell references.
|
||||
CTEST(worksheet, worksheet_condtional_format03b) {
|
||||
|
||||
char* got;
|
||||
char exp[] =
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
|
||||
"<worksheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\">"
|
||||
"<dimension ref=\"A1:A4\"/>"
|
||||
"<sheetViews>"
|
||||
"<sheetView tabSelected=\"1\" workbookViewId=\"0\"/>"
|
||||
"</sheetViews>"
|
||||
"<sheetFormatPr defaultRowHeight=\"15\"/>"
|
||||
"<sheetData>"
|
||||
"<row r=\"1\" spans=\"1:1\">"
|
||||
"<c r=\"A1\">"
|
||||
"<v>10</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"2\" spans=\"1:1\">"
|
||||
"<c r=\"A2\">"
|
||||
"<v>20</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"3\" spans=\"1:1\">"
|
||||
"<c r=\"A3\">"
|
||||
"<v>30</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"4\" spans=\"1:1\">"
|
||||
"<c r=\"A4\">"
|
||||
"<v>40</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"</sheetData>"
|
||||
"<conditionalFormatting sqref=\"A1:A4\">"
|
||||
"<cfRule type=\"cellIs\" priority=\"1\" operator=\"between\">"
|
||||
"<formula>$B$1</formula>"
|
||||
"<formula>$B$2</formula>"
|
||||
"</cfRule>"
|
||||
"<cfRule type=\"cellIs\" priority=\"2\" operator=\"notBetween\">"
|
||||
"<formula>$B$1</formula>"
|
||||
"<formula>$B$2</formula>"
|
||||
"</cfRule>"
|
||||
"</conditionalFormatting>"
|
||||
"<pageMargins left=\"0.7\" right=\"0.7\" top=\"0.75\" bottom=\"0.75\" header=\"0.3\" footer=\"0.3\"/>"
|
||||
"</worksheet>";
|
||||
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
worksheet_select(worksheet);
|
||||
|
||||
worksheet_write_number(worksheet, CELL("A1"), 10, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A2"), 20, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A3"), 30, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A4"), 40, NULL);
|
||||
|
||||
lxw_conditional_format *conditional_format = calloc(1, sizeof(lxw_conditional_format));
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_TYPE_CELL;
|
||||
conditional_format->criteria = LXW_CONDITIONAL_CRITERIA_BETWEEN;
|
||||
conditional_format->min_value_string = "$B$1";
|
||||
conditional_format->max_value_string = "$B$2";
|
||||
|
||||
worksheet_conditional_format_range(worksheet, RANGE("A1:A4"), conditional_format);
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_TYPE_CELL;
|
||||
conditional_format->criteria = LXW_CONDITIONAL_CRITERIA_NOT_BETWEEN;
|
||||
conditional_format->min_value_string = "=$B$1";
|
||||
conditional_format->max_value_string = "=$B$2";
|
||||
|
||||
worksheet_conditional_format_range(worksheet, RANGE("A1:A4"), conditional_format);
|
||||
|
||||
free(conditional_format);
|
||||
|
||||
lxw_worksheet_assemble_xml_file(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ_SHORT(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,84 @@
|
||||
/*
|
||||
* 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/shared_strings.h"
|
||||
|
||||
// Test assembling a complete Worksheet file.
|
||||
CTEST(worksheet, worksheet_condtional_format04) {
|
||||
|
||||
char* got;
|
||||
char exp[] =
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
|
||||
"<worksheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\">"
|
||||
"<dimension ref=\"A1:A4\"/>"
|
||||
"<sheetViews>"
|
||||
"<sheetView tabSelected=\"1\" workbookViewId=\"0\"/>"
|
||||
"</sheetViews>"
|
||||
"<sheetFormatPr defaultRowHeight=\"15\"/>"
|
||||
"<sheetData>"
|
||||
"<row r=\"1\" spans=\"1:1\">"
|
||||
"<c r=\"A1\">"
|
||||
"<v>10</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"2\" spans=\"1:1\">"
|
||||
"<c r=\"A2\">"
|
||||
"<v>20</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"3\" spans=\"1:1\">"
|
||||
"<c r=\"A3\">"
|
||||
"<v>30</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"4\" spans=\"1:1\">"
|
||||
"<c r=\"A4\">"
|
||||
"<v>40</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"</sheetData>"
|
||||
"<conditionalFormatting sqref=\"A1:A4\">"
|
||||
"<cfRule type=\"duplicateValues\" priority=\"1\"/>"
|
||||
"<cfRule type=\"uniqueValues\" priority=\"2\"/>"
|
||||
"</conditionalFormatting>"
|
||||
"<pageMargins left=\"0.7\" right=\"0.7\" top=\"0.75\" bottom=\"0.75\" header=\"0.3\" footer=\"0.3\"/>"
|
||||
"</worksheet>";
|
||||
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
worksheet_select(worksheet);
|
||||
|
||||
worksheet_write_number(worksheet, CELL("A1"), 10, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A2"), 20, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A3"), 30, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A4"), 40, NULL);
|
||||
|
||||
lxw_conditional_format *conditional_format = calloc(1, sizeof(lxw_conditional_format));
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_TYPE_DUPLICATE;
|
||||
worksheet_conditional_format_range(worksheet, RANGE("A1:A4"), conditional_format);
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_TYPE_UNIQUE;
|
||||
worksheet_conditional_format_range(worksheet, RANGE("A1:A4"), conditional_format);
|
||||
|
||||
|
||||
free(conditional_format);
|
||||
|
||||
lxw_worksheet_assemble_xml_file(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ_SHORT(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,123 @@
|
||||
/*
|
||||
* 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/shared_strings.h"
|
||||
|
||||
// Test assembling a complete Worksheet file.
|
||||
CTEST(worksheet, worksheet_condtional_format05) {
|
||||
|
||||
char* got;
|
||||
char exp[] =
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
|
||||
"<worksheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\">"
|
||||
"<dimension ref=\"A1:A4\"/>"
|
||||
"<sheetViews>"
|
||||
"<sheetView tabSelected=\"1\" workbookViewId=\"0\"/>"
|
||||
"</sheetViews>"
|
||||
"<sheetFormatPr defaultRowHeight=\"15\"/>"
|
||||
"<sheetData>"
|
||||
"<row r=\"1\" spans=\"1:1\">"
|
||||
"<c r=\"A1\">"
|
||||
"<v>10</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"2\" spans=\"1:1\">"
|
||||
"<c r=\"A2\">"
|
||||
"<v>20</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"3\" spans=\"1:1\">"
|
||||
"<c r=\"A3\">"
|
||||
"<v>30</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"4\" spans=\"1:1\">"
|
||||
"<c r=\"A4\">"
|
||||
"<v>40</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"</sheetData>"
|
||||
"<conditionalFormatting sqref=\"A1:A4\">"
|
||||
"<cfRule type=\"aboveAverage\" priority=\"1\"/>"
|
||||
"<cfRule type=\"aboveAverage\" priority=\"2\" aboveAverage=\"0\"/>"
|
||||
"<cfRule type=\"aboveAverage\" priority=\"3\" equalAverage=\"1\"/>"
|
||||
"<cfRule type=\"aboveAverage\" priority=\"4\" aboveAverage=\"0\" equalAverage=\"1\"/>"
|
||||
"<cfRule type=\"aboveAverage\" priority=\"5\" stdDev=\"1\"/>"
|
||||
"<cfRule type=\"aboveAverage\" priority=\"6\" aboveAverage=\"0\" stdDev=\"1\"/>"
|
||||
"<cfRule type=\"aboveAverage\" priority=\"7\" stdDev=\"2\"/>"
|
||||
"<cfRule type=\"aboveAverage\" priority=\"8\" aboveAverage=\"0\" stdDev=\"2\"/>"
|
||||
"<cfRule type=\"aboveAverage\" priority=\"9\" stdDev=\"3\"/>"
|
||||
"<cfRule type=\"aboveAverage\" priority=\"10\" aboveAverage=\"0\" stdDev=\"3\"/>"
|
||||
"</conditionalFormatting>"
|
||||
"<pageMargins left=\"0.7\" right=\"0.7\" top=\"0.75\" bottom=\"0.75\" header=\"0.3\" footer=\"0.3\"/>"
|
||||
"</worksheet>";
|
||||
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
worksheet_select(worksheet);
|
||||
|
||||
worksheet_write_number(worksheet, CELL("A1"), 10, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A2"), 20, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A3"), 30, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A4"), 40, NULL);
|
||||
|
||||
lxw_conditional_format *conditional_format = calloc(1, sizeof(lxw_conditional_format));
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_TYPE_AVERAGE;
|
||||
conditional_format->criteria = LXW_CONDITIONAL_CRITERIA_AVERAGE_ABOVE;
|
||||
worksheet_conditional_format_range(worksheet, RANGE("A1:A4"), conditional_format);
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_TYPE_AVERAGE;
|
||||
conditional_format->criteria = LXW_CONDITIONAL_CRITERIA_AVERAGE_BELOW;
|
||||
worksheet_conditional_format_range(worksheet, RANGE("A1:A4"), conditional_format);
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_TYPE_AVERAGE;
|
||||
conditional_format->criteria = LXW_CONDITIONAL_CRITERIA_AVERAGE_ABOVE_OR_EQUAL;
|
||||
worksheet_conditional_format_range(worksheet, RANGE("A1:A4"), conditional_format);
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_TYPE_AVERAGE;
|
||||
conditional_format->criteria = LXW_CONDITIONAL_CRITERIA_AVERAGE_BELOW_OR_EQUAL;
|
||||
worksheet_conditional_format_range(worksheet, RANGE("A1:A4"), conditional_format);
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_TYPE_AVERAGE;
|
||||
conditional_format->criteria = LXW_CONDITIONAL_CRITERIA_AVERAGE_1_STD_DEV_ABOVE;
|
||||
worksheet_conditional_format_range(worksheet, RANGE("A1:A4"), conditional_format);
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_TYPE_AVERAGE;
|
||||
conditional_format->criteria = LXW_CONDITIONAL_CRITERIA_AVERAGE_1_STD_DEV_BELOW;
|
||||
worksheet_conditional_format_range(worksheet, RANGE("A1:A4"), conditional_format);
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_TYPE_AVERAGE;
|
||||
conditional_format->criteria = LXW_CONDITIONAL_CRITERIA_AVERAGE_2_STD_DEV_ABOVE;
|
||||
worksheet_conditional_format_range(worksheet, RANGE("A1:A4"), conditional_format);
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_TYPE_AVERAGE;
|
||||
conditional_format->criteria = LXW_CONDITIONAL_CRITERIA_AVERAGE_2_STD_DEV_BELOW;
|
||||
worksheet_conditional_format_range(worksheet, RANGE("A1:A4"), conditional_format);
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_TYPE_AVERAGE;
|
||||
conditional_format->criteria = LXW_CONDITIONAL_CRITERIA_AVERAGE_3_STD_DEV_ABOVE;
|
||||
worksheet_conditional_format_range(worksheet, RANGE("A1:A4"), conditional_format);
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_TYPE_AVERAGE;
|
||||
conditional_format->criteria = LXW_CONDITIONAL_CRITERIA_AVERAGE_3_STD_DEV_BELOW;
|
||||
worksheet_conditional_format_range(worksheet, RANGE("A1:A4"), conditional_format);
|
||||
|
||||
free(conditional_format);
|
||||
|
||||
lxw_worksheet_assemble_xml_file(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ_SHORT(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
@ -0,0 +1,181 @@
|
||||
/*
|
||||
* 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/shared_strings.h"
|
||||
|
||||
// Test assembling a complete Worksheet file.
|
||||
CTEST(worksheet, worksheet_condtional_format06) {
|
||||
|
||||
char* got;
|
||||
char exp[] =
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
|
||||
"<worksheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\">"
|
||||
"<dimension ref=\"A1:A4\"/>"
|
||||
"<sheetViews>"
|
||||
"<sheetView tabSelected=\"1\" workbookViewId=\"0\"/>"
|
||||
"</sheetViews>"
|
||||
"<sheetFormatPr defaultRowHeight=\"15\"/>"
|
||||
"<sheetData>"
|
||||
"<row r=\"1\" spans=\"1:1\">"
|
||||
"<c r=\"A1\">"
|
||||
"<v>10</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"2\" spans=\"1:1\">"
|
||||
"<c r=\"A2\">"
|
||||
"<v>20</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"3\" spans=\"1:1\">"
|
||||
"<c r=\"A3\">"
|
||||
"<v>30</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"4\" spans=\"1:1\">"
|
||||
"<c r=\"A4\">"
|
||||
"<v>40</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"</sheetData>"
|
||||
"<conditionalFormatting sqref=\"A1:A4\">"
|
||||
"<cfRule type=\"top10\" priority=\"1\" rank=\"10\"/>"
|
||||
"<cfRule type=\"top10\" priority=\"2\" bottom=\"1\" rank=\"10\"/>"
|
||||
"<cfRule type=\"top10\" priority=\"3\" percent=\"1\" rank=\"10\"/>"
|
||||
"<cfRule type=\"top10\" priority=\"4\" percent=\"1\" bottom=\"1\" rank=\"10\"/>"
|
||||
"</conditionalFormatting>"
|
||||
"<pageMargins left=\"0.7\" right=\"0.7\" top=\"0.75\" bottom=\"0.75\" header=\"0.3\" footer=\"0.3\"/>"
|
||||
"</worksheet>";
|
||||
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
worksheet_select(worksheet);
|
||||
|
||||
worksheet_write_number(worksheet, CELL("A1"), 10, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A2"), 20, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A3"), 30, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A4"), 40, NULL);
|
||||
|
||||
lxw_conditional_format *conditional_format = calloc(1, sizeof(lxw_conditional_format));
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_TYPE_TOP;
|
||||
conditional_format->value = 10;
|
||||
worksheet_conditional_format_range(worksheet, RANGE("A1:A4"), conditional_format);
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_TYPE_BOTTOM;
|
||||
conditional_format->value = 10;
|
||||
worksheet_conditional_format_range(worksheet, RANGE("A1:A4"), conditional_format);
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_TYPE_TOP;
|
||||
conditional_format->criteria = LXW_CONDITIONAL_CRITERIA_TOP_OR_BOTTOM_PERCENT;
|
||||
conditional_format->value = 10;
|
||||
worksheet_conditional_format_range(worksheet, RANGE("A1:A4"), conditional_format);
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_TYPE_BOTTOM;
|
||||
conditional_format->criteria = LXW_CONDITIONAL_CRITERIA_TOP_OR_BOTTOM_PERCENT;
|
||||
conditional_format->value = 10;
|
||||
worksheet_conditional_format_range(worksheet, RANGE("A1:A4"), conditional_format);
|
||||
|
||||
|
||||
free(conditional_format);
|
||||
|
||||
lxw_worksheet_assemble_xml_file(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ_SHORT(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
// Test int truncation.
|
||||
CTEST(worksheet, worksheet_condtional_format06b) {
|
||||
|
||||
char* got;
|
||||
char exp[] =
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
|
||||
"<worksheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\">"
|
||||
"<dimension ref=\"A1:A4\"/>"
|
||||
"<sheetViews>"
|
||||
"<sheetView tabSelected=\"1\" workbookViewId=\"0\"/>"
|
||||
"</sheetViews>"
|
||||
"<sheetFormatPr defaultRowHeight=\"15\"/>"
|
||||
"<sheetData>"
|
||||
"<row r=\"1\" spans=\"1:1\">"
|
||||
"<c r=\"A1\">"
|
||||
"<v>10</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"2\" spans=\"1:1\">"
|
||||
"<c r=\"A2\">"
|
||||
"<v>20</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"3\" spans=\"1:1\">"
|
||||
"<c r=\"A3\">"
|
||||
"<v>30</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"4\" spans=\"1:1\">"
|
||||
"<c r=\"A4\">"
|
||||
"<v>40</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"</sheetData>"
|
||||
"<conditionalFormatting sqref=\"A1:A4\">"
|
||||
"<cfRule type=\"top10\" priority=\"1\" rank=\"10\"/>"
|
||||
"<cfRule type=\"top10\" priority=\"2\" bottom=\"1\" rank=\"10\"/>"
|
||||
"<cfRule type=\"top10\" priority=\"3\" percent=\"1\" rank=\"10\"/>"
|
||||
"<cfRule type=\"top10\" priority=\"4\" percent=\"1\" bottom=\"1\" rank=\"10\"/>"
|
||||
"</conditionalFormatting>"
|
||||
"<pageMargins left=\"0.7\" right=\"0.7\" top=\"0.75\" bottom=\"0.75\" header=\"0.3\" footer=\"0.3\"/>"
|
||||
"</worksheet>";
|
||||
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
worksheet_select(worksheet);
|
||||
|
||||
worksheet_write_number(worksheet, CELL("A1"), 10, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A2"), 20, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A3"), 30, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A4"), 40, NULL);
|
||||
|
||||
lxw_conditional_format *conditional_format = calloc(1, sizeof(lxw_conditional_format));
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_TYPE_TOP;
|
||||
conditional_format->value = 10.1;
|
||||
worksheet_conditional_format_range(worksheet, RANGE("A1:A4"), conditional_format);
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_TYPE_BOTTOM;
|
||||
conditional_format->value = 10.2;
|
||||
worksheet_conditional_format_range(worksheet, RANGE("A1:A4"), conditional_format);
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_TYPE_TOP;
|
||||
conditional_format->criteria = LXW_CONDITIONAL_CRITERIA_TOP_OR_BOTTOM_PERCENT;
|
||||
conditional_format->value = 10.3;
|
||||
worksheet_conditional_format_range(worksheet, RANGE("A1:A4"), conditional_format);
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_TYPE_BOTTOM;
|
||||
conditional_format->criteria = LXW_CONDITIONAL_CRITERIA_TOP_OR_BOTTOM_PERCENT;
|
||||
conditional_format->value = 10.4;
|
||||
worksheet_conditional_format_range(worksheet, RANGE("A1:A4"), conditional_format);
|
||||
|
||||
|
||||
free(conditional_format);
|
||||
|
||||
lxw_worksheet_assemble_xml_file(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ_SHORT(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
@ -0,0 +1,105 @@
|
||||
/*
|
||||
* 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/shared_strings.h"
|
||||
|
||||
// Test assembling a complete Worksheet file.
|
||||
CTEST(worksheet, worksheet_condtional_format07) {
|
||||
|
||||
char* got;
|
||||
char exp[] =
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
|
||||
"<worksheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\">"
|
||||
"<dimension ref=\"A1:A4\"/>"
|
||||
"<sheetViews>"
|
||||
"<sheetView tabSelected=\"1\" workbookViewId=\"0\"/>"
|
||||
"</sheetViews>"
|
||||
"<sheetFormatPr defaultRowHeight=\"15\"/>"
|
||||
"<sheetData>"
|
||||
"<row r=\"1\" spans=\"1:1\">"
|
||||
"<c r=\"A1\">"
|
||||
"<v>10</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"2\" spans=\"1:1\">"
|
||||
"<c r=\"A2\">"
|
||||
"<v>20</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"3\" spans=\"1:1\">"
|
||||
"<c r=\"A3\">"
|
||||
"<v>30</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"4\" spans=\"1:1\">"
|
||||
"<c r=\"A4\">"
|
||||
"<v>40</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"</sheetData>"
|
||||
"<conditionalFormatting sqref=\"A1:A4\">"
|
||||
"<cfRule type=\"containsText\" priority=\"1\" operator=\"containsText\" text=\"foo\">"
|
||||
"<formula>NOT(ISERROR(SEARCH(\"foo\",A1)))</formula>"
|
||||
"</cfRule>"
|
||||
"<cfRule type=\"notContainsText\" priority=\"2\" operator=\"notContains\" text=\"foo\">"
|
||||
"<formula>ISERROR(SEARCH(\"foo\",A1))</formula>"
|
||||
"</cfRule>"
|
||||
"<cfRule type=\"beginsWith\" priority=\"3\" operator=\"beginsWith\" text=\"b\">"
|
||||
"<formula>LEFT(A1,1)=\"b\"</formula>"
|
||||
"</cfRule>"
|
||||
"<cfRule type=\"endsWith\" priority=\"4\" operator=\"endsWith\" text=\"b\">"
|
||||
"<formula>RIGHT(A1,1)=\"b\"</formula>"
|
||||
"</cfRule>"
|
||||
"</conditionalFormatting>"
|
||||
"<pageMargins left=\"0.7\" right=\"0.7\" top=\"0.75\" bottom=\"0.75\" header=\"0.3\" footer=\"0.3\"/>"
|
||||
"</worksheet>";
|
||||
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
worksheet_select(worksheet);
|
||||
|
||||
worksheet_write_number(worksheet, CELL("A1"), 10, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A2"), 20, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A3"), 30, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A4"), 40, NULL);
|
||||
|
||||
lxw_conditional_format *conditional_format = calloc(1, sizeof(lxw_conditional_format));
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_TYPE_TEXT;
|
||||
conditional_format->criteria = LXW_CONDITIONAL_CRITERIA_TEXT_CONTAINING;
|
||||
conditional_format->value_string = "foo";
|
||||
worksheet_conditional_format_range(worksheet, RANGE("A1:A4"), conditional_format);
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_TYPE_TEXT;
|
||||
conditional_format->criteria = LXW_CONDITIONAL_CRITERIA_TEXT_NOT_CONTAINING;
|
||||
conditional_format->value_string = "foo";
|
||||
worksheet_conditional_format_range(worksheet, RANGE("A1:A4"), conditional_format);
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_TYPE_TEXT;
|
||||
conditional_format->criteria = LXW_CONDITIONAL_CRITERIA_TEXT_BEGINS_WITH;
|
||||
conditional_format->value_string = "b";
|
||||
worksheet_conditional_format_range(worksheet, RANGE("A1:A4"), conditional_format);
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_TYPE_TEXT;
|
||||
conditional_format->criteria = LXW_CONDITIONAL_CRITERIA_TEXT_ENDS_WITH;
|
||||
conditional_format->value_string = "b";
|
||||
worksheet_conditional_format_range(worksheet, RANGE("A1:A4"), conditional_format);
|
||||
|
||||
free(conditional_format);
|
||||
|
||||
lxw_worksheet_assemble_xml_file(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ_SHORT(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
@ -0,0 +1,144 @@
|
||||
/*
|
||||
* 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/shared_strings.h"
|
||||
|
||||
// Test assembling a complete Worksheet file.
|
||||
CTEST(worksheet, worksheet_condtional_format08) {
|
||||
|
||||
char* got;
|
||||
char exp[] =
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
|
||||
"<worksheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\">"
|
||||
"<dimension ref=\"A1:A4\"/>"
|
||||
"<sheetViews>"
|
||||
"<sheetView tabSelected=\"1\" workbookViewId=\"0\"/>"
|
||||
"</sheetViews>"
|
||||
"<sheetFormatPr defaultRowHeight=\"15\"/>"
|
||||
"<sheetData>"
|
||||
"<row r=\"1\" spans=\"1:1\">"
|
||||
"<c r=\"A1\">"
|
||||
"<v>10</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"2\" spans=\"1:1\">"
|
||||
"<c r=\"A2\">"
|
||||
"<v>20</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"3\" spans=\"1:1\">"
|
||||
"<c r=\"A3\">"
|
||||
"<v>30</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"4\" spans=\"1:1\">"
|
||||
"<c r=\"A4\">"
|
||||
"<v>40</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"</sheetData>"
|
||||
"<conditionalFormatting sqref=\"A1:A4\">"
|
||||
"<cfRule type=\"timePeriod\" priority=\"1\" timePeriod=\"yesterday\">"
|
||||
"<formula>FLOOR(A1,1)=TODAY()-1</formula>"
|
||||
"</cfRule>"
|
||||
"<cfRule type=\"timePeriod\" priority=\"2\" timePeriod=\"today\">"
|
||||
"<formula>FLOOR(A1,1)=TODAY()</formula>"
|
||||
"</cfRule>"
|
||||
"<cfRule type=\"timePeriod\" priority=\"3\" timePeriod=\"tomorrow\">"
|
||||
"<formula>FLOOR(A1,1)=TODAY()+1</formula>"
|
||||
"</cfRule>"
|
||||
"<cfRule type=\"timePeriod\" priority=\"4\" timePeriod=\"last7Days\">"
|
||||
"<formula>AND(TODAY()-FLOOR(A1,1)<=6,FLOOR(A1,1)<=TODAY())</formula>"
|
||||
"</cfRule>"
|
||||
"<cfRule type=\"timePeriod\" priority=\"5\" timePeriod=\"lastWeek\">"
|
||||
"<formula>AND(TODAY()-ROUNDDOWN(A1,0)>=(WEEKDAY(TODAY())),TODAY()-ROUNDDOWN(A1,0)<(WEEKDAY(TODAY())+7))</formula>"
|
||||
"</cfRule>"
|
||||
"<cfRule type=\"timePeriod\" priority=\"6\" timePeriod=\"thisWeek\">"
|
||||
"<formula>AND(TODAY()-ROUNDDOWN(A1,0)<=WEEKDAY(TODAY())-1,ROUNDDOWN(A1,0)-TODAY()<=7-WEEKDAY(TODAY()))</formula>"
|
||||
"</cfRule>"
|
||||
"<cfRule type=\"timePeriod\" priority=\"7\" timePeriod=\"nextWeek\">"
|
||||
"<formula>AND(ROUNDDOWN(A1,0)-TODAY()>(7-WEEKDAY(TODAY())),ROUNDDOWN(A1,0)-TODAY()<(15-WEEKDAY(TODAY())))</formula>"
|
||||
"</cfRule>"
|
||||
"<cfRule type=\"timePeriod\" priority=\"8\" timePeriod=\"lastMonth\">"
|
||||
"<formula>AND(MONTH(A1)=MONTH(TODAY())-1,OR(YEAR(A1)=YEAR(TODAY()),AND(MONTH(A1)=1,YEAR(A1)=YEAR(TODAY())-1)))</formula>"
|
||||
"</cfRule>"
|
||||
"<cfRule type=\"timePeriod\" priority=\"9\" timePeriod=\"thisMonth\">"
|
||||
"<formula>AND(MONTH(A1)=MONTH(TODAY()),YEAR(A1)=YEAR(TODAY()))</formula>"
|
||||
"</cfRule>"
|
||||
"<cfRule type=\"timePeriod\" priority=\"10\" timePeriod=\"nextMonth\">"
|
||||
"<formula>AND(MONTH(A1)=MONTH(TODAY())+1,OR(YEAR(A1)=YEAR(TODAY()),AND(MONTH(A1)=12,YEAR(A1)=YEAR(TODAY())+1)))</formula>"
|
||||
"</cfRule>"
|
||||
"</conditionalFormatting>"
|
||||
"<pageMargins left=\"0.7\" right=\"0.7\" top=\"0.75\" bottom=\"0.75\" header=\"0.3\" footer=\"0.3\"/>"
|
||||
"</worksheet>";
|
||||
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
worksheet_select(worksheet);
|
||||
|
||||
worksheet_write_number(worksheet, CELL("A1"), 10, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A2"), 20, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A3"), 30, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A4"), 40, NULL);
|
||||
|
||||
lxw_conditional_format *conditional_format = calloc(1, sizeof(lxw_conditional_format));
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_TYPE_TIME_PERIOD;
|
||||
conditional_format->criteria = LXW_CONDITIONAL_CRITERIA_TIME_PERIOD_YESTERDAY;
|
||||
worksheet_conditional_format_range(worksheet, RANGE("A1:A4"), conditional_format);
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_TYPE_TIME_PERIOD;
|
||||
conditional_format->criteria = LXW_CONDITIONAL_CRITERIA_TIME_PERIOD_TODAY;
|
||||
worksheet_conditional_format_range(worksheet, RANGE("A1:A4"), conditional_format);
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_TYPE_TIME_PERIOD;
|
||||
conditional_format->criteria = LXW_CONDITIONAL_CRITERIA_TIME_PERIOD_TOMORROW;
|
||||
worksheet_conditional_format_range(worksheet, RANGE("A1:A4"), conditional_format);
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_TYPE_TIME_PERIOD;
|
||||
conditional_format->criteria = LXW_CONDITIONAL_CRITERIA_TIME_PERIOD_LAST_7_DAYS;
|
||||
worksheet_conditional_format_range(worksheet, RANGE("A1:A4"), conditional_format);
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_TYPE_TIME_PERIOD;
|
||||
conditional_format->criteria = LXW_CONDITIONAL_CRITERIA_TIME_PERIOD_LAST_WEEK;
|
||||
worksheet_conditional_format_range(worksheet, RANGE("A1:A4"), conditional_format);
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_TYPE_TIME_PERIOD;
|
||||
conditional_format->criteria = LXW_CONDITIONAL_CRITERIA_TIME_PERIOD_THIS_WEEK;
|
||||
worksheet_conditional_format_range(worksheet, RANGE("A1:A4"), conditional_format);
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_TYPE_TIME_PERIOD;
|
||||
conditional_format->criteria = LXW_CONDITIONAL_CRITERIA_TIME_PERIOD_NEXT_WEEK;
|
||||
worksheet_conditional_format_range(worksheet, RANGE("A1:A4"), conditional_format);
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_TYPE_TIME_PERIOD;
|
||||
conditional_format->criteria = LXW_CONDITIONAL_CRITERIA_TIME_PERIOD_LAST_MONTH;
|
||||
worksheet_conditional_format_range(worksheet, RANGE("A1:A4"), conditional_format);
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_TYPE_TIME_PERIOD;
|
||||
conditional_format->criteria = LXW_CONDITIONAL_CRITERIA_TIME_PERIOD_THIS_MONTH;
|
||||
worksheet_conditional_format_range(worksheet, RANGE("A1:A4"), conditional_format);
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_TYPE_TIME_PERIOD;
|
||||
conditional_format->criteria = LXW_CONDITIONAL_CRITERIA_TIME_PERIOD_NEXT_MONTH;
|
||||
worksheet_conditional_format_range(worksheet, RANGE("A1:A4"), conditional_format);
|
||||
|
||||
|
||||
free(conditional_format);
|
||||
|
||||
lxw_worksheet_assemble_xml_file(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ_SHORT(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
@ -0,0 +1,97 @@
|
||||
/*
|
||||
* 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/shared_strings.h"
|
||||
|
||||
// Test assembling a complete Worksheet file.
|
||||
CTEST(worksheet, worksheet_condtional_format09) {
|
||||
|
||||
char* got;
|
||||
char exp[] =
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
|
||||
"<worksheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\">"
|
||||
"<dimension ref=\"A1:A4\"/>"
|
||||
"<sheetViews>"
|
||||
"<sheetView tabSelected=\"1\" workbookViewId=\"0\"/>"
|
||||
"</sheetViews>"
|
||||
"<sheetFormatPr defaultRowHeight=\"15\"/>"
|
||||
"<sheetData>"
|
||||
"<row r=\"1\" spans=\"1:1\">"
|
||||
"<c r=\"A1\">"
|
||||
"<v>10</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"2\" spans=\"1:1\">"
|
||||
"<c r=\"A2\">"
|
||||
"<v>20</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"3\" spans=\"1:1\">"
|
||||
"<c r=\"A3\">"
|
||||
"<v>30</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"4\" spans=\"1:1\">"
|
||||
"<c r=\"A4\">"
|
||||
"<v>40</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"</sheetData>"
|
||||
"<conditionalFormatting sqref=\"A1:A4\">"
|
||||
"<cfRule type=\"containsBlanks\" priority=\"1\">"
|
||||
"<formula>LEN(TRIM(A1))=0</formula>"
|
||||
"</cfRule>"
|
||||
"<cfRule type=\"notContainsBlanks\" priority=\"2\">"
|
||||
"<formula>LEN(TRIM(A1))>0</formula>"
|
||||
"</cfRule>"
|
||||
"<cfRule type=\"containsErrors\" priority=\"3\">"
|
||||
"<formula>ISERROR(A1)</formula>"
|
||||
"</cfRule>"
|
||||
"<cfRule type=\"notContainsErrors\" priority=\"4\">"
|
||||
"<formula>NOT(ISERROR(A1))</formula>"
|
||||
"</cfRule>"
|
||||
"</conditionalFormatting>"
|
||||
"<pageMargins left=\"0.7\" right=\"0.7\" top=\"0.75\" bottom=\"0.75\" header=\"0.3\" footer=\"0.3\"/>"
|
||||
"</worksheet>";
|
||||
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
worksheet_select(worksheet);
|
||||
|
||||
worksheet_write_number(worksheet, CELL("A1"), 10, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A2"), 20, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A3"), 30, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A4"), 40, NULL);
|
||||
|
||||
lxw_conditional_format *conditional_format = calloc(1, sizeof(lxw_conditional_format));
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_TYPE_BLANKS;
|
||||
worksheet_conditional_format_range(worksheet, RANGE("A1:A4"), conditional_format);
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_TYPE_NO_BLANKS;
|
||||
worksheet_conditional_format_range(worksheet, RANGE("A1:A4"), conditional_format);
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_TYPE_ERRORS;
|
||||
worksheet_conditional_format_range(worksheet, RANGE("A1:A4"), conditional_format);
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_TYPE_NO_ERRORS;
|
||||
worksheet_conditional_format_range(worksheet, RANGE("A1:A4"), conditional_format);
|
||||
|
||||
free(conditional_format);
|
||||
|
||||
lxw_worksheet_assemble_xml_file(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ_SHORT(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
@ -0,0 +1,86 @@
|
||||
/*
|
||||
* 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/shared_strings.h"
|
||||
|
||||
// Test assembling a complete Worksheet file.
|
||||
CTEST(worksheet, worksheet_condtional_format10) {
|
||||
|
||||
char* got;
|
||||
char exp[] =
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
|
||||
"<worksheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\">"
|
||||
"<dimension ref=\"A1:A4\"/>"
|
||||
"<sheetViews>"
|
||||
"<sheetView tabSelected=\"1\" workbookViewId=\"0\"/>"
|
||||
"</sheetViews>"
|
||||
"<sheetFormatPr defaultRowHeight=\"15\"/>"
|
||||
"<sheetData>"
|
||||
"<row r=\"1\" spans=\"1:1\">"
|
||||
"<c r=\"A1\">"
|
||||
"<v>10</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"2\" spans=\"1:1\">"
|
||||
"<c r=\"A2\">"
|
||||
"<v>20</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"3\" spans=\"1:1\">"
|
||||
"<c r=\"A3\">"
|
||||
"<v>30</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"4\" spans=\"1:1\">"
|
||||
"<c r=\"A4\">"
|
||||
"<v>40</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"</sheetData>"
|
||||
"<conditionalFormatting sqref=\"A1:A4\">"
|
||||
"<cfRule type=\"cellIs\" priority=\"1\" operator=\"greaterThan\">"
|
||||
"<formula>40544</formula>"
|
||||
"</cfRule>"
|
||||
"</conditionalFormatting>"
|
||||
"<pageMargins left=\"0.7\" right=\"0.7\" top=\"0.75\" bottom=\"0.75\" header=\"0.3\" footer=\"0.3\"/>"
|
||||
"</worksheet>";
|
||||
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
worksheet_select(worksheet);
|
||||
|
||||
worksheet_write_number(worksheet, CELL("A1"), 10, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A2"), 20, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A3"), 30, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A4"), 40, NULL);
|
||||
|
||||
lxw_datetime datetime1 = {2011, 1, 1, 0, 0, 0};
|
||||
|
||||
lxw_conditional_format *conditional_format = calloc(1, sizeof(lxw_conditional_format));
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_TYPE_CELL;
|
||||
conditional_format->criteria = LXW_CONDITIONAL_CRITERIA_GREATER_THAN;
|
||||
conditional_format->value = lxw_datetime_to_excel_datetime(&datetime1);
|
||||
conditional_format->format = NULL;
|
||||
worksheet_conditional_format_range(worksheet, RANGE("A1:A4"), conditional_format);
|
||||
|
||||
free(conditional_format);
|
||||
|
||||
lxw_worksheet_assemble_xml_file(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ_SHORT(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,87 @@
|
||||
/*
|
||||
* 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/shared_strings.h"
|
||||
|
||||
// Test assembling a complete Worksheet file.
|
||||
CTEST(worksheet, worksheet_condtional_format11) {
|
||||
|
||||
char* got;
|
||||
char exp[] =
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
|
||||
"<worksheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\">"
|
||||
"<dimension ref=\"A1:A4\"/>"
|
||||
"<sheetViews>"
|
||||
"<sheetView tabSelected=\"1\" workbookViewId=\"0\"/>"
|
||||
"</sheetViews>"
|
||||
"<sheetFormatPr defaultRowHeight=\"15\"/>"
|
||||
"<sheetData>"
|
||||
"<row r=\"1\" spans=\"1:1\">"
|
||||
"<c r=\"A1\">"
|
||||
"<v>10</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"2\" spans=\"1:1\">"
|
||||
"<c r=\"A2\">"
|
||||
"<v>20</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"3\" spans=\"1:1\">"
|
||||
"<c r=\"A3\">"
|
||||
"<v>30</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"4\" spans=\"1:1\">"
|
||||
"<c r=\"A4\">"
|
||||
"<v>40</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"</sheetData>"
|
||||
"<conditionalFormatting sqref=\"A1:A4\">"
|
||||
"<cfRule type=\"cellIs\" priority=\"1\" operator=\"between\">"
|
||||
"<formula>40544</formula>"
|
||||
"<formula>40908</formula>"
|
||||
"</cfRule>"
|
||||
"</conditionalFormatting>"
|
||||
"<pageMargins left=\"0.7\" right=\"0.7\" top=\"0.75\" bottom=\"0.75\" header=\"0.3\" footer=\"0.3\"/>"
|
||||
"</worksheet>";
|
||||
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
worksheet_select(worksheet);
|
||||
|
||||
worksheet_write_number(worksheet, CELL("A1"), 10, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A2"), 20, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A3"), 30, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A4"), 40, NULL);
|
||||
|
||||
lxw_datetime datetime1 = {2011, 1, 1, 0, 0, 0};
|
||||
lxw_datetime datetime2 = {2011, 12, 31, 0, 0, 0};
|
||||
|
||||
lxw_conditional_format *conditional_format = calloc(1, sizeof(lxw_conditional_format));
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_TYPE_CELL;
|
||||
conditional_format->criteria = LXW_CONDITIONAL_CRITERIA_BETWEEN;
|
||||
conditional_format->min_value = lxw_datetime_to_excel_datetime(&datetime1);
|
||||
conditional_format->max_value = lxw_datetime_to_excel_datetime(&datetime2);
|
||||
worksheet_conditional_format_range(worksheet, RANGE("A1:A4"), conditional_format);
|
||||
|
||||
|
||||
free(conditional_format);
|
||||
|
||||
lxw_worksheet_assemble_xml_file(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ_SHORT(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
@ -0,0 +1,515 @@
|
||||
/*
|
||||
* 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/shared_strings.h"
|
||||
|
||||
// Test assembling a complete Worksheet file.
|
||||
CTEST(worksheet, worksheet_condtional_format12) {
|
||||
|
||||
char* got;
|
||||
char exp[] =
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
|
||||
"<worksheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\">"
|
||||
"<dimension ref=\"A1:A12\"/>"
|
||||
"<sheetViews>"
|
||||
"<sheetView tabSelected=\"1\" workbookViewId=\"0\"/>"
|
||||
"</sheetViews>"
|
||||
"<sheetFormatPr defaultRowHeight=\"15\"/>"
|
||||
"<sheetData>"
|
||||
"<row r=\"1\" spans=\"1:1\">"
|
||||
"<c r=\"A1\">"
|
||||
"<v>1</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"2\" spans=\"1:1\">"
|
||||
"<c r=\"A2\">"
|
||||
"<v>2</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"3\" spans=\"1:1\">"
|
||||
"<c r=\"A3\">"
|
||||
"<v>3</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"4\" spans=\"1:1\">"
|
||||
"<c r=\"A4\">"
|
||||
"<v>4</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"5\" spans=\"1:1\">"
|
||||
"<c r=\"A5\">"
|
||||
"<v>5</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"6\" spans=\"1:1\">"
|
||||
"<c r=\"A6\">"
|
||||
"<v>6</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"7\" spans=\"1:1\">"
|
||||
"<c r=\"A7\">"
|
||||
"<v>7</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"8\" spans=\"1:1\">"
|
||||
"<c r=\"A8\">"
|
||||
"<v>8</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"9\" spans=\"1:1\">"
|
||||
"<c r=\"A9\">"
|
||||
"<v>9</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"10\" spans=\"1:1\">"
|
||||
"<c r=\"A10\">"
|
||||
"<v>10</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"11\" spans=\"1:1\">"
|
||||
"<c r=\"A11\">"
|
||||
"<v>11</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"12\" spans=\"1:1\">"
|
||||
"<c r=\"A12\">"
|
||||
"<v>12</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"</sheetData>"
|
||||
"<conditionalFormatting sqref=\"A1:A12\">"
|
||||
"<cfRule type=\"colorScale\" priority=\"1\">"
|
||||
"<colorScale>"
|
||||
"<cfvo type=\"min\" val=\"0\"/>"
|
||||
"<cfvo type=\"max\" val=\"0\"/>"
|
||||
"<color rgb=\"FFFF7128\"/>"
|
||||
"<color rgb=\"FFFFEF9C\"/>"
|
||||
"</colorScale>"
|
||||
"</cfRule>"
|
||||
"</conditionalFormatting>"
|
||||
"<pageMargins left=\"0.7\" right=\"0.7\" top=\"0.75\" bottom=\"0.75\" header=\"0.3\" footer=\"0.3\"/>"
|
||||
"</worksheet>";
|
||||
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
worksheet_select(worksheet);
|
||||
|
||||
worksheet_write_number(worksheet, CELL("A1"), 1, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A2"), 2, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A3"), 3, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A4"), 4, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A5"), 5, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A6"), 6, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A7"), 7, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A8"), 8, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A9"), 9, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A10"), 10, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A11"), 11, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A12"), 12, NULL);
|
||||
|
||||
lxw_conditional_format *conditional_format = calloc(1, sizeof(lxw_conditional_format));
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_2_COLOR_SCALE;
|
||||
worksheet_conditional_format_range(worksheet, RANGE("A1:A12"), conditional_format);
|
||||
|
||||
|
||||
free(conditional_format);
|
||||
|
||||
lxw_worksheet_assemble_xml_file(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ_SHORT(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
// Test with explicit options.
|
||||
CTEST(worksheet, worksheet_condtional_format12b) {
|
||||
|
||||
char* got;
|
||||
char exp[] =
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
|
||||
"<worksheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\">"
|
||||
"<dimension ref=\"A1:A12\"/>"
|
||||
"<sheetViews>"
|
||||
"<sheetView tabSelected=\"1\" workbookViewId=\"0\"/>"
|
||||
"</sheetViews>"
|
||||
"<sheetFormatPr defaultRowHeight=\"15\"/>"
|
||||
"<sheetData>"
|
||||
"<row r=\"1\" spans=\"1:1\">"
|
||||
"<c r=\"A1\">"
|
||||
"<v>1</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"2\" spans=\"1:1\">"
|
||||
"<c r=\"A2\">"
|
||||
"<v>2</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"3\" spans=\"1:1\">"
|
||||
"<c r=\"A3\">"
|
||||
"<v>3</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"4\" spans=\"1:1\">"
|
||||
"<c r=\"A4\">"
|
||||
"<v>4</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"5\" spans=\"1:1\">"
|
||||
"<c r=\"A5\">"
|
||||
"<v>5</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"6\" spans=\"1:1\">"
|
||||
"<c r=\"A6\">"
|
||||
"<v>6</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"7\" spans=\"1:1\">"
|
||||
"<c r=\"A7\">"
|
||||
"<v>7</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"8\" spans=\"1:1\">"
|
||||
"<c r=\"A8\">"
|
||||
"<v>8</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"9\" spans=\"1:1\">"
|
||||
"<c r=\"A9\">"
|
||||
"<v>9</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"10\" spans=\"1:1\">"
|
||||
"<c r=\"A10\">"
|
||||
"<v>10</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"11\" spans=\"1:1\">"
|
||||
"<c r=\"A11\">"
|
||||
"<v>11</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"12\" spans=\"1:1\">"
|
||||
"<c r=\"A12\">"
|
||||
"<v>12</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"</sheetData>"
|
||||
"<conditionalFormatting sqref=\"A1:A12\">"
|
||||
"<cfRule type=\"colorScale\" priority=\"1\">"
|
||||
"<colorScale>"
|
||||
"<cfvo type=\"min\" val=\"0\"/>"
|
||||
"<cfvo type=\"max\" val=\"0\"/>"
|
||||
"<color rgb=\"FFFF7128\"/>"
|
||||
"<color rgb=\"FFFFEF9C\"/>"
|
||||
"</colorScale>"
|
||||
"</cfRule>"
|
||||
"</conditionalFormatting>"
|
||||
"<pageMargins left=\"0.7\" right=\"0.7\" top=\"0.75\" bottom=\"0.75\" header=\"0.3\" footer=\"0.3\"/>"
|
||||
"</worksheet>";
|
||||
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
worksheet_select(worksheet);
|
||||
|
||||
worksheet_write_number(worksheet, CELL("A1"), 1, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A2"), 2, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A3"), 3, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A4"), 4, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A5"), 5, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A6"), 6, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A7"), 7, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A8"), 8, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A9"), 9, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A10"), 10, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A11"), 11, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A12"), 12, NULL);
|
||||
|
||||
lxw_conditional_format *conditional_format = calloc(1, sizeof(lxw_conditional_format));
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_2_COLOR_SCALE;
|
||||
conditional_format->min_rule_type = LXW_CONDITIONAL_RULE_TYPE_MINIMUM;
|
||||
conditional_format->max_rule_type = LXW_CONDITIONAL_RULE_TYPE_MAXIMUM;
|
||||
conditional_format->min_color = 0xFF7128;
|
||||
conditional_format->max_color = 0xFFEF9C;
|
||||
worksheet_conditional_format_range(worksheet, RANGE("A1:A12"), conditional_format);
|
||||
|
||||
|
||||
free(conditional_format);
|
||||
|
||||
lxw_worksheet_assemble_xml_file(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ_SHORT(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
#include "../ctest.h"
|
||||
#include "../helper.h"
|
||||
|
||||
#include "../../../include/xlsxwriter/worksheet.h"
|
||||
#include "../../../include/xlsxwriter/shared_strings.h"
|
||||
|
||||
// Test with number values.
|
||||
CTEST(worksheet, worksheet_condtional_format12c) {
|
||||
|
||||
char* got;
|
||||
char exp[] =
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
|
||||
"<worksheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\">"
|
||||
"<dimension ref=\"A1:A12\"/>"
|
||||
"<sheetViews>"
|
||||
"<sheetView tabSelected=\"1\" workbookViewId=\"0\"/>"
|
||||
"</sheetViews>"
|
||||
"<sheetFormatPr defaultRowHeight=\"15\"/>"
|
||||
"<sheetData>"
|
||||
"<row r=\"1\" spans=\"1:1\">"
|
||||
"<c r=\"A1\">"
|
||||
"<v>1</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"2\" spans=\"1:1\">"
|
||||
"<c r=\"A2\">"
|
||||
"<v>2</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"3\" spans=\"1:1\">"
|
||||
"<c r=\"A3\">"
|
||||
"<v>3</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"4\" spans=\"1:1\">"
|
||||
"<c r=\"A4\">"
|
||||
"<v>4</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"5\" spans=\"1:1\">"
|
||||
"<c r=\"A5\">"
|
||||
"<v>5</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"6\" spans=\"1:1\">"
|
||||
"<c r=\"A6\">"
|
||||
"<v>6</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"7\" spans=\"1:1\">"
|
||||
"<c r=\"A7\">"
|
||||
"<v>7</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"8\" spans=\"1:1\">"
|
||||
"<c r=\"A8\">"
|
||||
"<v>8</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"9\" spans=\"1:1\">"
|
||||
"<c r=\"A9\">"
|
||||
"<v>9</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"10\" spans=\"1:1\">"
|
||||
"<c r=\"A10\">"
|
||||
"<v>10</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"11\" spans=\"1:1\">"
|
||||
"<c r=\"A11\">"
|
||||
"<v>11</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"12\" spans=\"1:1\">"
|
||||
"<c r=\"A12\">"
|
||||
"<v>12</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"</sheetData>"
|
||||
"<conditionalFormatting sqref=\"A1:A12\">"
|
||||
"<cfRule type=\"colorScale\" priority=\"1\">"
|
||||
"<colorScale>"
|
||||
"<cfvo type=\"num\" val=\"20\"/>"
|
||||
"<cfvo type=\"num\" val=\"80\"/>"
|
||||
"<color rgb=\"FFFF7128\"/>"
|
||||
"<color rgb=\"FFFFEF9C\"/>"
|
||||
"</colorScale>"
|
||||
"</cfRule>"
|
||||
"</conditionalFormatting>"
|
||||
"<pageMargins left=\"0.7\" right=\"0.7\" top=\"0.75\" bottom=\"0.75\" header=\"0.3\" footer=\"0.3\"/>"
|
||||
"</worksheet>";
|
||||
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
worksheet_select(worksheet);
|
||||
|
||||
worksheet_write_number(worksheet, CELL("A1"), 1, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A2"), 2, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A3"), 3, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A4"), 4, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A5"), 5, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A6"), 6, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A7"), 7, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A8"), 8, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A9"), 9, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A10"), 10, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A11"), 11, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A12"), 12, NULL);
|
||||
|
||||
lxw_conditional_format *conditional_format = calloc(1, sizeof(lxw_conditional_format));
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_2_COLOR_SCALE;
|
||||
conditional_format->min_rule_type = LXW_CONDITIONAL_RULE_TYPE_NUMBER;
|
||||
conditional_format->max_rule_type = LXW_CONDITIONAL_RULE_TYPE_NUMBER;
|
||||
conditional_format->min_value = 20;
|
||||
conditional_format->max_value = 80;
|
||||
worksheet_conditional_format_range(worksheet, RANGE("A1:A12"), conditional_format);
|
||||
|
||||
|
||||
free(conditional_format);
|
||||
|
||||
lxw_worksheet_assemble_xml_file(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ_SHORT(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
// Test with cell reference values.
|
||||
CTEST(worksheet, worksheet_condtional_format12d) {
|
||||
|
||||
char* got;
|
||||
char exp[] =
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
|
||||
"<worksheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\">"
|
||||
"<dimension ref=\"A1:A12\"/>"
|
||||
"<sheetViews>"
|
||||
"<sheetView tabSelected=\"1\" workbookViewId=\"0\"/>"
|
||||
"</sheetViews>"
|
||||
"<sheetFormatPr defaultRowHeight=\"15\"/>"
|
||||
"<sheetData>"
|
||||
"<row r=\"1\" spans=\"1:1\">"
|
||||
"<c r=\"A1\">"
|
||||
"<v>1</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"2\" spans=\"1:1\">"
|
||||
"<c r=\"A2\">"
|
||||
"<v>2</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"3\" spans=\"1:1\">"
|
||||
"<c r=\"A3\">"
|
||||
"<v>3</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"4\" spans=\"1:1\">"
|
||||
"<c r=\"A4\">"
|
||||
"<v>4</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"5\" spans=\"1:1\">"
|
||||
"<c r=\"A5\">"
|
||||
"<v>5</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"6\" spans=\"1:1\">"
|
||||
"<c r=\"A6\">"
|
||||
"<v>6</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"7\" spans=\"1:1\">"
|
||||
"<c r=\"A7\">"
|
||||
"<v>7</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"8\" spans=\"1:1\">"
|
||||
"<c r=\"A8\">"
|
||||
"<v>8</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"9\" spans=\"1:1\">"
|
||||
"<c r=\"A9\">"
|
||||
"<v>9</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"10\" spans=\"1:1\">"
|
||||
"<c r=\"A10\">"
|
||||
"<v>10</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"11\" spans=\"1:1\">"
|
||||
"<c r=\"A11\">"
|
||||
"<v>11</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"12\" spans=\"1:1\">"
|
||||
"<c r=\"A12\">"
|
||||
"<v>12</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"</sheetData>"
|
||||
"<conditionalFormatting sqref=\"A1:A12\">"
|
||||
"<cfRule type=\"colorScale\" priority=\"1\">"
|
||||
"<colorScale>"
|
||||
"<cfvo type=\"num\" val=\"$D$1\"/>"
|
||||
"<cfvo type=\"num\" val=\"$D$2\"/>"
|
||||
"<color rgb=\"FFFF7128\"/>"
|
||||
"<color rgb=\"FFFFEF9C\"/>"
|
||||
"</colorScale>"
|
||||
"</cfRule>"
|
||||
"</conditionalFormatting>"
|
||||
"<pageMargins left=\"0.7\" right=\"0.7\" top=\"0.75\" bottom=\"0.75\" header=\"0.3\" footer=\"0.3\"/>"
|
||||
"</worksheet>";
|
||||
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
worksheet_select(worksheet);
|
||||
|
||||
worksheet_write_number(worksheet, CELL("A1"), 1, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A2"), 2, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A3"), 3, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A4"), 4, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A5"), 5, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A6"), 6, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A7"), 7, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A8"), 8, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A9"), 9, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A10"), 10, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A11"), 11, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A12"), 12, NULL);
|
||||
|
||||
lxw_conditional_format *conditional_format = calloc(1, sizeof(lxw_conditional_format));
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_2_COLOR_SCALE;
|
||||
conditional_format->min_rule_type = LXW_CONDITIONAL_RULE_TYPE_NUMBER;
|
||||
conditional_format->max_rule_type = LXW_CONDITIONAL_RULE_TYPE_NUMBER;
|
||||
conditional_format->min_value_string = "$D$1";
|
||||
conditional_format->max_value_string = "$D$2";
|
||||
worksheet_conditional_format_range(worksheet, RANGE("A1:A12"), conditional_format);
|
||||
|
||||
|
||||
free(conditional_format);
|
||||
|
||||
lxw_worksheet_assemble_xml_file(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ_SHORT(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
@ -0,0 +1,266 @@
|
||||
/*
|
||||
* 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/shared_strings.h"
|
||||
|
||||
// Test assembling a complete Worksheet file.
|
||||
CTEST(worksheet, worksheet_condtional_format13) {
|
||||
|
||||
char* got;
|
||||
char exp[] =
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
|
||||
"<worksheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\">"
|
||||
"<dimension ref=\"A1:A12\"/>"
|
||||
"<sheetViews>"
|
||||
"<sheetView tabSelected=\"1\" workbookViewId=\"0\"/>"
|
||||
"</sheetViews>"
|
||||
"<sheetFormatPr defaultRowHeight=\"15\"/>"
|
||||
"<sheetData>"
|
||||
"<row r=\"1\" spans=\"1:1\">"
|
||||
"<c r=\"A1\">"
|
||||
"<v>1</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"2\" spans=\"1:1\">"
|
||||
"<c r=\"A2\">"
|
||||
"<v>2</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"3\" spans=\"1:1\">"
|
||||
"<c r=\"A3\">"
|
||||
"<v>3</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"4\" spans=\"1:1\">"
|
||||
"<c r=\"A4\">"
|
||||
"<v>4</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"5\" spans=\"1:1\">"
|
||||
"<c r=\"A5\">"
|
||||
"<v>5</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"6\" spans=\"1:1\">"
|
||||
"<c r=\"A6\">"
|
||||
"<v>6</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"7\" spans=\"1:1\">"
|
||||
"<c r=\"A7\">"
|
||||
"<v>7</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"8\" spans=\"1:1\">"
|
||||
"<c r=\"A8\">"
|
||||
"<v>8</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"9\" spans=\"1:1\">"
|
||||
"<c r=\"A9\">"
|
||||
"<v>9</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"10\" spans=\"1:1\">"
|
||||
"<c r=\"A10\">"
|
||||
"<v>10</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"11\" spans=\"1:1\">"
|
||||
"<c r=\"A11\">"
|
||||
"<v>11</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"12\" spans=\"1:1\">"
|
||||
"<c r=\"A12\">"
|
||||
"<v>12</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"</sheetData>"
|
||||
"<conditionalFormatting sqref=\"A1:A12\">"
|
||||
"<cfRule type=\"colorScale\" priority=\"1\">"
|
||||
"<colorScale>"
|
||||
"<cfvo type=\"min\" val=\"0\"/>"
|
||||
"<cfvo type=\"percentile\" val=\"50\"/>"
|
||||
"<cfvo type=\"max\" val=\"0\"/>"
|
||||
"<color rgb=\"FFF8696B\"/>"
|
||||
"<color rgb=\"FFFFEB84\"/>"
|
||||
"<color rgb=\"FF63BE7B\"/>"
|
||||
"</colorScale>"
|
||||
"</cfRule>"
|
||||
"</conditionalFormatting>"
|
||||
"<pageMargins left=\"0.7\" right=\"0.7\" top=\"0.75\" bottom=\"0.75\" header=\"0.3\" footer=\"0.3\"/>"
|
||||
"</worksheet>";
|
||||
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
worksheet_select(worksheet);
|
||||
|
||||
worksheet_write_number(worksheet, CELL("A1"), 1, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A2"), 2, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A3"), 3, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A4"), 4, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A5"), 5, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A6"), 6, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A7"), 7, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A8"), 8, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A9"), 9, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A10"), 10, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A11"), 11, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A12"), 12, NULL);
|
||||
|
||||
lxw_conditional_format *conditional_format = calloc(1, sizeof(lxw_conditional_format));
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_3_COLOR_SCALE;
|
||||
worksheet_conditional_format_range(worksheet, RANGE("A1:A12"), conditional_format);
|
||||
|
||||
|
||||
free(conditional_format);
|
||||
|
||||
lxw_worksheet_assemble_xml_file(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ_SHORT(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
// Test with explicit options.
|
||||
CTEST(worksheet, worksheet_condtional_format13b) {
|
||||
|
||||
char* got;
|
||||
char exp[] =
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
|
||||
"<worksheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\">"
|
||||
"<dimension ref=\"A1:A12\"/>"
|
||||
"<sheetViews>"
|
||||
"<sheetView tabSelected=\"1\" workbookViewId=\"0\"/>"
|
||||
"</sheetViews>"
|
||||
"<sheetFormatPr defaultRowHeight=\"15\"/>"
|
||||
"<sheetData>"
|
||||
"<row r=\"1\" spans=\"1:1\">"
|
||||
"<c r=\"A1\">"
|
||||
"<v>1</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"2\" spans=\"1:1\">"
|
||||
"<c r=\"A2\">"
|
||||
"<v>2</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"3\" spans=\"1:1\">"
|
||||
"<c r=\"A3\">"
|
||||
"<v>3</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"4\" spans=\"1:1\">"
|
||||
"<c r=\"A4\">"
|
||||
"<v>4</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"5\" spans=\"1:1\">"
|
||||
"<c r=\"A5\">"
|
||||
"<v>5</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"6\" spans=\"1:1\">"
|
||||
"<c r=\"A6\">"
|
||||
"<v>6</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"7\" spans=\"1:1\">"
|
||||
"<c r=\"A7\">"
|
||||
"<v>7</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"8\" spans=\"1:1\">"
|
||||
"<c r=\"A8\">"
|
||||
"<v>8</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"9\" spans=\"1:1\">"
|
||||
"<c r=\"A9\">"
|
||||
"<v>9</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"10\" spans=\"1:1\">"
|
||||
"<c r=\"A10\">"
|
||||
"<v>10</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"11\" spans=\"1:1\">"
|
||||
"<c r=\"A11\">"
|
||||
"<v>11</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"12\" spans=\"1:1\">"
|
||||
"<c r=\"A12\">"
|
||||
"<v>12</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"</sheetData>"
|
||||
"<conditionalFormatting sqref=\"A1:A12\">"
|
||||
"<cfRule type=\"colorScale\" priority=\"1\">"
|
||||
"<colorScale>"
|
||||
"<cfvo type=\"min\" val=\"0\"/>"
|
||||
"<cfvo type=\"percentile\" val=\"50\"/>"
|
||||
"<cfvo type=\"max\" val=\"0\"/>"
|
||||
"<color rgb=\"FFF8696B\"/>"
|
||||
"<color rgb=\"FFFFEB84\"/>"
|
||||
"<color rgb=\"FF63BE7B\"/>"
|
||||
"</colorScale>"
|
||||
"</cfRule>"
|
||||
"</conditionalFormatting>"
|
||||
"<pageMargins left=\"0.7\" right=\"0.7\" top=\"0.75\" bottom=\"0.75\" header=\"0.3\" footer=\"0.3\"/>"
|
||||
"</worksheet>";
|
||||
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
worksheet_select(worksheet);
|
||||
|
||||
worksheet_write_number(worksheet, CELL("A1"), 1, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A2"), 2, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A3"), 3, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A4"), 4, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A5"), 5, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A6"), 6, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A7"), 7, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A8"), 8, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A9"), 9, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A10"), 10, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A11"), 11, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A12"), 12, NULL);
|
||||
|
||||
lxw_conditional_format *conditional_format = calloc(1, sizeof(lxw_conditional_format));
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_3_COLOR_SCALE;
|
||||
conditional_format->min_rule_type = LXW_CONDITIONAL_RULE_TYPE_MINIMUM;
|
||||
conditional_format->mid_rule_type = LXW_CONDITIONAL_RULE_TYPE_PERCENTILE;
|
||||
conditional_format->max_rule_type = LXW_CONDITIONAL_RULE_TYPE_MAXIMUM;
|
||||
conditional_format->mid_value = 50;
|
||||
conditional_format->min_color = 0xF8696B;
|
||||
conditional_format->max_color = 0xFFEB84;
|
||||
conditional_format->max_color = 0x63BE7B;
|
||||
worksheet_conditional_format_range(worksheet, RANGE("A1:A12"), conditional_format);
|
||||
|
||||
|
||||
free(conditional_format);
|
||||
|
||||
lxw_worksheet_assemble_xml_file(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ_SHORT(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
@ -0,0 +1,132 @@
|
||||
/*
|
||||
* 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/shared_strings.h"
|
||||
|
||||
// Test assembling a complete Worksheet file.
|
||||
CTEST(worksheet, worksheet_condtional_format14) {
|
||||
|
||||
char* got;
|
||||
char exp[] =
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
|
||||
"<worksheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\">"
|
||||
"<dimension ref=\"A1:A12\"/>"
|
||||
"<sheetViews>"
|
||||
"<sheetView tabSelected=\"1\" workbookViewId=\"0\"/>"
|
||||
"</sheetViews>"
|
||||
"<sheetFormatPr defaultRowHeight=\"15\"/>"
|
||||
"<sheetData>"
|
||||
"<row r=\"1\" spans=\"1:1\">"
|
||||
"<c r=\"A1\">"
|
||||
"<v>1</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"2\" spans=\"1:1\">"
|
||||
"<c r=\"A2\">"
|
||||
"<v>2</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"3\" spans=\"1:1\">"
|
||||
"<c r=\"A3\">"
|
||||
"<v>3</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"4\" spans=\"1:1\">"
|
||||
"<c r=\"A4\">"
|
||||
"<v>4</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"5\" spans=\"1:1\">"
|
||||
"<c r=\"A5\">"
|
||||
"<v>5</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"6\" spans=\"1:1\">"
|
||||
"<c r=\"A6\">"
|
||||
"<v>6</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"7\" spans=\"1:1\">"
|
||||
"<c r=\"A7\">"
|
||||
"<v>7</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"8\" spans=\"1:1\">"
|
||||
"<c r=\"A8\">"
|
||||
"<v>8</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"9\" spans=\"1:1\">"
|
||||
"<c r=\"A9\">"
|
||||
"<v>9</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"10\" spans=\"1:1\">"
|
||||
"<c r=\"A10\">"
|
||||
"<v>10</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"11\" spans=\"1:1\">"
|
||||
"<c r=\"A11\">"
|
||||
"<v>11</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"12\" spans=\"1:1\">"
|
||||
"<c r=\"A12\">"
|
||||
"<v>12</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"</sheetData>"
|
||||
"<conditionalFormatting sqref=\"A1:A12\">"
|
||||
"<cfRule type=\"dataBar\" priority=\"1\">"
|
||||
"<dataBar>"
|
||||
"<cfvo type=\"min\" val=\"0\"/>"
|
||||
"<cfvo type=\"max\" val=\"0\"/>"
|
||||
"<color rgb=\"FF638EC6\"/>"
|
||||
"</dataBar>"
|
||||
"</cfRule>"
|
||||
"</conditionalFormatting>"
|
||||
"<pageMargins left=\"0.7\" right=\"0.7\" top=\"0.75\" bottom=\"0.75\" header=\"0.3\" footer=\"0.3\"/>"
|
||||
"</worksheet>";
|
||||
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
worksheet_select(worksheet);
|
||||
|
||||
worksheet_write_number(worksheet, CELL("A1"), 1, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A2"), 2, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A3"), 3, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A4"), 4, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A5"), 5, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A6"), 6, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A7"), 7, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A8"), 8, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A9"), 9, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A10"), 10, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A11"), 11, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A12"), 12, NULL);
|
||||
|
||||
lxw_conditional_format *conditional_format = calloc(1, sizeof(lxw_conditional_format));
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_DATA_BAR;
|
||||
worksheet_conditional_format_range(worksheet, RANGE("A1:A12"), conditional_format);
|
||||
|
||||
|
||||
free(conditional_format);
|
||||
|
||||
lxw_worksheet_assemble_xml_file(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ_SHORT(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
@ -0,0 +1,103 @@
|
||||
/*
|
||||
* 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/shared_strings.h"
|
||||
|
||||
// Test assembling a complete Worksheet file.
|
||||
CTEST(worksheet, worksheet_condtional_format15) {
|
||||
|
||||
char* got;
|
||||
char exp[] =
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
|
||||
"<worksheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\">"
|
||||
"<dimension ref=\"A1:A4\"/>"
|
||||
"<sheetViews>"
|
||||
"<sheetView tabSelected=\"1\" workbookViewId=\"0\"/>"
|
||||
"</sheetViews>"
|
||||
"<sheetFormatPr defaultRowHeight=\"15\"/>"
|
||||
"<sheetData>"
|
||||
"<row r=\"1\" spans=\"1:1\">"
|
||||
"<c r=\"A1\">"
|
||||
"<v>10</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"2\" spans=\"1:1\">"
|
||||
"<c r=\"A2\">"
|
||||
"<v>20</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"3\" spans=\"1:1\">"
|
||||
"<c r=\"A3\">"
|
||||
"<v>30</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"4\" spans=\"1:1\">"
|
||||
"<c r=\"A4\">"
|
||||
"<v>40</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"</sheetData>"
|
||||
"<conditionalFormatting sqref=\"A1:A4\">"
|
||||
"<cfRule type=\"expression\" priority=\"1\">"
|
||||
"<formula>$A$1>5</formula>"
|
||||
"</cfRule>"
|
||||
"<cfRule type=\"expression\" priority=\"2\">"
|
||||
"<formula>$A$2<80</formula>"
|
||||
"</cfRule>"
|
||||
"<cfRule type=\"expression\" priority=\"3\">"
|
||||
"<formula>\"1+2\"</formula>"
|
||||
"</cfRule>"
|
||||
"<cfRule type=\"expression\" priority=\"4\">"
|
||||
"<formula>$A$3>$A$4</formula>"
|
||||
"</cfRule>"
|
||||
"</conditionalFormatting>"
|
||||
"<pageMargins left=\"0.7\" right=\"0.7\" top=\"0.75\" bottom=\"0.75\" header=\"0.3\" footer=\"0.3\"/>"
|
||||
"</worksheet>";
|
||||
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
worksheet_select(worksheet);
|
||||
|
||||
worksheet_write_number(worksheet, CELL("A1"), 10, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A2"), 20, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A3"), 30, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A4"), 40, NULL);
|
||||
|
||||
lxw_conditional_format *conditional_format = calloc(1, sizeof(lxw_conditional_format));
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_TYPE_FORMULA;
|
||||
conditional_format->value_string = "=$A$1>5";
|
||||
worksheet_conditional_format_range(worksheet, RANGE("A1:A4"), conditional_format);
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_TYPE_FORMULA;
|
||||
conditional_format->value_string = "=$A$2<80";
|
||||
worksheet_conditional_format_range(worksheet, RANGE("A1:A4"), conditional_format);
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_TYPE_FORMULA;
|
||||
conditional_format->value_string = "\"1+2\"";
|
||||
worksheet_conditional_format_range(worksheet, RANGE("A1:A4"), conditional_format);
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_TYPE_FORMULA;
|
||||
conditional_format->value_string = "=$A$3>$A$4";
|
||||
worksheet_conditional_format_range(worksheet, RANGE("A1:A4"), conditional_format);
|
||||
|
||||
free(conditional_format);
|
||||
|
||||
lxw_worksheet_assemble_xml_file(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ_SHORT(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,138 @@
|
||||
/*
|
||||
* 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/shared_strings.h"
|
||||
|
||||
// Test assembling a complete Worksheet file.
|
||||
CTEST(worksheet, worksheet_condtional_format16) {
|
||||
|
||||
char* got;
|
||||
char exp[] =
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
|
||||
"<worksheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\">"
|
||||
"<dimension ref=\"A1:A12\"/>"
|
||||
"<sheetViews>"
|
||||
"<sheetView tabSelected=\"1\" workbookViewId=\"0\"/>"
|
||||
"</sheetViews>"
|
||||
"<sheetFormatPr defaultRowHeight=\"15\"/>"
|
||||
"<sheetData>"
|
||||
"<row r=\"1\" spans=\"1:1\">"
|
||||
"<c r=\"A1\">"
|
||||
"<v>1</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"2\" spans=\"1:1\">"
|
||||
"<c r=\"A2\">"
|
||||
"<v>2</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"3\" spans=\"1:1\">"
|
||||
"<c r=\"A3\">"
|
||||
"<v>3</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"4\" spans=\"1:1\">"
|
||||
"<c r=\"A4\">"
|
||||
"<v>4</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"5\" spans=\"1:1\">"
|
||||
"<c r=\"A5\">"
|
||||
"<v>5</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"6\" spans=\"1:1\">"
|
||||
"<c r=\"A6\">"
|
||||
"<v>6</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"7\" spans=\"1:1\">"
|
||||
"<c r=\"A7\">"
|
||||
"<v>7</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"8\" spans=\"1:1\">"
|
||||
"<c r=\"A8\">"
|
||||
"<v>8</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"9\" spans=\"1:1\">"
|
||||
"<c r=\"A9\">"
|
||||
"<v>9</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"10\" spans=\"1:1\">"
|
||||
"<c r=\"A10\">"
|
||||
"<v>10</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"11\" spans=\"1:1\">"
|
||||
"<c r=\"A11\">"
|
||||
"<v>11</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"12\" spans=\"1:1\">"
|
||||
"<c r=\"A12\">"
|
||||
"<v>12</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"</sheetData>"
|
||||
"<conditionalFormatting sqref=\"A1:A12\">"
|
||||
"<cfRule type=\"colorScale\" priority=\"1\">"
|
||||
"<colorScale>"
|
||||
"<cfvo type=\"min\" val=\"0\"/>"
|
||||
"<cfvo type=\"percentile\" val=\"50\"/>"
|
||||
"<cfvo type=\"max\" val=\"0\"/>"
|
||||
"<color rgb=\"FFC5D9F1\"/>"
|
||||
"<color rgb=\"FF8DB4E3\"/>"
|
||||
"<color rgb=\"FF538ED5\"/>"
|
||||
"</colorScale>"
|
||||
"</cfRule>"
|
||||
"</conditionalFormatting>"
|
||||
"<pageMargins left=\"0.7\" right=\"0.7\" top=\"0.75\" bottom=\"0.75\" header=\"0.3\" footer=\"0.3\"/>"
|
||||
"</worksheet>";
|
||||
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
worksheet_select(worksheet);
|
||||
|
||||
worksheet_write_number(worksheet, CELL("A1"), 1, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A2"), 2, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A3"), 3, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A4"), 4, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A5"), 5, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A6"), 6, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A7"), 7, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A8"), 8, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A9"), 9, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A10"), 10, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A11"), 11, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A12"), 12, NULL);
|
||||
|
||||
lxw_conditional_format *conditional_format = calloc(1, sizeof(lxw_conditional_format));
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_3_COLOR_SCALE;
|
||||
conditional_format->min_color = 0xC5D9F1;
|
||||
conditional_format->mid_color = 0x8DB4E3;
|
||||
conditional_format->max_color = 0x538ED5;
|
||||
|
||||
worksheet_conditional_format_range(worksheet, RANGE("A1:A12"), conditional_format);
|
||||
|
||||
free(conditional_format);
|
||||
|
||||
lxw_worksheet_assemble_xml_file(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ_SHORT(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
@ -0,0 +1,270 @@
|
||||
/*
|
||||
* 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/shared_strings.h"
|
||||
|
||||
// Test assembling a complete Worksheet file.
|
||||
CTEST(worksheet, worksheet_condtional_format17) {
|
||||
|
||||
char* got;
|
||||
char exp[] =
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
|
||||
"<worksheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\">"
|
||||
"<dimension ref=\"A1:A12\"/>"
|
||||
"<sheetViews>"
|
||||
"<sheetView tabSelected=\"1\" workbookViewId=\"0\"/>"
|
||||
"</sheetViews>"
|
||||
"<sheetFormatPr defaultRowHeight=\"15\"/>"
|
||||
"<sheetData>"
|
||||
"<row r=\"1\" spans=\"1:1\">"
|
||||
"<c r=\"A1\">"
|
||||
"<v>1</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"2\" spans=\"1:1\">"
|
||||
"<c r=\"A2\">"
|
||||
"<v>2</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"3\" spans=\"1:1\">"
|
||||
"<c r=\"A3\">"
|
||||
"<v>3</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"4\" spans=\"1:1\">"
|
||||
"<c r=\"A4\">"
|
||||
"<v>4</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"5\" spans=\"1:1\">"
|
||||
"<c r=\"A5\">"
|
||||
"<v>5</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"6\" spans=\"1:1\">"
|
||||
"<c r=\"A6\">"
|
||||
"<v>6</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"7\" spans=\"1:1\">"
|
||||
"<c r=\"A7\">"
|
||||
"<v>7</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"8\" spans=\"1:1\">"
|
||||
"<c r=\"A8\">"
|
||||
"<v>8</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"9\" spans=\"1:1\">"
|
||||
"<c r=\"A9\">"
|
||||
"<v>9</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"10\" spans=\"1:1\">"
|
||||
"<c r=\"A10\">"
|
||||
"<v>10</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"11\" spans=\"1:1\">"
|
||||
"<c r=\"A11\">"
|
||||
"<v>11</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"12\" spans=\"1:1\">"
|
||||
"<c r=\"A12\">"
|
||||
"<v>12</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"</sheetData>"
|
||||
"<conditionalFormatting sqref=\"A1:A12\">"
|
||||
"<cfRule type=\"colorScale\" priority=\"1\">"
|
||||
"<colorScale>"
|
||||
"<cfvo type=\"num\" val=\"$A$10\"/>"
|
||||
"<cfvo type=\"percent\" val=\"52\"/>"
|
||||
"<cfvo type=\"percentile\" val=\"99\"/>"
|
||||
"<color rgb=\"FFF8696B\"/>"
|
||||
"<color rgb=\"FFFFEB84\"/>"
|
||||
"<color rgb=\"FF63BE7B\"/>"
|
||||
"</colorScale>"
|
||||
"</cfRule>"
|
||||
"</conditionalFormatting>"
|
||||
"<pageMargins left=\"0.7\" right=\"0.7\" top=\"0.75\" bottom=\"0.75\" header=\"0.3\" footer=\"0.3\"/>"
|
||||
"</worksheet>";
|
||||
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
worksheet_select(worksheet);
|
||||
|
||||
worksheet_write_number(worksheet, CELL("A1"), 1, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A2"), 2, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A3"), 3, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A4"), 4, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A5"), 5, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A6"), 6, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A7"), 7, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A8"), 8, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A9"), 9, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A10"), 10, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A11"), 11, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A12"), 12, NULL);
|
||||
|
||||
lxw_conditional_format *conditional_format = calloc(1, sizeof(lxw_conditional_format));
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_3_COLOR_SCALE;
|
||||
conditional_format->min_value_string = "$A$10";
|
||||
conditional_format->mid_value = 52;
|
||||
conditional_format->max_value = 99;
|
||||
conditional_format->min_rule_type = LXW_CONDITIONAL_RULE_TYPE_NUMBER;
|
||||
conditional_format->mid_rule_type = LXW_CONDITIONAL_RULE_TYPE_PERCENT;
|
||||
conditional_format->max_rule_type = LXW_CONDITIONAL_RULE_TYPE_PERCENTILE;
|
||||
|
||||
worksheet_conditional_format_range(worksheet, RANGE("A1:A12"), conditional_format);
|
||||
|
||||
free(conditional_format);
|
||||
|
||||
lxw_worksheet_assemble_xml_file(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ_SHORT(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
// Test with more cell ranges.
|
||||
CTEST(worksheet, worksheet_condtional_format17b) {
|
||||
|
||||
char* got;
|
||||
char exp[] =
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
|
||||
"<worksheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\">"
|
||||
"<dimension ref=\"A1:A12\"/>"
|
||||
"<sheetViews>"
|
||||
"<sheetView tabSelected=\"1\" workbookViewId=\"0\"/>"
|
||||
"</sheetViews>"
|
||||
"<sheetFormatPr defaultRowHeight=\"15\"/>"
|
||||
"<sheetData>"
|
||||
"<row r=\"1\" spans=\"1:1\">"
|
||||
"<c r=\"A1\">"
|
||||
"<v>1</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"2\" spans=\"1:1\">"
|
||||
"<c r=\"A2\">"
|
||||
"<v>2</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"3\" spans=\"1:1\">"
|
||||
"<c r=\"A3\">"
|
||||
"<v>3</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"4\" spans=\"1:1\">"
|
||||
"<c r=\"A4\">"
|
||||
"<v>4</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"5\" spans=\"1:1\">"
|
||||
"<c r=\"A5\">"
|
||||
"<v>5</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"6\" spans=\"1:1\">"
|
||||
"<c r=\"A6\">"
|
||||
"<v>6</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"7\" spans=\"1:1\">"
|
||||
"<c r=\"A7\">"
|
||||
"<v>7</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"8\" spans=\"1:1\">"
|
||||
"<c r=\"A8\">"
|
||||
"<v>8</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"9\" spans=\"1:1\">"
|
||||
"<c r=\"A9\">"
|
||||
"<v>9</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"10\" spans=\"1:1\">"
|
||||
"<c r=\"A10\">"
|
||||
"<v>10</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"11\" spans=\"1:1\">"
|
||||
"<c r=\"A11\">"
|
||||
"<v>11</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"12\" spans=\"1:1\">"
|
||||
"<c r=\"A12\">"
|
||||
"<v>12</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"</sheetData>"
|
||||
"<conditionalFormatting sqref=\"A1:A12\">"
|
||||
"<cfRule type=\"colorScale\" priority=\"1\">"
|
||||
"<colorScale>"
|
||||
"<cfvo type=\"num\" val=\"$A$1\"/>"
|
||||
"<cfvo type=\"percent\" val=\"$A$2\"/>"
|
||||
"<cfvo type=\"percentile\" val=\"$A$3\"/>"
|
||||
"<color rgb=\"FFF8696B\"/>"
|
||||
"<color rgb=\"FFFFEB84\"/>"
|
||||
"<color rgb=\"FF63BE7B\"/>"
|
||||
"</colorScale>"
|
||||
"</cfRule>"
|
||||
"</conditionalFormatting>"
|
||||
"<pageMargins left=\"0.7\" right=\"0.7\" top=\"0.75\" bottom=\"0.75\" header=\"0.3\" footer=\"0.3\"/>"
|
||||
"</worksheet>";
|
||||
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
worksheet_select(worksheet);
|
||||
|
||||
worksheet_write_number(worksheet, CELL("A1"), 1, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A2"), 2, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A3"), 3, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A4"), 4, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A5"), 5, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A6"), 6, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A7"), 7, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A8"), 8, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A9"), 9, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A10"), 10, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A11"), 11, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A12"), 12, NULL);
|
||||
|
||||
lxw_conditional_format *conditional_format = calloc(1, sizeof(lxw_conditional_format));
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_3_COLOR_SCALE;
|
||||
conditional_format->min_value_string = "$A$1";
|
||||
conditional_format->mid_value_string = "$A$2";
|
||||
conditional_format->max_value_string = "$A$3";
|
||||
conditional_format->min_rule_type = LXW_CONDITIONAL_RULE_TYPE_NUMBER;
|
||||
conditional_format->mid_rule_type = LXW_CONDITIONAL_RULE_TYPE_PERCENT;
|
||||
conditional_format->max_rule_type = LXW_CONDITIONAL_RULE_TYPE_PERCENTILE;
|
||||
|
||||
worksheet_conditional_format_range(worksheet, RANGE("A1:A12"), conditional_format);
|
||||
|
||||
free(conditional_format);
|
||||
|
||||
lxw_worksheet_assemble_xml_file(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ_SHORT(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
@ -0,0 +1,135 @@
|
||||
/*
|
||||
* 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/shared_strings.h"
|
||||
|
||||
// Test assembling a complete Worksheet file.
|
||||
CTEST(worksheet, worksheet_condtional_format18) {
|
||||
|
||||
char* got;
|
||||
char exp[] =
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
|
||||
"<worksheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\">"
|
||||
"<dimension ref=\"A1:A12\"/>"
|
||||
"<sheetViews>"
|
||||
"<sheetView tabSelected=\"1\" workbookViewId=\"0\"/>"
|
||||
"</sheetViews>"
|
||||
"<sheetFormatPr defaultRowHeight=\"15\"/>"
|
||||
"<sheetData>"
|
||||
"<row r=\"1\" spans=\"1:1\">"
|
||||
"<c r=\"A1\">"
|
||||
"<v>1</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"2\" spans=\"1:1\">"
|
||||
"<c r=\"A2\">"
|
||||
"<v>2</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"3\" spans=\"1:1\">"
|
||||
"<c r=\"A3\">"
|
||||
"<v>3</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"4\" spans=\"1:1\">"
|
||||
"<c r=\"A4\">"
|
||||
"<v>4</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"5\" spans=\"1:1\">"
|
||||
"<c r=\"A5\">"
|
||||
"<v>5</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"6\" spans=\"1:1\">"
|
||||
"<c r=\"A6\">"
|
||||
"<v>6</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"7\" spans=\"1:1\">"
|
||||
"<c r=\"A7\">"
|
||||
"<v>7</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"8\" spans=\"1:1\">"
|
||||
"<c r=\"A8\">"
|
||||
"<v>8</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"9\" spans=\"1:1\">"
|
||||
"<c r=\"A9\">"
|
||||
"<v>9</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"10\" spans=\"1:1\">"
|
||||
"<c r=\"A10\">"
|
||||
"<v>10</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"11\" spans=\"1:1\">"
|
||||
"<c r=\"A11\">"
|
||||
"<v>11</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"12\" spans=\"1:1\">"
|
||||
"<c r=\"A12\">"
|
||||
"<v>12</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"</sheetData>"
|
||||
"<conditionalFormatting sqref=\"A3:A4 A1 A6:A8 A10 A12\">"
|
||||
"<cfRule type=\"colorScale\" priority=\"1\">"
|
||||
"<colorScale>"
|
||||
"<cfvo type=\"min\" val=\"0\"/>"
|
||||
"<cfvo type=\"percentile\" val=\"50\"/>"
|
||||
"<cfvo type=\"max\" val=\"0\"/>"
|
||||
"<color rgb=\"FFF8696B\"/>"
|
||||
"<color rgb=\"FFFFEB84\"/>"
|
||||
"<color rgb=\"FF63BE7B\"/>"
|
||||
"</colorScale>"
|
||||
"</cfRule>"
|
||||
"</conditionalFormatting>"
|
||||
"<pageMargins left=\"0.7\" right=\"0.7\" top=\"0.75\" bottom=\"0.75\" header=\"0.3\" footer=\"0.3\"/>"
|
||||
"</worksheet>";
|
||||
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
worksheet_select(worksheet);
|
||||
|
||||
worksheet_write_number(worksheet, CELL("A1"), 1, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A2"), 2, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A3"), 3, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A4"), 4, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A5"), 5, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A6"), 6, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A7"), 7, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A8"), 8, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A9"), 9, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A10"), 10, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A11"), 11, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A12"), 12, NULL);
|
||||
|
||||
lxw_conditional_format *conditional_format = calloc(1, sizeof(lxw_conditional_format));
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_3_COLOR_SCALE;
|
||||
conditional_format->multi_range = "A3:A4 A1 A6:A8 A10 A12";
|
||||
worksheet_conditional_format_range(worksheet, RANGE("A1:A12"), conditional_format);
|
||||
|
||||
free(conditional_format);
|
||||
|
||||
lxw_worksheet_assemble_xml_file(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ_SHORT(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
@ -0,0 +1,142 @@
|
||||
/*
|
||||
* 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/shared_strings.h"
|
||||
|
||||
// Test assembling a complete Worksheet file.
|
||||
CTEST(worksheet, worksheet_condtional_format19) {
|
||||
|
||||
char* got;
|
||||
char exp[] =
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
|
||||
"<worksheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\">"
|
||||
"<dimension ref=\"A1:A12\"/>"
|
||||
"<sheetViews>"
|
||||
"<sheetView tabSelected=\"1\" workbookViewId=\"0\"/>"
|
||||
"</sheetViews>"
|
||||
"<sheetFormatPr defaultRowHeight=\"15\"/>"
|
||||
"<sheetData>"
|
||||
"<row r=\"1\" spans=\"1:1\">"
|
||||
"<c r=\"A1\">"
|
||||
"<v>1</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"2\" spans=\"1:1\">"
|
||||
"<c r=\"A2\">"
|
||||
"<v>2</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"3\" spans=\"1:1\">"
|
||||
"<c r=\"A3\">"
|
||||
"<v>3</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"4\" spans=\"1:1\">"
|
||||
"<c r=\"A4\">"
|
||||
"<v>4</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"5\" spans=\"1:1\">"
|
||||
"<c r=\"A5\">"
|
||||
"<v>5</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"6\" spans=\"1:1\">"
|
||||
"<c r=\"A6\">"
|
||||
"<v>6</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"7\" spans=\"1:1\">"
|
||||
"<c r=\"A7\">"
|
||||
"<v>7</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"8\" spans=\"1:1\">"
|
||||
"<c r=\"A8\">"
|
||||
"<v>8</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"9\" spans=\"1:1\">"
|
||||
"<c r=\"A9\">"
|
||||
"<v>9</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"10\" spans=\"1:1\">"
|
||||
"<c r=\"A10\">"
|
||||
"<v>10</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"11\" spans=\"1:1\">"
|
||||
"<c r=\"A11\">"
|
||||
"<v>11</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"12\" spans=\"1:1\">"
|
||||
"<c r=\"A12\">"
|
||||
"<v>12</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"</sheetData>"
|
||||
"<conditionalFormatting sqref=\"A1:A12\">"
|
||||
"<cfRule type=\"dataBar\" priority=\"1\">"
|
||||
"<dataBar>"
|
||||
"<cfvo type=\"num\" val=\"5\"/>"
|
||||
"<cfvo type=\"percent\" val=\"90\"/>"
|
||||
"<color rgb=\"FF8DB4E3\"/>"
|
||||
"</dataBar>"
|
||||
"</cfRule>"
|
||||
"</conditionalFormatting>"
|
||||
"<pageMargins left=\"0.7\" right=\"0.7\" top=\"0.75\" bottom=\"0.75\" header=\"0.3\" footer=\"0.3\"/>"
|
||||
"</worksheet>";
|
||||
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
worksheet_select(worksheet);
|
||||
|
||||
worksheet_write_number(worksheet, CELL("A1"), 1, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A2"), 2, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A3"), 3, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A4"), 4, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A5"), 5, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A6"), 6, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A7"), 7, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A8"), 8, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A9"), 9, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A10"), 10, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A11"), 11, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A12"), 12, NULL);
|
||||
|
||||
lxw_conditional_format *conditional_format = calloc(1, sizeof(lxw_conditional_format));
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_DATA_BAR;
|
||||
conditional_format->min_value = 5;
|
||||
conditional_format->max_value = 90;
|
||||
conditional_format->min_rule_type = LXW_CONDITIONAL_RULE_TYPE_NUMBER;
|
||||
conditional_format->max_rule_type = LXW_CONDITIONAL_RULE_TYPE_PERCENT;
|
||||
conditional_format->bar_color = 0x8DB4E3;
|
||||
|
||||
// Mid values should be ignored.
|
||||
conditional_format->mid_value = 52;
|
||||
conditional_format->mid_rule_type = LXW_CONDITIONAL_RULE_TYPE_PERCENTILE;
|
||||
|
||||
worksheet_conditional_format_range(worksheet, RANGE("A1:A12"), conditional_format);
|
||||
|
||||
|
||||
free(conditional_format);
|
||||
|
||||
lxw_worksheet_assemble_xml_file(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ_SHORT(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
@ -0,0 +1,105 @@
|
||||
/*
|
||||
* 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/shared_strings.h"
|
||||
|
||||
// Test assembling a complete Worksheet file.
|
||||
CTEST(worksheet, worksheet_condtional_format20) {
|
||||
|
||||
char* got;
|
||||
char exp[] =
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
|
||||
"<worksheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\">"
|
||||
"<dimension ref=\"A1:A4\"/>"
|
||||
"<sheetViews>"
|
||||
"<sheetView tabSelected=\"1\" workbookViewId=\"0\"/>"
|
||||
"</sheetViews>"
|
||||
"<sheetFormatPr defaultRowHeight=\"15\"/>"
|
||||
"<sheetData>"
|
||||
"<row r=\"1\" spans=\"1:1\">"
|
||||
"<c r=\"A1\">"
|
||||
"<v>10</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"2\" spans=\"1:1\">"
|
||||
"<c r=\"A2\">"
|
||||
"<v>20</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"3\" spans=\"1:1\">"
|
||||
"<c r=\"A3\">"
|
||||
"<v>30</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"4\" spans=\"1:1\">"
|
||||
"<c r=\"A4\">"
|
||||
"<v>40</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"</sheetData>"
|
||||
"<conditionalFormatting sqref=\"A1:A4\">"
|
||||
"<cfRule type=\"beginsWith\" priority=\"1\" operator=\"beginsWith\" text=\"b\">"
|
||||
"<formula>LEFT(A1,1)=\"b\"</formula>"
|
||||
"</cfRule>"
|
||||
"<cfRule type=\"beginsWith\" priority=\"2\" operator=\"beginsWith\" text=\"bc\">"
|
||||
"<formula>LEFT(A1,2)=\"bc\"</formula>"
|
||||
"</cfRule>"
|
||||
"<cfRule type=\"endsWith\" priority=\"3\" operator=\"endsWith\" text=\"z\">"
|
||||
"<formula>RIGHT(A1,1)=\"z\"</formula>"
|
||||
"</cfRule>"
|
||||
"<cfRule type=\"endsWith\" priority=\"4\" operator=\"endsWith\" text=\"yz\">"
|
||||
"<formula>RIGHT(A1,2)=\"yz\"</formula>"
|
||||
"</cfRule>"
|
||||
"</conditionalFormatting>"
|
||||
"<pageMargins left=\"0.7\" right=\"0.7\" top=\"0.75\" bottom=\"0.75\" header=\"0.3\" footer=\"0.3\"/>"
|
||||
"</worksheet>";
|
||||
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
worksheet_select(worksheet);
|
||||
|
||||
worksheet_write_number(worksheet, CELL("A1"), 10, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A2"), 20, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A3"), 30, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A4"), 40, NULL);
|
||||
|
||||
lxw_conditional_format *conditional_format = calloc(1, sizeof(lxw_conditional_format));
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_TYPE_TEXT;
|
||||
conditional_format->criteria = LXW_CONDITIONAL_CRITERIA_TEXT_BEGINS_WITH;
|
||||
conditional_format->value_string = "b";
|
||||
worksheet_conditional_format_range(worksheet, RANGE("A1:A4"), conditional_format);
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_TYPE_TEXT;
|
||||
conditional_format->criteria = LXW_CONDITIONAL_CRITERIA_TEXT_BEGINS_WITH;
|
||||
conditional_format->value_string = "bc";
|
||||
worksheet_conditional_format_range(worksheet, RANGE("A1:A4"), conditional_format);
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_TYPE_TEXT;
|
||||
conditional_format->criteria = LXW_CONDITIONAL_CRITERIA_TEXT_ENDS_WITH;
|
||||
conditional_format->value_string = "z";
|
||||
worksheet_conditional_format_range(worksheet, RANGE("A1:A4"), conditional_format);
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_TYPE_TEXT;
|
||||
conditional_format->criteria = LXW_CONDITIONAL_CRITERIA_TEXT_ENDS_WITH;
|
||||
conditional_format->value_string = "yz";
|
||||
worksheet_conditional_format_range(worksheet, RANGE("A1:A4"), conditional_format);
|
||||
|
||||
free(conditional_format);
|
||||
|
||||
lxw_worksheet_assemble_xml_file(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ_SHORT(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
@ -0,0 +1,84 @@
|
||||
/*
|
||||
* 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/shared_strings.h"
|
||||
|
||||
// Test assembling a complete Worksheet file.
|
||||
CTEST(worksheet, worksheet_condtional_format21) {
|
||||
|
||||
char* got;
|
||||
char exp[] =
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
|
||||
"<worksheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\">"
|
||||
"<dimension ref=\"A1:A4\"/>"
|
||||
"<sheetViews>"
|
||||
"<sheetView tabSelected=\"1\" workbookViewId=\"0\"/>"
|
||||
"</sheetViews>"
|
||||
"<sheetFormatPr defaultRowHeight=\"15\"/>"
|
||||
"<sheetData>"
|
||||
"<row r=\"1\" spans=\"1:1\">"
|
||||
"<c r=\"A1\">"
|
||||
"<v>10</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"2\" spans=\"1:1\">"
|
||||
"<c r=\"A2\">"
|
||||
"<v>20</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"3\" spans=\"1:1\">"
|
||||
"<c r=\"A3\">"
|
||||
"<v>30</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"4\" spans=\"1:1\">"
|
||||
"<c r=\"A4\">"
|
||||
"<v>40</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"</sheetData>"
|
||||
"<conditionalFormatting sqref=\"A1\">"
|
||||
"<cfRule type=\"cellIs\" priority=\"1\" stopIfTrue=\"1\" operator=\"greaterThan\">"
|
||||
"<formula>5</formula>"
|
||||
"</cfRule>"
|
||||
"</conditionalFormatting>"
|
||||
"<pageMargins left=\"0.7\" right=\"0.7\" top=\"0.75\" bottom=\"0.75\" header=\"0.3\" footer=\"0.3\"/>"
|
||||
"</worksheet>";
|
||||
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
worksheet_select(worksheet);
|
||||
|
||||
worksheet_write_number(worksheet, CELL("A1"), 10, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A2"), 20, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A3"), 30, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A4"), 40, NULL);
|
||||
|
||||
lxw_conditional_format *conditional_format = calloc(1, sizeof(lxw_conditional_format));
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_TYPE_CELL;
|
||||
conditional_format->criteria = LXW_CONDITIONAL_CRITERIA_GREATER_THAN;
|
||||
conditional_format->value = 5;
|
||||
conditional_format->stop_if_true = LXW_TRUE;
|
||||
worksheet_conditional_format_cell(worksheet, CELL("A1"), conditional_format);
|
||||
|
||||
free(conditional_format);
|
||||
|
||||
lxw_worksheet_assemble_xml_file(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ_SHORT(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,227 @@
|
||||
/*
|
||||
* 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/shared_strings.h"
|
||||
|
||||
// Test assembling a complete Worksheet file.
|
||||
CTEST(worksheet, worksheet_condtional_format22) {
|
||||
|
||||
char* got;
|
||||
char exp[] =
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
|
||||
"<worksheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\">"
|
||||
"<dimension ref=\"A1:A9\"/>"
|
||||
"<sheetViews>"
|
||||
"<sheetView tabSelected=\"1\" workbookViewId=\"0\"/>"
|
||||
"</sheetViews>"
|
||||
"<sheetFormatPr defaultRowHeight=\"15\"/>"
|
||||
"<sheetData>"
|
||||
"<row r=\"1\" spans=\"1:1\">"
|
||||
"<c r=\"A1\">"
|
||||
"<v>1</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"2\" spans=\"1:1\">"
|
||||
"<c r=\"A2\">"
|
||||
"<v>2</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"3\" spans=\"1:1\">"
|
||||
"<c r=\"A3\">"
|
||||
"<v>3</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"4\" spans=\"1:1\">"
|
||||
"<c r=\"A4\">"
|
||||
"<v>4</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"5\" spans=\"1:1\">"
|
||||
"<c r=\"A5\">"
|
||||
"<v>5</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"6\" spans=\"1:1\">"
|
||||
"<c r=\"A6\">"
|
||||
"<v>6</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"7\" spans=\"1:1\">"
|
||||
"<c r=\"A7\">"
|
||||
"<v>7</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"8\" spans=\"1:1\">"
|
||||
"<c r=\"A8\">"
|
||||
"<v>8</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"9\" spans=\"1:1\">"
|
||||
"<c r=\"A9\">"
|
||||
"<v>9</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"</sheetData>"
|
||||
"<conditionalFormatting sqref=\"A1\">"
|
||||
"<cfRule type=\"iconSet\" priority=\"1\">"
|
||||
"<iconSet iconSet=\"3Arrows\">"
|
||||
"<cfvo type=\"percent\" val=\"0\"/>"
|
||||
"<cfvo type=\"percent\" val=\"33\"/>"
|
||||
"<cfvo type=\"percent\" val=\"67\"/>"
|
||||
"</iconSet>"
|
||||
"</cfRule>"
|
||||
"</conditionalFormatting>"
|
||||
"<conditionalFormatting sqref=\"A2\">"
|
||||
"<cfRule type=\"iconSet\" priority=\"2\">"
|
||||
"<iconSet iconSet=\"3Flags\">"
|
||||
"<cfvo type=\"percent\" val=\"0\"/>"
|
||||
"<cfvo type=\"percent\" val=\"33\"/>"
|
||||
"<cfvo type=\"percent\" val=\"67\"/>"
|
||||
"</iconSet>"
|
||||
"</cfRule>"
|
||||
"</conditionalFormatting>"
|
||||
"<conditionalFormatting sqref=\"A3\">"
|
||||
"<cfRule type=\"iconSet\" priority=\"3\">"
|
||||
"<iconSet iconSet=\"3TrafficLights2\">"
|
||||
"<cfvo type=\"percent\" val=\"0\"/>"
|
||||
"<cfvo type=\"percent\" val=\"33\"/>"
|
||||
"<cfvo type=\"percent\" val=\"67\"/>"
|
||||
"</iconSet>"
|
||||
"</cfRule>"
|
||||
"</conditionalFormatting>"
|
||||
"<conditionalFormatting sqref=\"A4\">"
|
||||
"<cfRule type=\"iconSet\" priority=\"4\">"
|
||||
"<iconSet iconSet=\"3Symbols\">"
|
||||
"<cfvo type=\"percent\" val=\"0\"/>"
|
||||
"<cfvo type=\"percent\" val=\"33\"/>"
|
||||
"<cfvo type=\"percent\" val=\"67\"/>"
|
||||
"</iconSet>"
|
||||
"</cfRule>"
|
||||
"</conditionalFormatting>"
|
||||
"<conditionalFormatting sqref=\"A5\">"
|
||||
"<cfRule type=\"iconSet\" priority=\"5\">"
|
||||
"<iconSet iconSet=\"4Arrows\">"
|
||||
"<cfvo type=\"percent\" val=\"0\"/>"
|
||||
"<cfvo type=\"percent\" val=\"25\"/>"
|
||||
"<cfvo type=\"percent\" val=\"50\"/>"
|
||||
"<cfvo type=\"percent\" val=\"75\"/>"
|
||||
"</iconSet>"
|
||||
"</cfRule>"
|
||||
"</conditionalFormatting>"
|
||||
"<conditionalFormatting sqref=\"A6\">"
|
||||
"<cfRule type=\"iconSet\" priority=\"6\">"
|
||||
"<iconSet iconSet=\"4RedToBlack\">"
|
||||
"<cfvo type=\"percent\" val=\"0\"/>"
|
||||
"<cfvo type=\"percent\" val=\"25\"/>"
|
||||
"<cfvo type=\"percent\" val=\"50\"/>"
|
||||
"<cfvo type=\"percent\" val=\"75\"/>"
|
||||
"</iconSet>"
|
||||
"</cfRule>"
|
||||
"</conditionalFormatting>"
|
||||
"<conditionalFormatting sqref=\"A7\">"
|
||||
"<cfRule type=\"iconSet\" priority=\"7\">"
|
||||
"<iconSet iconSet=\"4TrafficLights\">"
|
||||
"<cfvo type=\"percent\" val=\"0\"/>"
|
||||
"<cfvo type=\"percent\" val=\"25\"/>"
|
||||
"<cfvo type=\"percent\" val=\"50\"/>"
|
||||
"<cfvo type=\"percent\" val=\"75\"/>"
|
||||
"</iconSet>"
|
||||
"</cfRule>"
|
||||
"</conditionalFormatting>"
|
||||
"<conditionalFormatting sqref=\"A8\">"
|
||||
"<cfRule type=\"iconSet\" priority=\"8\">"
|
||||
"<iconSet iconSet=\"5ArrowsGray\">"
|
||||
"<cfvo type=\"percent\" val=\"0\"/>"
|
||||
"<cfvo type=\"percent\" val=\"20\"/>"
|
||||
"<cfvo type=\"percent\" val=\"40\"/>"
|
||||
"<cfvo type=\"percent\" val=\"60\"/>"
|
||||
"<cfvo type=\"percent\" val=\"80\"/>"
|
||||
"</iconSet>"
|
||||
"</cfRule>"
|
||||
"</conditionalFormatting>"
|
||||
"<conditionalFormatting sqref=\"A9\">"
|
||||
"<cfRule type=\"iconSet\" priority=\"9\">"
|
||||
"<iconSet iconSet=\"5Quarters\">"
|
||||
"<cfvo type=\"percent\" val=\"0\"/>"
|
||||
"<cfvo type=\"percent\" val=\"20\"/>"
|
||||
"<cfvo type=\"percent\" val=\"40\"/>"
|
||||
"<cfvo type=\"percent\" val=\"60\"/>"
|
||||
"<cfvo type=\"percent\" val=\"80\"/>"
|
||||
"</iconSet>"
|
||||
"</cfRule>"
|
||||
"</conditionalFormatting>"
|
||||
"<pageMargins left=\"0.7\" right=\"0.7\" top=\"0.75\" bottom=\"0.75\" header=\"0.3\" footer=\"0.3\"/>"
|
||||
"</worksheet>";
|
||||
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
worksheet_select(worksheet);
|
||||
|
||||
worksheet_write_number(worksheet, CELL("A1"), 1, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A2"), 2, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A3"), 3, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A4"), 4, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A5"), 5, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A6"), 6, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A7"), 7, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A8"), 8, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A9"), 9, NULL);
|
||||
|
||||
lxw_conditional_format *conditional_format = calloc(1, sizeof(lxw_conditional_format));
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_TYPE_ICON_SETS;
|
||||
conditional_format->icon_style = LXW_CONDITIONAL_ICONS_3_ARROWS_COLORED;
|
||||
worksheet_conditional_format_cell(worksheet, CELL("A1"), conditional_format);
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_TYPE_ICON_SETS;
|
||||
conditional_format->icon_style = LXW_CONDITIONAL_ICONS_3_FLAGS;
|
||||
worksheet_conditional_format_cell(worksheet, CELL("A2"), conditional_format);
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_TYPE_ICON_SETS;
|
||||
conditional_format->icon_style = LXW_CONDITIONAL_ICONS_3_TRAFFIC_LIGHTS_RIMMED;
|
||||
worksheet_conditional_format_cell(worksheet, CELL("A3"), conditional_format);
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_TYPE_ICON_SETS;
|
||||
conditional_format->icon_style = LXW_CONDITIONAL_ICONS_3_SYMBOLS_CIRCLED;
|
||||
worksheet_conditional_format_cell(worksheet, CELL("A4"), conditional_format);
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_TYPE_ICON_SETS;
|
||||
conditional_format->icon_style = LXW_CONDITIONAL_ICONS_4_ARROWS_COLORED;
|
||||
worksheet_conditional_format_cell(worksheet, CELL("A5"), conditional_format);
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_TYPE_ICON_SETS;
|
||||
conditional_format->icon_style = LXW_CONDITIONAL_ICONS_4_RED_TO_BLACK;
|
||||
worksheet_conditional_format_cell(worksheet, CELL("A6"), conditional_format);
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_TYPE_ICON_SETS;
|
||||
conditional_format->icon_style = LXW_CONDITIONAL_ICONS_4_TRAFFIC_LIGHTS;
|
||||
worksheet_conditional_format_cell(worksheet, CELL("A7"), conditional_format);
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_TYPE_ICON_SETS;
|
||||
conditional_format->icon_style = LXW_CONDITIONAL_ICONS_5_ARROWS_GRAY;
|
||||
worksheet_conditional_format_cell(worksheet, CELL("A8"), conditional_format);
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_TYPE_ICON_SETS;
|
||||
conditional_format->icon_style = LXW_CONDITIONAL_ICONS_5_QUARTERS;
|
||||
worksheet_conditional_format_cell(worksheet, CELL("A9"), conditional_format);
|
||||
|
||||
free(conditional_format);
|
||||
|
||||
lxw_worksheet_assemble_xml_file(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ_SHORT(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,207 @@
|
||||
/*
|
||||
* 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/shared_strings.h"
|
||||
|
||||
// Test assembling a complete Worksheet file.
|
||||
CTEST(worksheet, worksheet_condtional_format23) {
|
||||
|
||||
char* got;
|
||||
char exp[] =
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
|
||||
"<worksheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\">"
|
||||
"<dimension ref=\"A1:A8\"/>"
|
||||
"<sheetViews>"
|
||||
"<sheetView tabSelected=\"1\" workbookViewId=\"0\"/>"
|
||||
"</sheetViews>"
|
||||
"<sheetFormatPr defaultRowHeight=\"15\"/>"
|
||||
"<sheetData>"
|
||||
"<row r=\"1\" spans=\"1:1\">"
|
||||
"<c r=\"A1\">"
|
||||
"<v>1</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"2\" spans=\"1:1\">"
|
||||
"<c r=\"A2\">"
|
||||
"<v>2</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"3\" spans=\"1:1\">"
|
||||
"<c r=\"A3\">"
|
||||
"<v>3</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"4\" spans=\"1:1\">"
|
||||
"<c r=\"A4\">"
|
||||
"<v>4</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"5\" spans=\"1:1\">"
|
||||
"<c r=\"A5\">"
|
||||
"<v>5</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"6\" spans=\"1:1\">"
|
||||
"<c r=\"A6\">"
|
||||
"<v>6</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"7\" spans=\"1:1\">"
|
||||
"<c r=\"A7\">"
|
||||
"<v>7</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"8\" spans=\"1:1\">"
|
||||
"<c r=\"A8\">"
|
||||
"<v>8</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"</sheetData>"
|
||||
"<conditionalFormatting sqref=\"A1\">"
|
||||
"<cfRule type=\"iconSet\" priority=\"1\">"
|
||||
"<iconSet iconSet=\"3ArrowsGray\">"
|
||||
"<cfvo type=\"percent\" val=\"0\"/>"
|
||||
"<cfvo type=\"percent\" val=\"33\"/>"
|
||||
"<cfvo type=\"percent\" val=\"67\"/>"
|
||||
"</iconSet>"
|
||||
"</cfRule>"
|
||||
"</conditionalFormatting>"
|
||||
"<conditionalFormatting sqref=\"A2\">"
|
||||
"<cfRule type=\"iconSet\" priority=\"2\">"
|
||||
"<iconSet>"
|
||||
"<cfvo type=\"percent\" val=\"0\"/>"
|
||||
"<cfvo type=\"percent\" val=\"33\"/>"
|
||||
"<cfvo type=\"percent\" val=\"67\"/>"
|
||||
"</iconSet>"
|
||||
"</cfRule>"
|
||||
"</conditionalFormatting>"
|
||||
"<conditionalFormatting sqref=\"A3\">"
|
||||
"<cfRule type=\"iconSet\" priority=\"3\">"
|
||||
"<iconSet iconSet=\"3Signs\">"
|
||||
"<cfvo type=\"percent\" val=\"0\"/>"
|
||||
"<cfvo type=\"percent\" val=\"33\"/>"
|
||||
"<cfvo type=\"percent\" val=\"67\"/>"
|
||||
"</iconSet>"
|
||||
"</cfRule>"
|
||||
"</conditionalFormatting>"
|
||||
"<conditionalFormatting sqref=\"A4\">"
|
||||
"<cfRule type=\"iconSet\" priority=\"4\">"
|
||||
"<iconSet iconSet=\"3Symbols2\">"
|
||||
"<cfvo type=\"percent\" val=\"0\"/>"
|
||||
"<cfvo type=\"percent\" val=\"33\"/>"
|
||||
"<cfvo type=\"percent\" val=\"67\"/>"
|
||||
"</iconSet>"
|
||||
"</cfRule>"
|
||||
"</conditionalFormatting>"
|
||||
"<conditionalFormatting sqref=\"A5\">"
|
||||
"<cfRule type=\"iconSet\" priority=\"5\">"
|
||||
"<iconSet iconSet=\"4ArrowsGray\">"
|
||||
"<cfvo type=\"percent\" val=\"0\"/>"
|
||||
"<cfvo type=\"percent\" val=\"25\"/>"
|
||||
"<cfvo type=\"percent\" val=\"50\"/>"
|
||||
"<cfvo type=\"percent\" val=\"75\"/>"
|
||||
"</iconSet>"
|
||||
"</cfRule>"
|
||||
"</conditionalFormatting>"
|
||||
"<conditionalFormatting sqref=\"A6\">"
|
||||
"<cfRule type=\"iconSet\" priority=\"6\">"
|
||||
"<iconSet iconSet=\"4Rating\">"
|
||||
"<cfvo type=\"percent\" val=\"0\"/>"
|
||||
"<cfvo type=\"percent\" val=\"25\"/>"
|
||||
"<cfvo type=\"percent\" val=\"50\"/>"
|
||||
"<cfvo type=\"percent\" val=\"75\"/>"
|
||||
"</iconSet>"
|
||||
"</cfRule>"
|
||||
"</conditionalFormatting>"
|
||||
"<conditionalFormatting sqref=\"A7\">"
|
||||
"<cfRule type=\"iconSet\" priority=\"7\">"
|
||||
"<iconSet iconSet=\"5Arrows\">"
|
||||
"<cfvo type=\"percent\" val=\"0\"/>"
|
||||
"<cfvo type=\"percent\" val=\"20\"/>"
|
||||
"<cfvo type=\"percent\" val=\"40\"/>"
|
||||
"<cfvo type=\"percent\" val=\"60\"/>"
|
||||
"<cfvo type=\"percent\" val=\"80\"/>"
|
||||
"</iconSet>"
|
||||
"</cfRule>"
|
||||
"</conditionalFormatting>"
|
||||
"<conditionalFormatting sqref=\"A8\">"
|
||||
"<cfRule type=\"iconSet\" priority=\"8\">"
|
||||
"<iconSet iconSet=\"5Rating\">"
|
||||
"<cfvo type=\"percent\" val=\"0\"/>"
|
||||
"<cfvo type=\"percent\" val=\"20\"/>"
|
||||
"<cfvo type=\"percent\" val=\"40\"/>"
|
||||
"<cfvo type=\"percent\" val=\"60\"/>"
|
||||
"<cfvo type=\"percent\" val=\"80\"/>"
|
||||
"</iconSet>"
|
||||
"</cfRule>"
|
||||
"</conditionalFormatting>"
|
||||
"<pageMargins left=\"0.7\" right=\"0.7\" top=\"0.75\" bottom=\"0.75\" header=\"0.3\" footer=\"0.3\"/>"
|
||||
"</worksheet>";
|
||||
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
worksheet_select(worksheet);
|
||||
|
||||
worksheet_write_number(worksheet, CELL("A1"), 1, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A2"), 2, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A3"), 3, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A4"), 4, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A5"), 5, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A6"), 6, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A7"), 7, NULL);
|
||||
worksheet_write_number(worksheet, CELL("A8"), 8, NULL);
|
||||
|
||||
lxw_conditional_format *conditional_format = calloc(1, sizeof(lxw_conditional_format));
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_TYPE_ICON_SETS;
|
||||
conditional_format->icon_style = LXW_CONDITIONAL_ICONS_3_ARROWS_GRAY;
|
||||
worksheet_conditional_format_cell(worksheet, CELL("A1"), conditional_format);
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_TYPE_ICON_SETS;
|
||||
conditional_format->icon_style = LXW_CONDITIONAL_ICONS_3_TRAFFIC_LIGHTS_UNRIMMED;
|
||||
worksheet_conditional_format_cell(worksheet, CELL("A2"), conditional_format);
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_TYPE_ICON_SETS;
|
||||
conditional_format->icon_style = LXW_CONDITIONAL_ICONS_3_SIGNS;
|
||||
worksheet_conditional_format_cell(worksheet, CELL("A3"), conditional_format);
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_TYPE_ICON_SETS;
|
||||
conditional_format->icon_style = LXW_CONDITIONAL_ICONS_3_SYMBOLS_UNCIRCLED;
|
||||
worksheet_conditional_format_cell(worksheet, CELL("A4"), conditional_format);
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_TYPE_ICON_SETS;
|
||||
conditional_format->icon_style = LXW_CONDITIONAL_ICONS_4_ARROWS_GRAY;
|
||||
worksheet_conditional_format_cell(worksheet, CELL("A5"), conditional_format);
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_TYPE_ICON_SETS;
|
||||
conditional_format->icon_style = LXW_CONDITIONAL_ICONS_4_RATINGS;
|
||||
worksheet_conditional_format_cell(worksheet, CELL("A6"), conditional_format);
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_TYPE_ICON_SETS;
|
||||
conditional_format->icon_style = LXW_CONDITIONAL_ICONS_5_ARROWS_COLORED;
|
||||
worksheet_conditional_format_cell(worksheet, CELL("A7"), conditional_format);
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_TYPE_ICON_SETS;
|
||||
conditional_format->icon_style = LXW_CONDITIONAL_ICONS_5_RATINGS;
|
||||
worksheet_conditional_format_cell(worksheet, CELL("A8"), conditional_format);
|
||||
|
||||
free(conditional_format);
|
||||
|
||||
lxw_worksheet_assemble_xml_file(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ_SHORT(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
@ -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/shared_strings.h"
|
||||
|
||||
// Test assembling a complete Worksheet file.
|
||||
CTEST(worksheet, worksheet_data_bar01) {
|
||||
|
||||
char* got;
|
||||
char exp[] =
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
|
||||
"<worksheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\">"
|
||||
"<dimension ref=\"A1\"/>"
|
||||
"<sheetViews>"
|
||||
"<sheetView tabSelected=\"1\" workbookViewId=\"0\"/>"
|
||||
"</sheetViews>"
|
||||
"<sheetFormatPr defaultRowHeight=\"15\"/>"
|
||||
"<sheetData/>"
|
||||
"<conditionalFormatting sqref=\"A1\">"
|
||||
"<cfRule type=\"dataBar\" priority=\"1\">"
|
||||
"<dataBar>"
|
||||
"<cfvo type=\"min\" val=\"0\"/>"
|
||||
"<cfvo type=\"max\" val=\"0\"/>"
|
||||
"<color rgb=\"FF638EC6\"/>"
|
||||
"</dataBar>"
|
||||
"</cfRule>"
|
||||
"</conditionalFormatting>"
|
||||
"<pageMargins left=\"0.7\" right=\"0.7\" top=\"0.75\" bottom=\"0.75\" header=\"0.3\" footer=\"0.3\"/>"
|
||||
"</worksheet>";
|
||||
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
worksheet_select(worksheet);
|
||||
|
||||
lxw_conditional_format *conditional_format = calloc(1, sizeof(lxw_conditional_format));
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_DATA_BAR;
|
||||
worksheet_conditional_format_cell(worksheet, CELL("A1"), conditional_format);
|
||||
|
||||
free(conditional_format);
|
||||
lxw_worksheet_assemble_xml_file(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ_SHORT(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
@ -0,0 +1,81 @@
|
||||
/*
|
||||
* 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/shared_strings.h"
|
||||
|
||||
// Test assembling a complete Worksheet file.
|
||||
CTEST(worksheet, worksheet_data_bar02) {
|
||||
|
||||
char* got;
|
||||
char exp[] =
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
|
||||
"<worksheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\" xmlns:x14ac=\"http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac\" mc:Ignorable=\"x14ac\">"
|
||||
"<dimension ref=\"A1\"/>"
|
||||
"<sheetViews>"
|
||||
"<sheetView tabSelected=\"1\" workbookViewId=\"0\"/>"
|
||||
"</sheetViews>"
|
||||
"<sheetFormatPr defaultRowHeight=\"15\" x14ac:dyDescent=\"0.25\"/>"
|
||||
"<sheetData/>"
|
||||
"<conditionalFormatting sqref=\"A1\">"
|
||||
"<cfRule type=\"dataBar\" priority=\"1\">"
|
||||
"<dataBar>"
|
||||
"<cfvo type=\"min\"/>"
|
||||
"<cfvo type=\"max\"/>"
|
||||
"<color rgb=\"FF638EC6\"/>"
|
||||
"</dataBar>"
|
||||
"<extLst>"
|
||||
"<ext xmlns:x14=\"http://schemas.microsoft.com/office/spreadsheetml/2009/9/main\" uri=\"{B025F937-C7B1-47D3-B67F-A62EFF666E3E}\">"
|
||||
"<x14:id>{DA7ABA51-AAAA-BBBB-0001-000000000001}</x14:id>"
|
||||
"</ext>"
|
||||
"</extLst>"
|
||||
"</cfRule>"
|
||||
"</conditionalFormatting>"
|
||||
"<pageMargins left=\"0.7\" right=\"0.7\" top=\"0.75\" bottom=\"0.75\" header=\"0.3\" footer=\"0.3\"/>"
|
||||
"<extLst>"
|
||||
"<ext xmlns:x14=\"http://schemas.microsoft.com/office/spreadsheetml/2009/9/main\" uri=\"{78C0D931-6437-407d-A8EE-F0AAD7539E65}\">"
|
||||
"<x14:conditionalFormattings>"
|
||||
"<x14:conditionalFormatting xmlns:xm=\"http://schemas.microsoft.com/office/excel/2006/main\">"
|
||||
"<x14:cfRule type=\"dataBar\" id=\"{DA7ABA51-AAAA-BBBB-0001-000000000001}\">"
|
||||
"<x14:dataBar minLength=\"0\" maxLength=\"100\" border=\"1\" negativeBarBorderColorSameAsPositive=\"0\">"
|
||||
"<x14:cfvo type=\"autoMin\"/>"
|
||||
"<x14:cfvo type=\"autoMax\"/>"
|
||||
"<x14:borderColor rgb=\"FF638EC6\"/>"
|
||||
"<x14:negativeFillColor rgb=\"FFFF0000\"/>"
|
||||
"<x14:negativeBorderColor rgb=\"FFFF0000\"/>"
|
||||
"<x14:axisColor rgb=\"FF000000\"/>"
|
||||
"</x14:dataBar>"
|
||||
"</x14:cfRule>"
|
||||
"<xm:sqref>A1</xm:sqref>"
|
||||
"</x14:conditionalFormatting>"
|
||||
"</x14:conditionalFormattings>"
|
||||
"</ext>"
|
||||
"</extLst>"
|
||||
"</worksheet>";
|
||||
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
worksheet_select(worksheet);
|
||||
|
||||
lxw_conditional_format *conditional_format = calloc(1, sizeof(lxw_conditional_format));
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_DATA_BAR;
|
||||
conditional_format->data_bar_2010 = LXW_TRUE;
|
||||
worksheet_conditional_format_cell(worksheet, CELL("A1"), conditional_format);
|
||||
|
||||
free(conditional_format);
|
||||
lxw_worksheet_assemble_xml_file(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ_SHORT(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
@ -0,0 +1,145 @@
|
||||
/*
|
||||
* 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/shared_strings.h"
|
||||
|
||||
// Test assembling a complete Worksheet file.
|
||||
CTEST(worksheet, worksheet_data_bar03) {
|
||||
|
||||
char* got;
|
||||
char exp[] =
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
|
||||
"<worksheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\" xmlns:x14ac=\"http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac\" mc:Ignorable=\"x14ac\">"
|
||||
"<dimension ref=\"A1\"/>"
|
||||
"<sheetViews>"
|
||||
"<sheetView tabSelected=\"1\" workbookViewId=\"0\"/>"
|
||||
"</sheetViews>"
|
||||
"<sheetFormatPr defaultRowHeight=\"15\" x14ac:dyDescent=\"0.25\"/>"
|
||||
"<sheetData/>"
|
||||
"<conditionalFormatting sqref=\"A1\">"
|
||||
"<cfRule type=\"dataBar\" priority=\"1\">"
|
||||
"<dataBar>"
|
||||
"<cfvo type=\"min\"/>"
|
||||
"<cfvo type=\"max\"/>"
|
||||
"<color rgb=\"FF638EC6\"/>"
|
||||
"</dataBar>"
|
||||
"<extLst>"
|
||||
"<ext xmlns:x14=\"http://schemas.microsoft.com/office/spreadsheetml/2009/9/main\" uri=\"{B025F937-C7B1-47D3-B67F-A62EFF666E3E}\">"
|
||||
"<x14:id>{DA7ABA51-AAAA-BBBB-0001-000000000001}</x14:id>"
|
||||
"</ext>"
|
||||
"</extLst>"
|
||||
"</cfRule>"
|
||||
"</conditionalFormatting>"
|
||||
"<conditionalFormatting sqref=\"A2:B2\">"
|
||||
"<cfRule type=\"dataBar\" priority=\"2\">"
|
||||
"<dataBar>"
|
||||
"<cfvo type=\"min\"/>"
|
||||
"<cfvo type=\"max\"/>"
|
||||
"<color rgb=\"FF63C384\"/>"
|
||||
"</dataBar>"
|
||||
"<extLst>"
|
||||
"<ext xmlns:x14=\"http://schemas.microsoft.com/office/spreadsheetml/2009/9/main\" uri=\"{B025F937-C7B1-47D3-B67F-A62EFF666E3E}\">"
|
||||
"<x14:id>{DA7ABA51-AAAA-BBBB-0001-000000000002}</x14:id>"
|
||||
"</ext>"
|
||||
"</extLst>"
|
||||
"</cfRule>"
|
||||
"</conditionalFormatting>"
|
||||
"<conditionalFormatting sqref=\"A3:C3\">"
|
||||
"<cfRule type=\"dataBar\" priority=\"3\">"
|
||||
"<dataBar>"
|
||||
"<cfvo type=\"min\"/>"
|
||||
"<cfvo type=\"max\"/>"
|
||||
"<color rgb=\"FFFF555A\"/>"
|
||||
"</dataBar>"
|
||||
"<extLst>"
|
||||
"<ext xmlns:x14=\"http://schemas.microsoft.com/office/spreadsheetml/2009/9/main\" uri=\"{B025F937-C7B1-47D3-B67F-A62EFF666E3E}\">"
|
||||
"<x14:id>{DA7ABA51-AAAA-BBBB-0001-000000000003}</x14:id>"
|
||||
"</ext>"
|
||||
"</extLst>"
|
||||
"</cfRule>"
|
||||
"</conditionalFormatting>"
|
||||
"<pageMargins left=\"0.7\" right=\"0.7\" top=\"0.75\" bottom=\"0.75\" header=\"0.3\" footer=\"0.3\"/>"
|
||||
"<extLst>"
|
||||
"<ext xmlns:x14=\"http://schemas.microsoft.com/office/spreadsheetml/2009/9/main\" uri=\"{78C0D931-6437-407d-A8EE-F0AAD7539E65}\">"
|
||||
"<x14:conditionalFormattings>"
|
||||
"<x14:conditionalFormatting xmlns:xm=\"http://schemas.microsoft.com/office/excel/2006/main\">"
|
||||
"<x14:cfRule type=\"dataBar\" id=\"{DA7ABA51-AAAA-BBBB-0001-000000000001}\">"
|
||||
"<x14:dataBar minLength=\"0\" maxLength=\"100\" border=\"1\" negativeBarBorderColorSameAsPositive=\"0\">"
|
||||
"<x14:cfvo type=\"autoMin\"/>"
|
||||
"<x14:cfvo type=\"autoMax\"/>"
|
||||
"<x14:borderColor rgb=\"FF638EC6\"/>"
|
||||
"<x14:negativeFillColor rgb=\"FFFF0000\"/>"
|
||||
"<x14:negativeBorderColor rgb=\"FFFF0000\"/>"
|
||||
"<x14:axisColor rgb=\"FF000000\"/>"
|
||||
"</x14:dataBar>"
|
||||
"</x14:cfRule>"
|
||||
"<xm:sqref>A1</xm:sqref>"
|
||||
"</x14:conditionalFormatting>"
|
||||
"<x14:conditionalFormatting xmlns:xm=\"http://schemas.microsoft.com/office/excel/2006/main\">"
|
||||
"<x14:cfRule type=\"dataBar\" id=\"{DA7ABA51-AAAA-BBBB-0001-000000000002}\">"
|
||||
"<x14:dataBar minLength=\"0\" maxLength=\"100\" border=\"1\" negativeBarBorderColorSameAsPositive=\"0\">"
|
||||
"<x14:cfvo type=\"autoMin\"/>"
|
||||
"<x14:cfvo type=\"autoMax\"/>"
|
||||
"<x14:borderColor rgb=\"FF63C384\"/>"
|
||||
"<x14:negativeFillColor rgb=\"FFFF0000\"/>"
|
||||
"<x14:negativeBorderColor rgb=\"FFFF0000\"/>"
|
||||
"<x14:axisColor rgb=\"FF000000\"/>"
|
||||
"</x14:dataBar>"
|
||||
"</x14:cfRule>"
|
||||
"<xm:sqref>A2:B2</xm:sqref>"
|
||||
"</x14:conditionalFormatting>"
|
||||
"<x14:conditionalFormatting xmlns:xm=\"http://schemas.microsoft.com/office/excel/2006/main\">"
|
||||
"<x14:cfRule type=\"dataBar\" id=\"{DA7ABA51-AAAA-BBBB-0001-000000000003}\">"
|
||||
"<x14:dataBar minLength=\"0\" maxLength=\"100\" border=\"1\" negativeBarBorderColorSameAsPositive=\"0\">"
|
||||
"<x14:cfvo type=\"autoMin\"/>"
|
||||
"<x14:cfvo type=\"autoMax\"/>"
|
||||
"<x14:borderColor rgb=\"FFFF555A\"/>"
|
||||
"<x14:negativeFillColor rgb=\"FFFF0000\"/>"
|
||||
"<x14:negativeBorderColor rgb=\"FFFF0000\"/>"
|
||||
"<x14:axisColor rgb=\"FF000000\"/>"
|
||||
"</x14:dataBar>"
|
||||
"</x14:cfRule>"
|
||||
"<xm:sqref>A3:C3</xm:sqref>"
|
||||
"</x14:conditionalFormatting>"
|
||||
"</x14:conditionalFormattings>"
|
||||
"</ext>"
|
||||
"</extLst>"
|
||||
"</worksheet>";
|
||||
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
worksheet_select(worksheet);
|
||||
|
||||
lxw_conditional_format *conditional_format = calloc(1, sizeof(lxw_conditional_format));
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_DATA_BAR;
|
||||
conditional_format->data_bar_2010 = LXW_TRUE;
|
||||
worksheet_conditional_format_cell(worksheet, CELL("A1"), conditional_format);
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_DATA_BAR;
|
||||
conditional_format->data_bar_2010 = LXW_TRUE;
|
||||
conditional_format->bar_color = 0x63C384;
|
||||
worksheet_conditional_format_range(worksheet, RANGE("A2:B2"), conditional_format);
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_DATA_BAR;
|
||||
conditional_format->data_bar_2010 = LXW_TRUE;
|
||||
conditional_format->bar_color = 0xFF555A;
|
||||
worksheet_conditional_format_range(worksheet, RANGE("A3:C3"), conditional_format);
|
||||
|
||||
free(conditional_format);
|
||||
lxw_worksheet_assemble_xml_file(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ_SHORT(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
@ -0,0 +1,145 @@
|
||||
/*
|
||||
* 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/shared_strings.h"
|
||||
|
||||
// Test assembling a complete Worksheet file.
|
||||
CTEST(worksheet, worksheet_data_bar04) {
|
||||
|
||||
char* got;
|
||||
char exp[] =
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
|
||||
"<worksheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\" xmlns:x14ac=\"http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac\" mc:Ignorable=\"x14ac\">"
|
||||
"<dimension ref=\"A1\"/>"
|
||||
"<sheetViews>"
|
||||
"<sheetView tabSelected=\"1\" workbookViewId=\"0\"/>"
|
||||
"</sheetViews>"
|
||||
"<sheetFormatPr defaultRowHeight=\"15\" x14ac:dyDescent=\"0.25\"/>"
|
||||
"<sheetData/>"
|
||||
"<conditionalFormatting sqref=\"A1\">"
|
||||
"<cfRule type=\"dataBar\" priority=\"1\">"
|
||||
"<dataBar>"
|
||||
"<cfvo type=\"min\"/>"
|
||||
"<cfvo type=\"max\"/>"
|
||||
"<color rgb=\"FF638EC6\"/>"
|
||||
"</dataBar>"
|
||||
"<extLst>"
|
||||
"<ext xmlns:x14=\"http://schemas.microsoft.com/office/spreadsheetml/2009/9/main\" uri=\"{B025F937-C7B1-47D3-B67F-A62EFF666E3E}\">"
|
||||
"<x14:id>{DA7ABA51-AAAA-BBBB-0001-000000000001}</x14:id>"
|
||||
"</ext>"
|
||||
"</extLst>"
|
||||
"</cfRule>"
|
||||
"</conditionalFormatting>"
|
||||
"<conditionalFormatting sqref=\"A2:B2\">"
|
||||
"<cfRule type=\"dataBar\" priority=\"2\">"
|
||||
"<dataBar>"
|
||||
"<cfvo type=\"min\"/>"
|
||||
"<cfvo type=\"max\"/>"
|
||||
"<color rgb=\"FF63C384\"/>"
|
||||
"</dataBar>"
|
||||
"<extLst>"
|
||||
"<ext xmlns:x14=\"http://schemas.microsoft.com/office/spreadsheetml/2009/9/main\" uri=\"{B025F937-C7B1-47D3-B67F-A62EFF666E3E}\">"
|
||||
"<x14:id>{DA7ABA51-AAAA-BBBB-0001-000000000002}</x14:id>"
|
||||
"</ext>"
|
||||
"</extLst>"
|
||||
"</cfRule>"
|
||||
"</conditionalFormatting>"
|
||||
"<conditionalFormatting sqref=\"A3:C3\">"
|
||||
"<cfRule type=\"dataBar\" priority=\"3\">"
|
||||
"<dataBar>"
|
||||
"<cfvo type=\"min\"/>"
|
||||
"<cfvo type=\"max\"/>"
|
||||
"<color rgb=\"FFFF555A\"/>"
|
||||
"</dataBar>"
|
||||
"<extLst>"
|
||||
"<ext xmlns:x14=\"http://schemas.microsoft.com/office/spreadsheetml/2009/9/main\" uri=\"{B025F937-C7B1-47D3-B67F-A62EFF666E3E}\">"
|
||||
"<x14:id>{DA7ABA51-AAAA-BBBB-0001-000000000003}</x14:id>"
|
||||
"</ext>"
|
||||
"</extLst>"
|
||||
"</cfRule>"
|
||||
"</conditionalFormatting>"
|
||||
"<pageMargins left=\"0.7\" right=\"0.7\" top=\"0.75\" bottom=\"0.75\" header=\"0.3\" footer=\"0.3\"/>"
|
||||
"<extLst>"
|
||||
"<ext xmlns:x14=\"http://schemas.microsoft.com/office/spreadsheetml/2009/9/main\" uri=\"{78C0D931-6437-407d-A8EE-F0AAD7539E65}\">"
|
||||
"<x14:conditionalFormattings>"
|
||||
"<x14:conditionalFormatting xmlns:xm=\"http://schemas.microsoft.com/office/excel/2006/main\">"
|
||||
"<x14:cfRule type=\"dataBar\" id=\"{DA7ABA51-AAAA-BBBB-0001-000000000001}\">"
|
||||
"<x14:dataBar minLength=\"0\" maxLength=\"100\" border=\"1\" gradient=\"0\" negativeBarBorderColorSameAsPositive=\"0\">"
|
||||
"<x14:cfvo type=\"autoMin\"/>"
|
||||
"<x14:cfvo type=\"autoMax\"/>"
|
||||
"<x14:borderColor rgb=\"FF638EC6\"/>"
|
||||
"<x14:negativeFillColor rgb=\"FFFF0000\"/>"
|
||||
"<x14:negativeBorderColor rgb=\"FFFF0000\"/>"
|
||||
"<x14:axisColor rgb=\"FF000000\"/>"
|
||||
"</x14:dataBar>"
|
||||
"</x14:cfRule>"
|
||||
"<xm:sqref>A1</xm:sqref>"
|
||||
"</x14:conditionalFormatting>"
|
||||
"<x14:conditionalFormatting xmlns:xm=\"http://schemas.microsoft.com/office/excel/2006/main\">"
|
||||
"<x14:cfRule type=\"dataBar\" id=\"{DA7ABA51-AAAA-BBBB-0001-000000000002}\">"
|
||||
"<x14:dataBar minLength=\"0\" maxLength=\"100\">"
|
||||
"<x14:cfvo type=\"autoMin\"/>"
|
||||
"<x14:cfvo type=\"autoMax\"/>"
|
||||
"<x14:negativeFillColor rgb=\"FFFF0000\"/>"
|
||||
"<x14:axisColor rgb=\"FF000000\"/>"
|
||||
"</x14:dataBar>"
|
||||
"</x14:cfRule>"
|
||||
"<xm:sqref>A2:B2</xm:sqref>"
|
||||
"</x14:conditionalFormatting>"
|
||||
"<x14:conditionalFormatting xmlns:xm=\"http://schemas.microsoft.com/office/excel/2006/main\">"
|
||||
"<x14:cfRule type=\"dataBar\" id=\"{DA7ABA51-AAAA-BBBB-0001-000000000003}\">"
|
||||
"<x14:dataBar minLength=\"0\" maxLength=\"100\" border=\"1\" negativeBarBorderColorSameAsPositive=\"0\">"
|
||||
"<x14:cfvo type=\"autoMin\"/>"
|
||||
"<x14:cfvo type=\"autoMax\"/>"
|
||||
"<x14:borderColor rgb=\"FFFF0000\"/>"
|
||||
"<x14:negativeFillColor rgb=\"FFFF0000\"/>"
|
||||
"<x14:negativeBorderColor rgb=\"FFFF0000\"/>"
|
||||
"<x14:axisColor rgb=\"FF000000\"/>"
|
||||
"</x14:dataBar>"
|
||||
"</x14:cfRule>"
|
||||
"<xm:sqref>A3:C3</xm:sqref>"
|
||||
"</x14:conditionalFormatting>"
|
||||
"</x14:conditionalFormattings>"
|
||||
"</ext>"
|
||||
"</extLst>"
|
||||
"</worksheet>";
|
||||
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
worksheet_select(worksheet);
|
||||
|
||||
lxw_conditional_format *conditional_format = calloc(1, sizeof(lxw_conditional_format));
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_DATA_BAR;
|
||||
conditional_format->bar_solid = LXW_TRUE;
|
||||
worksheet_conditional_format_cell(worksheet, CELL("A1"), conditional_format);
|
||||
memset(conditional_format, 0, sizeof(lxw_conditional_format));
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_DATA_BAR;
|
||||
conditional_format->bar_no_border = LXW_TRUE;
|
||||
conditional_format->bar_color = 0x63C384;
|
||||
worksheet_conditional_format_range(worksheet, RANGE("A2:B2"), conditional_format);
|
||||
memset(conditional_format, 0, sizeof(lxw_conditional_format));
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_DATA_BAR;
|
||||
conditional_format->bar_color = 0xFF555A;
|
||||
conditional_format->bar_border_color = 0xFF0000;
|
||||
worksheet_conditional_format_range(worksheet, RANGE("A3:C3"), conditional_format);
|
||||
|
||||
free(conditional_format);
|
||||
lxw_worksheet_assemble_xml_file(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ_SHORT(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
@ -0,0 +1,147 @@
|
||||
/*
|
||||
* 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/shared_strings.h"
|
||||
|
||||
// Test assembling a complete Worksheet file.
|
||||
CTEST(worksheet, worksheet_data_bar05) {
|
||||
|
||||
char* got;
|
||||
char exp[] =
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
|
||||
"<worksheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\" xmlns:x14ac=\"http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac\" mc:Ignorable=\"x14ac\">"
|
||||
"<dimension ref=\"A1\"/>"
|
||||
"<sheetViews>"
|
||||
"<sheetView tabSelected=\"1\" workbookViewId=\"0\"/>"
|
||||
"</sheetViews>"
|
||||
"<sheetFormatPr defaultRowHeight=\"15\" x14ac:dyDescent=\"0.25\"/>"
|
||||
"<sheetData/>"
|
||||
"<conditionalFormatting sqref=\"A1\">"
|
||||
"<cfRule type=\"dataBar\" priority=\"1\">"
|
||||
"<dataBar>"
|
||||
"<cfvo type=\"min\"/>"
|
||||
"<cfvo type=\"max\"/>"
|
||||
"<color rgb=\"FF638EC6\"/>"
|
||||
"</dataBar>"
|
||||
"<extLst>"
|
||||
"<ext xmlns:x14=\"http://schemas.microsoft.com/office/spreadsheetml/2009/9/main\" uri=\"{B025F937-C7B1-47D3-B67F-A62EFF666E3E}\">"
|
||||
"<x14:id>{DA7ABA51-AAAA-BBBB-0001-000000000001}</x14:id>"
|
||||
"</ext>"
|
||||
"</extLst>"
|
||||
"</cfRule>"
|
||||
"</conditionalFormatting>"
|
||||
"<conditionalFormatting sqref=\"A2:B2\">"
|
||||
"<cfRule type=\"dataBar\" priority=\"2\">"
|
||||
"<dataBar>"
|
||||
"<cfvo type=\"min\"/>"
|
||||
"<cfvo type=\"max\"/>"
|
||||
"<color rgb=\"FF63C384\"/>"
|
||||
"</dataBar>"
|
||||
"<extLst>"
|
||||
"<ext xmlns:x14=\"http://schemas.microsoft.com/office/spreadsheetml/2009/9/main\" uri=\"{B025F937-C7B1-47D3-B67F-A62EFF666E3E}\">"
|
||||
"<x14:id>{DA7ABA51-AAAA-BBBB-0001-000000000002}</x14:id>"
|
||||
"</ext>"
|
||||
"</extLst>"
|
||||
"</cfRule>"
|
||||
"</conditionalFormatting>"
|
||||
"<conditionalFormatting sqref=\"A3:C3\">"
|
||||
"<cfRule type=\"dataBar\" priority=\"3\">"
|
||||
"<dataBar>"
|
||||
"<cfvo type=\"min\"/>"
|
||||
"<cfvo type=\"max\"/>"
|
||||
"<color rgb=\"FFFF555A\"/>"
|
||||
"</dataBar>"
|
||||
"<extLst>"
|
||||
"<ext xmlns:x14=\"http://schemas.microsoft.com/office/spreadsheetml/2009/9/main\" uri=\"{B025F937-C7B1-47D3-B67F-A62EFF666E3E}\">"
|
||||
"<x14:id>{DA7ABA51-AAAA-BBBB-0001-000000000003}</x14:id>"
|
||||
"</ext>"
|
||||
"</extLst>"
|
||||
"</cfRule>"
|
||||
"</conditionalFormatting>"
|
||||
"<pageMargins left=\"0.7\" right=\"0.7\" top=\"0.75\" bottom=\"0.75\" header=\"0.3\" footer=\"0.3\"/>"
|
||||
"<extLst>"
|
||||
"<ext xmlns:x14=\"http://schemas.microsoft.com/office/spreadsheetml/2009/9/main\" uri=\"{78C0D931-6437-407d-A8EE-F0AAD7539E65}\">"
|
||||
"<x14:conditionalFormattings>"
|
||||
"<x14:conditionalFormatting xmlns:xm=\"http://schemas.microsoft.com/office/excel/2006/main\">"
|
||||
"<x14:cfRule type=\"dataBar\" id=\"{DA7ABA51-AAAA-BBBB-0001-000000000001}\">"
|
||||
"<x14:dataBar minLength=\"0\" maxLength=\"100\" border=\"1\" direction=\"leftToRight\" negativeBarBorderColorSameAsPositive=\"0\">"
|
||||
"<x14:cfvo type=\"autoMin\"/>"
|
||||
"<x14:cfvo type=\"autoMax\"/>"
|
||||
"<x14:borderColor rgb=\"FF638EC6\"/>"
|
||||
"<x14:negativeFillColor rgb=\"FFFF0000\"/>"
|
||||
"<x14:negativeBorderColor rgb=\"FFFF0000\"/>"
|
||||
"<x14:axisColor rgb=\"FF000000\"/>"
|
||||
"</x14:dataBar>"
|
||||
"</x14:cfRule>"
|
||||
"<xm:sqref>A1</xm:sqref>"
|
||||
"</x14:conditionalFormatting>"
|
||||
"<x14:conditionalFormatting xmlns:xm=\"http://schemas.microsoft.com/office/excel/2006/main\">"
|
||||
"<x14:cfRule type=\"dataBar\" id=\"{DA7ABA51-AAAA-BBBB-0001-000000000002}\">"
|
||||
"<x14:dataBar minLength=\"0\" maxLength=\"100\" border=\"1\" direction=\"rightToLeft\" negativeBarBorderColorSameAsPositive=\"0\">"
|
||||
"<x14:cfvo type=\"autoMin\"/>"
|
||||
"<x14:cfvo type=\"autoMax\"/>"
|
||||
"<x14:borderColor rgb=\"FF63C384\"/>"
|
||||
"<x14:negativeFillColor rgb=\"FFFF0000\"/>"
|
||||
"<x14:negativeBorderColor rgb=\"FFFF0000\"/>"
|
||||
"<x14:axisColor rgb=\"FF000000\"/>"
|
||||
"</x14:dataBar>"
|
||||
"</x14:cfRule>"
|
||||
"<xm:sqref>A2:B2</xm:sqref>"
|
||||
"</x14:conditionalFormatting>"
|
||||
"<x14:conditionalFormatting xmlns:xm=\"http://schemas.microsoft.com/office/excel/2006/main\">"
|
||||
"<x14:cfRule type=\"dataBar\" id=\"{DA7ABA51-AAAA-BBBB-0001-000000000003}\">"
|
||||
"<x14:dataBar minLength=\"0\" maxLength=\"100\" border=\"1\" negativeBarBorderColorSameAsPositive=\"0\">"
|
||||
"<x14:cfvo type=\"autoMin\"/>"
|
||||
"<x14:cfvo type=\"autoMax\"/>"
|
||||
"<x14:borderColor rgb=\"FFFF555A\"/>"
|
||||
"<x14:negativeFillColor rgb=\"FFFFFF00\"/>"
|
||||
"<x14:negativeBorderColor rgb=\"FFFF0000\"/>"
|
||||
"<x14:axisColor rgb=\"FF000000\"/>"
|
||||
"</x14:dataBar>"
|
||||
"</x14:cfRule>"
|
||||
"<xm:sqref>A3:C3</xm:sqref>"
|
||||
"</x14:conditionalFormatting>"
|
||||
"</x14:conditionalFormattings>"
|
||||
"</ext>"
|
||||
"</extLst>"
|
||||
"</worksheet>";
|
||||
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
worksheet_select(worksheet);
|
||||
|
||||
lxw_conditional_format *conditional_format = calloc(1, sizeof(lxw_conditional_format));
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_DATA_BAR;
|
||||
conditional_format->bar_direction = LXW_CONDITIONAL_BAR_DIRECTION_LEFT_TO_RIGHT;
|
||||
worksheet_conditional_format_cell(worksheet, CELL("A1"), conditional_format);
|
||||
memset(conditional_format, 0, sizeof(lxw_conditional_format));
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_DATA_BAR;
|
||||
conditional_format->bar_color = 0x63C384;
|
||||
conditional_format->bar_direction = LXW_CONDITIONAL_BAR_DIRECTION_RIGHT_TO_LEFT;
|
||||
worksheet_conditional_format_range(worksheet, RANGE("A2:B2"), conditional_format);
|
||||
memset(conditional_format, 0, sizeof(lxw_conditional_format));
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_DATA_BAR;
|
||||
conditional_format->bar_color = 0xFF555A;
|
||||
conditional_format->bar_negative_color = 0xFFFF00;
|
||||
worksheet_conditional_format_range(worksheet, RANGE("A3:C3"), conditional_format);
|
||||
|
||||
free(conditional_format);
|
||||
lxw_worksheet_assemble_xml_file(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ_SHORT(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
@ -0,0 +1,145 @@
|
||||
/*
|
||||
* 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/shared_strings.h"
|
||||
|
||||
// Test assembling a complete Worksheet file.
|
||||
CTEST(worksheet, worksheet_data_bar06) {
|
||||
|
||||
char* got;
|
||||
char exp[] =
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
|
||||
"<worksheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\" xmlns:x14ac=\"http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac\" mc:Ignorable=\"x14ac\">"
|
||||
"<dimension ref=\"A1\"/>"
|
||||
"<sheetViews>"
|
||||
"<sheetView tabSelected=\"1\" workbookViewId=\"0\"/>"
|
||||
"</sheetViews>"
|
||||
"<sheetFormatPr defaultRowHeight=\"15\" x14ac:dyDescent=\"0.25\"/>"
|
||||
"<sheetData/>"
|
||||
"<conditionalFormatting sqref=\"A1\">"
|
||||
"<cfRule type=\"dataBar\" priority=\"1\">"
|
||||
"<dataBar>"
|
||||
"<cfvo type=\"min\"/>"
|
||||
"<cfvo type=\"max\"/>"
|
||||
"<color rgb=\"FF638EC6\"/>"
|
||||
"</dataBar>"
|
||||
"<extLst>"
|
||||
"<ext xmlns:x14=\"http://schemas.microsoft.com/office/spreadsheetml/2009/9/main\" uri=\"{B025F937-C7B1-47D3-B67F-A62EFF666E3E}\">"
|
||||
"<x14:id>{DA7ABA51-AAAA-BBBB-0001-000000000001}</x14:id>"
|
||||
"</ext>"
|
||||
"</extLst>"
|
||||
"</cfRule>"
|
||||
"</conditionalFormatting>"
|
||||
"<conditionalFormatting sqref=\"A2:B2\">"
|
||||
"<cfRule type=\"dataBar\" priority=\"2\">"
|
||||
"<dataBar>"
|
||||
"<cfvo type=\"min\"/>"
|
||||
"<cfvo type=\"max\"/>"
|
||||
"<color rgb=\"FF63C384\"/>"
|
||||
"</dataBar>"
|
||||
"<extLst>"
|
||||
"<ext xmlns:x14=\"http://schemas.microsoft.com/office/spreadsheetml/2009/9/main\" uri=\"{B025F937-C7B1-47D3-B67F-A62EFF666E3E}\">"
|
||||
"<x14:id>{DA7ABA51-AAAA-BBBB-0001-000000000002}</x14:id>"
|
||||
"</ext>"
|
||||
"</extLst>"
|
||||
"</cfRule>"
|
||||
"</conditionalFormatting>"
|
||||
"<conditionalFormatting sqref=\"A3:C3\">"
|
||||
"<cfRule type=\"dataBar\" priority=\"3\">"
|
||||
"<dataBar>"
|
||||
"<cfvo type=\"min\"/>"
|
||||
"<cfvo type=\"max\"/>"
|
||||
"<color rgb=\"FFFF555A\"/>"
|
||||
"</dataBar>"
|
||||
"<extLst>"
|
||||
"<ext xmlns:x14=\"http://schemas.microsoft.com/office/spreadsheetml/2009/9/main\" uri=\"{B025F937-C7B1-47D3-B67F-A62EFF666E3E}\">"
|
||||
"<x14:id>{DA7ABA51-AAAA-BBBB-0001-000000000003}</x14:id>"
|
||||
"</ext>"
|
||||
"</extLst>"
|
||||
"</cfRule>"
|
||||
"</conditionalFormatting>"
|
||||
"<pageMargins left=\"0.7\" right=\"0.7\" top=\"0.75\" bottom=\"0.75\" header=\"0.3\" footer=\"0.3\"/>"
|
||||
"<extLst>"
|
||||
"<ext xmlns:x14=\"http://schemas.microsoft.com/office/spreadsheetml/2009/9/main\" uri=\"{78C0D931-6437-407d-A8EE-F0AAD7539E65}\">"
|
||||
"<x14:conditionalFormattings>"
|
||||
"<x14:conditionalFormatting xmlns:xm=\"http://schemas.microsoft.com/office/excel/2006/main\">"
|
||||
"<x14:cfRule type=\"dataBar\" id=\"{DA7ABA51-AAAA-BBBB-0001-000000000001}\">"
|
||||
"<x14:dataBar minLength=\"0\" maxLength=\"100\" border=\"1\" negativeBarColorSameAsPositive=\"1\" negativeBarBorderColorSameAsPositive=\"0\">"
|
||||
"<x14:cfvo type=\"autoMin\"/>"
|
||||
"<x14:cfvo type=\"autoMax\"/>"
|
||||
"<x14:borderColor rgb=\"FF638EC6\"/>"
|
||||
"<x14:negativeBorderColor rgb=\"FFFF0000\"/>"
|
||||
"<x14:axisColor rgb=\"FF000000\"/>"
|
||||
"</x14:dataBar>"
|
||||
"</x14:cfRule>"
|
||||
"<xm:sqref>A1</xm:sqref>"
|
||||
"</x14:conditionalFormatting>"
|
||||
"<x14:conditionalFormatting xmlns:xm=\"http://schemas.microsoft.com/office/excel/2006/main\">"
|
||||
"<x14:cfRule type=\"dataBar\" id=\"{DA7ABA51-AAAA-BBBB-0001-000000000002}\">"
|
||||
"<x14:dataBar minLength=\"0\" maxLength=\"100\" border=\"1\" negativeBarBorderColorSameAsPositive=\"0\">"
|
||||
"<x14:cfvo type=\"autoMin\"/>"
|
||||
"<x14:cfvo type=\"autoMax\"/>"
|
||||
"<x14:borderColor rgb=\"FF63C384\"/>"
|
||||
"<x14:negativeFillColor rgb=\"FFFF0000\"/>"
|
||||
"<x14:negativeBorderColor rgb=\"FF92D050\"/>"
|
||||
"<x14:axisColor rgb=\"FF000000\"/>"
|
||||
"</x14:dataBar>"
|
||||
"</x14:cfRule>"
|
||||
"<xm:sqref>A2:B2</xm:sqref>"
|
||||
"</x14:conditionalFormatting>"
|
||||
"<x14:conditionalFormatting xmlns:xm=\"http://schemas.microsoft.com/office/excel/2006/main\">"
|
||||
"<x14:cfRule type=\"dataBar\" id=\"{DA7ABA51-AAAA-BBBB-0001-000000000003}\">"
|
||||
"<x14:dataBar minLength=\"0\" maxLength=\"100\" border=\"1\">"
|
||||
"<x14:cfvo type=\"autoMin\"/>"
|
||||
"<x14:cfvo type=\"autoMax\"/>"
|
||||
"<x14:borderColor rgb=\"FFFF555A\"/>"
|
||||
"<x14:negativeFillColor rgb=\"FFFF0000\"/>"
|
||||
"<x14:axisColor rgb=\"FF000000\"/>"
|
||||
"</x14:dataBar>"
|
||||
"</x14:cfRule>"
|
||||
"<xm:sqref>A3:C3</xm:sqref>"
|
||||
"</x14:conditionalFormatting>"
|
||||
"</x14:conditionalFormattings>"
|
||||
"</ext>"
|
||||
"</extLst>"
|
||||
"</worksheet>";
|
||||
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
worksheet_select(worksheet);
|
||||
|
||||
lxw_conditional_format *conditional_format = calloc(1, sizeof(lxw_conditional_format));
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_DATA_BAR;
|
||||
conditional_format->bar_negative_color_same = LXW_TRUE;
|
||||
worksheet_conditional_format_cell(worksheet, CELL("A1"), conditional_format);
|
||||
memset(conditional_format, 0, sizeof(lxw_conditional_format));
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_DATA_BAR;
|
||||
conditional_format->bar_color = 0x63C384;
|
||||
conditional_format->bar_negative_border_color = 0x92D050;
|
||||
worksheet_conditional_format_range(worksheet, RANGE("A2:B2"), conditional_format);
|
||||
memset(conditional_format, 0, sizeof(lxw_conditional_format));
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_DATA_BAR;
|
||||
conditional_format->bar_color = 0xFF555A;
|
||||
conditional_format->bar_negative_border_color_same = LXW_TRUE;
|
||||
worksheet_conditional_format_range(worksheet, RANGE("A3:C3"), conditional_format);
|
||||
|
||||
free(conditional_format);
|
||||
lxw_worksheet_assemble_xml_file(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ_SHORT(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
@ -0,0 +1,146 @@
|
||||
/*
|
||||
* 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/shared_strings.h"
|
||||
|
||||
// Test assembling a complete Worksheet file.
|
||||
CTEST(worksheet, worksheet_data_bar07) {
|
||||
|
||||
char* got;
|
||||
char exp[] =
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
|
||||
"<worksheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\" xmlns:x14ac=\"http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac\" mc:Ignorable=\"x14ac\">"
|
||||
"<dimension ref=\"A1\"/>"
|
||||
"<sheetViews>"
|
||||
"<sheetView tabSelected=\"1\" workbookViewId=\"0\"/>"
|
||||
"</sheetViews>"
|
||||
"<sheetFormatPr defaultRowHeight=\"15\" x14ac:dyDescent=\"0.25\"/>"
|
||||
"<sheetData/>"
|
||||
"<conditionalFormatting sqref=\"A1\">"
|
||||
"<cfRule type=\"dataBar\" priority=\"1\">"
|
||||
"<dataBar>"
|
||||
"<cfvo type=\"min\"/>"
|
||||
"<cfvo type=\"max\"/>"
|
||||
"<color rgb=\"FF638EC6\"/>"
|
||||
"</dataBar>"
|
||||
"<extLst>"
|
||||
"<ext xmlns:x14=\"http://schemas.microsoft.com/office/spreadsheetml/2009/9/main\" uri=\"{B025F937-C7B1-47D3-B67F-A62EFF666E3E}\">"
|
||||
"<x14:id>{DA7ABA51-AAAA-BBBB-0001-000000000001}</x14:id>"
|
||||
"</ext>"
|
||||
"</extLst>"
|
||||
"</cfRule>"
|
||||
"</conditionalFormatting>"
|
||||
"<conditionalFormatting sqref=\"A2:B2\">"
|
||||
"<cfRule type=\"dataBar\" priority=\"2\">"
|
||||
"<dataBar>"
|
||||
"<cfvo type=\"min\"/>"
|
||||
"<cfvo type=\"max\"/>"
|
||||
"<color rgb=\"FF63C384\"/>"
|
||||
"</dataBar>"
|
||||
"<extLst>"
|
||||
"<ext xmlns:x14=\"http://schemas.microsoft.com/office/spreadsheetml/2009/9/main\" uri=\"{B025F937-C7B1-47D3-B67F-A62EFF666E3E}\">"
|
||||
"<x14:id>{DA7ABA51-AAAA-BBBB-0001-000000000002}</x14:id>"
|
||||
"</ext>"
|
||||
"</extLst>"
|
||||
"</cfRule>"
|
||||
"</conditionalFormatting>"
|
||||
"<conditionalFormatting sqref=\"A3:C3\">"
|
||||
"<cfRule type=\"dataBar\" priority=\"3\">"
|
||||
"<dataBar>"
|
||||
"<cfvo type=\"min\"/>"
|
||||
"<cfvo type=\"max\"/>"
|
||||
"<color rgb=\"FFFF555A\"/>"
|
||||
"</dataBar>"
|
||||
"<extLst>"
|
||||
"<ext xmlns:x14=\"http://schemas.microsoft.com/office/spreadsheetml/2009/9/main\" uri=\"{B025F937-C7B1-47D3-B67F-A62EFF666E3E}\">"
|
||||
"<x14:id>{DA7ABA51-AAAA-BBBB-0001-000000000003}</x14:id>"
|
||||
"</ext>"
|
||||
"</extLst>"
|
||||
"</cfRule>"
|
||||
"</conditionalFormatting>"
|
||||
"<pageMargins left=\"0.7\" right=\"0.7\" top=\"0.75\" bottom=\"0.75\" header=\"0.3\" footer=\"0.3\"/>"
|
||||
"<extLst>"
|
||||
"<ext xmlns:x14=\"http://schemas.microsoft.com/office/spreadsheetml/2009/9/main\" uri=\"{78C0D931-6437-407d-A8EE-F0AAD7539E65}\">"
|
||||
"<x14:conditionalFormattings>"
|
||||
"<x14:conditionalFormatting xmlns:xm=\"http://schemas.microsoft.com/office/excel/2006/main\">"
|
||||
"<x14:cfRule type=\"dataBar\" id=\"{DA7ABA51-AAAA-BBBB-0001-000000000001}\">"
|
||||
"<x14:dataBar minLength=\"0\" maxLength=\"100\" border=\"1\" negativeBarBorderColorSameAsPositive=\"0\" axisPosition=\"middle\">"
|
||||
"<x14:cfvo type=\"autoMin\"/>"
|
||||
"<x14:cfvo type=\"autoMax\"/>"
|
||||
"<x14:borderColor rgb=\"FF638EC6\"/>"
|
||||
"<x14:negativeFillColor rgb=\"FFFF0000\"/>"
|
||||
"<x14:negativeBorderColor rgb=\"FFFF0000\"/>"
|
||||
"<x14:axisColor rgb=\"FF000000\"/>"
|
||||
"</x14:dataBar>"
|
||||
"</x14:cfRule>"
|
||||
"<xm:sqref>A1</xm:sqref>"
|
||||
"</x14:conditionalFormatting>"
|
||||
"<x14:conditionalFormatting xmlns:xm=\"http://schemas.microsoft.com/office/excel/2006/main\">"
|
||||
"<x14:cfRule type=\"dataBar\" id=\"{DA7ABA51-AAAA-BBBB-0001-000000000002}\">"
|
||||
"<x14:dataBar minLength=\"0\" maxLength=\"100\" border=\"1\" negativeBarBorderColorSameAsPositive=\"0\" axisPosition=\"none\">"
|
||||
"<x14:cfvo type=\"autoMin\"/>"
|
||||
"<x14:cfvo type=\"autoMax\"/>"
|
||||
"<x14:borderColor rgb=\"FF63C384\"/>"
|
||||
"<x14:negativeFillColor rgb=\"FFFF0000\"/>"
|
||||
"<x14:negativeBorderColor rgb=\"FFFF0000\"/>"
|
||||
"</x14:dataBar>"
|
||||
"</x14:cfRule>"
|
||||
"<xm:sqref>A2:B2</xm:sqref>"
|
||||
"</x14:conditionalFormatting>"
|
||||
"<x14:conditionalFormatting xmlns:xm=\"http://schemas.microsoft.com/office/excel/2006/main\">"
|
||||
"<x14:cfRule type=\"dataBar\" id=\"{DA7ABA51-AAAA-BBBB-0001-000000000003}\">"
|
||||
"<x14:dataBar minLength=\"0\" maxLength=\"100\" border=\"1\" negativeBarBorderColorSameAsPositive=\"0\">"
|
||||
"<x14:cfvo type=\"autoMin\"/>"
|
||||
"<x14:cfvo type=\"autoMax\"/>"
|
||||
"<x14:borderColor rgb=\"FFFF555A\"/>"
|
||||
"<x14:negativeFillColor rgb=\"FFFF0000\"/>"
|
||||
"<x14:negativeBorderColor rgb=\"FFFF0000\"/>"
|
||||
"<x14:axisColor rgb=\"FF0070C0\"/>"
|
||||
"</x14:dataBar>"
|
||||
"</x14:cfRule>"
|
||||
"<xm:sqref>A3:C3</xm:sqref>"
|
||||
"</x14:conditionalFormatting>"
|
||||
"</x14:conditionalFormattings>"
|
||||
"</ext>"
|
||||
"</extLst>"
|
||||
"</worksheet>";
|
||||
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
worksheet_select(worksheet);
|
||||
|
||||
lxw_conditional_format *conditional_format = calloc(1, sizeof(lxw_conditional_format));
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_DATA_BAR;
|
||||
conditional_format->bar_axis_position = LXW_CONDITIONAL_BAR_AXIS_MIDPOINT;
|
||||
worksheet_conditional_format_cell(worksheet, CELL("A1"), conditional_format);
|
||||
memset(conditional_format, 0, sizeof(lxw_conditional_format));
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_DATA_BAR;
|
||||
conditional_format->bar_color = 0x63C384;
|
||||
conditional_format->bar_axis_position = LXW_CONDITIONAL_BAR_AXIS_NONE;
|
||||
worksheet_conditional_format_range(worksheet, RANGE("A2:B2"), conditional_format);
|
||||
memset(conditional_format, 0, sizeof(lxw_conditional_format));
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_DATA_BAR;
|
||||
conditional_format->bar_color = 0xFF555A;
|
||||
conditional_format->bar_axis_color = 0x0070C0;
|
||||
worksheet_conditional_format_range(worksheet, RANGE("A3:C3"), conditional_format);
|
||||
|
||||
free(conditional_format);
|
||||
lxw_worksheet_assemble_xml_file(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ_SHORT(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
/*
|
||||
* 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/shared_strings.h"
|
||||
|
||||
// Test assembling a complete Worksheet file.
|
||||
CTEST(worksheet, worksheet_data_bar08) {
|
||||
|
||||
char* got;
|
||||
char exp[] =
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
|
||||
"<worksheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\">"
|
||||
"<dimension ref=\"A1\"/>"
|
||||
"<sheetViews>"
|
||||
"<sheetView tabSelected=\"1\" workbookViewId=\"0\"/>"
|
||||
"</sheetViews>"
|
||||
"<sheetFormatPr defaultRowHeight=\"15\"/>"
|
||||
"<sheetData/>"
|
||||
"<conditionalFormatting sqref=\"A1\">"
|
||||
"<cfRule type=\"dataBar\" priority=\"1\">"
|
||||
"<dataBar showValue=\"0\">"
|
||||
"<cfvo type=\"min\" val=\"0\"/>"
|
||||
"<cfvo type=\"max\" val=\"0\"/>"
|
||||
"<color rgb=\"FF638EC6\"/>"
|
||||
"</dataBar>"
|
||||
"</cfRule>"
|
||||
"</conditionalFormatting>"
|
||||
"<pageMargins left=\"0.7\" right=\"0.7\" top=\"0.75\" bottom=\"0.75\" header=\"0.3\" footer=\"0.3\"/>"
|
||||
"</worksheet>";
|
||||
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
worksheet_select(worksheet);
|
||||
|
||||
lxw_conditional_format *conditional_format = calloc(1, sizeof(lxw_conditional_format));
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_DATA_BAR;
|
||||
conditional_format->bar_only = LXW_TRUE;
|
||||
worksheet_conditional_format_cell(worksheet, CELL("A1"), conditional_format);
|
||||
|
||||
free(conditional_format);
|
||||
lxw_worksheet_assemble_xml_file(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ_SHORT(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
@ -0,0 +1,82 @@
|
||||
/*
|
||||
* 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/shared_strings.h"
|
||||
|
||||
// Test assembling a complete Worksheet file.
|
||||
CTEST(worksheet, worksheet_data_bar09) {
|
||||
|
||||
char* got;
|
||||
char exp[] =
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
|
||||
"<worksheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\" xmlns:x14ac=\"http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac\" mc:Ignorable=\"x14ac\">"
|
||||
"<dimension ref=\"A1\"/>"
|
||||
"<sheetViews>"
|
||||
"<sheetView tabSelected=\"1\" workbookViewId=\"0\"/>"
|
||||
"</sheetViews>"
|
||||
"<sheetFormatPr defaultRowHeight=\"15\" x14ac:dyDescent=\"0.25\"/>"
|
||||
"<sheetData/>"
|
||||
"<conditionalFormatting sqref=\"A1\">"
|
||||
"<cfRule type=\"dataBar\" priority=\"1\">"
|
||||
"<dataBar showValue=\"0\">"
|
||||
"<cfvo type=\"min\"/>"
|
||||
"<cfvo type=\"max\"/>"
|
||||
"<color rgb=\"FF638EC6\"/>"
|
||||
"</dataBar>"
|
||||
"<extLst>"
|
||||
"<ext xmlns:x14=\"http://schemas.microsoft.com/office/spreadsheetml/2009/9/main\" uri=\"{B025F937-C7B1-47D3-B67F-A62EFF666E3E}\">"
|
||||
"<x14:id>{DA7ABA51-AAAA-BBBB-0001-000000000001}</x14:id>"
|
||||
"</ext>"
|
||||
"</extLst>"
|
||||
"</cfRule>"
|
||||
"</conditionalFormatting>"
|
||||
"<pageMargins left=\"0.7\" right=\"0.7\" top=\"0.75\" bottom=\"0.75\" header=\"0.3\" footer=\"0.3\"/>"
|
||||
"<extLst>"
|
||||
"<ext xmlns:x14=\"http://schemas.microsoft.com/office/spreadsheetml/2009/9/main\" uri=\"{78C0D931-6437-407d-A8EE-F0AAD7539E65}\">"
|
||||
"<x14:conditionalFormattings>"
|
||||
"<x14:conditionalFormatting xmlns:xm=\"http://schemas.microsoft.com/office/excel/2006/main\">"
|
||||
"<x14:cfRule type=\"dataBar\" id=\"{DA7ABA51-AAAA-BBBB-0001-000000000001}\">"
|
||||
"<x14:dataBar minLength=\"0\" maxLength=\"100\" border=\"1\" negativeBarBorderColorSameAsPositive=\"0\">"
|
||||
"<x14:cfvo type=\"autoMin\"/>"
|
||||
"<x14:cfvo type=\"autoMax\"/>"
|
||||
"<x14:borderColor rgb=\"FF638EC6\"/>"
|
||||
"<x14:negativeFillColor rgb=\"FFFF0000\"/>"
|
||||
"<x14:negativeBorderColor rgb=\"FFFF0000\"/>"
|
||||
"<x14:axisColor rgb=\"FF000000\"/>"
|
||||
"</x14:dataBar>"
|
||||
"</x14:cfRule>"
|
||||
"<xm:sqref>A1</xm:sqref>"
|
||||
"</x14:conditionalFormatting>"
|
||||
"</x14:conditionalFormattings>"
|
||||
"</ext>"
|
||||
"</extLst>"
|
||||
"</worksheet>";
|
||||
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
worksheet_select(worksheet);
|
||||
|
||||
lxw_conditional_format *conditional_format = calloc(1, sizeof(lxw_conditional_format));
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_DATA_BAR;
|
||||
conditional_format->bar_only = LXW_TRUE;
|
||||
conditional_format->data_bar_2010 = LXW_TRUE;
|
||||
worksheet_conditional_format_cell(worksheet, CELL("A1"), conditional_format);
|
||||
|
||||
free(conditional_format);
|
||||
lxw_worksheet_assemble_xml_file(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ_SHORT(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
@ -0,0 +1,165 @@
|
||||
/*
|
||||
* 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/shared_strings.h"
|
||||
|
||||
// Test assembling a complete Worksheet file.
|
||||
CTEST(worksheet, worksheet_data_bar10) {
|
||||
|
||||
char* got;
|
||||
char exp[] =
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
|
||||
"<worksheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\" xmlns:x14ac=\"http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac\" mc:Ignorable=\"x14ac\">"
|
||||
"<dimension ref=\"A1\"/>"
|
||||
"<sheetViews>"
|
||||
"<sheetView tabSelected=\"1\" workbookViewId=\"0\"/>"
|
||||
"</sheetViews>"
|
||||
"<sheetFormatPr defaultRowHeight=\"15\" x14ac:dyDescent=\"0.25\"/>"
|
||||
"<sheetData/>"
|
||||
"<conditionalFormatting sqref=\"A1\">"
|
||||
"<cfRule type=\"dataBar\" priority=\"1\">"
|
||||
"<dataBar>"
|
||||
"<cfvo type=\"min\"/>"
|
||||
"<cfvo type=\"max\"/>"
|
||||
"<color rgb=\"FF638EC6\"/>"
|
||||
"</dataBar>"
|
||||
"<extLst>"
|
||||
"<ext xmlns:x14=\"http://schemas.microsoft.com/office/spreadsheetml/2009/9/main\" uri=\"{B025F937-C7B1-47D3-B67F-A62EFF666E3E}\">"
|
||||
"<x14:id>{DA7ABA51-AAAA-BBBB-0001-000000000001}</x14:id>"
|
||||
"</ext>"
|
||||
"</extLst>"
|
||||
"</cfRule>"
|
||||
"</conditionalFormatting>"
|
||||
"<conditionalFormatting sqref=\"A2:B2\">"
|
||||
"<cfRule type=\"dataBar\" priority=\"2\">"
|
||||
"<dataBar>"
|
||||
"<cfvo type=\"num\" val=\"0\"/>"
|
||||
"<cfvo type=\"num\" val=\"0\"/>"
|
||||
"<color rgb=\"FF63C384\"/>"
|
||||
"</dataBar>"
|
||||
"<extLst>"
|
||||
"<ext xmlns:x14=\"http://schemas.microsoft.com/office/spreadsheetml/2009/9/main\" uri=\"{B025F937-C7B1-47D3-B67F-A62EFF666E3E}\">"
|
||||
"<x14:id>{DA7ABA51-AAAA-BBBB-0001-000000000002}</x14:id>"
|
||||
"</ext>"
|
||||
"</extLst>"
|
||||
"</cfRule>"
|
||||
"</conditionalFormatting>"
|
||||
"<conditionalFormatting sqref=\"A3:C3\">"
|
||||
"<cfRule type=\"dataBar\" priority=\"3\">"
|
||||
"<dataBar>"
|
||||
"<cfvo type=\"percent\" val=\"0\"/>"
|
||||
"<cfvo type=\"percent\" val=\"100\"/>"
|
||||
"<color rgb=\"FFFF555A\"/>"
|
||||
"</dataBar>"
|
||||
"<extLst>"
|
||||
"<ext xmlns:x14=\"http://schemas.microsoft.com/office/spreadsheetml/2009/9/main\" uri=\"{B025F937-C7B1-47D3-B67F-A62EFF666E3E}\">"
|
||||
"<x14:id>{DA7ABA51-AAAA-BBBB-0001-000000000003}</x14:id>"
|
||||
"</ext>"
|
||||
"</extLst>"
|
||||
"</cfRule>"
|
||||
"</conditionalFormatting>"
|
||||
"<pageMargins left=\"0.7\" right=\"0.7\" top=\"0.75\" bottom=\"0.75\" header=\"0.3\" footer=\"0.3\"/>"
|
||||
"<extLst>"
|
||||
"<ext xmlns:x14=\"http://schemas.microsoft.com/office/spreadsheetml/2009/9/main\" uri=\"{78C0D931-6437-407d-A8EE-F0AAD7539E65}\">"
|
||||
"<x14:conditionalFormattings>"
|
||||
"<x14:conditionalFormatting xmlns:xm=\"http://schemas.microsoft.com/office/excel/2006/main\">"
|
||||
"<x14:cfRule type=\"dataBar\" id=\"{DA7ABA51-AAAA-BBBB-0001-000000000001}\">"
|
||||
"<x14:dataBar minLength=\"0\" maxLength=\"100\" border=\"1\" negativeBarBorderColorSameAsPositive=\"0\">"
|
||||
"<x14:cfvo type=\"min\"/>"
|
||||
"<x14:cfvo type=\"max\"/>"
|
||||
"<x14:borderColor rgb=\"FF638EC6\"/>"
|
||||
"<x14:negativeFillColor rgb=\"FFFF0000\"/>"
|
||||
"<x14:negativeBorderColor rgb=\"FFFF0000\"/>"
|
||||
"<x14:axisColor rgb=\"FF000000\"/>"
|
||||
"</x14:dataBar>"
|
||||
"</x14:cfRule>"
|
||||
"<xm:sqref>A1</xm:sqref>"
|
||||
"</x14:conditionalFormatting>"
|
||||
"<x14:conditionalFormatting xmlns:xm=\"http://schemas.microsoft.com/office/excel/2006/main\">"
|
||||
"<x14:cfRule type=\"dataBar\" id=\"{DA7ABA51-AAAA-BBBB-0001-000000000002}\">"
|
||||
"<x14:dataBar minLength=\"0\" maxLength=\"100\" border=\"1\" negativeBarBorderColorSameAsPositive=\"0\">"
|
||||
"<x14:cfvo type=\"num\">"
|
||||
"<xm:f>0</xm:f>"
|
||||
"</x14:cfvo>"
|
||||
"<x14:cfvo type=\"num\">"
|
||||
"<xm:f>0</xm:f>"
|
||||
"</x14:cfvo>"
|
||||
"<x14:borderColor rgb=\"FF63C384\"/>"
|
||||
"<x14:negativeFillColor rgb=\"FFFF0000\"/>"
|
||||
"<x14:negativeBorderColor rgb=\"FFFF0000\"/>"
|
||||
"<x14:axisColor rgb=\"FF000000\"/>"
|
||||
"</x14:dataBar>"
|
||||
"</x14:cfRule>"
|
||||
"<xm:sqref>A2:B2</xm:sqref>"
|
||||
"</x14:conditionalFormatting>"
|
||||
"<x14:conditionalFormatting xmlns:xm=\"http://schemas.microsoft.com/office/excel/2006/main\">"
|
||||
"<x14:cfRule type=\"dataBar\" id=\"{DA7ABA51-AAAA-BBBB-0001-000000000003}\">"
|
||||
"<x14:dataBar minLength=\"0\" maxLength=\"100\" border=\"1\" negativeBarBorderColorSameAsPositive=\"0\">"
|
||||
"<x14:cfvo type=\"percent\">"
|
||||
"<xm:f>0</xm:f>"
|
||||
"</x14:cfvo>"
|
||||
"<x14:cfvo type=\"percent\">"
|
||||
"<xm:f>100</xm:f>"
|
||||
"</x14:cfvo>"
|
||||
"<x14:borderColor rgb=\"FFFF555A\"/>"
|
||||
"<x14:negativeFillColor rgb=\"FFFF0000\"/>"
|
||||
"<x14:negativeBorderColor rgb=\"FFFF0000\"/>"
|
||||
"<x14:axisColor rgb=\"FF000000\"/>"
|
||||
"</x14:dataBar>"
|
||||
"</x14:cfRule>"
|
||||
"<xm:sqref>A3:C3</xm:sqref>"
|
||||
"</x14:conditionalFormatting>"
|
||||
"</x14:conditionalFormattings>"
|
||||
"</ext>"
|
||||
"</extLst>"
|
||||
"</worksheet>";
|
||||
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
worksheet_select(worksheet);
|
||||
|
||||
lxw_conditional_format *conditional_format = calloc(1, sizeof(lxw_conditional_format));
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_DATA_BAR;
|
||||
conditional_format->data_bar_2010 = LXW_TRUE;
|
||||
conditional_format->min_rule_type = LXW_CONDITIONAL_RULE_TYPE_MINIMUM;
|
||||
conditional_format->max_rule_type = LXW_CONDITIONAL_RULE_TYPE_MAXIMUM;
|
||||
worksheet_conditional_format_cell(worksheet, CELL("A1"), conditional_format);
|
||||
memset(conditional_format, 0, sizeof(lxw_conditional_format));
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_DATA_BAR;
|
||||
conditional_format->bar_color = 0x63C384;
|
||||
conditional_format->data_bar_2010 = LXW_TRUE;
|
||||
conditional_format->min_rule_type = LXW_CONDITIONAL_RULE_TYPE_NUMBER;
|
||||
conditional_format->max_rule_type = LXW_CONDITIONAL_RULE_TYPE_NUMBER;
|
||||
conditional_format->min_value = 0;
|
||||
conditional_format->max_value = 0;
|
||||
worksheet_conditional_format_range(worksheet, RANGE("A2:B2"), conditional_format);
|
||||
memset(conditional_format, 0, sizeof(lxw_conditional_format));
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_DATA_BAR;
|
||||
conditional_format->data_bar_2010 = LXW_TRUE;
|
||||
conditional_format->bar_color = 0xFF555A;
|
||||
conditional_format->min_rule_type = LXW_CONDITIONAL_RULE_TYPE_PERCENT;
|
||||
conditional_format->max_rule_type = LXW_CONDITIONAL_RULE_TYPE_PERCENT;
|
||||
conditional_format->min_value = 0;
|
||||
conditional_format->max_value = 100;
|
||||
worksheet_conditional_format_range(worksheet, RANGE("A3:C3"), conditional_format);
|
||||
|
||||
free(conditional_format);
|
||||
lxw_worksheet_assemble_xml_file(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ_SHORT(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
@ -0,0 +1,169 @@
|
||||
/*
|
||||
* 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/shared_strings.h"
|
||||
|
||||
// Test assembling a complete Worksheet file.
|
||||
CTEST(worksheet, worksheet_data_bar11) {
|
||||
|
||||
char* got;
|
||||
char exp[] =
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
|
||||
"<worksheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\" xmlns:x14ac=\"http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac\" mc:Ignorable=\"x14ac\">"
|
||||
"<dimension ref=\"A1\"/>"
|
||||
"<sheetViews>"
|
||||
"<sheetView tabSelected=\"1\" workbookViewId=\"0\"/>"
|
||||
"</sheetViews>"
|
||||
"<sheetFormatPr defaultRowHeight=\"15\" x14ac:dyDescent=\"0.25\"/>"
|
||||
"<sheetData/>"
|
||||
"<conditionalFormatting sqref=\"A1\">"
|
||||
"<cfRule type=\"dataBar\" priority=\"1\">"
|
||||
"<dataBar>"
|
||||
"<cfvo type=\"formula\" val=\"$B$1\"/>"
|
||||
"<cfvo type=\"max\"/>"
|
||||
"<color rgb=\"FF638EC6\"/>"
|
||||
"</dataBar>"
|
||||
"<extLst>"
|
||||
"<ext xmlns:x14=\"http://schemas.microsoft.com/office/spreadsheetml/2009/9/main\" uri=\"{B025F937-C7B1-47D3-B67F-A62EFF666E3E}\">"
|
||||
"<x14:id>{DA7ABA51-AAAA-BBBB-0001-000000000001}</x14:id>"
|
||||
"</ext>"
|
||||
"</extLst>"
|
||||
"</cfRule>"
|
||||
"</conditionalFormatting>"
|
||||
"<conditionalFormatting sqref=\"A2:B2\">"
|
||||
"<cfRule type=\"dataBar\" priority=\"2\">"
|
||||
"<dataBar>"
|
||||
"<cfvo type=\"formula\" val=\"$B$1\"/>"
|
||||
"<cfvo type=\"formula\" val=\"$C$1\"/>"
|
||||
"<color rgb=\"FF63C384\"/>"
|
||||
"</dataBar>"
|
||||
"<extLst>"
|
||||
"<ext xmlns:x14=\"http://schemas.microsoft.com/office/spreadsheetml/2009/9/main\" uri=\"{B025F937-C7B1-47D3-B67F-A62EFF666E3E}\">"
|
||||
"<x14:id>{DA7ABA51-AAAA-BBBB-0001-000000000002}</x14:id>"
|
||||
"</ext>"
|
||||
"</extLst>"
|
||||
"</cfRule>"
|
||||
"</conditionalFormatting>"
|
||||
"<conditionalFormatting sqref=\"A3:C3\">"
|
||||
"<cfRule type=\"dataBar\" priority=\"3\">"
|
||||
"<dataBar>"
|
||||
"<cfvo type=\"percentile\" val=\"10\"/>"
|
||||
"<cfvo type=\"percentile\" val=\"90\"/>"
|
||||
"<color rgb=\"FFFF555A\"/>"
|
||||
"</dataBar>"
|
||||
"<extLst>"
|
||||
"<ext xmlns:x14=\"http://schemas.microsoft.com/office/spreadsheetml/2009/9/main\" uri=\"{B025F937-C7B1-47D3-B67F-A62EFF666E3E}\">"
|
||||
"<x14:id>{DA7ABA51-AAAA-BBBB-0001-000000000003}</x14:id>"
|
||||
"</ext>"
|
||||
"</extLst>"
|
||||
"</cfRule>"
|
||||
"</conditionalFormatting>"
|
||||
"<pageMargins left=\"0.7\" right=\"0.7\" top=\"0.75\" bottom=\"0.75\" header=\"0.3\" footer=\"0.3\"/>"
|
||||
"<extLst>"
|
||||
"<ext xmlns:x14=\"http://schemas.microsoft.com/office/spreadsheetml/2009/9/main\" uri=\"{78C0D931-6437-407d-A8EE-F0AAD7539E65}\">"
|
||||
"<x14:conditionalFormattings>"
|
||||
"<x14:conditionalFormatting xmlns:xm=\"http://schemas.microsoft.com/office/excel/2006/main\">"
|
||||
"<x14:cfRule type=\"dataBar\" id=\"{DA7ABA51-AAAA-BBBB-0001-000000000001}\">"
|
||||
"<x14:dataBar minLength=\"0\" maxLength=\"100\" border=\"1\" negativeBarBorderColorSameAsPositive=\"0\">"
|
||||
"<x14:cfvo type=\"formula\">"
|
||||
"<xm:f>$B$1</xm:f>"
|
||||
"</x14:cfvo>"
|
||||
"<x14:cfvo type=\"autoMax\"/>"
|
||||
"<x14:borderColor rgb=\"FF638EC6\"/>"
|
||||
"<x14:negativeFillColor rgb=\"FFFF0000\"/>"
|
||||
"<x14:negativeBorderColor rgb=\"FFFF0000\"/>"
|
||||
"<x14:axisColor rgb=\"FF000000\"/>"
|
||||
"</x14:dataBar>"
|
||||
"</x14:cfRule>"
|
||||
"<xm:sqref>A1</xm:sqref>"
|
||||
"</x14:conditionalFormatting>"
|
||||
"<x14:conditionalFormatting xmlns:xm=\"http://schemas.microsoft.com/office/excel/2006/main\">"
|
||||
"<x14:cfRule type=\"dataBar\" id=\"{DA7ABA51-AAAA-BBBB-0001-000000000002}\">"
|
||||
"<x14:dataBar minLength=\"0\" maxLength=\"100\" border=\"1\" negativeBarBorderColorSameAsPositive=\"0\">"
|
||||
"<x14:cfvo type=\"formula\">"
|
||||
"<xm:f>$B$1</xm:f>"
|
||||
"</x14:cfvo>"
|
||||
"<x14:cfvo type=\"formula\">"
|
||||
"<xm:f>$C$1</xm:f>"
|
||||
"</x14:cfvo>"
|
||||
"<x14:borderColor rgb=\"FF63C384\"/>"
|
||||
"<x14:negativeFillColor rgb=\"FFFF0000\"/>"
|
||||
"<x14:negativeBorderColor rgb=\"FFFF0000\"/>"
|
||||
"<x14:axisColor rgb=\"FF000000\"/>"
|
||||
"</x14:dataBar>"
|
||||
"</x14:cfRule>"
|
||||
"<xm:sqref>A2:B2</xm:sqref>"
|
||||
"</x14:conditionalFormatting>"
|
||||
"<x14:conditionalFormatting xmlns:xm=\"http://schemas.microsoft.com/office/excel/2006/main\">"
|
||||
"<x14:cfRule type=\"dataBar\" id=\"{DA7ABA51-AAAA-BBBB-0001-000000000003}\">"
|
||||
"<x14:dataBar minLength=\"0\" maxLength=\"100\" border=\"1\" negativeBarBorderColorSameAsPositive=\"0\">"
|
||||
"<x14:cfvo type=\"percentile\">"
|
||||
"<xm:f>10</xm:f>"
|
||||
"</x14:cfvo>"
|
||||
"<x14:cfvo type=\"percentile\">"
|
||||
"<xm:f>90</xm:f>"
|
||||
"</x14:cfvo>"
|
||||
"<x14:borderColor rgb=\"FFFF555A\"/>"
|
||||
"<x14:negativeFillColor rgb=\"FFFF0000\"/>"
|
||||
"<x14:negativeBorderColor rgb=\"FFFF0000\"/>"
|
||||
"<x14:axisColor rgb=\"FF000000\"/>"
|
||||
"</x14:dataBar>"
|
||||
"</x14:cfRule>"
|
||||
"<xm:sqref>A3:C3</xm:sqref>"
|
||||
"</x14:conditionalFormatting>"
|
||||
"</x14:conditionalFormattings>"
|
||||
"</ext>"
|
||||
"</extLst>"
|
||||
"</worksheet>";
|
||||
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
worksheet_select(worksheet);
|
||||
|
||||
lxw_conditional_format *conditional_format = calloc(1, sizeof(lxw_conditional_format));
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_DATA_BAR;
|
||||
conditional_format->data_bar_2010 = LXW_TRUE;
|
||||
conditional_format->min_rule_type = LXW_CONDITIONAL_RULE_TYPE_FORMULA;
|
||||
conditional_format->min_value_string = "=$B$1";
|
||||
worksheet_conditional_format_cell(worksheet, CELL("A1"), conditional_format);
|
||||
memset(conditional_format, 0, sizeof(lxw_conditional_format));
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_DATA_BAR;
|
||||
conditional_format->bar_color = 0x63C384;
|
||||
conditional_format->data_bar_2010 = LXW_TRUE;
|
||||
conditional_format->min_rule_type = LXW_CONDITIONAL_RULE_TYPE_FORMULA;
|
||||
conditional_format->max_rule_type = LXW_CONDITIONAL_RULE_TYPE_FORMULA;
|
||||
conditional_format->min_value_string = "=$B$1";
|
||||
conditional_format->max_value_string = "=$C$1";
|
||||
|
||||
worksheet_conditional_format_range(worksheet, RANGE("A2:B2"), conditional_format);
|
||||
memset(conditional_format, 0, sizeof(lxw_conditional_format));
|
||||
|
||||
conditional_format->type = LXW_CONDITIONAL_DATA_BAR;
|
||||
conditional_format->data_bar_2010 = LXW_TRUE;
|
||||
conditional_format->bar_color = 0xFF555A;
|
||||
conditional_format->min_rule_type = LXW_CONDITIONAL_RULE_TYPE_PERCENTILE;
|
||||
conditional_format->max_rule_type = LXW_CONDITIONAL_RULE_TYPE_PERCENTILE;
|
||||
conditional_format->min_value = 10;
|
||||
conditional_format->max_value = 90;
|
||||
worksheet_conditional_format_range(worksheet, RANGE("A3:C3"), conditional_format);
|
||||
|
||||
|
||||
free(conditional_format);
|
||||
lxw_worksheet_assemble_xml_file(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ_SHORT(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Tests for the lib_xlsx_writer library.
|
||||
*
|
||||
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
|
||||
*
|
||||
*/
|
||||
|
||||
#include "../ctest.h"
|
||||
#include "../helper.h"
|
||||
|
||||
#include "../../../include/xlsxwriter/worksheet.h"
|
||||
#include "../../../include/xlsxwriter/shared_strings.h"
|
||||
|
||||
// Test assembling a complete Worksheet file.
|
||||
CTEST(merged_range, merged_range01) {
|
||||
|
||||
char* got;
|
||||
char exp[] =
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
|
||||
"<worksheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\">"
|
||||
"<dimension ref=\"B3:C3\"/>"
|
||||
"<sheetViews>"
|
||||
"<sheetView tabSelected=\"1\" workbookViewId=\"0\"/>"
|
||||
"</sheetViews>"
|
||||
"<sheetFormatPr defaultRowHeight=\"15\"/>"
|
||||
"<sheetData>"
|
||||
"<row r=\"3\" spans=\"2:3\">"
|
||||
"<c r=\"B3\" s=\"1\" t=\"s\">"
|
||||
"<v>0</v>"
|
||||
"</c>"
|
||||
"<c r=\"C3\" s=\"1\"/>"
|
||||
"</row>"
|
||||
"</sheetData>"
|
||||
"<mergeCells count=\"1\">"
|
||||
"<mergeCell ref=\"B3:C3\"/>"
|
||||
"</mergeCells>"
|
||||
"<pageMargins left=\"0.7\" right=\"0.7\" top=\"0.75\" bottom=\"0.75\" header=\"0.3\" footer=\"0.3\"/>"
|
||||
"</worksheet>";
|
||||
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
worksheet->sst = lxw_sst_new();
|
||||
worksheet_select(worksheet);
|
||||
|
||||
lxw_format *format = lxw_format_new();
|
||||
format->xf_index = 1;
|
||||
|
||||
worksheet_merge_range(worksheet, 2, 1, 2, 2, "Foo", format);
|
||||
|
||||
lxw_worksheet_assemble_xml_file(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ_SHORT(exp, got);
|
||||
|
||||
lxw_sst_free(worksheet->sst);
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Tests for the lib_xlsx_writer library.
|
||||
*
|
||||
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
|
||||
*
|
||||
*/
|
||||
|
||||
#include "../ctest.h"
|
||||
#include "../helper.h"
|
||||
|
||||
#include "../../../include/xlsxwriter/worksheet.h"
|
||||
|
||||
|
||||
// Function used for testing.
|
||||
uint32_t
|
||||
width_to_pixels(double width)
|
||||
{
|
||||
double max_digit_width = 7.0;
|
||||
double padding = 5.0;
|
||||
double pixels;
|
||||
|
||||
if (width < 1.0)
|
||||
pixels = (uint32_t) (width * (max_digit_width + padding) + 0.5);
|
||||
else
|
||||
pixels = (uint32_t) (width * max_digit_width + 0.5) + 5;
|
||||
|
||||
return pixels;
|
||||
}
|
||||
|
||||
// Function used for testing.
|
||||
uint32_t
|
||||
height_to_pixels(double height)
|
||||
{
|
||||
return (uint32_t) (height / 0.75);
|
||||
}
|
||||
|
||||
|
||||
// Test the Worksheet _pixels_to_width() function.
|
||||
CTEST(worksheet, pixel_to_width01) {
|
||||
|
||||
int pixels;
|
||||
double got;
|
||||
double exp;
|
||||
|
||||
for (pixels = 0; pixels <= 1790; pixels++) {
|
||||
exp = pixels;
|
||||
got = width_to_pixels(_pixels_to_width(pixels));
|
||||
ASSERT_DOUBLE(exp, got);
|
||||
}
|
||||
}
|
||||
|
||||
// Test the Worksheet _pixels_to_height() function.
|
||||
CTEST(worksheet, pixel_to_height01) {
|
||||
|
||||
int pixels;
|
||||
double got;
|
||||
double exp;
|
||||
|
||||
for (pixels = 0; pixels <= 545; pixels++) {
|
||||
exp = pixels;
|
||||
got = height_to_pixels(_pixels_to_height(pixels));
|
||||
ASSERT_DOUBLE(exp, got);
|
||||
}
|
||||
}
|
@ -0,0 +1,110 @@
|
||||
/*
|
||||
* Tests for the lib_xlsx_writer library.
|
||||
*
|
||||
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
|
||||
*
|
||||
*/
|
||||
|
||||
#include "../ctest.h"
|
||||
#include "../helper.h"
|
||||
|
||||
#include "../../../include/xlsxwriter/worksheet.h"
|
||||
|
||||
|
||||
// Test the return value for various worksheet functions that handle 1 or 2D ranges.
|
||||
CTEST(worksheet, bound_checks01) {
|
||||
|
||||
int err;
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_row_t MAX_ROW = 1048576;
|
||||
lxw_col_t MAX_COL = 16384;
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
lxw_format *format = lxw_format_new();
|
||||
|
||||
worksheet->file = testfile;
|
||||
worksheet_select(worksheet);
|
||||
|
||||
err = worksheet_write_number(worksheet, 0, MAX_COL, 123, NULL);
|
||||
ASSERT_EQUAL(LXW_ERROR_WORKSHEET_INDEX_OUT_OF_RANGE, err);
|
||||
|
||||
err = worksheet_write_number(worksheet, MAX_ROW, 0, 123, NULL);
|
||||
ASSERT_EQUAL(LXW_ERROR_WORKSHEET_INDEX_OUT_OF_RANGE, err);
|
||||
|
||||
err = worksheet_write_number(worksheet, MAX_ROW, MAX_COL, 123, NULL);
|
||||
ASSERT_EQUAL(LXW_ERROR_WORKSHEET_INDEX_OUT_OF_RANGE, err);
|
||||
|
||||
err = worksheet_write_string(worksheet, MAX_ROW, 0, "Foo", NULL);
|
||||
ASSERT_EQUAL(LXW_ERROR_WORKSHEET_INDEX_OUT_OF_RANGE, err);
|
||||
|
||||
err = worksheet_write_string(worksheet, 0, MAX_COL, "Foo", NULL);
|
||||
ASSERT_EQUAL(LXW_ERROR_WORKSHEET_INDEX_OUT_OF_RANGE, err);
|
||||
|
||||
err = worksheet_write_string(worksheet, MAX_ROW, MAX_COL, "Foo", NULL);
|
||||
ASSERT_EQUAL(LXW_ERROR_WORKSHEET_INDEX_OUT_OF_RANGE, err);
|
||||
|
||||
err = worksheet_write_number(worksheet, MAX_ROW, 0, 123, NULL);
|
||||
ASSERT_EQUAL(LXW_ERROR_WORKSHEET_INDEX_OUT_OF_RANGE, err);
|
||||
|
||||
err = worksheet_write_number(worksheet, 0, MAX_COL, 123, NULL);
|
||||
ASSERT_EQUAL(LXW_ERROR_WORKSHEET_INDEX_OUT_OF_RANGE, err);
|
||||
|
||||
err = worksheet_write_number(worksheet, MAX_ROW, MAX_COL, 123, NULL);
|
||||
ASSERT_EQUAL(LXW_ERROR_WORKSHEET_INDEX_OUT_OF_RANGE, err);
|
||||
|
||||
err = worksheet_write_blank(worksheet, MAX_ROW, 0, format);
|
||||
ASSERT_EQUAL(LXW_ERROR_WORKSHEET_INDEX_OUT_OF_RANGE, err);
|
||||
|
||||
err = worksheet_write_blank(worksheet, 0, MAX_COL, format);
|
||||
ASSERT_EQUAL(LXW_ERROR_WORKSHEET_INDEX_OUT_OF_RANGE, err);
|
||||
|
||||
err = worksheet_write_blank(worksheet, MAX_ROW, MAX_COL, format);
|
||||
ASSERT_EQUAL(LXW_ERROR_WORKSHEET_INDEX_OUT_OF_RANGE, err);
|
||||
|
||||
err = worksheet_write_formula(worksheet, MAX_ROW, 0, "=A1", NULL);
|
||||
ASSERT_EQUAL(LXW_ERROR_WORKSHEET_INDEX_OUT_OF_RANGE, err);
|
||||
|
||||
err = worksheet_write_formula(worksheet, 0, MAX_COL, "=A1", NULL);
|
||||
ASSERT_EQUAL(LXW_ERROR_WORKSHEET_INDEX_OUT_OF_RANGE, err);
|
||||
|
||||
err = worksheet_write_formula(worksheet, MAX_ROW, MAX_COL, "=A1", NULL);
|
||||
ASSERT_EQUAL(LXW_ERROR_WORKSHEET_INDEX_OUT_OF_RANGE, err);
|
||||
|
||||
err = worksheet_write_array_formula(worksheet, 0, 0, 0, MAX_COL, "=A1", NULL);
|
||||
ASSERT_EQUAL(LXW_ERROR_WORKSHEET_INDEX_OUT_OF_RANGE, err);
|
||||
|
||||
err = worksheet_write_array_formula(worksheet, 0, 0, MAX_ROW, 0, "=A1", NULL);
|
||||
ASSERT_EQUAL(LXW_ERROR_WORKSHEET_INDEX_OUT_OF_RANGE, err);
|
||||
|
||||
err = worksheet_write_array_formula(worksheet, 0, MAX_COL, 0, 0, "=A1", NULL);
|
||||
ASSERT_EQUAL(LXW_ERROR_WORKSHEET_INDEX_OUT_OF_RANGE, err);
|
||||
|
||||
err = worksheet_write_array_formula(worksheet, MAX_ROW, 0, 0, 0, "=A1", NULL);
|
||||
ASSERT_EQUAL(LXW_ERROR_WORKSHEET_INDEX_OUT_OF_RANGE, err);
|
||||
|
||||
err = worksheet_write_array_formula(worksheet, MAX_ROW, MAX_COL, MAX_ROW, MAX_COL, "=A1", NULL);
|
||||
ASSERT_EQUAL(LXW_ERROR_WORKSHEET_INDEX_OUT_OF_RANGE, err);
|
||||
|
||||
err = worksheet_merge_range(worksheet, 0, 0, 0, MAX_COL, "Foo", NULL);
|
||||
ASSERT_EQUAL(LXW_ERROR_WORKSHEET_INDEX_OUT_OF_RANGE, err);
|
||||
|
||||
err = worksheet_merge_range(worksheet, 0, 0, MAX_ROW, 0, "Foo", NULL);
|
||||
ASSERT_EQUAL(LXW_ERROR_WORKSHEET_INDEX_OUT_OF_RANGE, err);
|
||||
|
||||
err = worksheet_merge_range(worksheet, 0, MAX_COL, 0, 0, "Foo", NULL);
|
||||
ASSERT_EQUAL(LXW_ERROR_WORKSHEET_INDEX_OUT_OF_RANGE, err);
|
||||
|
||||
err = worksheet_merge_range(worksheet, MAX_ROW, 0, 0, 0, "Foo", NULL);
|
||||
ASSERT_EQUAL(LXW_ERROR_WORKSHEET_INDEX_OUT_OF_RANGE, err);
|
||||
|
||||
err = worksheet_set_column(worksheet, 6, MAX_COL, 17, NULL);
|
||||
ASSERT_EQUAL(LXW_ERROR_WORKSHEET_INDEX_OUT_OF_RANGE, err);
|
||||
|
||||
err = worksheet_set_column(worksheet, MAX_COL, 6, 17, NULL);
|
||||
ASSERT_EQUAL(LXW_ERROR_WORKSHEET_INDEX_OUT_OF_RANGE, err);
|
||||
|
||||
lxw_worksheet_assemble_xml_file(worksheet);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
317
library/libxlsxwriter/test/unit/worksheet/test_worksheet_spans.c
Normal file
317
library/libxlsxwriter/test/unit/worksheet/test_worksheet_spans.c
Normal file
@ -0,0 +1,317 @@
|
||||
/*
|
||||
* Tests for the lib_xlsx_writer library.
|
||||
*
|
||||
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
|
||||
*
|
||||
*/
|
||||
|
||||
#include "../ctest.h"
|
||||
#include "../helper.h"
|
||||
|
||||
#include "../../../include/xlsxwriter/worksheet.h"
|
||||
|
||||
// Test assembling a Worksheet file with different span ranges.
|
||||
CTEST(worksheet, spans01) {
|
||||
|
||||
char* got;
|
||||
char exp[] =
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
|
||||
"<worksheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\">"
|
||||
"<dimension ref=\"B3\"/>"
|
||||
"<sheetViews>"
|
||||
"<sheetView tabSelected=\"1\" workbookViewId=\"0\"/>"
|
||||
"</sheetViews>"
|
||||
"<sheetFormatPr defaultRowHeight=\"15\"/>"
|
||||
"<sheetData>"
|
||||
"<row r=\"3\" spans=\"2:2\">"
|
||||
"<c r=\"B3\">"
|
||||
"<v>2000</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"</sheetData>"
|
||||
"<pageMargins left=\"0.7\" right=\"0.7\" top=\"0.75\" bottom=\"0.75\" header=\"0.3\" footer=\"0.3\"/>"
|
||||
"</worksheet>";
|
||||
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
worksheet_select(worksheet);
|
||||
|
||||
worksheet_write_number(worksheet, 2, 1, 2000, NULL);
|
||||
|
||||
lxw_worksheet_assemble_xml_file(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ_SHORT(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
// Test assembling a Worksheet file with different span ranges.
|
||||
CTEST(worksheet, spans02) {
|
||||
|
||||
char* got;
|
||||
char exp[] =
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
|
||||
"<worksheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\">"
|
||||
"<dimension ref=\"A1048576\"/>"
|
||||
"<sheetViews>"
|
||||
"<sheetView tabSelected=\"1\" workbookViewId=\"0\"/>"
|
||||
"</sheetViews>"
|
||||
"<sheetFormatPr defaultRowHeight=\"15\"/>"
|
||||
"<sheetData>"
|
||||
"<row r=\"1048576\" spans=\"1:1\">"
|
||||
"<c r=\"A1048576\">"
|
||||
"<v>123</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"</sheetData>"
|
||||
"<pageMargins left=\"0.7\" right=\"0.7\" top=\"0.75\" bottom=\"0.75\" header=\"0.3\" footer=\"0.3\"/>"
|
||||
"</worksheet>";
|
||||
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
worksheet_select(worksheet);
|
||||
|
||||
worksheet_write_number(worksheet, 1048575, 0, 123, NULL);
|
||||
|
||||
lxw_worksheet_assemble_xml_file(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ_SHORT(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
// Test assembling a Worksheet file with different span ranges.
|
||||
CTEST(worksheet, spans03) {
|
||||
|
||||
char* got;
|
||||
char exp[] =
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
|
||||
"<worksheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\">"
|
||||
"<dimension ref=\"XFD1\"/>"
|
||||
"<sheetViews>"
|
||||
"<sheetView tabSelected=\"1\" workbookViewId=\"0\"/>"
|
||||
"</sheetViews>"
|
||||
"<sheetFormatPr defaultRowHeight=\"15\"/>"
|
||||
"<sheetData>"
|
||||
"<row r=\"1\" spans=\"16384:16384\">"
|
||||
"<c r=\"XFD1\">"
|
||||
"<v>123</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"</sheetData>"
|
||||
"<pageMargins left=\"0.7\" right=\"0.7\" top=\"0.75\" bottom=\"0.75\" header=\"0.3\" footer=\"0.3\"/>"
|
||||
"</worksheet>";
|
||||
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
worksheet_select(worksheet);
|
||||
|
||||
worksheet_write_number(worksheet, 0, 16383, 123, NULL);
|
||||
|
||||
lxw_worksheet_assemble_xml_file(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ_SHORT(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
// Test assembling a Worksheet file with different span ranges.
|
||||
CTEST(worksheet, spans04) {
|
||||
|
||||
char* got;
|
||||
char exp[] =
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
|
||||
"<worksheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\">"
|
||||
"<dimension ref=\"XFD1048576\"/>"
|
||||
"<sheetViews>"
|
||||
"<sheetView tabSelected=\"1\" workbookViewId=\"0\"/>"
|
||||
"</sheetViews>"
|
||||
"<sheetFormatPr defaultRowHeight=\"15\"/>"
|
||||
"<sheetData>"
|
||||
"<row r=\"1048576\" spans=\"16384:16384\">"
|
||||
"<c r=\"XFD1048576\">"
|
||||
"<v>123</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"</sheetData>"
|
||||
"<pageMargins left=\"0.7\" right=\"0.7\" top=\"0.75\" bottom=\"0.75\" header=\"0.3\" footer=\"0.3\"/>"
|
||||
"</worksheet>";
|
||||
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
worksheet_select(worksheet);
|
||||
|
||||
worksheet_write_number(worksheet, 1048575, 16383, 123, NULL);
|
||||
|
||||
lxw_worksheet_assemble_xml_file(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ_SHORT(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
// Test assembling a Worksheet file with different span ranges.
|
||||
CTEST(worksheet, spans05) {
|
||||
|
||||
int i;
|
||||
char* got;
|
||||
char exp[] =
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
|
||||
"<worksheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\">"
|
||||
"<dimension ref=\"A1:T20\"/>"
|
||||
"<sheetViews>"
|
||||
"<sheetView tabSelected=\"1\" workbookViewId=\"0\"/>"
|
||||
"</sheetViews>"
|
||||
"<sheetFormatPr defaultRowHeight=\"15\"/>"
|
||||
"<sheetData>"
|
||||
"<row r=\"1\" spans=\"1:16\">"
|
||||
"<c r=\"A1\">"
|
||||
"<v>1</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"2\" spans=\"1:16\">"
|
||||
"<c r=\"B2\">"
|
||||
"<v>2</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"3\" spans=\"1:16\">"
|
||||
"<c r=\"C3\">"
|
||||
"<v>3</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"4\" spans=\"1:16\">"
|
||||
"<c r=\"D4\">"
|
||||
"<v>4</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"5\" spans=\"1:16\">"
|
||||
"<c r=\"E5\">"
|
||||
"<v>5</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"6\" spans=\"1:16\">"
|
||||
"<c r=\"F6\">"
|
||||
"<v>6</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"7\" spans=\"1:16\">"
|
||||
"<c r=\"G7\">"
|
||||
"<v>7</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"8\" spans=\"1:16\">"
|
||||
"<c r=\"H8\">"
|
||||
"<v>8</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"9\" spans=\"1:16\">"
|
||||
"<c r=\"I9\">"
|
||||
"<v>9</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"10\" spans=\"1:16\">"
|
||||
"<c r=\"J10\">"
|
||||
"<v>10</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"11\" spans=\"1:16\">"
|
||||
"<c r=\"K11\">"
|
||||
"<v>11</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"12\" spans=\"1:16\">"
|
||||
"<c r=\"L12\">"
|
||||
"<v>12</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"13\" spans=\"1:16\">"
|
||||
"<c r=\"M13\">"
|
||||
"<v>13</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"14\" spans=\"1:16\">"
|
||||
"<c r=\"N14\">"
|
||||
"<v>14</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"15\" spans=\"1:16\">"
|
||||
"<c r=\"O15\">"
|
||||
"<v>15</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"16\" spans=\"1:16\">"
|
||||
"<c r=\"P16\">"
|
||||
"<v>16</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"17\" spans=\"17:20\">"
|
||||
"<c r=\"Q17\">"
|
||||
"<v>17</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"18\" spans=\"17:20\">"
|
||||
"<c r=\"R18\">"
|
||||
"<v>18</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"19\" spans=\"17:20\">"
|
||||
"<c r=\"S19\">"
|
||||
"<v>19</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"<row r=\"20\" spans=\"17:20\">"
|
||||
"<c r=\"T20\">"
|
||||
"<v>20</v>"
|
||||
"</c>"
|
||||
"</row>"
|
||||
"</sheetData>"
|
||||
"<pageMargins left=\"0.7\" right=\"0.7\" top=\"0.75\" bottom=\"0.75\" header=\"0.3\" footer=\"0.3\"/>"
|
||||
"</worksheet>";
|
||||
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
worksheet_select(worksheet);
|
||||
|
||||
for (i = 0; i < 20; i++)
|
||||
worksheet_write_number(worksheet, i, i, i + 1, NULL);
|
||||
|
||||
lxw_worksheet_assemble_xml_file(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
// Test some out of bound writes.
|
||||
CTEST(worksheet, spans06) {
|
||||
|
||||
int err;
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
worksheet_select(worksheet);
|
||||
|
||||
err = worksheet_write_number(worksheet, 0, 16384, 123, NULL);
|
||||
ASSERT_EQUAL(LXW_ERROR_WORKSHEET_INDEX_OUT_OF_RANGE, err);
|
||||
|
||||
err = worksheet_write_number(worksheet, 1048576, 0, 123, NULL);
|
||||
ASSERT_EQUAL(LXW_ERROR_WORKSHEET_INDEX_OUT_OF_RANGE, err);
|
||||
|
||||
err = worksheet_write_number(worksheet, 1048576, 16384, 123, NULL);
|
||||
ASSERT_EQUAL(LXW_ERROR_WORKSHEET_INDEX_OUT_OF_RANGE, err);
|
||||
|
||||
lxw_worksheet_assemble_xml_file(worksheet);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
@ -0,0 +1,516 @@
|
||||
/*
|
||||
* Tests for the libxlsxwriter library.
|
||||
*
|
||||
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
|
||||
*
|
||||
*/
|
||||
|
||||
#include "../ctest.h"
|
||||
#include "../helper.h"
|
||||
|
||||
#include "xlsxwriter/worksheet.h"
|
||||
|
||||
|
||||
/* Test the _write_auto_filter() method with no filter. */
|
||||
CTEST(worksheet, write_write_auto_filter01) {
|
||||
char* got;
|
||||
char exp[] = "<autoFilter ref=\"A1:D51\"/>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_autofilter(worksheet, 0, 0, 50, 3);
|
||||
_worksheet_write_auto_filter(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
||||
/* Test the _write_auto_filter() method with a filter. */
|
||||
CTEST(worksheet, write_write_auto_filter02) {
|
||||
char* got;
|
||||
char exp[] = "<autoFilter ref=\"A1:D51\"><filterColumn colId=\"0\"><filters><filter val=\"East\"/></filters></filterColumn></autoFilter>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_autofilter(worksheet, 0, 0, 50, 3);
|
||||
|
||||
lxw_filter_rule filter_rule1 = {.criteria = LXW_FILTER_CRITERIA_EQUAL_TO,
|
||||
.value_string = "East"};
|
||||
|
||||
worksheet_filter_column(worksheet, 0, &filter_rule1);
|
||||
|
||||
_worksheet_write_auto_filter(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
||||
/* Test the _write_auto_filter() method with a filter. */
|
||||
CTEST(worksheet, write_write_auto_filter03) {
|
||||
char* got;
|
||||
char exp[] = "<autoFilter ref=\"A1:D51\"><filterColumn colId=\"0\"><filters><filter val=\"East\"/><filter val=\"North\"/></filters></filterColumn></autoFilter>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_autofilter(worksheet, 0, 0, 50, 3);
|
||||
|
||||
lxw_filter_rule filter_rule1 = {.criteria = LXW_FILTER_CRITERIA_EQUAL_TO,
|
||||
.value_string = "East"};
|
||||
|
||||
lxw_filter_rule filter_rule2 = {.criteria = LXW_FILTER_CRITERIA_EQUAL_TO,
|
||||
.value_string = "North"};
|
||||
|
||||
worksheet_filter_column2(worksheet, 0, &filter_rule1, &filter_rule2, LXW_FILTER_OR);
|
||||
|
||||
|
||||
_worksheet_write_auto_filter(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
||||
/* Test the _write_auto_filter() method with a filter. */
|
||||
CTEST(worksheet, write_write_auto_filter04) {
|
||||
char* got;
|
||||
char exp[] = "<autoFilter ref=\"A1:D51\"><filterColumn colId=\"0\"><customFilters and=\"1\"><customFilter val=\"East\"/><customFilter val=\"North\"/></customFilters></filterColumn></autoFilter>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_autofilter(worksheet, 0, 0, 50, 3);
|
||||
|
||||
lxw_filter_rule filter_rule1 = {.criteria = LXW_FILTER_CRITERIA_EQUAL_TO,
|
||||
.value_string = "East"};
|
||||
|
||||
lxw_filter_rule filter_rule2 = {.criteria = LXW_FILTER_CRITERIA_EQUAL_TO,
|
||||
.value_string = "North"};
|
||||
|
||||
worksheet_filter_column2(worksheet, 0, &filter_rule1, &filter_rule2, LXW_FILTER_AND);
|
||||
|
||||
|
||||
_worksheet_write_auto_filter(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
||||
/* Test the _write_auto_filter() method with a filter. */
|
||||
CTEST(worksheet, write_write_auto_filter05) {
|
||||
char* got;
|
||||
char exp[] = "<autoFilter ref=\"A1:D51\"><filterColumn colId=\"0\"><customFilters><customFilter operator=\"notEqual\" val=\"East\"/></customFilters></filterColumn></autoFilter>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_autofilter(worksheet, 0, 0, 50, 3);
|
||||
|
||||
lxw_filter_rule filter_rule1 = {.criteria = LXW_FILTER_CRITERIA_NOT_EQUAL_TO,
|
||||
.value_string = "East"};
|
||||
|
||||
worksheet_filter_column(worksheet, 0, &filter_rule1);
|
||||
_worksheet_write_auto_filter(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
||||
/* Test the _write_auto_filter() method with a filter. */
|
||||
CTEST(worksheet, write_write_auto_filter06) {
|
||||
char* got;
|
||||
char exp[] = "<autoFilter ref=\"A1:D51\"><filterColumn colId=\"0\"><customFilters><customFilter val=\"S*\"/></customFilters></filterColumn></autoFilter>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_autofilter(worksheet, 0, 0, 50, 3);
|
||||
|
||||
lxw_filter_rule filter_rule1 = {.criteria = LXW_FILTER_CRITERIA_EQUAL_TO,
|
||||
.value_string = "S*"};
|
||||
|
||||
worksheet_filter_column(worksheet, 0, &filter_rule1);
|
||||
|
||||
_worksheet_write_auto_filter(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
||||
/* Test the _write_auto_filter() method with a filter. */
|
||||
CTEST(worksheet, write_write_auto_filter07) {
|
||||
char* got;
|
||||
char exp[] = "<autoFilter ref=\"A1:D51\"><filterColumn colId=\"0\"><customFilters><customFilter operator=\"notEqual\" val=\"S*\"/></customFilters></filterColumn></autoFilter>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_autofilter(worksheet, 0, 0, 50, 3);
|
||||
|
||||
lxw_filter_rule filter_rule1 = {.criteria = LXW_FILTER_CRITERIA_NOT_EQUAL_TO,
|
||||
.value_string = "S*"};
|
||||
|
||||
worksheet_filter_column(worksheet, 0, &filter_rule1);
|
||||
|
||||
_worksheet_write_auto_filter(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
||||
/* Test the _write_auto_filter() method with a filter. */
|
||||
CTEST(worksheet, write_write_auto_filter08) {
|
||||
char* got;
|
||||
char exp[] = "<autoFilter ref=\"A1:D51\"><filterColumn colId=\"0\"><customFilters><customFilter val=\"*h\"/></customFilters></filterColumn></autoFilter>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_autofilter(worksheet, 0, 0, 50, 3);
|
||||
|
||||
lxw_filter_rule filter_rule1 = {.criteria = LXW_FILTER_CRITERIA_EQUAL_TO,
|
||||
.value_string = "*h"};
|
||||
|
||||
worksheet_filter_column(worksheet, 0, &filter_rule1);
|
||||
|
||||
_worksheet_write_auto_filter(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
||||
/* Test the _write_auto_filter() method with a filter. */
|
||||
CTEST(worksheet, write_write_auto_filter09) {
|
||||
char* got;
|
||||
char exp[] = "<autoFilter ref=\"A1:D51\"><filterColumn colId=\"0\"><customFilters><customFilter operator=\"notEqual\" val=\"*h\"/></customFilters></filterColumn></autoFilter>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_autofilter(worksheet, 0, 0, 50, 3);
|
||||
|
||||
lxw_filter_rule filter_rule1 = {.criteria = LXW_FILTER_CRITERIA_NOT_EQUAL_TO,
|
||||
.value_string = "*h"};
|
||||
|
||||
worksheet_filter_column(worksheet, 0, &filter_rule1);
|
||||
|
||||
_worksheet_write_auto_filter(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
||||
/* Test the _write_auto_filter() method with a filter. */
|
||||
CTEST(worksheet, write_write_auto_filter10) {
|
||||
char* got;
|
||||
char exp[] = "<autoFilter ref=\"A1:D51\"><filterColumn colId=\"0\"><customFilters><customFilter val=\"*o*\"/></customFilters></filterColumn></autoFilter>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_autofilter(worksheet, 0, 0, 50, 3);
|
||||
|
||||
lxw_filter_rule filter_rule1 = {.criteria = LXW_FILTER_CRITERIA_EQUAL_TO,
|
||||
.value_string = "*o*"};
|
||||
|
||||
worksheet_filter_column(worksheet, 0, &filter_rule1);
|
||||
|
||||
_worksheet_write_auto_filter(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
||||
/* Test the _write_auto_filter() method with a filter. */
|
||||
CTEST(worksheet, write_write_auto_filter11) {
|
||||
char* got;
|
||||
char exp[] = "<autoFilter ref=\"A1:D51\"><filterColumn colId=\"0\"><customFilters><customFilter operator=\"notEqual\" val=\"*r*\"/></customFilters></filterColumn></autoFilter>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_autofilter(worksheet, 0, 0, 50, 3);
|
||||
|
||||
lxw_filter_rule filter_rule1 = {.criteria = LXW_FILTER_CRITERIA_NOT_EQUAL_TO,
|
||||
.value_string = "*r*"};
|
||||
|
||||
worksheet_filter_column(worksheet, 0, &filter_rule1);
|
||||
|
||||
_worksheet_write_auto_filter(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
||||
/* Test the _write_auto_filter() method with a filter. */
|
||||
CTEST(worksheet, write_write_auto_filter12) {
|
||||
char* got;
|
||||
char exp[] = "<autoFilter ref=\"A1:D51\"><filterColumn colId=\"2\"><filters><filter val=\"1000\"/></filters></filterColumn></autoFilter>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_autofilter(worksheet, 0, 0, 50, 3);
|
||||
|
||||
lxw_filter_rule filter_rule1 = {.criteria = LXW_FILTER_CRITERIA_EQUAL_TO,
|
||||
.value = 1000};
|
||||
|
||||
worksheet_filter_column(worksheet, 2, &filter_rule1);
|
||||
|
||||
_worksheet_write_auto_filter(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
||||
/* Test the _write_auto_filter() method with a filter. */
|
||||
CTEST(worksheet, write_write_auto_filter13) {
|
||||
char* got;
|
||||
char exp[] = "<autoFilter ref=\"A1:D51\"><filterColumn colId=\"2\"><customFilters><customFilter operator=\"notEqual\" val=\"2000\"/></customFilters></filterColumn></autoFilter>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_autofilter(worksheet, 0, 0, 50, 3);
|
||||
|
||||
lxw_filter_rule filter_rule1 = {.criteria = LXW_FILTER_CRITERIA_NOT_EQUAL_TO,
|
||||
.value = 2000};
|
||||
|
||||
worksheet_filter_column(worksheet, 2, &filter_rule1);
|
||||
|
||||
_worksheet_write_auto_filter(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
||||
/* Test the _write_auto_filter() method with a filter. */
|
||||
CTEST(worksheet, write_write_auto_filter14) {
|
||||
char* got;
|
||||
char exp[] = "<autoFilter ref=\"A1:D51\"><filterColumn colId=\"2\"><customFilters><customFilter operator=\"greaterThan\" val=\"3000\"/></customFilters></filterColumn></autoFilter>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_autofilter(worksheet, 0, 0, 50, 3);
|
||||
|
||||
lxw_filter_rule filter_rule1 = {.criteria = LXW_FILTER_CRITERIA_GREATER_THAN,
|
||||
.value = 3000};
|
||||
|
||||
worksheet_filter_column(worksheet, 2, &filter_rule1);
|
||||
|
||||
_worksheet_write_auto_filter(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
||||
/* Test the _write_auto_filter() method with a filter. */
|
||||
CTEST(worksheet, write_write_auto_filter15) {
|
||||
char* got;
|
||||
char exp[] = "<autoFilter ref=\"A1:D51\"><filterColumn colId=\"2\"><customFilters><customFilter operator=\"greaterThanOrEqual\" val=\"4000\"/></customFilters></filterColumn></autoFilter>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_autofilter(worksheet, 0, 0, 50, 3);
|
||||
|
||||
lxw_filter_rule filter_rule1 = {.criteria = LXW_FILTER_CRITERIA_GREATER_THAN_OR_EQUAL_TO,
|
||||
.value = 4000};
|
||||
|
||||
worksheet_filter_column(worksheet, 2, &filter_rule1);
|
||||
|
||||
_worksheet_write_auto_filter(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
||||
/* Test the _write_auto_filter() method with a filter. */
|
||||
CTEST(worksheet, write_write_auto_filter16) {
|
||||
char* got;
|
||||
char exp[] = "<autoFilter ref=\"A1:D51\"><filterColumn colId=\"2\"><customFilters><customFilter operator=\"lessThan\" val=\"5000\"/></customFilters></filterColumn></autoFilter>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_autofilter(worksheet, 0, 0, 50, 3);
|
||||
|
||||
lxw_filter_rule filter_rule1 = {.criteria = LXW_FILTER_CRITERIA_LESS_THAN,
|
||||
.value = 5000};
|
||||
|
||||
worksheet_filter_column(worksheet, 2, &filter_rule1);
|
||||
|
||||
_worksheet_write_auto_filter(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
||||
/* Test the _write_auto_filter() method with a filter. */
|
||||
CTEST(worksheet, write_write_auto_filter17) {
|
||||
char* got;
|
||||
char exp[] = "<autoFilter ref=\"A1:D51\"><filterColumn colId=\"2\"><customFilters><customFilter operator=\"lessThanOrEqual\" val=\"6000\"/></customFilters></filterColumn></autoFilter>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_autofilter(worksheet, 0, 0, 50, 3);
|
||||
|
||||
lxw_filter_rule filter_rule1 = {.criteria = LXW_FILTER_CRITERIA_LESS_THAN_OR_EQUAL_TO,
|
||||
.value = 6000};
|
||||
|
||||
worksheet_filter_column(worksheet, 2, &filter_rule1);
|
||||
|
||||
_worksheet_write_auto_filter(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
||||
/* Test the _write_auto_filter() method with a filter. */
|
||||
CTEST(worksheet, write_write_auto_filter18) {
|
||||
char* got;
|
||||
char exp[] = "<autoFilter ref=\"A1:D51\"><filterColumn colId=\"2\"><customFilters and=\"1\"><customFilter operator=\"greaterThanOrEqual\" val=\"1000\"/><customFilter operator=\"lessThanOrEqual\" val=\"2000\"/></customFilters></filterColumn></autoFilter>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_autofilter(worksheet, 0, 0, 50, 3);
|
||||
|
||||
lxw_filter_rule filter_rule1 = {.criteria = LXW_FILTER_CRITERIA_GREATER_THAN_OR_EQUAL_TO,
|
||||
.value = 1000};
|
||||
|
||||
lxw_filter_rule filter_rule2 = {.criteria = LXW_FILTER_CRITERIA_LESS_THAN_OR_EQUAL_TO,
|
||||
.value = 2000};
|
||||
|
||||
worksheet_filter_column2(worksheet, 2, &filter_rule1, &filter_rule2, LXW_FILTER_AND);
|
||||
|
||||
_worksheet_write_auto_filter(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
||||
/* Test the _write_auto_filter_list() method with a filter. */
|
||||
CTEST(worksheet, write_write_auto_filter19) {
|
||||
char* got;
|
||||
char exp[] = "<autoFilter ref=\"A1:D51\"><filterColumn colId=\"0\"><filters><filter val=\"East\"/></filters></filterColumn></autoFilter>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_autofilter(worksheet, 0, 0, 50, 3);
|
||||
|
||||
char* list[] = {"East", NULL};
|
||||
|
||||
worksheet_filter_list(worksheet, 0, list);
|
||||
|
||||
_worksheet_write_auto_filter(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
||||
/* Test the _write_auto_filter_list() method with a filter. */
|
||||
CTEST(worksheet, write_write_auto_filter20) {
|
||||
char* got;
|
||||
char exp[] = "<autoFilter ref=\"A1:D51\"><filterColumn colId=\"0\"><filters><filter val=\"East\"/><filter val=\"North\"/></filters></filterColumn></autoFilter>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_autofilter(worksheet, 0, 0, 50, 3);
|
||||
|
||||
char* list[] = {"East", "North", NULL};
|
||||
|
||||
worksheet_filter_list(worksheet, 0, list);
|
||||
|
||||
_worksheet_write_auto_filter(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
||||
/* Test the _write_auto_filter_list() method with a filter. */
|
||||
CTEST(worksheet, write_write_auto_filter21) {
|
||||
char* got;
|
||||
char exp[] = "<autoFilter ref=\"A1:D51\"><filterColumn colId=\"3\"><filters><filter val=\"February\"/><filter val=\"January\"/><filter val=\"July\"/><filter val=\"June\"/></filters></filterColumn></autoFilter>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_autofilter(worksheet, 0, 0, 50, 3);
|
||||
|
||||
char* list[] = {"February", "January", "July", "June", NULL};
|
||||
|
||||
worksheet_filter_list(worksheet, 3, list);
|
||||
|
||||
_worksheet_write_auto_filter(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
@ -0,0 +1,128 @@
|
||||
/*
|
||||
* Tests for the lib_xlsx_writer library.
|
||||
*
|
||||
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
|
||||
*
|
||||
*/
|
||||
|
||||
#include "../ctest.h"
|
||||
#include "../helper.h"
|
||||
|
||||
#include "../../../include/xlsxwriter/worksheet.h"
|
||||
#include "../../../include/xlsxwriter/format.h"
|
||||
|
||||
// Test the _write_col_info() function.
|
||||
CTEST(worksheet, write_col_info01) {
|
||||
|
||||
char* got;
|
||||
char exp[] = "<col min=\"2\" max=\"4\" width=\"5.7109375\" customWidth=\"1\"/>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
lxw_col_options col_options = {1, 3, 5, NULL, 0, 0, 0};
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
_worksheet_write_col_info(worksheet, &col_options);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
||||
CTEST(worksheet, write_col_info02) {
|
||||
|
||||
char* got;
|
||||
char exp[] = "<col min=\"6\" max=\"6\" width=\"8.7109375\" hidden=\"1\" customWidth=\"1\"/>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
lxw_col_options col_options = {5, 5, 8, NULL, 1, 0, 0};
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
_worksheet_write_col_info(worksheet, &col_options);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
||||
CTEST(worksheet, write_col_info03) {
|
||||
|
||||
char* got;
|
||||
char exp[] = "<col min=\"8\" max=\"8\" width=\"9.140625\" style=\"1\"/>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_format *format = lxw_format_new();
|
||||
format->xf_index = 1;
|
||||
|
||||
lxw_col_options col_options = {7, 7, LXW_DEF_COL_WIDTH, format, 0, 0, 0};
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
_worksheet_write_col_info(worksheet, &col_options);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
||||
CTEST(worksheet, write_col_info04) {
|
||||
|
||||
char* got;
|
||||
char exp[] = "<col min=\"9\" max=\"9\" width=\"9.140625\" style=\"1\"/>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_format *format = lxw_format_new();
|
||||
format->xf_index = 1;
|
||||
|
||||
lxw_col_options col_options = {8, 8, LXW_DEF_COL_WIDTH, format, 0, 0, 0};
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
_worksheet_write_col_info(worksheet, &col_options);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
||||
CTEST(worksheet, write_col_info05) {
|
||||
|
||||
char* got;
|
||||
char exp[] = "<col min=\"10\" max=\"10\" width=\"2.7109375\" customWidth=\"1\"/>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
lxw_col_options col_options = {9, 9, 2, NULL, 0, 0, 0};
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
_worksheet_write_col_info(worksheet, &col_options);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
||||
CTEST(worksheet, write_col_info06) {
|
||||
|
||||
char* got;
|
||||
char exp[] = "<col min=\"12\" max=\"12\" width=\"0\" hidden=\"1\" customWidth=\"1\"/>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
lxw_col_options col_options = {11, 11, LXW_DEF_COL_WIDTH, NULL, 1, 0, 0};
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
_worksheet_write_col_info(worksheet, &col_options);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
@ -0,0 +1,215 @@
|
||||
/*
|
||||
* Tests for the lib_xlsx_writer library.
|
||||
*
|
||||
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
|
||||
*
|
||||
*/
|
||||
|
||||
#include "../ctest.h"
|
||||
#include "../helper.h"
|
||||
|
||||
#include "../../../include/xlsxwriter/worksheet.h"
|
||||
|
||||
|
||||
//Test the _write_data_validations() function.
|
||||
CTEST(worksheet, write_data_validations01) {
|
||||
char* got;
|
||||
char exp[] = "<dataValidations count=\"1\"><dataValidation type=\"whole\" operator=\"greaterThan\" allowBlank=\"1\" showInputMessage=\"1\" showErrorMessage=\"1\" sqref=\"A1\"><formula1>0</formula1></dataValidation></dataValidations>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_data_validation *data_validation = calloc(1, sizeof(lxw_data_validation));
|
||||
data_validation->validate = LXW_VALIDATION_TYPE_INTEGER;
|
||||
data_validation->criteria = LXW_VALIDATION_CRITERIA_GREATER_THAN;
|
||||
data_validation->value_number = 0;
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_data_validation_cell(worksheet, 0, 0, data_validation);
|
||||
_worksheet_write_data_validations(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
CTEST(worksheet, write_data_validations01a) {
|
||||
char* got;
|
||||
char exp[] = "<dataValidations count=\"1\"><dataValidation type=\"whole\" operator=\"greaterThan\" allowBlank=\"1\" showInputMessage=\"1\" showErrorMessage=\"1\" sqref=\"A1\"><formula1>0</formula1></dataValidation></dataValidations>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_data_validation *data_validation = calloc(1, sizeof(lxw_data_validation));
|
||||
data_validation->validate = LXW_VALIDATION_TYPE_INTEGER;
|
||||
data_validation->criteria = LXW_VALIDATION_CRITERIA_GREATER_THAN;
|
||||
data_validation->value_number = 0;
|
||||
data_validation->ignore_blank = LXW_VALIDATION_ON;
|
||||
data_validation->show_input = LXW_VALIDATION_ON;
|
||||
data_validation->show_error = LXW_VALIDATION_ON;
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_data_validation_cell(worksheet, 0, 0, data_validation);
|
||||
_worksheet_write_data_validations(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
CTEST(worksheet, write_data_validations01b) {
|
||||
char* got;
|
||||
char exp[] = "<dataValidations count=\"1\"><dataValidation type=\"whole\" operator=\"greaterThan\" sqref=\"A1\"><formula1>0</formula1></dataValidation></dataValidations>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_data_validation *data_validation = calloc(1, sizeof(lxw_data_validation));
|
||||
data_validation->validate = LXW_VALIDATION_TYPE_INTEGER;
|
||||
data_validation->criteria = LXW_VALIDATION_CRITERIA_GREATER_THAN;
|
||||
data_validation->value_number = 0;
|
||||
data_validation->ignore_blank = LXW_VALIDATION_OFF;
|
||||
data_validation->show_input = LXW_VALIDATION_OFF;
|
||||
data_validation->show_error = LXW_VALIDATION_OFF;
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_data_validation_cell(worksheet, 0, 0, data_validation);
|
||||
_worksheet_write_data_validations(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
CTEST(worksheet, write_data_validations02) {
|
||||
char* got;
|
||||
char exp[] = "<dataValidations count=\"1\"><dataValidation type=\"whole\" operator=\"greaterThan\" allowBlank=\"1\" showInputMessage=\"1\" showErrorMessage=\"1\" sqref=\"A2\"><formula1>E3</formula1></dataValidation></dataValidations>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_data_validation *data_validation = calloc(1, sizeof(lxw_data_validation));
|
||||
data_validation->validate = LXW_VALIDATION_TYPE_INTEGER_FORMULA;
|
||||
data_validation->criteria = LXW_VALIDATION_CRITERIA_GREATER_THAN;
|
||||
data_validation->value_formula = "=E3";
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_data_validation_cell(worksheet, CELL("A2"), data_validation);
|
||||
_worksheet_write_data_validations(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
CTEST(worksheet, write_data_validations03) {
|
||||
char* got;
|
||||
char exp[] = "<dataValidations count=\"1\"><dataValidation type=\"decimal\" allowBlank=\"1\" showInputMessage=\"1\" showErrorMessage=\"1\" sqref=\"A3\"><formula1>0.1</formula1><formula2>0.5</formula2></dataValidation></dataValidations>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_data_validation *data_validation = calloc(1, sizeof(lxw_data_validation));
|
||||
data_validation->validate = LXW_VALIDATION_TYPE_DECIMAL;
|
||||
data_validation->criteria = LXW_VALIDATION_CRITERIA_BETWEEN;
|
||||
data_validation->minimum_number = 0.1;
|
||||
data_validation->maximum_number = 0.5;
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_data_validation_cell(worksheet, CELL("A3"), data_validation);
|
||||
_worksheet_write_data_validations(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
CTEST(worksheet, write_data_validations04) {
|
||||
char* got;
|
||||
char exp[] = "<dataValidations count=\"1\"><dataValidation type=\"list\" allowBlank=\"1\" showInputMessage=\"1\" showErrorMessage=\"1\" sqref=\"A4\"><formula1>\"open,high,close\"</formula1></dataValidation></dataValidations>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
char *list[] = {"open", "high", "close", NULL};
|
||||
|
||||
lxw_data_validation *data_validation = calloc(1, sizeof(lxw_data_validation));
|
||||
data_validation->validate = LXW_VALIDATION_TYPE_LIST;
|
||||
data_validation->value_list = list;
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_data_validation_cell(worksheet, CELL("A4"), data_validation);
|
||||
_worksheet_write_data_validations(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
CTEST(worksheet, write_data_validations05) {
|
||||
char* got;
|
||||
char exp[] = "<dataValidations count=\"1\"><dataValidation type=\"list\" allowBlank=\"1\" showInputMessage=\"1\" showErrorMessage=\"1\" sqref=\"A5\"><formula1>$E$4:$G$4</formula1></dataValidation></dataValidations>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_data_validation *data_validation = calloc(1, sizeof(lxw_data_validation));
|
||||
data_validation->validate = LXW_VALIDATION_TYPE_LIST_FORMULA;
|
||||
data_validation->value_formula = "=$E$4:$G$4";
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_data_validation_cell(worksheet, CELL("A5"), data_validation);
|
||||
_worksheet_write_data_validations(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
CTEST(worksheet, write_data_validations06) {
|
||||
char* got;
|
||||
char exp[] = "<dataValidations count=\"1\"><dataValidation type=\"date\" allowBlank=\"1\" showInputMessage=\"1\" showErrorMessage=\"1\" sqref=\"A6\"><formula1>39448</formula1><formula2>39794</formula2></dataValidation></dataValidations>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
lxw_datetime datetime1 = {2008, 1, 1, 0, 0, 0};
|
||||
lxw_datetime datetime2 = {2008, 12, 12, 0, 0, 0};
|
||||
|
||||
lxw_data_validation *data_validation = calloc(1, sizeof(lxw_data_validation));
|
||||
data_validation->validate = LXW_VALIDATION_TYPE_DATE;
|
||||
data_validation->criteria = LXW_VALIDATION_CRITERIA_BETWEEN;
|
||||
data_validation->minimum_datetime = datetime1;
|
||||
data_validation->maximum_datetime = datetime2;
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_data_validation_cell(worksheet, CELL("A6"), data_validation);
|
||||
_worksheet_write_data_validations(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
CTEST(worksheet, write_data_validations07) {
|
||||
char* got;
|
||||
char exp[] = "<dataValidations count=\"1\"><dataValidation type=\"whole\" allowBlank=\"1\" showInputMessage=\"1\" showErrorMessage=\"1\" promptTitle=\"Enter an integer:\" prompt=\"between 1 and 100\" sqref=\"A7\"><formula1>1</formula1><formula2>100</formula2></dataValidation></dataValidations>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_data_validation *data_validation = calloc(1, sizeof(lxw_data_validation));
|
||||
data_validation->validate = LXW_VALIDATION_TYPE_INTEGER;
|
||||
data_validation->criteria = LXW_VALIDATION_CRITERIA_BETWEEN;
|
||||
data_validation->minimum_number = 1;
|
||||
data_validation->maximum_number = 100;
|
||||
data_validation->input_title = "Enter an integer:";
|
||||
data_validation->input_message = "between 1 and 100";
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_data_validation_cell(worksheet, CELL("A7"), data_validation);
|
||||
_worksheet_write_data_validations(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
@ -0,0 +1,984 @@
|
||||
/*
|
||||
* Tests for the lib_xlsx_writer library.
|
||||
*
|
||||
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
|
||||
*
|
||||
*/
|
||||
|
||||
#include "../ctest.h"
|
||||
#include "../helper.h"
|
||||
|
||||
#include "../../../include/xlsxwriter/worksheet.h"
|
||||
|
||||
|
||||
/* Test: Integer between 1 and 10. */
|
||||
CTEST(worksheet, test_write_data_validations_201) {
|
||||
char* got;
|
||||
char exp[] = "<dataValidations count=\"1\"><dataValidation type=\"whole\" allowBlank=\"1\" showInputMessage=\"1\" showErrorMessage=\"1\" sqref=\"B5\"><formula1>1</formula1><formula2>10</formula2></dataValidation></dataValidations>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_data_validation *data_validation = calloc(1, sizeof(lxw_data_validation));
|
||||
data_validation->validate = LXW_VALIDATION_TYPE_INTEGER;
|
||||
data_validation->criteria = LXW_VALIDATION_CRITERIA_BETWEEN;
|
||||
data_validation->minimum_number = 1;
|
||||
data_validation->maximum_number = 10;
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_data_validation_cell(worksheet, CELL("B5"), data_validation);
|
||||
_worksheet_write_data_validations(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
free(data_validation);
|
||||
}
|
||||
|
||||
/* Test: Integer not between 1 and 10. */
|
||||
CTEST(worksheet, test_write_data_validations_202) {
|
||||
char* got;
|
||||
char exp[] = "<dataValidations count=\"1\"><dataValidation type=\"whole\" operator=\"notBetween\" allowBlank=\"1\" showInputMessage=\"1\" showErrorMessage=\"1\" sqref=\"B5\"><formula1>1</formula1><formula2>10</formula2></dataValidation></dataValidations>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_data_validation *data_validation = calloc(1, sizeof(lxw_data_validation));
|
||||
data_validation->validate = LXW_VALIDATION_TYPE_INTEGER;
|
||||
data_validation->criteria = LXW_VALIDATION_CRITERIA_NOT_BETWEEN;
|
||||
data_validation->minimum_number = 1;
|
||||
data_validation->maximum_number = 10;
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_data_validation_cell(worksheet, CELL("B5"), data_validation);
|
||||
_worksheet_write_data_validations(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
free(data_validation);
|
||||
}
|
||||
|
||||
|
||||
/* Test: Integer == 1. */
|
||||
CTEST(worksheet, test_write_data_validations_203) {
|
||||
char* got;
|
||||
char exp[] = "<dataValidations count=\"1\"><dataValidation type=\"whole\" operator=\"equal\" allowBlank=\"1\" showInputMessage=\"1\" showErrorMessage=\"1\" sqref=\"B5\"><formula1>1</formula1></dataValidation></dataValidations>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_data_validation *data_validation = calloc(1, sizeof(lxw_data_validation));
|
||||
data_validation->validate = LXW_VALIDATION_TYPE_INTEGER;
|
||||
data_validation->criteria = LXW_VALIDATION_CRITERIA_EQUAL_TO;
|
||||
data_validation->value_number = 1;
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_data_validation_cell(worksheet, CELL("B5"), data_validation);
|
||||
_worksheet_write_data_validations(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
free(data_validation);
|
||||
}
|
||||
|
||||
/* Test: Integer != 1. */
|
||||
CTEST(worksheet, test_write_data_validations_204) {
|
||||
char* got;
|
||||
char exp[] = "<dataValidations count=\"1\"><dataValidation type=\"whole\" operator=\"notEqual\" allowBlank=\"1\" showInputMessage=\"1\" showErrorMessage=\"1\" sqref=\"B5\"><formula1>1</formula1></dataValidation></dataValidations>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_data_validation *data_validation = calloc(1, sizeof(lxw_data_validation));
|
||||
data_validation->validate = LXW_VALIDATION_TYPE_INTEGER;
|
||||
data_validation->criteria = LXW_VALIDATION_CRITERIA_NOT_EQUAL_TO;
|
||||
data_validation->value_number = 1;
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_data_validation_cell(worksheet, CELL("B5"), data_validation);
|
||||
_worksheet_write_data_validations(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
free(data_validation);
|
||||
}
|
||||
|
||||
/* Test: Integer > 1. */
|
||||
CTEST(worksheet, test_write_data_validations_205) {
|
||||
char* got;
|
||||
char exp[] = "<dataValidations count=\"1\"><dataValidation type=\"whole\" operator=\"greaterThan\" allowBlank=\"1\" showInputMessage=\"1\" showErrorMessage=\"1\" sqref=\"B5\"><formula1>1</formula1></dataValidation></dataValidations>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_data_validation *data_validation = calloc(1, sizeof(lxw_data_validation));
|
||||
data_validation->validate = LXW_VALIDATION_TYPE_INTEGER;
|
||||
data_validation->criteria = LXW_VALIDATION_CRITERIA_GREATER_THAN;
|
||||
data_validation->value_number = 1;
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_data_validation_cell(worksheet, CELL("B5"), data_validation);
|
||||
_worksheet_write_data_validations(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
free(data_validation);
|
||||
}
|
||||
|
||||
/* Test: Integer < 1. */
|
||||
CTEST(worksheet, test_write_data_validations_206) {
|
||||
char* got;
|
||||
char exp[] = "<dataValidations count=\"1\"><dataValidation type=\"whole\" operator=\"lessThan\" allowBlank=\"1\" showInputMessage=\"1\" showErrorMessage=\"1\" sqref=\"B5\"><formula1>1</formula1></dataValidation></dataValidations>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_data_validation *data_validation = calloc(1, sizeof(lxw_data_validation));
|
||||
data_validation->validate = LXW_VALIDATION_TYPE_INTEGER;
|
||||
data_validation->criteria = LXW_VALIDATION_CRITERIA_LESS_THAN;
|
||||
data_validation->value_number = 1;
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_data_validation_cell(worksheet, CELL("B5"), data_validation);
|
||||
_worksheet_write_data_validations(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
free(data_validation);
|
||||
}
|
||||
|
||||
/* Test: 1Integer >= 1. */
|
||||
CTEST(worksheet, test_write_data_validations_207) {
|
||||
char* got;
|
||||
char exp[] = "<dataValidations count=\"1\"><dataValidation type=\"whole\" operator=\"greaterThanOrEqual\" allowBlank=\"1\" showInputMessage=\"1\" showErrorMessage=\"1\" sqref=\"B5\"><formula1>1</formula1></dataValidation></dataValidations>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_data_validation *data_validation = calloc(1, sizeof(lxw_data_validation));
|
||||
data_validation->validate = LXW_VALIDATION_TYPE_INTEGER;
|
||||
data_validation->criteria = LXW_VALIDATION_CRITERIA_GREATER_THAN_OR_EQUAL_TO;
|
||||
data_validation->value_number = 1;
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_data_validation_cell(worksheet, CELL("B5"), data_validation);
|
||||
_worksheet_write_data_validations(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
free(data_validation);
|
||||
}
|
||||
|
||||
/* Test: Integer <= 1. */
|
||||
CTEST(worksheet, test_write_data_validations_208) {
|
||||
char* got;
|
||||
char exp[] = "<dataValidations count=\"1\"><dataValidation type=\"whole\" operator=\"lessThanOrEqual\" allowBlank=\"1\" showInputMessage=\"1\" showErrorMessage=\"1\" sqref=\"B5\"><formula1>1</formula1></dataValidation></dataValidations>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_data_validation *data_validation = calloc(1, sizeof(lxw_data_validation));
|
||||
data_validation->validate = LXW_VALIDATION_TYPE_INTEGER;
|
||||
data_validation->criteria = LXW_VALIDATION_CRITERIA_LESS_THAN_OR_EQUAL_TO;
|
||||
data_validation->value_number = 1;
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_data_validation_cell(worksheet, CELL("B5"), data_validation);
|
||||
_worksheet_write_data_validations(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
free(data_validation);
|
||||
}
|
||||
|
||||
/* Test: Ignore blank off. */
|
||||
CTEST(worksheet, test_write_data_validations_209) {
|
||||
char* got;
|
||||
char exp[] = "<dataValidations count=\"1\"><dataValidation type=\"whole\" showInputMessage=\"1\" showErrorMessage=\"1\" sqref=\"B5\"><formula1>1</formula1><formula2>10</formula2></dataValidation></dataValidations>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_data_validation *data_validation = calloc(1, sizeof(lxw_data_validation));
|
||||
data_validation->validate = LXW_VALIDATION_TYPE_INTEGER;
|
||||
data_validation->criteria = LXW_VALIDATION_CRITERIA_BETWEEN;
|
||||
data_validation->minimum_number = 1;
|
||||
data_validation->maximum_number = 10;
|
||||
data_validation->ignore_blank = LXW_VALIDATION_OFF;
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_data_validation_cell(worksheet, CELL("B5"), data_validation);
|
||||
_worksheet_write_data_validations(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
free(data_validation);
|
||||
}
|
||||
|
||||
/* Test: Error style == warning. */
|
||||
CTEST(worksheet, test_write_data_validations_210) {
|
||||
char* got;
|
||||
char exp[] = "<dataValidations count=\"1\"><dataValidation type=\"whole\" errorStyle=\"warning\" allowBlank=\"1\" showInputMessage=\"1\" showErrorMessage=\"1\" sqref=\"B5\"><formula1>1</formula1><formula2>10</formula2></dataValidation></dataValidations>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_data_validation *data_validation = calloc(1, sizeof(lxw_data_validation));
|
||||
data_validation->validate = LXW_VALIDATION_TYPE_INTEGER;
|
||||
data_validation->criteria = LXW_VALIDATION_CRITERIA_BETWEEN;
|
||||
data_validation->minimum_number = 1;
|
||||
data_validation->maximum_number = 10;
|
||||
data_validation->error_type = LXW_VALIDATION_ERROR_TYPE_WARNING;
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_data_validation_cell(worksheet, CELL("B5"), data_validation);
|
||||
_worksheet_write_data_validations(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
free(data_validation);
|
||||
}
|
||||
|
||||
/* Test: Error style == information */
|
||||
CTEST(worksheet, test_write_data_validations_211) {
|
||||
char* got;
|
||||
char exp[] = "<dataValidations count=\"1\"><dataValidation type=\"whole\" errorStyle=\"information\" allowBlank=\"1\" showInputMessage=\"1\" showErrorMessage=\"1\" sqref=\"B5\"><formula1>1</formula1><formula2>10</formula2></dataValidation></dataValidations>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_data_validation *data_validation = calloc(1, sizeof(lxw_data_validation));
|
||||
data_validation->validate = LXW_VALIDATION_TYPE_INTEGER;
|
||||
data_validation->criteria = LXW_VALIDATION_CRITERIA_BETWEEN;
|
||||
data_validation->minimum_number = 1;
|
||||
data_validation->maximum_number = 10;
|
||||
data_validation->error_type = LXW_VALIDATION_ERROR_TYPE_INFORMATION;
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_data_validation_cell(worksheet, CELL("B5"), data_validation);
|
||||
_worksheet_write_data_validations(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
free(data_validation);
|
||||
}
|
||||
|
||||
/* Test: Input title. */
|
||||
CTEST(worksheet, test_write_data_validations_212) {
|
||||
char* got;
|
||||
char exp[] = "<dataValidations count=\"1\"><dataValidation type=\"whole\" allowBlank=\"1\" showInputMessage=\"1\" showErrorMessage=\"1\" promptTitle=\"Input title January\" sqref=\"B5\"><formula1>1</formula1><formula2>10</formula2></dataValidation></dataValidations>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_data_validation *data_validation = calloc(1, sizeof(lxw_data_validation));
|
||||
data_validation->validate = LXW_VALIDATION_TYPE_INTEGER;
|
||||
data_validation->criteria = LXW_VALIDATION_CRITERIA_BETWEEN;
|
||||
data_validation->minimum_number = 1;
|
||||
data_validation->maximum_number = 10;
|
||||
data_validation->input_title = "Input title January";
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_data_validation_cell(worksheet, CELL("B5"), data_validation);
|
||||
_worksheet_write_data_validations(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
free(data_validation);
|
||||
}
|
||||
|
||||
/* Test: Input title + input message. */
|
||||
CTEST(worksheet, test_write_data_validations_213) {
|
||||
char* got;
|
||||
char exp[] = "<dataValidations count=\"1\"><dataValidation type=\"whole\" allowBlank=\"1\" showInputMessage=\"1\" showErrorMessage=\"1\" promptTitle=\"Input title January\" prompt=\"Input message February\" sqref=\"B5\"><formula1>1</formula1><formula2>10</formula2></dataValidation></dataValidations>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_data_validation *data_validation = calloc(1, sizeof(lxw_data_validation));
|
||||
data_validation->validate = LXW_VALIDATION_TYPE_INTEGER;
|
||||
data_validation->criteria = LXW_VALIDATION_CRITERIA_BETWEEN;
|
||||
data_validation->minimum_number = 1;
|
||||
data_validation->maximum_number = 10;
|
||||
data_validation->input_title = "Input title January";
|
||||
data_validation->input_message = "Input message February";
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_data_validation_cell(worksheet, CELL("B5"), data_validation);
|
||||
_worksheet_write_data_validations(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
free(data_validation);
|
||||
}
|
||||
|
||||
/* Test: Input title + input message + error title. */
|
||||
CTEST(worksheet, test_write_data_validations_214) {
|
||||
char* got;
|
||||
char exp[] = "<dataValidations count=\"1\"><dataValidation type=\"whole\" allowBlank=\"1\" showInputMessage=\"1\" showErrorMessage=\"1\" errorTitle=\"Error title March\" promptTitle=\"Input title January\" prompt=\"Input message February\" sqref=\"B5\"><formula1>1</formula1><formula2>10</formula2></dataValidation></dataValidations>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_data_validation *data_validation = calloc(1, sizeof(lxw_data_validation));
|
||||
data_validation->validate = LXW_VALIDATION_TYPE_INTEGER;
|
||||
data_validation->criteria = LXW_VALIDATION_CRITERIA_BETWEEN;
|
||||
data_validation->minimum_number = 1;
|
||||
data_validation->maximum_number = 10;
|
||||
data_validation->input_title = "Input title January";
|
||||
data_validation->input_message = "Input message February";
|
||||
data_validation->error_title = "Error title March";
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_data_validation_cell(worksheet, CELL("B5"), data_validation);
|
||||
_worksheet_write_data_validations(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
free(data_validation);
|
||||
}
|
||||
|
||||
/* Test: Input title + input message + error title + error message. */
|
||||
CTEST(worksheet, test_write_data_validations_215) {
|
||||
char* got;
|
||||
char exp[] = "<dataValidations count=\"1\"><dataValidation type=\"whole\" allowBlank=\"1\" showInputMessage=\"1\" showErrorMessage=\"1\" errorTitle=\"Error title March\" error=\"Error message April\" promptTitle=\"Input title January\" prompt=\"Input message February\" sqref=\"B5\"><formula1>1</formula1><formula2>10</formula2></dataValidation></dataValidations>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_data_validation *data_validation = calloc(1, sizeof(lxw_data_validation));
|
||||
data_validation->validate = LXW_VALIDATION_TYPE_INTEGER;
|
||||
data_validation->criteria = LXW_VALIDATION_CRITERIA_BETWEEN;
|
||||
data_validation->minimum_number = 1;
|
||||
data_validation->maximum_number = 10;
|
||||
data_validation->input_title = "Input title January";
|
||||
data_validation->input_message = "Input message February";
|
||||
data_validation->error_title = "Error title March";
|
||||
data_validation->error_message = "Error message April";
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_data_validation_cell(worksheet, CELL("B5"), data_validation);
|
||||
_worksheet_write_data_validations(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
free(data_validation);
|
||||
}
|
||||
/* Test: Input title. + input message + error title + error message - input message box. */
|
||||
CTEST(worksheet, test_write_data_validations_216) {
|
||||
char* got;
|
||||
char exp[] = "<dataValidations count=\"1\"><dataValidation type=\"whole\" allowBlank=\"1\" showErrorMessage=\"1\" errorTitle=\"Error title March\" error=\"Error message April\" promptTitle=\"Input title January\" prompt=\"Input message February\" sqref=\"B5\"><formula1>1</formula1><formula2>10</formula2></dataValidation></dataValidations>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_data_validation *data_validation = calloc(1, sizeof(lxw_data_validation));
|
||||
data_validation->validate = LXW_VALIDATION_TYPE_INTEGER;
|
||||
data_validation->criteria = LXW_VALIDATION_CRITERIA_BETWEEN;
|
||||
data_validation->minimum_number = 1;
|
||||
data_validation->maximum_number = 10;
|
||||
data_validation->input_title = "Input title January";
|
||||
data_validation->input_message = "Input message February";
|
||||
data_validation->error_title = "Error title March";
|
||||
data_validation->error_message = "Error message April";
|
||||
data_validation->show_input = LXW_VALIDATION_OFF;
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_data_validation_cell(worksheet, CELL("B5"), data_validation);
|
||||
_worksheet_write_data_validations(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
free(data_validation);
|
||||
}
|
||||
|
||||
/* Test: Input title + input message + error title + error message - input message box - error message box. */
|
||||
CTEST(worksheet, test_write_data_validations_217) {
|
||||
char* got;
|
||||
char exp[] = "<dataValidations count=\"1\"><dataValidation type=\"whole\" allowBlank=\"1\" errorTitle=\"Error title March\" error=\"Error message April\" promptTitle=\"Input title January\" prompt=\"Input message February\" sqref=\"B5\"><formula1>1</formula1><formula2>10</formula2></dataValidation></dataValidations>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_data_validation *data_validation = calloc(1, sizeof(lxw_data_validation));
|
||||
data_validation->validate = LXW_VALIDATION_TYPE_INTEGER;
|
||||
data_validation->criteria = LXW_VALIDATION_CRITERIA_BETWEEN;
|
||||
data_validation->minimum_number = 1;
|
||||
data_validation->maximum_number = 10;
|
||||
data_validation->input_title = "Input title January";
|
||||
data_validation->input_message = "Input message February";
|
||||
data_validation->error_title = "Error title March";
|
||||
data_validation->error_message = "Error message April";
|
||||
data_validation->show_input = LXW_VALIDATION_OFF;
|
||||
data_validation->show_error = LXW_VALIDATION_OFF;
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_data_validation_cell(worksheet, CELL("B5"), data_validation);
|
||||
_worksheet_write_data_validations(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
free(data_validation);
|
||||
}
|
||||
|
||||
/* Test: 'any' value on its own shouldn't produce a DV record. */
|
||||
CTEST(worksheet, test_write_data_validations_218) {
|
||||
char* got;
|
||||
char exp[] = "";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_data_validation *data_validation = calloc(1, sizeof(lxw_data_validation));
|
||||
data_validation->validate = LXW_VALIDATION_TYPE_ANY;
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_data_validation_cell(worksheet, CELL("B5"), data_validation);
|
||||
_worksheet_write_data_validations(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
free(data_validation);
|
||||
}
|
||||
|
||||
/* Test: Decimal = 1.2345 */
|
||||
CTEST(worksheet, test_write_data_validations_219) {
|
||||
char* got;
|
||||
char exp[] = "<dataValidations count=\"1\"><dataValidation type=\"decimal\" operator=\"equal\" allowBlank=\"1\" showInputMessage=\"1\" showErrorMessage=\"1\" sqref=\"B5\"><formula1>1.2345</formula1></dataValidation></dataValidations>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_data_validation *data_validation = calloc(1, sizeof(lxw_data_validation));
|
||||
data_validation->validate = LXW_VALIDATION_TYPE_DECIMAL;
|
||||
data_validation->criteria = LXW_VALIDATION_CRITERIA_EQUAL_TO;
|
||||
data_validation->value_number = 1.2345;
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_data_validation_cell(worksheet, CELL("B5"), data_validation);
|
||||
_worksheet_write_data_validations(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
free(data_validation);
|
||||
}
|
||||
|
||||
/* Test: 28 List = a,bb,ccc */
|
||||
CTEST(worksheet, test_write_data_validations_220) {
|
||||
char* got;
|
||||
char exp[] = "<dataValidations count=\"1\"><dataValidation type=\"list\" allowBlank=\"1\" showInputMessage=\"1\" showErrorMessage=\"1\" sqref=\"B5\"><formula1>\"a,bb,ccc\"</formula1></dataValidation></dataValidations>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
char *list[] = {"a", "bb", "ccc", NULL};
|
||||
|
||||
lxw_data_validation *data_validation = calloc(1, sizeof(lxw_data_validation));
|
||||
data_validation->validate = LXW_VALIDATION_TYPE_LIST;
|
||||
data_validation->value_list = list;
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_data_validation_cell(worksheet, CELL("B5"), data_validation);
|
||||
_worksheet_write_data_validations(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
free(data_validation);
|
||||
}
|
||||
|
||||
/* Test: List = a,bb,ccc, No dropdown */
|
||||
CTEST(worksheet, test_write_data_validations_221) {
|
||||
char* got;
|
||||
char exp[] = "<dataValidations count=\"1\"><dataValidation type=\"list\" allowBlank=\"1\" showDropDown=\"1\" showInputMessage=\"1\" showErrorMessage=\"1\" sqref=\"B5\"><formula1>\"a,bb,ccc\"</formula1></dataValidation></dataValidations>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
char *list[] = {"a", "bb", "ccc", NULL};
|
||||
|
||||
lxw_data_validation *data_validation = calloc(1, sizeof(lxw_data_validation));
|
||||
data_validation->validate = LXW_VALIDATION_TYPE_LIST;
|
||||
data_validation->value_list = list;
|
||||
data_validation->dropdown = LXW_VALIDATION_OFF;
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_data_validation_cell(worksheet, CELL("B5"), data_validation);
|
||||
_worksheet_write_data_validations(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
free(data_validation);
|
||||
}
|
||||
|
||||
/* Test: List = $D$1:$D$5 */
|
||||
CTEST(worksheet, test_write_data_validations_222) {
|
||||
char* got;
|
||||
char exp[] = "<dataValidations count=\"1\"><dataValidation type=\"list\" allowBlank=\"1\" showInputMessage=\"1\" showErrorMessage=\"1\" sqref=\"A1\"><formula1>$D$1:$D$5</formula1></dataValidation></dataValidations>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_data_validation *data_validation = calloc(1, sizeof(lxw_data_validation));
|
||||
data_validation->validate = LXW_VALIDATION_TYPE_LIST_FORMULA;
|
||||
data_validation->value_formula = "=$D$1:$D$5";
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_data_validation_cell(worksheet, CELL("A1"), data_validation);
|
||||
_worksheet_write_data_validations(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
free(data_validation);
|
||||
}
|
||||
|
||||
/* Test: Date = 39653 (2008-07-24) */
|
||||
CTEST(worksheet, test_write_data_validations_223) {
|
||||
char* got;
|
||||
char exp[] = "<dataValidations count=\"1\"><dataValidation type=\"date\" operator=\"equal\" allowBlank=\"1\" showInputMessage=\"1\" showErrorMessage=\"1\" sqref=\"B5\"><formula1>39653</formula1></dataValidation></dataValidations>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_data_validation *data_validation = calloc(1, sizeof(lxw_data_validation));
|
||||
data_validation->validate = LXW_VALIDATION_TYPE_DATE_NUMBER;
|
||||
data_validation->criteria = LXW_VALIDATION_CRITERIA_EQUAL_TO;
|
||||
data_validation->value_number = 39653;
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_data_validation_cell(worksheet, CELL("B5"), data_validation);
|
||||
_worksheet_write_data_validations(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
free(data_validation);
|
||||
}
|
||||
|
||||
/* Test: Date = 2008-07-24 */
|
||||
CTEST(worksheet, test_write_data_validations_224) {
|
||||
char* got;
|
||||
char exp[] = "<dataValidations count=\"1\"><dataValidation type=\"date\" operator=\"equal\" allowBlank=\"1\" showInputMessage=\"1\" showErrorMessage=\"1\" sqref=\"B5\"><formula1>39653</formula1></dataValidation></dataValidations>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
lxw_datetime datetime1 = {2008, 7, 24, 0, 0, 0};
|
||||
|
||||
lxw_data_validation *data_validation = calloc(1, sizeof(lxw_data_validation));
|
||||
data_validation->validate = LXW_VALIDATION_TYPE_DATE;
|
||||
data_validation->criteria = LXW_VALIDATION_CRITERIA_EQUAL_TO;
|
||||
data_validation->value_datetime = datetime1;
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_data_validation_cell(worksheet, CELL("B5"), data_validation);
|
||||
_worksheet_write_data_validations(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
free(data_validation);
|
||||
}
|
||||
|
||||
/* Test: Date between ranges. */
|
||||
CTEST(worksheet, test_write_data_validations_225) {
|
||||
char* got;
|
||||
char exp[] = "<dataValidations count=\"1\"><dataValidation type=\"date\" allowBlank=\"1\" showInputMessage=\"1\" showErrorMessage=\"1\" sqref=\"B5\"><formula1>39448</formula1><formula2>39794</formula2></dataValidation></dataValidations>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
lxw_datetime datetime1 = {2008, 1, 1, 0, 0, 0};
|
||||
lxw_datetime datetime2 = {2008, 12, 12, 0, 0, 0};
|
||||
|
||||
lxw_data_validation *data_validation = calloc(1, sizeof(lxw_data_validation));
|
||||
data_validation->validate = LXW_VALIDATION_TYPE_DATE;
|
||||
data_validation->criteria = LXW_VALIDATION_CRITERIA_BETWEEN;
|
||||
data_validation->minimum_datetime = datetime1;
|
||||
data_validation->maximum_datetime = datetime2;
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_data_validation_cell(worksheet, CELL("B5"), data_validation);
|
||||
_worksheet_write_data_validations(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
free(data_validation);
|
||||
}
|
||||
|
||||
/* Test: Time = 0.5 (12:00:00) */
|
||||
CTEST(worksheet, test_write_data_validations_226) {
|
||||
char* got;
|
||||
char exp[] = "<dataValidations count=\"1\"><dataValidation type=\"time\" operator=\"equal\" allowBlank=\"1\" showInputMessage=\"1\" showErrorMessage=\"1\" sqref=\"B5\"><formula1>0.5</formula1></dataValidation></dataValidations>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_data_validation *data_validation = calloc(1, sizeof(lxw_data_validation));
|
||||
data_validation->validate = LXW_VALIDATION_TYPE_TIME_NUMBER;
|
||||
data_validation->criteria = LXW_VALIDATION_CRITERIA_EQUAL_TO;
|
||||
data_validation->value_number = 0.5;
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_data_validation_cell(worksheet, CELL("B5:B5"), data_validation);
|
||||
_worksheet_write_data_validations(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
free(data_validation);
|
||||
}
|
||||
|
||||
/* Test: Time = 12:00:00 */
|
||||
CTEST(worksheet, test_write_data_validations_227) {
|
||||
char* got;
|
||||
char exp[] = "<dataValidations count=\"1\"><dataValidation type=\"time\" operator=\"equal\" allowBlank=\"1\" showInputMessage=\"1\" showErrorMessage=\"1\" sqref=\"B5\"><formula1>0.5</formula1></dataValidation></dataValidations>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
lxw_datetime datetime1 = {0, 0, 0, 12, 0, 0};
|
||||
|
||||
lxw_data_validation *data_validation = calloc(1, sizeof(lxw_data_validation));
|
||||
data_validation->validate = LXW_VALIDATION_TYPE_TIME;
|
||||
data_validation->criteria = LXW_VALIDATION_CRITERIA_EQUAL_TO;
|
||||
data_validation->value_datetime = datetime1;
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_data_validation_cell(worksheet, CELL("B5"), data_validation);
|
||||
_worksheet_write_data_validations(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
free(data_validation);
|
||||
}
|
||||
|
||||
/* Test: Check data validation range. */
|
||||
CTEST(worksheet, test_write_data_validations_228) {
|
||||
char* got;
|
||||
char exp[] = "<dataValidations count=\"1\"><dataValidation type=\"whole\" allowBlank=\"1\" showInputMessage=\"1\" showErrorMessage=\"1\" sqref=\"B5:B10\"><formula1>1</formula1><formula2>10</formula2></dataValidation></dataValidations>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_data_validation *data_validation = calloc(1, sizeof(lxw_data_validation));
|
||||
data_validation->validate = LXW_VALIDATION_TYPE_INTEGER;
|
||||
data_validation->criteria = LXW_VALIDATION_CRITERIA_BETWEEN;
|
||||
data_validation->minimum_number = 1;
|
||||
data_validation->maximum_number = 10;
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_data_validation_range(worksheet, RANGE("B5:B10"), data_validation);
|
||||
_worksheet_write_data_validations(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
free(data_validation);
|
||||
}
|
||||
|
||||
/* Test: Multiple validations. */
|
||||
CTEST(worksheet, test_write_data_validations_229) {
|
||||
char* got;
|
||||
char exp[] = "<dataValidations count=\"2\"><dataValidation type=\"whole\" operator=\"greaterThan\" allowBlank=\"1\" showInputMessage=\"1\" showErrorMessage=\"1\" sqref=\"B5\"><formula1>10</formula1></dataValidation><dataValidation type=\"whole\" operator=\"lessThan\" allowBlank=\"1\" showInputMessage=\"1\" showErrorMessage=\"1\" sqref=\"C10\"><formula1>10</formula1></dataValidation></dataValidations>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_data_validation *data_validation = calloc(1, sizeof(lxw_data_validation));
|
||||
data_validation->validate = LXW_VALIDATION_TYPE_INTEGER;
|
||||
data_validation->criteria = LXW_VALIDATION_CRITERIA_GREATER_THAN;
|
||||
data_validation->value_number = 10;
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_data_validation_cell(worksheet, CELL("B5"), data_validation);
|
||||
|
||||
data_validation->validate = LXW_VALIDATION_TYPE_INTEGER;
|
||||
data_validation->criteria = LXW_VALIDATION_CRITERIA_LESS_THAN;
|
||||
data_validation->value_number = 10;
|
||||
worksheet_data_validation_cell(worksheet, CELL("C10"), data_validation);
|
||||
|
||||
_worksheet_write_data_validations(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
free(data_validation);
|
||||
}
|
||||
|
||||
/* Test: 'any' with an input message should produce a dataValidation record. */
|
||||
CTEST(worksheet, test_write_data_validations_230) {
|
||||
char* got;
|
||||
char exp[] = "<dataValidations count=\"1\"><dataValidation allowBlank=\"1\" showInputMessage=\"1\" showErrorMessage=\"1\" promptTitle=\"Input title January\" prompt=\"Input message February\" sqref=\"B5\"/></dataValidations>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_data_validation *data_validation = calloc(1, sizeof(lxw_data_validation));
|
||||
data_validation->validate = LXW_VALIDATION_TYPE_ANY;
|
||||
data_validation->input_title = "Input title January";
|
||||
data_validation->input_message = "Input message February";
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_data_validation_cell(worksheet, CELL("B5"), data_validation);
|
||||
_worksheet_write_data_validations(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
free(data_validation);
|
||||
}
|
||||
|
||||
/* Test: length */
|
||||
CTEST(worksheet, test_write_data_validations_231) {
|
||||
char* got;
|
||||
char exp[] = "<dataValidations count=\"1\"><dataValidation type=\"textLength\" operator=\"greaterThan\" allowBlank=\"1\" showInputMessage=\"1\" showErrorMessage=\"1\" sqref=\"A1\"><formula1>5</formula1></dataValidation></dataValidations>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_data_validation *data_validation = calloc(1, sizeof(lxw_data_validation));
|
||||
data_validation->validate = LXW_VALIDATION_TYPE_LENGTH;
|
||||
data_validation->criteria = LXW_VALIDATION_CRITERIA_GREATER_THAN;
|
||||
data_validation->value_number = 5;
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_data_validation_cell(worksheet, CELL("A1"), data_validation);
|
||||
_worksheet_write_data_validations(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
free(data_validation);
|
||||
}
|
||||
|
||||
|
||||
/* Test: length */
|
||||
CTEST(worksheet, test_write_data_validations_232) {
|
||||
char* got;
|
||||
char exp[] = "<dataValidations count=\"1\"><dataValidation type=\"textLength\" allowBlank=\"1\" showInputMessage=\"1\" showErrorMessage=\"1\" sqref=\"A1\"><formula1>5</formula1><formula2>10</formula2></dataValidation></dataValidations>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_data_validation *data_validation = calloc(1, sizeof(lxw_data_validation));
|
||||
data_validation->validate = LXW_VALIDATION_TYPE_LENGTH;
|
||||
data_validation->criteria = LXW_VALIDATION_CRITERIA_BETWEEN;
|
||||
data_validation->minimum_number = 5;
|
||||
data_validation->maximum_number = 10;
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_data_validation_cell(worksheet, CELL("A1"), data_validation);
|
||||
_worksheet_write_data_validations(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
free(data_validation);
|
||||
}
|
||||
|
||||
/* Test: length formula. */
|
||||
CTEST(worksheet, test_write_data_validations_233) {
|
||||
char* got;
|
||||
char exp[] = "<dataValidations count=\"1\"><dataValidation type=\"textLength\" operator=\"greaterThan\" allowBlank=\"1\" showInputMessage=\"1\" showErrorMessage=\"1\" sqref=\"A1\"><formula1>H1</formula1></dataValidation></dataValidations>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_data_validation *data_validation = calloc(1, sizeof(lxw_data_validation));
|
||||
data_validation->validate = LXW_VALIDATION_TYPE_LENGTH_FORMULA;
|
||||
data_validation->criteria = LXW_VALIDATION_CRITERIA_GREATER_THAN;
|
||||
data_validation->value_formula = "=H1";
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_data_validation_cell(worksheet, CELL("A1"), data_validation);
|
||||
_worksheet_write_data_validations(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
free(data_validation);
|
||||
}
|
||||
|
||||
/* Test: length formula. */
|
||||
CTEST(worksheet, test_write_data_validations_234) {
|
||||
char* got;
|
||||
char exp[] = "<dataValidations count=\"1\"><dataValidation type=\"textLength\" allowBlank=\"1\" showInputMessage=\"1\" showErrorMessage=\"1\" sqref=\"A1\"><formula1>H1</formula1><formula2>H2</formula2></dataValidation></dataValidations>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_data_validation *data_validation = calloc(1, sizeof(lxw_data_validation));
|
||||
data_validation->validate = LXW_VALIDATION_TYPE_LENGTH_FORMULA;
|
||||
data_validation->criteria = LXW_VALIDATION_CRITERIA_BETWEEN;
|
||||
data_validation->minimum_formula = "=H1";
|
||||
data_validation->maximum_formula = "=H2";
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_data_validation_cell(worksheet, CELL("A1"), data_validation);
|
||||
_worksheet_write_data_validations(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
free(data_validation);
|
||||
}
|
||||
|
||||
/* Test: Date = 2008-07-24 */
|
||||
CTEST(worksheet, test_write_data_validations_235) {
|
||||
char* got;
|
||||
char exp[] = "<dataValidations count=\"1\"><dataValidation type=\"date\" operator=\"equal\" allowBlank=\"1\" showInputMessage=\"1\" showErrorMessage=\"1\" sqref=\"B5\"><formula1>H1</formula1></dataValidation></dataValidations>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_data_validation *data_validation = calloc(1, sizeof(lxw_data_validation));
|
||||
data_validation->validate = LXW_VALIDATION_TYPE_DATE_FORMULA;
|
||||
data_validation->criteria = LXW_VALIDATION_CRITERIA_EQUAL_TO;
|
||||
data_validation->value_formula = "=H1";
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_data_validation_cell(worksheet, CELL("B5"), data_validation);
|
||||
_worksheet_write_data_validations(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
free(data_validation);
|
||||
}
|
||||
|
||||
/* Test: Date between ranges. */
|
||||
CTEST(worksheet, test_write_data_validations_236) {
|
||||
char* got;
|
||||
char exp[] = "<dataValidations count=\"1\"><dataValidation type=\"date\" allowBlank=\"1\" showInputMessage=\"1\" showErrorMessage=\"1\" sqref=\"B5\"><formula1>H1</formula1><formula2>H2</formula2></dataValidation></dataValidations>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_data_validation *data_validation = calloc(1, sizeof(lxw_data_validation));
|
||||
data_validation->validate = LXW_VALIDATION_TYPE_DATE_FORMULA;
|
||||
data_validation->criteria = LXW_VALIDATION_CRITERIA_BETWEEN;
|
||||
data_validation->minimum_formula = "=H1";
|
||||
data_validation->maximum_formula = "=H2";
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_data_validation_cell(worksheet, CELL("B5"), data_validation);
|
||||
_worksheet_write_data_validations(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
free(data_validation);
|
||||
}
|
||||
|
||||
/* Test: Time between ranges. */
|
||||
CTEST(worksheet, test_write_data_validations_237) {
|
||||
char* got;
|
||||
char exp[] = "<dataValidations count=\"1\"><dataValidation type=\"time\" allowBlank=\"1\" showInputMessage=\"1\" showErrorMessage=\"1\" sqref=\"B5\"><formula1>0</formula1><formula2>0.5</formula2></dataValidation></dataValidations>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
lxw_datetime datetime1 = {0, 0, 0, 0, 0, 0};
|
||||
lxw_datetime datetime2 = {0, 0, 0, 12, 0, 0};
|
||||
|
||||
lxw_data_validation *data_validation = calloc(1, sizeof(lxw_data_validation));
|
||||
data_validation->validate = LXW_VALIDATION_TYPE_TIME;
|
||||
data_validation->criteria = LXW_VALIDATION_CRITERIA_BETWEEN;
|
||||
data_validation->minimum_datetime = datetime1;
|
||||
data_validation->maximum_datetime = datetime2;
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_data_validation_cell(worksheet, CELL("B5"), data_validation);
|
||||
_worksheet_write_data_validations(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
free(data_validation);
|
||||
}
|
||||
|
||||
/* Test: Time formula */
|
||||
CTEST(worksheet, test_write_data_validations_238) {
|
||||
char* got;
|
||||
char exp[] = "<dataValidations count=\"1\"><dataValidation type=\"time\" operator=\"equal\" allowBlank=\"1\" showInputMessage=\"1\" showErrorMessage=\"1\" sqref=\"B5\"><formula1>H1</formula1></dataValidation></dataValidations>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_data_validation *data_validation = calloc(1, sizeof(lxw_data_validation));
|
||||
data_validation->validate = LXW_VALIDATION_TYPE_TIME_FORMULA;
|
||||
data_validation->criteria = LXW_VALIDATION_CRITERIA_EQUAL_TO;
|
||||
data_validation->value_formula = "=H1";
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_data_validation_cell(worksheet, CELL("B5"), data_validation);
|
||||
_worksheet_write_data_validations(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
free(data_validation);
|
||||
}
|
||||
|
||||
/* Test: Time formula */
|
||||
CTEST(worksheet, test_write_data_validations_239) {
|
||||
char* got;
|
||||
char exp[] = "<dataValidations count=\"1\"><dataValidation type=\"time\" allowBlank=\"1\" showInputMessage=\"1\" showErrorMessage=\"1\" sqref=\"B5\"><formula1>H1</formula1><formula2>H2</formula2></dataValidation></dataValidations>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_data_validation *data_validation = calloc(1, sizeof(lxw_data_validation));
|
||||
data_validation->validate = LXW_VALIDATION_TYPE_TIME_FORMULA;
|
||||
data_validation->criteria = LXW_VALIDATION_CRITERIA_BETWEEN;
|
||||
data_validation->minimum_formula = "=H1";
|
||||
data_validation->maximum_formula = "=H2";
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_data_validation_cell(worksheet, CELL("B5"), data_validation);
|
||||
_worksheet_write_data_validations(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
free(data_validation);
|
||||
}
|
||||
|
||||
/* Test: length formula. */
|
||||
CTEST(worksheet, test_write_data_validations_240) {
|
||||
char* got;
|
||||
char exp[] = "<dataValidations count=\"1\"><dataValidation type=\"custom\" allowBlank=\"1\" showInputMessage=\"1\" showErrorMessage=\"1\" sqref=\"B5\"><formula1>10</formula1></dataValidation></dataValidations>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_data_validation *data_validation = calloc(1, sizeof(lxw_data_validation));
|
||||
data_validation->validate = LXW_VALIDATION_TYPE_CUSTOM_FORMULA;
|
||||
data_validation->value_formula = "10";
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_data_validation_cell(worksheet, CELL("B5"), data_validation);
|
||||
_worksheet_write_data_validations(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
free(data_validation);
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Tests for the lib_xlsx_writer library.
|
||||
*
|
||||
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
|
||||
*
|
||||
*/
|
||||
|
||||
#include "../ctest.h"
|
||||
#include "../helper.h"
|
||||
|
||||
#include "../../../include/xlsxwriter/worksheet.h"
|
||||
|
||||
// Test the _write_dimension() function.
|
||||
CTEST(worksheet, write_dimension) {
|
||||
|
||||
char* got;
|
||||
char exp[] = "<dimension ref=\"A1\"/>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
_worksheet_write_dimension(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
@ -0,0 +1,108 @@
|
||||
/*
|
||||
* Tests for the lib_xlsx_writer library.
|
||||
*
|
||||
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
|
||||
*
|
||||
*/
|
||||
|
||||
#include "../ctest.h"
|
||||
#include "../helper.h"
|
||||
|
||||
#include "../../../include/xlsxwriter/worksheet.h"
|
||||
|
||||
// Test the header and footer functions.
|
||||
CTEST(worksheet, write_odd_header) {
|
||||
|
||||
char* got;
|
||||
char exp[] = "<oddHeader>Page &P of &N</oddHeader>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_set_header(worksheet, "Page &P of &N");
|
||||
|
||||
_worksheet_write_odd_header(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
// Test the header and footer functions.
|
||||
CTEST(worksheet, write_odd_footer) {
|
||||
|
||||
char* got;
|
||||
char exp[] = "<oddFooter>&F</oddFooter>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_set_footer(worksheet, "&F");
|
||||
|
||||
_worksheet_write_odd_footer(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
||||
// Test the header and footer functions.
|
||||
CTEST(worksheet, _worksheet_write_header_footer1) {
|
||||
|
||||
char* got;
|
||||
char exp[] = "<headerFooter><oddHeader>Page &P of &N</oddHeader></headerFooter>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_set_header(worksheet, "Page &P of &N");
|
||||
|
||||
_worksheet_write_header_footer(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
// Test the header and footer functions.
|
||||
CTEST(worksheet, _worksheet_write_header_footer2) {
|
||||
|
||||
char* got;
|
||||
char exp[] = "<headerFooter><oddFooter>&F</oddFooter></headerFooter>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_set_footer(worksheet, "&F");
|
||||
|
||||
_worksheet_write_header_footer(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
// Test the header and footer functions.
|
||||
CTEST(worksheet, _worksheet_write_header_footer3) {
|
||||
|
||||
char* got;
|
||||
char exp[] = "<headerFooter><oddHeader>Page &P of &N</oddHeader><oddFooter>&F</oddFooter></headerFooter>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_set_header(worksheet, "Page &P of &N");
|
||||
worksheet_set_footer(worksheet, "&F");
|
||||
|
||||
_worksheet_write_header_footer(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
@ -0,0 +1,141 @@
|
||||
/*
|
||||
* Tests for the lib_xlsx_writer library.
|
||||
*
|
||||
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
|
||||
*
|
||||
*/
|
||||
|
||||
#include "../ctest.h"
|
||||
#include "../helper.h"
|
||||
|
||||
#include "../../../include/xlsxwriter/worksheet.h"
|
||||
|
||||
/* Test the _write_page_margins() method. */
|
||||
CTEST(worksheet, write_page_margin01) {
|
||||
char* got;
|
||||
char exp[] = "<pageMargins left=\"0.7\" right=\"0.7\" top=\"0.75\" "
|
||||
"bottom=\"0.75\" header=\"0.3\" footer=\"0.3\"/>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
_worksheet_write_page_margins(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
/* Test the _write_page_margins() method. */
|
||||
CTEST(worksheet, write_page_margin02) {
|
||||
char* got;
|
||||
char exp[] = "<pageMargins left=\"0.7\" right=\"0.7\" top=\"0.75\" "
|
||||
"bottom=\"0.75\" header=\"0.3\" footer=\"0.3\"/>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_set_margins(worksheet, -1, -1, -1, -1);
|
||||
_worksheet_write_page_margins(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
/* Test the _write_page_margins() method. */
|
||||
CTEST(worksheet, write_page_margin03) {
|
||||
char* got;
|
||||
char exp[] = "<pageMargins left=\"0.8\" right=\"0.7\" top=\"0.75\" "
|
||||
"bottom=\"0.75\" header=\"0.3\" footer=\"0.3\"/>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_set_margins(worksheet, 0.8, -1, -1, -1);
|
||||
_worksheet_write_page_margins(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
/* Test the _write_page_margins() method. */
|
||||
CTEST(worksheet, write_page_margin04) {
|
||||
char* got;
|
||||
char exp[] = "<pageMargins left=\"0.7\" right=\"0.8\" top=\"0.75\" "
|
||||
"bottom=\"0.75\" header=\"0.3\" footer=\"0.3\"/>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_set_margins(worksheet, -1, 0.8, -1, -1);
|
||||
_worksheet_write_page_margins(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
/* Test the _write_page_margins() method. */
|
||||
CTEST(worksheet, write_page_margin05) {
|
||||
char* got;
|
||||
char exp[] = "<pageMargins left=\"0.7\" right=\"0.7\" top=\"0.8\" "
|
||||
"bottom=\"0.75\" header=\"0.3\" footer=\"0.3\"/>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_set_margins(worksheet, -1, -1, 0.8, -1);
|
||||
_worksheet_write_page_margins(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
/* Test the _write_page_margins() method. */
|
||||
CTEST(worksheet, write_page_margin06) {
|
||||
char* got;
|
||||
char exp[] = "<pageMargins left=\"0.7\" right=\"0.7\" top=\"0.75\" "
|
||||
"bottom=\"0.8\" header=\"0.3\" footer=\"0.3\"/>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_set_margins(worksheet, -1, -1, -1, 0.8);
|
||||
_worksheet_write_page_margins(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
/* Test the _write_page_margins() method. */
|
||||
CTEST(worksheet, write_page_margin07) {
|
||||
char* got;
|
||||
char exp[] = "<pageMargins left=\"0.7\" right=\"0.7\" top=\"0.75\" "
|
||||
"bottom=\"0.75\" header=\"0.2\" footer=\"0.4\"/>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
lxw_header_footer_options header_options = {.margin = 0.2};
|
||||
lxw_header_footer_options footer_options = {.margin = 0.4};
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_set_header_opt(worksheet, "", &header_options);
|
||||
worksheet_set_footer_opt(worksheet, "", &footer_options);
|
||||
|
||||
_worksheet_write_page_margins(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Tests for the lib_xlsx_writer library.
|
||||
*
|
||||
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
|
||||
*
|
||||
*/
|
||||
|
||||
#include "../ctest.h"
|
||||
#include "../helper.h"
|
||||
|
||||
#include "../../../include/xlsxwriter/worksheet.h"
|
||||
|
||||
// Test the _write_page_margins() function.
|
||||
CTEST(worksheet, write_page_margins) {
|
||||
|
||||
char* got;
|
||||
char exp[] = "<pageMargins left=\"0.7\" right=\"0.7\" top=\"0.75\" bottom=\"0.75\" header=\"0.3\" footer=\"0.3\"/>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
_worksheet_write_page_margins(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
@ -0,0 +1,100 @@
|
||||
/*
|
||||
* Tests for the lib_xlsx_writer library.
|
||||
*
|
||||
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
|
||||
*
|
||||
*/
|
||||
|
||||
#include "../ctest.h"
|
||||
#include "../helper.h"
|
||||
|
||||
#include "../../../include/xlsxwriter/worksheet.h"
|
||||
|
||||
|
||||
/* Test the _write_page_setup() method. Without any page setup. */
|
||||
CTEST(worksheet, write_page_setup01) {
|
||||
char* got;
|
||||
char exp[] = "";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
_worksheet_write_page_setup(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
||||
/* Test the _write_page_setup() method. With set_landscape(); */
|
||||
CTEST(worksheet, write_page_setup02) {
|
||||
char* got;
|
||||
char exp[] = "<pageSetup orientation=\"landscape\"/>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_set_landscape(worksheet);
|
||||
_worksheet_write_page_setup(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
||||
/* Test the _write_page_setup() method. With set_portrait(); */
|
||||
CTEST(worksheet, write_page_setup03) {
|
||||
char* got;
|
||||
char exp[] = "<pageSetup orientation=\"portrait\"/>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_set_portrait(worksheet);
|
||||
_worksheet_write_page_setup(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
||||
/* Test the _write_page_setup() method. With set_paper(); */
|
||||
CTEST(worksheet, write_page_setup04) {
|
||||
char* got;
|
||||
char exp[] = "<pageSetup paperSize=\"9\" orientation=\"portrait\"/>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_set_paper(worksheet, 9);
|
||||
_worksheet_write_page_setup(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
||||
/* Test the _write_page_setup() method. With print_across(); */
|
||||
CTEST(worksheet, write_page_setup05) {
|
||||
char* got;
|
||||
char exp[] = "<pageSetup pageOrder=\"overThenDown\" orientation=\"portrait\"/>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_print_across(worksheet);
|
||||
_worksheet_write_page_setup(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
@ -0,0 +1,94 @@
|
||||
/*
|
||||
* Tests for the lib_xlsx_writer library.
|
||||
*
|
||||
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
|
||||
*
|
||||
*/
|
||||
|
||||
#include "../ctest.h"
|
||||
#include "../helper.h"
|
||||
|
||||
#include "../../../include/xlsxwriter/worksheet.h"
|
||||
|
||||
// Test the _write_print_options() function.
|
||||
CTEST(worksheet, write_print_options1) {
|
||||
|
||||
char* got;
|
||||
char exp[] = "<printOptions horizontalCentered=\"1\"/>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
worksheet_select(worksheet);
|
||||
|
||||
worksheet_center_horizontally(worksheet);
|
||||
|
||||
_worksheet_write_print_options(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
// Test the _write_print_options() function.
|
||||
CTEST(worksheet, write_print_options2) {
|
||||
|
||||
char* got;
|
||||
char exp[] = "<printOptions verticalCentered=\"1\"/>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
worksheet_select(worksheet);
|
||||
|
||||
worksheet_center_vertically(worksheet);
|
||||
|
||||
_worksheet_write_print_options(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
// Test the _write_print_options() function.
|
||||
CTEST(worksheet, write_print_options3) {
|
||||
|
||||
char* got;
|
||||
char exp[] = "<printOptions horizontalCentered=\"1\" verticalCentered=\"1\"/>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
worksheet_select(worksheet);
|
||||
|
||||
worksheet_center_horizontally(worksheet);
|
||||
worksheet_center_vertically(worksheet);
|
||||
|
||||
_worksheet_write_print_options(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
||||
// Test the _write_print_options() function.
|
||||
CTEST(worksheet, write_print_options4) {
|
||||
|
||||
char* got;
|
||||
char exp[] = "<printOptions gridLines=\"1\"/>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
worksheet_select(worksheet);
|
||||
|
||||
worksheet_gridlines(worksheet, LXW_SHOW_PRINT_GRIDLINES);
|
||||
|
||||
_worksheet_write_print_options(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Tests for the lib_xlsx_writer library.
|
||||
*
|
||||
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
|
||||
*
|
||||
*/
|
||||
|
||||
#include "../ctest.h"
|
||||
#include "../helper.h"
|
||||
|
||||
#include "../../../include/xlsxwriter/worksheet.h"
|
||||
|
||||
// Test the _write_row() function.
|
||||
CTEST(worksheet, write_row) {
|
||||
|
||||
char* got;
|
||||
char exp[] = "<row r=\"1\"/>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
lxw_row *row = _get_row_list(worksheet->table, 0);
|
||||
|
||||
_write_row(worksheet, row, NULL);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Tests for the lib_xlsx_writer library.
|
||||
*
|
||||
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
|
||||
*
|
||||
*/
|
||||
|
||||
#include "../ctest.h"
|
||||
#include "../helper.h"
|
||||
|
||||
#include "../../../include/xlsxwriter/worksheet.h"
|
||||
|
||||
// Test the _write_sheet_data() function.
|
||||
CTEST(worksheet, write_sheet_data) {
|
||||
|
||||
char* got;
|
||||
char exp[] = "<sheetData/>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
_worksheet_write_sheet_data(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Tests for the lib_xlsx_writer library.
|
||||
*
|
||||
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
|
||||
*
|
||||
*/
|
||||
|
||||
#include "../ctest.h"
|
||||
#include "../helper.h"
|
||||
|
||||
#include "../../../include/xlsxwriter/worksheet.h"
|
||||
|
||||
// Test the _write_sheet_format_pr() function.
|
||||
CTEST(worksheet, write_sheet_format_pr) {
|
||||
|
||||
char* got;
|
||||
char exp[] = "<sheetFormatPr defaultRowHeight=\"15\"/>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
_worksheet_write_sheet_format_pr(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Tests for the lib_xlsx_writer library.
|
||||
*
|
||||
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
|
||||
*
|
||||
*/
|
||||
|
||||
#include "../ctest.h"
|
||||
#include "../helper.h"
|
||||
|
||||
#include "../../../include/xlsxwriter/worksheet.h"
|
||||
|
||||
|
||||
/* 1. Test the _write_sheet_pr() method. */
|
||||
CTEST(worksheet, write_write_sheet_pr01) {
|
||||
char* got;
|
||||
char exp[] = "<sheetPr><pageSetUpPr fitToPage=\"1\"/></sheetPr>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
worksheet->fit_page = 1;
|
||||
|
||||
_worksheet_write_sheet_pr(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
||||
/* 2. Test the _write_sheet_pr() method. */
|
||||
CTEST(worksheet, write_write_sheet_pr02) {
|
||||
char* got;
|
||||
char exp[] = "<sheetPr><tabColor rgb=\"FFFF0000\"/></sheetPr>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_set_tab_color(worksheet, LXW_COLOR_RED);
|
||||
_worksheet_write_sheet_pr(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
||||
/* 3. Test the _write_sheet_pr() method. */
|
||||
CTEST(worksheet, write_write_sheet_pr03) {
|
||||
char* got;
|
||||
char exp[] = "<sheetPr><tabColor rgb=\"FFFF0000\"/><pageSetUpPr fitToPage=\"1\"/></sheetPr>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
worksheet->fit_page = 1;
|
||||
|
||||
worksheet_set_tab_color(worksheet, LXW_COLOR_RED);
|
||||
_worksheet_write_sheet_pr(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,386 @@
|
||||
/*
|
||||
* Tests for the lib_xlsx_writer library.
|
||||
*
|
||||
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
|
||||
*
|
||||
*/
|
||||
|
||||
#include "../ctest.h"
|
||||
#include "../helper.h"
|
||||
|
||||
#include "../../../include/xlsxwriter/worksheet.h"
|
||||
|
||||
|
||||
/* 1. Test the _write_sheet_protection() method. */
|
||||
CTEST(worksheet, write_write_sheet_protection01) {
|
||||
char* got;
|
||||
char exp[] = "<sheetProtection sheet=\"1\" objects=\"1\" scenarios=\"1\"/>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_protect(worksheet, NULL, NULL);
|
||||
_worksheet_write_sheet_protection(worksheet, &worksheet->protection);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
||||
/* 2. Test the _write_sheet_protection() method. */
|
||||
CTEST(worksheet, write_write_sheet_protection02) {
|
||||
char* got;
|
||||
char exp[] = "<sheetProtection password=\"83AF\" sheet=\"1\" objects=\"1\" scenarios=\"1\"/>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_protect(worksheet, "password", NULL);
|
||||
_worksheet_write_sheet_protection(worksheet, &worksheet->protection);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
/* 3. Test the _write_sheet_protection() method. */
|
||||
CTEST(worksheet, write_write_sheet_protection03) {
|
||||
char* got;
|
||||
char exp[] = "<sheetProtection sheet=\"1\" objects=\"1\" scenarios=\"1\" selectLockedCells=\"1\"/>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
lxw_protection options = {.no_select_locked_cells = 1};
|
||||
|
||||
worksheet_protect(worksheet, NULL, &options);
|
||||
_worksheet_write_sheet_protection(worksheet, &worksheet->protection);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
||||
/* 4. Test the _write_sheet_protection() method. */
|
||||
CTEST(worksheet, write_write_sheet_protection04) {
|
||||
char* got;
|
||||
char exp[] = "<sheetProtection sheet=\"1\" objects=\"1\" scenarios=\"1\" formatCells=\"0\"/>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
lxw_protection options = {.format_cells = 1};
|
||||
|
||||
worksheet_protect(worksheet, NULL, &options);
|
||||
_worksheet_write_sheet_protection(worksheet, &worksheet->protection);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
||||
/* 5. Test the _write_sheet_protection() method. */
|
||||
CTEST(worksheet, write_write_sheet_protection05) {
|
||||
char* got;
|
||||
char exp[] = "<sheetProtection sheet=\"1\" objects=\"1\" scenarios=\"1\" formatColumns=\"0\"/>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
lxw_protection options = {.format_columns = 1};
|
||||
|
||||
worksheet_protect(worksheet, NULL, &options);
|
||||
_worksheet_write_sheet_protection(worksheet, &worksheet->protection);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
||||
/* 6. Test the _write_sheet_protection() method. */
|
||||
CTEST(worksheet, write_write_sheet_protection06) {
|
||||
char* got;
|
||||
char exp[] = "<sheetProtection sheet=\"1\" objects=\"1\" scenarios=\"1\" formatRows=\"0\"/>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
lxw_protection options = {.format_rows = 1};
|
||||
|
||||
worksheet_protect(worksheet, NULL, &options);
|
||||
_worksheet_write_sheet_protection(worksheet, &worksheet->protection);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
||||
/* 7. Test the _write_sheet_protection() method. */
|
||||
CTEST(worksheet, write_write_sheet_protection07) {
|
||||
char* got;
|
||||
char exp[] = "<sheetProtection sheet=\"1\" objects=\"1\" scenarios=\"1\" insertColumns=\"0\"/>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
lxw_protection options = {.insert_columns = 1};
|
||||
|
||||
worksheet_protect(worksheet, NULL, &options);
|
||||
_worksheet_write_sheet_protection(worksheet, &worksheet->protection);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
||||
/* 8. Test the _write_sheet_protection() method. */
|
||||
CTEST(worksheet, write_write_sheet_protection08) {
|
||||
char* got;
|
||||
char exp[] = "<sheetProtection sheet=\"1\" objects=\"1\" scenarios=\"1\" insertRows=\"0\"/>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
lxw_protection options = {.insert_rows = 1};
|
||||
|
||||
worksheet_protect(worksheet, NULL, &options);
|
||||
_worksheet_write_sheet_protection(worksheet, &worksheet->protection);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
||||
/* 9. Test the _write_sheet_protection() method. */
|
||||
CTEST(worksheet, write_write_sheet_protection09) {
|
||||
char* got;
|
||||
char exp[] = "<sheetProtection sheet=\"1\" objects=\"1\" scenarios=\"1\" insertHyperlinks=\"0\"/>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
lxw_protection options = {.insert_hyperlinks = 1};
|
||||
|
||||
worksheet_protect(worksheet, NULL, &options);
|
||||
_worksheet_write_sheet_protection(worksheet, &worksheet->protection);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
||||
/* 10. Test the _write_sheet_protection() method. */
|
||||
CTEST(worksheet, write_write_sheet_protection10) {
|
||||
char* got;
|
||||
char exp[] = "<sheetProtection sheet=\"1\" objects=\"1\" scenarios=\"1\" deleteColumns=\"0\"/>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
lxw_protection options = {.delete_columns = 1};
|
||||
|
||||
worksheet_protect(worksheet, NULL, &options);
|
||||
_worksheet_write_sheet_protection(worksheet, &worksheet->protection);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
||||
/* 11. Test the _write_sheet_protection() method. */
|
||||
CTEST(worksheet, write_write_sheet_protection11) {
|
||||
char* got;
|
||||
char exp[] = "<sheetProtection sheet=\"1\" objects=\"1\" scenarios=\"1\" deleteRows=\"0\"/>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
lxw_protection options = {.delete_rows = 1};
|
||||
|
||||
worksheet_protect(worksheet, NULL, &options);
|
||||
_worksheet_write_sheet_protection(worksheet, &worksheet->protection);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
||||
/* 12. Test the _write_sheet_protection() method. */
|
||||
CTEST(worksheet, write_write_sheet_protection12) {
|
||||
char* got;
|
||||
char exp[] = "<sheetProtection sheet=\"1\" objects=\"1\" scenarios=\"1\" sort=\"0\"/>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
lxw_protection options = {.sort = 1};
|
||||
|
||||
worksheet_protect(worksheet, NULL, &options);
|
||||
_worksheet_write_sheet_protection(worksheet, &worksheet->protection);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
||||
/* 13. Test the _write_sheet_protection() method. */
|
||||
CTEST(worksheet, write_write_sheet_protection13) {
|
||||
char* got;
|
||||
char exp[] = "<sheetProtection sheet=\"1\" objects=\"1\" scenarios=\"1\" autoFilter=\"0\"/>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
lxw_protection options = {.autofilter = 1};
|
||||
|
||||
worksheet_protect(worksheet, NULL, &options);
|
||||
_worksheet_write_sheet_protection(worksheet, &worksheet->protection);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
||||
/* 14. Test the _write_sheet_protection() method. */
|
||||
CTEST(worksheet, write_write_sheet_protection14) {
|
||||
char* got;
|
||||
char exp[] = "<sheetProtection sheet=\"1\" objects=\"1\" scenarios=\"1\" pivotTables=\"0\"/>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
lxw_protection options = {.pivot_tables = 1};
|
||||
|
||||
worksheet_protect(worksheet, NULL, &options);
|
||||
_worksheet_write_sheet_protection(worksheet, &worksheet->protection);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
||||
/* 15. Test the _write_sheet_protection() method. */
|
||||
CTEST(worksheet, write_write_sheet_protection15) {
|
||||
char* got;
|
||||
char exp[] = "<sheetProtection sheet=\"1\" scenarios=\"1\"/>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
lxw_protection options = {.objects = 1};
|
||||
|
||||
worksheet_protect(worksheet, NULL, &options);
|
||||
_worksheet_write_sheet_protection(worksheet, &worksheet->protection);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
||||
/* 16. Test the _write_sheet_protection() method. */
|
||||
CTEST(worksheet, write_write_sheet_protection16) {
|
||||
char* got;
|
||||
char exp[] = "<sheetProtection sheet=\"1\" objects=\"1\"/>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
lxw_protection options = {.scenarios = 1};
|
||||
|
||||
worksheet_protect(worksheet, NULL, &options);
|
||||
_worksheet_write_sheet_protection(worksheet, &worksheet->protection);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
||||
/* 17. Test the _write_sheet_protection() method. */
|
||||
CTEST(worksheet, write_write_sheet_protection17) {
|
||||
char* got;
|
||||
char exp[] = "<sheetProtection sheet=\"1\" objects=\"1\" scenarios=\"1\" formatCells=\"0\" selectLockedCells=\"1\" selectUnlockedCells=\"1\"/>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
lxw_protection options = {
|
||||
.format_cells = 1,
|
||||
.no_select_locked_cells = 1,
|
||||
.no_select_unlocked_cells = 1,
|
||||
};
|
||||
|
||||
worksheet_protect(worksheet, NULL, &options);
|
||||
_worksheet_write_sheet_protection(worksheet, &worksheet->protection);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
||||
/* 18. Test the _write_sheet_protection() method. */
|
||||
CTEST(worksheet, write_write_sheet_protection18) {
|
||||
char* got;
|
||||
char exp[] = "<sheetProtection password=\"996B\" sheet=\"1\" formatCells=\"0\" formatColumns=\"0\" formatRows=\"0\" insertColumns=\"0\" insertRows=\"0\" insertHyperlinks=\"0\" deleteColumns=\"0\" deleteRows=\"0\" selectLockedCells=\"1\" sort=\"0\" autoFilter=\"0\" pivotTables=\"0\" selectUnlockedCells=\"1\"/>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
lxw_protection options = {
|
||||
.objects = 1,
|
||||
.scenarios = 1,
|
||||
.format_cells = 1,
|
||||
.format_columns = 1,
|
||||
.format_rows = 1,
|
||||
.insert_columns = 1,
|
||||
.insert_rows = 1,
|
||||
.insert_hyperlinks = 1,
|
||||
.delete_columns = 1,
|
||||
.delete_rows = 1,
|
||||
.no_select_locked_cells = 1,
|
||||
.sort = 1,
|
||||
.autofilter = 1,
|
||||
.pivot_tables = 1,
|
||||
.no_select_unlocked_cells = 1,
|
||||
};
|
||||
|
||||
worksheet_protect(worksheet, "drowssap", &options);
|
||||
_worksheet_write_sheet_protection(worksheet, &worksheet->protection);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Tests for the lib_xlsx_writer library.
|
||||
*
|
||||
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
|
||||
*
|
||||
*/
|
||||
|
||||
#include "../ctest.h"
|
||||
#include "../helper.h"
|
||||
|
||||
#include "../../../include/xlsxwriter/worksheet.h"
|
||||
|
||||
// Test the _write_sheet_view() function.
|
||||
CTEST(worksheet, write_sheet_view1) {
|
||||
|
||||
char* got;
|
||||
char exp[] = "<sheetView tabSelected=\"1\" workbookViewId=\"0\"/>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
worksheet_select(worksheet);
|
||||
|
||||
_worksheet_write_sheet_view(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
// Test the _write_sheet_view() function.
|
||||
CTEST(worksheet, write_sheet_view2) {
|
||||
|
||||
char* got;
|
||||
char exp[] = "<sheetView showGridLines=\"0\" tabSelected=\"1\" workbookViewId=\"0\"/>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
worksheet_select(worksheet);
|
||||
|
||||
worksheet_gridlines(worksheet, LXW_HIDE_ALL_GRIDLINES);
|
||||
|
||||
_worksheet_write_sheet_view(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
||||
|
@ -0,0 +1,124 @@
|
||||
/*
|
||||
* Tests for the lib_xlsx_writer library.
|
||||
*
|
||||
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
|
||||
*
|
||||
*/
|
||||
|
||||
#include "../ctest.h"
|
||||
#include "../helper.h"
|
||||
|
||||
#include "../../../include/xlsxwriter/worksheet.h"
|
||||
|
||||
|
||||
/* 1. Test the _write_sheet_views() method. */
|
||||
CTEST(worksheet, write_sheet_views01) {
|
||||
char* got;
|
||||
char exp[] = "<sheetViews><sheetView tabSelected=\"1\" workbookViewId=\"0\"/></sheetViews>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_select(worksheet);
|
||||
_worksheet_write_sheet_views(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
||||
/* 2. Test the _write_sheet_views() method. */
|
||||
CTEST(worksheet, write_sheet_views02) {
|
||||
char* got;
|
||||
char exp[] = "<sheetViews><sheetView tabSelected=\"1\" workbookViewId=\"0\"/></sheetViews>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_select(worksheet);
|
||||
worksheet_set_zoom(worksheet, 100);
|
||||
_worksheet_write_sheet_views(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
||||
/* 3. Test the _write_sheet_views() method. With zoom. */
|
||||
CTEST(worksheet, write_sheet_views03) {
|
||||
char* got;
|
||||
char exp[] = "<sheetViews><sheetView tabSelected=\"1\" zoomScale=\"200\" zoomScaleNormal=\"200\" workbookViewId=\"0\"/></sheetViews>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_select(worksheet);
|
||||
worksheet_set_zoom(worksheet, 200);
|
||||
_worksheet_write_sheet_views(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
||||
/* 4. Test the _write_sheet_views() method. Right to left. */
|
||||
CTEST(worksheet, write_sheet_views04) {
|
||||
char* got;
|
||||
char exp[] = "<sheetViews><sheetView rightToLeft=\"1\" tabSelected=\"1\" workbookViewId=\"0\"/></sheetViews>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_select(worksheet);
|
||||
worksheet_right_to_left(worksheet);
|
||||
_worksheet_write_sheet_views(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
||||
/* 5. Test the _write_sheet_views() method. Hide zeroes. */
|
||||
CTEST(worksheet, write_sheet_views05) {
|
||||
char* got;
|
||||
char exp[] = "<sheetViews><sheetView showZeros=\"0\" tabSelected=\"1\" workbookViewId=\"0\"/></sheetViews>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_select(worksheet);
|
||||
worksheet_hide_zero(worksheet);
|
||||
_worksheet_write_sheet_views(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
||||
/* 6. Test the _write_sheet_views() method. Set page view mode. */
|
||||
CTEST(worksheet, write_sheet_views06) {
|
||||
char* got;
|
||||
char exp[] = "<sheetViews><sheetView tabSelected=\"1\" view=\"pageLayout\" workbookViewId=\"0\"/></sheetViews>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_select(worksheet);
|
||||
worksheet_set_page_view(worksheet);
|
||||
_worksheet_write_sheet_views(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
@ -0,0 +1,105 @@
|
||||
/*
|
||||
* Tests for the lib_xlsx_writer library.
|
||||
*
|
||||
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
|
||||
*
|
||||
*/
|
||||
|
||||
#include "../ctest.h"
|
||||
#include "../helper.h"
|
||||
|
||||
#include "../../../include/xlsxwriter/worksheet.h"
|
||||
|
||||
/* 1. Test the _write_sheet_views() method with freeze panes. */
|
||||
CTEST(worksheet, write_freeze_panes01) {
|
||||
char* got;
|
||||
char exp[] = "<sheetViews><sheetView tabSelected=\"1\" workbookViewId=\"0\"><pane ySplit=\"1\" topLeftCell=\"A2\" activePane=\"bottomLeft\" state=\"frozen\"/><selection pane=\"bottomLeft\"/></sheetView></sheetViews>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_select(worksheet);
|
||||
worksheet_freeze_panes(worksheet, 1, 0);
|
||||
_worksheet_write_sheet_views(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
||||
/* 2. Test the _write_sheet_views() method with freeze panes. */
|
||||
CTEST(worksheet, write_freeze_panes02) {
|
||||
char* got;
|
||||
char exp[] = "<sheetViews><sheetView tabSelected=\"1\" workbookViewId=\"0\"><pane xSplit=\"1\" topLeftCell=\"B1\" activePane=\"topRight\" state=\"frozen\"/><selection pane=\"topRight\"/></sheetView></sheetViews>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_select(worksheet);
|
||||
worksheet_freeze_panes(worksheet, 0, 1);
|
||||
_worksheet_write_sheet_views(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
||||
/* 3. Test the _write_sheet_views() method with freeze panes. */
|
||||
CTEST(worksheet, write_freeze_panes03) {
|
||||
char* got;
|
||||
char exp[] = "<sheetViews><sheetView tabSelected=\"1\" workbookViewId=\"0\"><pane xSplit=\"1\" ySplit=\"1\" topLeftCell=\"B2\" activePane=\"bottomRight\" state=\"frozen\"/><selection pane=\"topRight\" activeCell=\"B1\" sqref=\"B1\"/><selection pane=\"bottomLeft\" activeCell=\"A2\" sqref=\"A2\"/><selection pane=\"bottomRight\"/></sheetView></sheetViews>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_select(worksheet);
|
||||
worksheet_freeze_panes(worksheet, 1, 1);
|
||||
_worksheet_write_sheet_views(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
||||
/* 4. Test the _write_sheet_views() method with freeze panes. */
|
||||
CTEST(worksheet, write_freeze_panes04) {
|
||||
char* got;
|
||||
char exp[] = "<sheetViews><sheetView tabSelected=\"1\" workbookViewId=\"0\"><pane xSplit=\"6\" ySplit=\"3\" topLeftCell=\"G4\" activePane=\"bottomRight\" state=\"frozen\"/><selection pane=\"topRight\" activeCell=\"G1\" sqref=\"G1\"/><selection pane=\"bottomLeft\" activeCell=\"A4\" sqref=\"A4\"/><selection pane=\"bottomRight\"/></sheetView></sheetViews>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_select(worksheet);
|
||||
worksheet_freeze_panes(worksheet, CELL("G4"));
|
||||
_worksheet_write_sheet_views(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
||||
/* 5. Test the _write_sheet_views() method with freeze panes. */
|
||||
CTEST(worksheet, write_freeze_panes05) {
|
||||
char* got;
|
||||
char exp[] = "<sheetViews><sheetView tabSelected=\"1\" workbookViewId=\"0\"><pane xSplit=\"6\" ySplit=\"3\" topLeftCell=\"G4\" activePane=\"bottomRight\" state=\"frozenSplit\"/><selection pane=\"topRight\" activeCell=\"G1\" sqref=\"G1\"/><selection pane=\"bottomLeft\" activeCell=\"A4\" sqref=\"A4\"/><selection pane=\"bottomRight\"/></sheetView></sheetViews>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_select(worksheet);
|
||||
worksheet_freeze_panes_opt(worksheet, 3, 6, 3, 6, 1);
|
||||
_worksheet_write_sheet_views(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
@ -0,0 +1,162 @@
|
||||
/*
|
||||
* Tests for the lib_xlsx_writer library.
|
||||
*
|
||||
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
|
||||
*
|
||||
*/
|
||||
|
||||
#include "../ctest.h"
|
||||
#include "../helper.h"
|
||||
|
||||
#include "../../../include/xlsxwriter/worksheet.h"
|
||||
|
||||
/* 1. Test the _write_sheet_views() method with split panes. */
|
||||
CTEST(worksheet, write_split_panes01) {
|
||||
char* got;
|
||||
char exp[] = "<sheetViews><sheetView tabSelected=\"1\" workbookViewId=\"0\"><pane ySplit=\"600\" topLeftCell=\"A2\"/><selection pane=\"bottomLeft\" activeCell=\"A2\" sqref=\"A2\"/></sheetView></sheetViews>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_select(worksheet);
|
||||
worksheet_split_panes(worksheet, 15, 0);
|
||||
_worksheet_write_sheet_views(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
||||
/* 2. Test the _write_sheet_views() method with split panes. */
|
||||
CTEST(worksheet, write_split_panes02) {
|
||||
char* got;
|
||||
char exp[] = "<sheetViews><sheetView tabSelected=\"1\" workbookViewId=\"0\"><pane ySplit=\"900\" topLeftCell=\"A3\"/><selection pane=\"bottomLeft\" activeCell=\"A3\" sqref=\"A3\"/></sheetView></sheetViews>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_select(worksheet);
|
||||
worksheet_split_panes(worksheet, 30, 0);
|
||||
_worksheet_write_sheet_views(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
||||
/* 3. Test the _write_sheet_views() method with split panes. */
|
||||
CTEST(worksheet, write_split_panes03) {
|
||||
char* got;
|
||||
char exp[] = "<sheetViews><sheetView tabSelected=\"1\" workbookViewId=\"0\"><pane ySplit=\"2400\" topLeftCell=\"A8\"/><selection pane=\"bottomLeft\" activeCell=\"A8\" sqref=\"A8\"/></sheetView></sheetViews>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_select(worksheet);
|
||||
worksheet_split_panes(worksheet, 105, 0);
|
||||
_worksheet_write_sheet_views(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
||||
/* 4. Test the _write_sheet_views() method with split panes. */
|
||||
CTEST(worksheet, write_split_panes04) {
|
||||
char* got;
|
||||
char exp[] = "<sheetViews><sheetView tabSelected=\"1\" workbookViewId=\"0\"><pane xSplit=\"1350\" topLeftCell=\"B1\"/><selection pane=\"topRight\" activeCell=\"B1\" sqref=\"B1\"/></sheetView></sheetViews>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_select(worksheet);
|
||||
worksheet_split_panes(worksheet, 0, 8.43);
|
||||
_worksheet_write_sheet_views(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
||||
/* 5. Test the _write_sheet_views() method with split panes. */
|
||||
CTEST(worksheet, write_split_panes05) {
|
||||
char* got;
|
||||
char exp[] = "<sheetViews><sheetView tabSelected=\"1\" workbookViewId=\"0\"><pane xSplit=\"2310\" topLeftCell=\"C1\"/><selection pane=\"topRight\" activeCell=\"C1\" sqref=\"C1\"/></sheetView></sheetViews>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_select(worksheet);
|
||||
worksheet_split_panes(worksheet, 0, 17.57);
|
||||
_worksheet_write_sheet_views(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
||||
/* 6. Test the _write_sheet_views() method with split panes. */
|
||||
CTEST(worksheet, write_split_panes06) {
|
||||
char* got;
|
||||
char exp[] = "<sheetViews><sheetView tabSelected=\"1\" workbookViewId=\"0\"><pane xSplit=\"5190\" topLeftCell=\"F1\"/><selection pane=\"topRight\" activeCell=\"F1\" sqref=\"F1\"/></sheetView></sheetViews>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_select(worksheet);
|
||||
worksheet_split_panes(worksheet, 0, 45 );
|
||||
_worksheet_write_sheet_views(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
||||
/* 7. Test the _write_sheet_views() method with split panes. */
|
||||
CTEST(worksheet, write_split_panes07) {
|
||||
char* got;
|
||||
char exp[] = "<sheetViews><sheetView tabSelected=\"1\" workbookViewId=\"0\"><pane xSplit=\"1350\" ySplit=\"600\" topLeftCell=\"B2\"/><selection pane=\"topRight\" activeCell=\"B1\" sqref=\"B1\"/><selection pane=\"bottomLeft\" activeCell=\"A2\" sqref=\"A2\"/><selection pane=\"bottomRight\" activeCell=\"B2\" sqref=\"B2\"/></sheetView></sheetViews>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_select(worksheet);
|
||||
worksheet_split_panes(worksheet, 15, 8.43);
|
||||
_worksheet_write_sheet_views(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
||||
/* 8. Test the _write_sheet_views() method with split panes. */
|
||||
CTEST(worksheet, write_split_panes08) {
|
||||
char* got;
|
||||
char exp[] = "<sheetViews><sheetView tabSelected=\"1\" workbookViewId=\"0\"><pane xSplit=\"6150\" ySplit=\"1200\" topLeftCell=\"G4\"/><selection pane=\"topRight\" activeCell=\"G1\" sqref=\"G1\"/><selection pane=\"bottomLeft\" activeCell=\"A4\" sqref=\"A4\"/><selection pane=\"bottomRight\" activeCell=\"G4\" sqref=\"G4\"/></sheetView></sheetViews>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_select(worksheet);
|
||||
worksheet_split_panes(worksheet, 45, 54.14);
|
||||
_worksheet_write_sheet_views(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
@ -0,0 +1,162 @@
|
||||
/*
|
||||
* Tests for the lib_xlsx_writer library.
|
||||
*
|
||||
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
|
||||
*
|
||||
*/
|
||||
|
||||
#include "../ctest.h"
|
||||
#include "../helper.h"
|
||||
|
||||
#include "../../../include/xlsxwriter/worksheet.h"
|
||||
|
||||
/* 1. Test the _write_sheet_views() method with split panes. */
|
||||
CTEST(worksheet, write_split_panes_opt01) {
|
||||
char* got;
|
||||
char exp[] = "<sheetViews><sheetView tabSelected=\"1\" workbookViewId=\"0\"><pane ySplit=\"600\" topLeftCell=\"A2\"/><selection pane=\"bottomLeft\" activeCell=\"A2\" sqref=\"A2\"/></sheetView></sheetViews>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_select(worksheet);
|
||||
worksheet_split_panes_opt(worksheet, 15, 0, 1, 0);
|
||||
_worksheet_write_sheet_views(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
||||
/* 2. Test the _write_sheet_views() method with split panes. */
|
||||
CTEST(worksheet, write_split_panes_opt02) {
|
||||
char* got;
|
||||
char exp[] = "<sheetViews><sheetView tabSelected=\"1\" workbookViewId=\"0\"><pane ySplit=\"900\" topLeftCell=\"A3\"/><selection pane=\"bottomLeft\" activeCell=\"A3\" sqref=\"A3\"/></sheetView></sheetViews>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_select(worksheet);
|
||||
worksheet_split_panes_opt(worksheet, 30, 0, 2, 0);
|
||||
_worksheet_write_sheet_views(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
||||
/* 3. Test the _write_sheet_views() method with split panes. */
|
||||
CTEST(worksheet, write_split_panes_opt03) {
|
||||
char* got;
|
||||
char exp[] = "<sheetViews><sheetView tabSelected=\"1\" workbookViewId=\"0\"><pane ySplit=\"2400\" topLeftCell=\"A8\"/><selection pane=\"bottomLeft\" activeCell=\"A8\" sqref=\"A8\"/></sheetView></sheetViews>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_select(worksheet);
|
||||
worksheet_split_panes_opt(worksheet, 105, 0, 7, 0);
|
||||
_worksheet_write_sheet_views(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
||||
/* 4. Test the _write_sheet_views() method with split panes. */
|
||||
CTEST(worksheet, write_split_panes_opt04) {
|
||||
char* got;
|
||||
char exp[] = "<sheetViews><sheetView tabSelected=\"1\" workbookViewId=\"0\"><pane xSplit=\"1350\" topLeftCell=\"B1\"/><selection pane=\"topRight\" activeCell=\"B1\" sqref=\"B1\"/></sheetView></sheetViews>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_select(worksheet);
|
||||
worksheet_split_panes_opt(worksheet, 0, 8.43, 0, 1);
|
||||
_worksheet_write_sheet_views(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
||||
/* 5. Test the _write_sheet_views() method with split panes. */
|
||||
CTEST(worksheet, write_split_panes_opt05) {
|
||||
char* got;
|
||||
char exp[] = "<sheetViews><sheetView tabSelected=\"1\" workbookViewId=\"0\"><pane xSplit=\"2310\" topLeftCell=\"C1\"/><selection pane=\"topRight\" activeCell=\"C1\" sqref=\"C1\"/></sheetView></sheetViews>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_select(worksheet);
|
||||
worksheet_split_panes_opt(worksheet, 0, 17.57, 0, 2);
|
||||
_worksheet_write_sheet_views(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
||||
/* 6. Test the _write_sheet_views() method with split panes. */
|
||||
CTEST(worksheet, write_split_panes_opt06) {
|
||||
char* got;
|
||||
char exp[] = "<sheetViews><sheetView tabSelected=\"1\" workbookViewId=\"0\"><pane xSplit=\"5190\" topLeftCell=\"F1\"/><selection pane=\"topRight\" activeCell=\"F1\" sqref=\"F1\"/></sheetView></sheetViews>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_select(worksheet);
|
||||
worksheet_split_panes_opt(worksheet, 0, 45, 0, 5);
|
||||
_worksheet_write_sheet_views(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
||||
/* 7. Test the _write_sheet_views() method with split panes. */
|
||||
CTEST(worksheet, write_split_panes_opt07) {
|
||||
char* got;
|
||||
char exp[] = "<sheetViews><sheetView tabSelected=\"1\" workbookViewId=\"0\"><pane xSplit=\"1350\" ySplit=\"600\" topLeftCell=\"B2\"/><selection pane=\"topRight\" activeCell=\"B1\" sqref=\"B1\"/><selection pane=\"bottomLeft\" activeCell=\"A2\" sqref=\"A2\"/><selection pane=\"bottomRight\" activeCell=\"B2\" sqref=\"B2\"/></sheetView></sheetViews>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_select(worksheet);
|
||||
worksheet_split_panes_opt(worksheet, 15, 8.43, 1, 1);
|
||||
_worksheet_write_sheet_views(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
||||
/* 8. Test the _write_sheet_views() method with split panes. */
|
||||
CTEST(worksheet, write_split_panes_opt08) {
|
||||
char* got;
|
||||
char exp[] = "<sheetViews><sheetView tabSelected=\"1\" workbookViewId=\"0\"><pane xSplit=\"6150\" ySplit=\"1200\" topLeftCell=\"G4\"/><selection pane=\"topRight\" activeCell=\"G1\" sqref=\"G1\"/><selection pane=\"bottomLeft\" activeCell=\"A4\" sqref=\"A4\"/><selection pane=\"bottomRight\" activeCell=\"G4\" sqref=\"G4\"/></sheetView></sheetViews>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_select(worksheet);
|
||||
worksheet_split_panes_opt(worksheet, 45, 54.14, 3, 6);
|
||||
_worksheet_write_sheet_views(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
@ -0,0 +1,143 @@
|
||||
/*
|
||||
* Tests for the lib_xlsx_writer library.
|
||||
*
|
||||
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
|
||||
*
|
||||
*/
|
||||
|
||||
#include "../ctest.h"
|
||||
#include "../helper.h"
|
||||
|
||||
#include "../../../include/xlsxwriter/worksheet.h"
|
||||
|
||||
/* 1. Test the _write_sheet_views() method with selection set. */
|
||||
CTEST(worksheet, set_selection01) {
|
||||
char* got;
|
||||
char exp[] = "<sheetViews><sheetView tabSelected=\"1\" workbookViewId=\"0\"/></sheetViews>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_select(worksheet);
|
||||
worksheet_set_selection(worksheet, 0, 0, 0, 0);
|
||||
_worksheet_write_sheet_views(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
||||
/* 2. Test the _write_sheet_views() method with selection set. */
|
||||
CTEST(worksheet, set_selection02) {
|
||||
char* got;
|
||||
char exp[] = "<sheetViews><sheetView tabSelected=\"1\" workbookViewId=\"0\"><selection activeCell=\"A2\" sqref=\"A2\"/></sheetView></sheetViews>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_select(worksheet);
|
||||
worksheet_set_selection(worksheet, 1, 0, 1, 0);
|
||||
_worksheet_write_sheet_views(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
||||
/* 3. Test the _write_sheet_views() method with selection set. */
|
||||
CTEST(worksheet, set_selection03) {
|
||||
char* got;
|
||||
char exp[] = "<sheetViews><sheetView tabSelected=\"1\" workbookViewId=\"0\"><selection activeCell=\"B1\" sqref=\"B1\"/></sheetView></sheetViews>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_select(worksheet);
|
||||
worksheet_set_selection(worksheet, RANGE("B1:B1"));
|
||||
_worksheet_write_sheet_views(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
||||
/* 4. Test the _write_sheet_views() method with selection set. */
|
||||
CTEST(worksheet, set_selection04) {
|
||||
char* got;
|
||||
char exp[] = "<sheetViews><sheetView tabSelected=\"1\" workbookViewId=\"0\"><selection activeCell=\"D3\" sqref=\"D3\"/></sheetView></sheetViews>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_select(worksheet);
|
||||
worksheet_set_selection(worksheet, RANGE("D3:D3"));
|
||||
_worksheet_write_sheet_views(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
||||
/* 5. Test the _write_sheet_views() method with selection set. */
|
||||
CTEST(worksheet, set_selection05) {
|
||||
char* got;
|
||||
char exp[] = "<sheetViews><sheetView tabSelected=\"1\" workbookViewId=\"0\"><selection activeCell=\"D3\" sqref=\"D3:F4\"/></sheetView></sheetViews>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_select(worksheet);
|
||||
worksheet_set_selection(worksheet, RANGE("D3:F4"));
|
||||
_worksheet_write_sheet_views(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
||||
/* 6. Test the _write_sheet_views() method with selection set. */
|
||||
CTEST(worksheet, set_selection06) {
|
||||
char* got;
|
||||
char exp[] = "<sheetViews><sheetView tabSelected=\"1\" workbookViewId=\"0\"><selection activeCell=\"F4\" sqref=\"D3:F4\"/></sheetView></sheetViews>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_select(worksheet);
|
||||
worksheet_set_selection(worksheet, RANGE("F4:D3"));
|
||||
_worksheet_write_sheet_views(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
||||
/* 7. Test the _write_sheet_views() method with selection set. */
|
||||
CTEST(worksheet, set_selection07) {
|
||||
char* got;
|
||||
char exp[] = "<sheetViews><sheetView tabSelected=\"1\" workbookViewId=\"0\"><selection activeCell=\"A2\" sqref=\"A2\"/></sheetView></sheetViews>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_select(worksheet);
|
||||
worksheet_set_selection(worksheet, RANGE("A2:A2"));
|
||||
_worksheet_write_sheet_views(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Tests for the lib_xlsx_writer library.
|
||||
*
|
||||
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
|
||||
*
|
||||
*/
|
||||
|
||||
#include "../ctest.h"
|
||||
#include "../helper.h"
|
||||
|
||||
#include "../../../include/xlsxwriter/worksheet.h"
|
||||
|
||||
/* 1. Test the _write_sheet_views() method with freeze panes + selection. */
|
||||
CTEST(worksheet, set_selection11) {
|
||||
char* got;
|
||||
char exp[] = "<sheetViews><sheetView tabSelected=\"1\" workbookViewId=\"0\"><pane ySplit=\"1\" topLeftCell=\"A2\" activePane=\"bottomLeft\" state=\"frozen\"/><selection pane=\"bottomLeft\" activeCell=\"A2\" sqref=\"A2\"/></sheetView></sheetViews>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_select(worksheet);
|
||||
worksheet_set_selection(worksheet, RANGE("A2:A2"));
|
||||
worksheet_freeze_panes(worksheet, 1, 0);
|
||||
_worksheet_write_sheet_views(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
||||
/* 2. Test the _write_sheet_views() method with freeze panes + selection. */
|
||||
CTEST(worksheet, set_selection12) {
|
||||
char* got;
|
||||
char exp[] = "<sheetViews><sheetView tabSelected=\"1\" workbookViewId=\"0\"><pane xSplit=\"1\" topLeftCell=\"B1\" activePane=\"topRight\" state=\"frozen\"/><selection pane=\"topRight\" activeCell=\"B1\" sqref=\"B1\"/></sheetView></sheetViews>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_select(worksheet);
|
||||
worksheet_set_selection(worksheet, RANGE("B1:B1"));
|
||||
worksheet_freeze_panes(worksheet, 0, 1);
|
||||
_worksheet_write_sheet_views(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
||||
/* 3. Test the _write_sheet_views() method with freeze panes + selection. */
|
||||
CTEST(worksheet, set_selection13) {
|
||||
char* got;
|
||||
char exp[] = "<sheetViews><sheetView tabSelected=\"1\" workbookViewId=\"0\"><pane xSplit=\"6\" ySplit=\"3\" topLeftCell=\"G4\" activePane=\"bottomRight\" state=\"frozen\"/><selection pane=\"topRight\" activeCell=\"G1\" sqref=\"G1\"/><selection pane=\"bottomLeft\" activeCell=\"A4\" sqref=\"A4\"/><selection pane=\"bottomRight\" activeCell=\"G4\" sqref=\"G4\"/></sheetView></sheetViews>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_select(worksheet);
|
||||
worksheet_set_selection(worksheet, RANGE("G4:G4"));
|
||||
worksheet_freeze_panes(worksheet, CELL("G4"));
|
||||
_worksheet_write_sheet_views(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
||||
/* 4. Test the _write_sheet_views() method with freeze panes + selection. */
|
||||
CTEST(worksheet, set_selection14) {
|
||||
char* got;
|
||||
char exp[] = "<sheetViews><sheetView tabSelected=\"1\" workbookViewId=\"0\"><pane xSplit=\"6\" ySplit=\"3\" topLeftCell=\"G4\" activePane=\"bottomRight\" state=\"frozen\"/><selection pane=\"topRight\" activeCell=\"G1\" sqref=\"G1\"/><selection pane=\"bottomLeft\" activeCell=\"A4\" sqref=\"A4\"/><selection pane=\"bottomRight\" activeCell=\"I5\" sqref=\"I5\"/></sheetView></sheetViews>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_select(worksheet);
|
||||
worksheet_set_selection(worksheet, RANGE("I5:I5"));
|
||||
worksheet_freeze_panes(worksheet, CELL("G4"));
|
||||
_worksheet_write_sheet_views(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
@ -0,0 +1,131 @@
|
||||
/*
|
||||
* Tests for the lib_xlsx_writer library.
|
||||
*
|
||||
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
|
||||
*
|
||||
*/
|
||||
|
||||
#include "../ctest.h"
|
||||
#include "../helper.h"
|
||||
|
||||
#include "../../../include/xlsxwriter/worksheet.h"
|
||||
|
||||
|
||||
/* 1. Test the _write_sheet_views() method with freeze panes. */
|
||||
CTEST(worksheet, set_selection21) {
|
||||
char* got;
|
||||
char exp[] = "<sheetViews><sheetView tabSelected=\"1\" workbookViewId=\"0\"><pane ySplit=\"1\" topLeftCell=\"A21\" activePane=\"bottomLeft\" state=\"frozen\"/><selection pane=\"bottomLeft\" activeCell=\"A2\" sqref=\"A2\"/></sheetView></sheetViews>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_select(worksheet);
|
||||
worksheet_set_selection(worksheet, RANGE("A2:A2"));
|
||||
worksheet_freeze_panes_opt(worksheet, 1, 0, 20, 0, 0);
|
||||
_worksheet_write_sheet_views(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
||||
/* 2. Test the _write_sheet_views() method with freeze panes. */
|
||||
CTEST(worksheet, set_selection22) {
|
||||
char* got;
|
||||
char exp[] = "<sheetViews><sheetView tabSelected=\"1\" workbookViewId=\"0\"><pane ySplit=\"1\" topLeftCell=\"A21\" activePane=\"bottomLeft\" state=\"frozen\"/><selection pane=\"bottomLeft\"/></sheetView></sheetViews>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_select(worksheet);
|
||||
worksheet_set_selection(worksheet, RANGE("A1:A1"));
|
||||
worksheet_freeze_panes_opt(worksheet, 1, 0, 20, 0, 0);
|
||||
_worksheet_write_sheet_views(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
||||
/* 3. Test the _write_sheet_views() method with freeze panes. */
|
||||
CTEST(worksheet, set_selection23) {
|
||||
char* got;
|
||||
char exp[] = "<sheetViews><sheetView tabSelected=\"1\" workbookViewId=\"0\"><pane xSplit=\"1\" topLeftCell=\"E1\" activePane=\"topRight\" state=\"frozen\"/><selection pane=\"topRight\" activeCell=\"B1\" sqref=\"B1\"/></sheetView></sheetViews>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_select(worksheet);
|
||||
worksheet_set_selection(worksheet, RANGE("B1:B1"));
|
||||
worksheet_freeze_panes_opt(worksheet, 0, 1, 0, 4, 0);
|
||||
_worksheet_write_sheet_views(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
||||
/* 4. Test the _write_sheet_views() method with freeze panes. */
|
||||
CTEST(worksheet, set_selection24) {
|
||||
char* got;
|
||||
char exp[] = "<sheetViews><sheetView tabSelected=\"1\" workbookViewId=\"0\"><pane xSplit=\"1\" topLeftCell=\"E1\" activePane=\"topRight\" state=\"frozen\"/><selection pane=\"topRight\"/></sheetView></sheetViews>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_select(worksheet);
|
||||
worksheet_set_selection(worksheet, RANGE("A1:A1"));
|
||||
worksheet_freeze_panes_opt(worksheet, 0, 1, 0, 4, 0);
|
||||
_worksheet_write_sheet_views(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
||||
/* 5. Test the _write_sheet_views() method with freeze panes. */
|
||||
CTEST(worksheet, set_selection25) {
|
||||
char* got;
|
||||
char exp[] = "<sheetViews><sheetView tabSelected=\"1\" workbookViewId=\"0\"><pane xSplit=\"6\" ySplit=\"3\" topLeftCell=\"I7\" activePane=\"bottomRight\" state=\"frozen\"/><selection pane=\"topRight\" activeCell=\"G1\" sqref=\"G1\"/><selection pane=\"bottomLeft\" activeCell=\"A4\" sqref=\"A4\"/><selection pane=\"bottomRight\" activeCell=\"G4\" sqref=\"G4\"/></sheetView></sheetViews>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_select(worksheet);
|
||||
worksheet_set_selection(worksheet, RANGE("G4:G4"));
|
||||
worksheet_freeze_panes_opt(worksheet, 3, 6, 6, 8, 0);
|
||||
_worksheet_write_sheet_views(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
||||
/* 6. Test the _write_sheet_views() method with freeze panes. */
|
||||
CTEST(worksheet, set_selection26) {
|
||||
char* got;
|
||||
char exp[] = "<sheetViews><sheetView tabSelected=\"1\" workbookViewId=\"0\"><pane xSplit=\"6\" ySplit=\"3\" topLeftCell=\"I7\" activePane=\"bottomRight\" state=\"frozen\"/><selection pane=\"topRight\" activeCell=\"G1\" sqref=\"G1\"/><selection pane=\"bottomLeft\" activeCell=\"A4\" sqref=\"A4\"/><selection pane=\"bottomRight\"/></sheetView></sheetViews>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_select(worksheet);
|
||||
worksheet_set_selection(worksheet, RANGE("A1:A1"));
|
||||
worksheet_freeze_panes_opt(worksheet, 3, 6, 6, 8, 0);
|
||||
_worksheet_write_sheet_views(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Tests for the lib_xlsx_writer library.
|
||||
*
|
||||
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
|
||||
*
|
||||
*/
|
||||
|
||||
#include "../ctest.h"
|
||||
#include "../helper.h"
|
||||
|
||||
#include "../../../include/xlsxwriter/worksheet.h"
|
||||
|
||||
/* 1. Test the _write_sheet_views() method with split panes + selection. */
|
||||
CTEST(worksheet, set_selection31) {
|
||||
char* got;
|
||||
char exp[] = "<sheetViews><sheetView tabSelected=\"1\" workbookViewId=\"0\"><pane ySplit=\"600\" topLeftCell=\"A2\" activePane=\"bottomLeft\"/><selection pane=\"bottomLeft\" activeCell=\"A2\" sqref=\"A2\"/></sheetView></sheetViews>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_select(worksheet);
|
||||
worksheet_set_selection(worksheet, RANGE("A2:A2"));
|
||||
worksheet_split_panes(worksheet, 15, 0);
|
||||
_worksheet_write_sheet_views(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
||||
/* 2. Test the _write_sheet_views() method with split panes + selection. */
|
||||
CTEST(worksheet, set_selection32) {
|
||||
char* got;
|
||||
char exp[] = "<sheetViews><sheetView tabSelected=\"1\" workbookViewId=\"0\"><pane xSplit=\"1350\" topLeftCell=\"B1\" activePane=\"topRight\"/><selection pane=\"topRight\" activeCell=\"B1\" sqref=\"B1\"/></sheetView></sheetViews>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_select(worksheet);
|
||||
worksheet_set_selection(worksheet, RANGE("B1:B1"));
|
||||
worksheet_split_panes(worksheet, 0, 8.43);
|
||||
_worksheet_write_sheet_views(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
||||
/* 3. Test the _write_sheet_views() method with split panes + selection. */
|
||||
CTEST(worksheet, set_selection33) {
|
||||
char* got;
|
||||
char exp[] = "<sheetViews><sheetView tabSelected=\"1\" workbookViewId=\"0\"><pane xSplit=\"6150\" ySplit=\"1200\" topLeftCell=\"G4\" activePane=\"bottomRight\"/><selection pane=\"topRight\" activeCell=\"G1\" sqref=\"G1\"/><selection pane=\"bottomLeft\" activeCell=\"A4\" sqref=\"A4\"/><selection pane=\"bottomRight\" activeCell=\"G4\" sqref=\"G4\"/></sheetView></sheetViews>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_select(worksheet);
|
||||
worksheet_set_selection(worksheet, RANGE("G4:G4"));
|
||||
worksheet_split_panes(worksheet, 45, 54.14);
|
||||
_worksheet_write_sheet_views(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
||||
/* 4. Test the _write_sheet_views() method with split panes + selection. */
|
||||
CTEST(worksheet, set_selection34) {
|
||||
char* got;
|
||||
char exp[] = "<sheetViews><sheetView tabSelected=\"1\" workbookViewId=\"0\"><pane xSplit=\"6150\" ySplit=\"1200\" topLeftCell=\"G4\" activePane=\"bottomRight\"/><selection pane=\"topRight\" activeCell=\"G1\" sqref=\"G1\"/><selection pane=\"bottomLeft\" activeCell=\"A4\" sqref=\"A4\"/><selection pane=\"bottomRight\" activeCell=\"I5\" sqref=\"I5\"/></sheetView></sheetViews>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_select(worksheet);
|
||||
worksheet_set_selection(worksheet, RANGE("I5:I5"));
|
||||
worksheet_split_panes(worksheet, 45, 54.14);
|
||||
_worksheet_write_sheet_views(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Tests for the lib_xlsx_writer library.
|
||||
*
|
||||
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
|
||||
*
|
||||
*/
|
||||
|
||||
#include "../ctest.h"
|
||||
#include "../helper.h"
|
||||
|
||||
#include "../../../include/xlsxwriter/worksheet.h"
|
||||
|
||||
/* 1. Test the _write_sheet_views() method with split panes + selection. */
|
||||
CTEST(worksheet, set_selection41) {
|
||||
char* got;
|
||||
char exp[] = "<sheetViews><sheetView tabSelected=\"1\" workbookViewId=\"0\"><pane ySplit=\"600\" topLeftCell=\"A21\" activePane=\"bottomLeft\"/><selection pane=\"bottomLeft\" activeCell=\"A2\" sqref=\"A2\"/></sheetView></sheetViews>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_select(worksheet);
|
||||
worksheet_set_selection(worksheet, RANGE("A2:A2"));
|
||||
worksheet_split_panes_opt(worksheet, 15, 0, 20, 0);
|
||||
_worksheet_write_sheet_views(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
||||
/* 2. Test the _write_sheet_views() method with split panes + selection. */
|
||||
CTEST(worksheet, set_selection42) {
|
||||
char* got;
|
||||
char exp[] = "<sheetViews><sheetView tabSelected=\"1\" workbookViewId=\"0\"><pane ySplit=\"600\" topLeftCell=\"A21\" activePane=\"bottomLeft\"/><selection pane=\"bottomLeft\" activeCell=\"A21\" sqref=\"A21\"/></sheetView></sheetViews>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_select(worksheet);
|
||||
worksheet_set_selection(worksheet, RANGE("A21:A21"));
|
||||
worksheet_split_panes_opt(worksheet, 15, 0, 20, 0);
|
||||
_worksheet_write_sheet_views(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
||||
/* 3. Test the _write_sheet_views() method with split panes + selection. */
|
||||
CTEST(worksheet, set_selection43) {
|
||||
char* got;
|
||||
char exp[] = "<sheetViews><sheetView tabSelected=\"1\" workbookViewId=\"0\"><pane xSplit=\"1350\" topLeftCell=\"E1\" activePane=\"topRight\"/><selection pane=\"topRight\" activeCell=\"B1\" sqref=\"B1\"/></sheetView></sheetViews>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_select(worksheet);
|
||||
worksheet_set_selection(worksheet, RANGE("B1:B1"));
|
||||
worksheet_split_panes_opt(worksheet, 0, 8.43, 0, 4);
|
||||
_worksheet_write_sheet_views(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
||||
|
||||
|
||||
/* 4. Test the _write_sheet_views() method with split panes + selection. */
|
||||
CTEST(worksheet, set_selection44) {
|
||||
char* got;
|
||||
char exp[] = "<sheetViews><sheetView tabSelected=\"1\" workbookViewId=\"0\"><pane xSplit=\"1350\" topLeftCell=\"E1\" activePane=\"topRight\"/><selection pane=\"topRight\" activeCell=\"E1\" sqref=\"E1\"/></sheetView></sheetViews>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
worksheet_select(worksheet);
|
||||
worksheet_set_selection(worksheet, RANGE("E1:E1"));
|
||||
worksheet_split_panes_opt(worksheet, 0, 8.43, 0, 4);
|
||||
_worksheet_write_sheet_views(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Tests for the libxlsxwriter library.
|
||||
*
|
||||
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
|
||||
*
|
||||
*/
|
||||
|
||||
#include "../ctest.h"
|
||||
#include "../helper.h"
|
||||
|
||||
#include "../../../include/xlsxwriter/worksheet.h"
|
||||
|
||||
// Test _xml_declaration().
|
||||
CTEST(worksheet, xml_declaration) {
|
||||
|
||||
char* got;
|
||||
char exp[] = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
|
||||
worksheet->file = testfile;
|
||||
|
||||
_worksheet_xml_declaration(worksheet);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_worksheet_free(worksheet);
|
||||
}
|
Reference in New Issue
Block a user