// 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);
}
/* 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 = tmpfile();

    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);
}
/* 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 = tmpfile();

    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);
}
/* 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 = tmpfile();

    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);
}
/* 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 = tmpfile();

    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);
}
/* 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);
}
/* 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);
}
/* 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);
}
// Test the _write_print_options() function.
CTEST(worksheet, write_print_options4) {

    char* got;
    char exp[] = "<printOptions gridLines=\"1\"/>";
    FILE* testfile = tmpfile();

    lxw_worksheet *worksheet = _new_worksheet(NULL);
    worksheet->file = testfile;
    worksheet_select(worksheet);

    worksheet_gridlines(worksheet, LXW_SHOW_PRINT_GRIDLINES);

    _worksheet_write_print_options(worksheet);

    RUN_XLSX_STREQ(exp, got);

    _free_worksheet(worksheet);
}
// Test the _write_print_options() function.
CTEST(worksheet, write_print_options2) {

    char* got;
    char exp[] = "<printOptions verticalCentered=\"1\"/>";
    FILE* testfile = tmpfile();

    lxw_worksheet *worksheet = _new_worksheet(NULL);
    worksheet->file = testfile;
    worksheet_select(worksheet);

    worksheet_center_vertically(worksheet);

    _worksheet_write_print_options(worksheet);

    RUN_XLSX_STREQ(exp, got);

    _free_worksheet(worksheet);
}
// 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);
}
示例#12
0
// Test some out of bound writes.
CTEST(worksheet, spans06) {

    int err;
    FILE* testfile = tmpfile();

    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);
}
// 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);
}
示例#14
0
// 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 = tmpfile();

    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);
}