// Test assembling a complete Relationships file. CTEST(relationships, relationships01) { char* got; char exp[] = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" "<Relationships xmlns=\"http://schemas.openxmlformats.org/package/2006/relationships\">" "<Relationship Id=\"rId1\" Type=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet\" Target=\"worksheets/sheet1.xml\"/>" "<Relationship Id=\"rId2\" Type=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme\" Target=\"theme/theme1.xml\"/>" "<Relationship Id=\"rId3\" Type=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles\" Target=\"styles.xml\"/>" "<Relationship Id=\"rId4\" Type=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings\" Target=\"sharedStrings.xml\"/>" "<Relationship Id=\"rId5\" Type=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/calcChain\" Target=\"calcChain.xml\"/>" "</Relationships>"; FILE* testfile = tmpfile(); lxw_relationships *rels = _new_relationships(); rels->file = testfile; _add_document_relationship(rels, "/worksheet", "worksheets/sheet1.xml"); _add_document_relationship(rels, "/theme", "theme/theme1.xml"); _add_document_relationship(rels, "/styles", "styles.xml"); _add_document_relationship(rels, "/sharedStrings", "sharedStrings.xml"); _add_document_relationship(rels, "/calcChain", "calcChain.xml"); _relationships_assemble_xml_file(rels); RUN_XLSX_STREQ_SHORT(exp, got); _free_relationships(rels); }
// Test assembling a complete SharedStrings file. CTEST(sst, sst02) { char* got; char exp[] = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" "<sst xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" count=\"3\" uniqueCount=\"3\">" "<si>" "<t>abcdefg</t>" "</si>" "<si>" "<t xml:space=\"preserve\"> abcdefg</t>" "</si>" "<si>" "<t xml:space=\"preserve\">abcdefg </t>" "</si>" "</sst>"; FILE* testfile = tmpfile(); lxw_sst *sst = lxw_sst_new(); sst->file = testfile; // Test strings with whitespace that must be preserved. lxw_get_sst_index(sst, "abcdefg"); lxw_get_sst_index(sst, " abcdefg"); lxw_get_sst_index(sst, "abcdefg "); lxw_sst_assemble_xml_file(sst); RUN_XLSX_STREQ_SHORT(exp, got); lxw_sst_free(sst); }
// 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 = tmpfile(); 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 complete App file. CTEST(app, app03) { char* got; char exp[] = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" "<Properties xmlns=\"http://schemas.openxmlformats.org/officeDocument/2006/extended-properties\" xmlns:vt=\"http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes\">" "<Application>Microsoft Excel</Application>" "<DocSecurity>0</DocSecurity>" "<ScaleCrop>false</ScaleCrop>" "<HeadingPairs>" "<vt:vector size=\"4\" baseType=\"variant\">" "<vt:variant>" "<vt:lpstr>Worksheets</vt:lpstr>" "</vt:variant>" "<vt:variant>" "<vt:i4>1</vt:i4>" "</vt:variant>" "<vt:variant>" "<vt:lpstr>Named Ranges</vt:lpstr>" "</vt:variant>" "<vt:variant>" "<vt:i4>1</vt:i4>" "</vt:variant>" "</vt:vector>" "</HeadingPairs>" "<TitlesOfParts>" "<vt:vector size=\"2\" baseType=\"lpstr\">" "<vt:lpstr>Sheet1</vt:lpstr>" "<vt:lpstr>Sheet1!Print_Titles</vt:lpstr>" "</vt:vector>" "</TitlesOfParts>" "<Company>" "</Company>" "<LinksUpToDate>false</LinksUpToDate>" "<SharedDoc>false</SharedDoc>" "<HyperlinksChanged>false</HyperlinksChanged>" "<AppVersion>12.0000</AppVersion>" "</Properties>"; FILE* testfile = tmpfile(); lxw_app *app = _new_app(); app->file = testfile; _add_part_name(app,"Sheet1"); _add_part_name(app,"Sheet1!Print_Titles"); _add_heading_pair(app, "Worksheets", "1"); _add_heading_pair(app, "Named Ranges", "1"); _app_assemble_xml_file(app); RUN_XLSX_STREQ_SHORT(exp, got); _free_app(app); }
// 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 = tmpfile(); lxw_worksheet *worksheet = _new_worksheet(NULL); worksheet->file = testfile; worksheet->sst = _new_sst(); worksheet_select(worksheet); lxw_format *format = _new_format(); format->xf_index = 1; worksheet_merge_range(worksheet, 2, 1, 2, 2, "Foo", format); _worksheet_assemble_xml_file(worksheet); RUN_XLSX_STREQ_SHORT(exp, got); _free_sst(worksheet->sst); _free_worksheet(worksheet); }
// Test assembling a complete ContentTypes file. CTEST(content_types, content_types01) { char* got; char exp[] = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" "<Types xmlns=\"http://schemas.openxmlformats.org/package/2006/content-types\">" "<Default Extension=\"rels\" ContentType=\"application/vnd.openxmlformats-package.relationships+xml\"/>" "<Default Extension=\"xml\" ContentType=\"application/xml\"/>" "<Default Extension=\"jpeg\" ContentType=\"image/jpeg\"/>" "<Override PartName=\"/docProps/app.xml\" ContentType=\"application/vnd.openxmlformats-officedocument.extended-properties+xml\"/>" "<Override PartName=\"/docProps/core.xml\" ContentType=\"application/vnd.openxmlformats-package.core-properties+xml\"/>" "<Override PartName=\"/xl/styles.xml\" ContentType=\"application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml\"/>" "<Override PartName=\"/xl/theme/theme1.xml\" ContentType=\"application/vnd.openxmlformats-officedocument.theme+xml\"/>" "<Override PartName=\"/xl/workbook.xml\" ContentType=\"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml\"/>" "<Override PartName=\"/xl/worksheets/sheet1.xml\" ContentType=\"application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml\"/>" "<Override PartName=\"/xl/sharedStrings.xml\" ContentType=\"application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml\"/>" "<Override PartName=\"/xl/calcChain.xml\" ContentType=\"application/vnd.openxmlformats-officedocument.spreadsheetml.calcChain+xml\"/>" "</Types>"; FILE* testfile = tmpfile(); lxw_content_types *content_types = lxw_content_types_new(); content_types->file = testfile; lxw_ct_add_worksheet_name(content_types, "/xl/worksheets/sheet1.xml"); lxw_ct_add_default(content_types, "jpeg", "image/jpeg"); lxw_ct_add_shared_strings(content_types); lxw_ct_add_calc_chain(content_types); lxw_content_types_assemble_xml_file(content_types); RUN_XLSX_STREQ_SHORT(exp, got); lxw_content_types_free(content_types); }
// Test assembling a complete SharedStrings file. CTEST(sst, sst01) { char* got; char exp[] = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" "<sst xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" count=\"7\" uniqueCount=\"3\">" "<si>" "<t>neptune</t>" "</si>" "<si>" "<t>mars</t>" "</si>" "<si>" "<t>venus</t>" "</si>" "</sst>"; FILE* testfile = tmpfile(); lxw_sst *sst = lxw_sst_new(); sst->file = testfile; lxw_get_sst_index(sst, "neptune"); lxw_get_sst_index(sst, "neptune"); lxw_get_sst_index(sst, "neptune"); lxw_get_sst_index(sst, "mars"); lxw_get_sst_index(sst, "mars"); lxw_get_sst_index(sst, "venus"); lxw_get_sst_index(sst, "venus"); lxw_sst_assemble_xml_file(sst); RUN_XLSX_STREQ_SHORT(exp, got); lxw_sst_free(sst); }
// Test assembling a complete Relationships file. CTEST(relationships, relationships02) { char* got; char exp[] = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" "<Relationships xmlns=\"http://schemas.openxmlformats.org/package/2006/relationships\">" "<Relationship Id=\"rId1\" Type=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink\" Target=\"www.foo.com\" TargetMode=\"External\"/>" "<Relationship Id=\"rId2\" Type=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink\" Target=\"link00.xlsx\" TargetMode=\"External\"/>" "</Relationships>"; FILE* testfile = tmpfile(); lxw_relationships *rels = _new_relationships(); rels->file = testfile; _add_worksheet_relationship(rels, "/hyperlink", "www.foo.com", "External"); _add_worksheet_relationship(rels, "/hyperlink", "link00.xlsx", "External"); _relationships_assemble_xml_file(rels); RUN_XLSX_STREQ_SHORT(exp, got); _free_relationships(rels); }
// 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 = tmpfile(); lxw_worksheet *worksheet = _new_worksheet(NULL); worksheet->file = testfile; //worksheet->sst = _new_sst(); worksheet_select(worksheet); lxw_format *format = _new_format(); 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); _worksheet_assemble_xml_file(worksheet); RUN_XLSX_STREQ_SHORT(exp, got); //_free_sst(worksheet->sst); _free_worksheet(worksheet); }
// Test assembling a complete Chart file. CTEST(chart, chart01) { lxw_chart_series *series1; lxw_chart_series *series2; uint8_t data[5][3] = { {1, 2, 3}, {2, 4, 6}, {3, 6, 9}, {4, 8, 12}, {5, 10, 15} }; char* got; char exp[] = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" "<c:chartSpace xmlns:c=\"http://schemas.openxmlformats.org/drawingml/2006/chart\" xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\">" "<c:lang val=\"en-US\"/>" "<c:chart>" "<c:plotArea>" "<c:layout/>" "<c:barChart>" "<c:barDir val=\"bar\"/>" "<c:grouping val=\"clustered\"/>" "<c:ser>" "<c:idx val=\"0\"/>" "<c:order val=\"0\"/>" "<c:val>" "<c:numRef>" "<c:f>Sheet1!$A$1:$A$5</c:f>" "<c:numCache>" "<c:formatCode>General</c:formatCode>" "<c:ptCount val=\"5\"/>" "<c:pt idx=\"0\">" "<c:v>1</c:v>" "</c:pt>" "<c:pt idx=\"1\">" "<c:v>2</c:v>" "</c:pt>" "<c:pt idx=\"2\">" "<c:v>3</c:v>" "</c:pt>" "<c:pt idx=\"3\">" "<c:v>4</c:v>" "</c:pt>" "<c:pt idx=\"4\">" "<c:v>5</c:v>" "</c:pt>" "</c:numCache>" "</c:numRef>" "</c:val>" "</c:ser>" "<c:ser>" "<c:idx val=\"1\"/>" "<c:order val=\"1\"/>" "<c:val>" "<c:numRef>" "<c:f>Sheet1!$B$1:$B$5</c:f>" "<c:numCache>" "<c:formatCode>General</c:formatCode>" "<c:ptCount val=\"5\"/>" "<c:pt idx=\"0\">" "<c:v>2</c:v>" "</c:pt>" "<c:pt idx=\"1\">" "<c:v>4</c:v>" "</c:pt>" "<c:pt idx=\"2\">" "<c:v>6</c:v>" "</c:pt>" "<c:pt idx=\"3\">" "<c:v>8</c:v>" "</c:pt>" "<c:pt idx=\"4\">" "<c:v>10</c:v>" "</c:pt>" "</c:numCache>" "</c:numRef>" "</c:val>" "</c:ser>" "<c:axId val=\"50010001\"/>" "<c:axId val=\"50010002\"/>" "</c:barChart>" "<c:catAx>" "<c:axId val=\"50010001\"/>" "<c:scaling>" "<c:orientation val=\"minMax\"/>" "</c:scaling>" "<c:axPos val=\"l\"/>" "<c:tickLblPos val=\"nextTo\"/>" "<c:crossAx val=\"50010002\"/>" "<c:crosses val=\"autoZero\"/>" "<c:auto val=\"1\"/>" "<c:lblAlgn val=\"ctr\"/>" "<c:lblOffset val=\"100\"/>" "</c:catAx>" "<c:valAx>" "<c:axId val=\"50010002\"/>" "<c:scaling>" "<c:orientation val=\"minMax\"/>" "</c:scaling>" "<c:axPos val=\"b\"/>" "<c:majorGridlines/>" "<c:numFmt formatCode=\"General\" sourceLinked=\"1\"/>" "<c:tickLblPos val=\"nextTo\"/>" "<c:crossAx val=\"50010001\"/>" "<c:crosses val=\"autoZero\"/>" "<c:crossBetween val=\"between\"/>" "</c:valAx>" "</c:plotArea>" "<c:legend>" "<c:legendPos val=\"r\"/>" "<c:layout/>" "</c:legend>" "<c:plotVisOnly val=\"1\"/>" "</c:chart>" "<c:printSettings>" "<c:headerFooter/>" "<c:pageMargins b=\"0.75\" l=\"0.7\" r=\"0.7\" t=\"0.75\" header=\"0.3\" footer=\"0.3\"/>" "<c:pageSetup/>" "</c:printSettings>" "</c:chartSpace>"; FILE* testfile = lxw_tmpfile(NULL); lxw_chart *chart = lxw_chart_new(LXW_CHART_BAR); chart->file = testfile; series1 = chart_add_series(chart, NULL, "Sheet1!$A$1:$A$5"); series2 = chart_add_series(chart, NULL, "Sheet1!$B$1:$B$5"); lxw_chart_add_data_cache(series1->values, data[0], 5, 3, 0); lxw_chart_add_data_cache(series2->values, data[0], 5, 3, 1); lxw_chart_assemble_xml_file(chart); RUN_XLSX_STREQ_SHORT(exp, got); lxw_chart_free(chart); }