Merge pull request #356 from kostasdizas/issue353

Fixed block calculation in xlsx_producer
This commit is contained in:
Thomas Fussell 2019-06-22 10:52:14 -04:00 committed by GitHub
commit b6455ff6d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 40 additions and 6 deletions

View File

@ -63,6 +63,13 @@ public:
/// The index to the style used by all cells in this row /// The index to the style used by all cells in this row
/// </summary> /// </summary>
optional<std::size_t> style; optional<std::size_t> style;
/// <summary>
/// The row column span, used as part of the row block optimisation.
/// This used for loading this attribute from existing excel files mainly for inspecting
/// and not used when saving, it is calculated in the xlsx_producer.
/// </summary>
optional<std::string> spans;
}; };
inline bool operator==(const row_properties &lhs, const row_properties &rhs) inline bool operator==(const row_properties &lhs, const row_properties &rhs)
@ -72,7 +79,8 @@ inline bool operator==(const row_properties &lhs, const row_properties &rhs)
&& lhs.custom_height == rhs.custom_height && lhs.custom_height == rhs.custom_height
&& lhs.hidden == rhs.hidden && lhs.hidden == rhs.hidden
&& lhs.custom_format == rhs.custom_format && lhs.custom_format == rhs.custom_format
&& lhs.style == rhs.style; && lhs.style == rhs.style
&& lhs.spans == rhs.spans;
} }
} // namespace xlnt } // namespace xlnt

View File

@ -221,9 +221,13 @@ cell xlsx_consumer::read_cell()
row_properties.dy_descent = parser().attribute<double>(qn("x14ac", "dyDescent")); row_properties.dy_descent = parser().attribute<double>(qn("x14ac", "dyDescent"));
} }
if (parser().attribute_present("spans")) {
row_properties.spans = parser().attribute("spans");
}
skip_attributes({"customFormat", "s", "customFont", skip_attributes({"customFormat", "s", "customFont",
"outlineLevel", "collapsed", "thickTop", "thickBot", "outlineLevel", "collapsed", "thickTop", "thickBot",
"ph", "spans"}); "ph"});
} }
if (!in_element(qn("spreadsheetml", "row"))) if (!in_element(qn("spreadsheetml", "row")))
@ -713,9 +717,13 @@ void xlsx_consumer::read_worksheet_sheetdata()
row_properties.custom_format.set(parser().attribute<bool>("customFormat")); row_properties.custom_format.set(parser().attribute<bool>("customFormat"));
} }
if (parser().attribute_present("spans")) {
row_properties.spans = parser().attribute("spans");
}
skip_attributes({"customFont", skip_attributes({"customFont",
"outlineLevel", "collapsed", "thickTop", "thickBot", "outlineLevel", "collapsed", "thickTop", "thickBot",
"ph", "spans"}); "ph"});
while (in_element(qn("spreadsheetml", "row"))) while (in_element(qn("spreadsheetml", "row")))
{ {

View File

@ -2439,6 +2439,10 @@ void xlsx_producer::write_worksheet(const relationship &rel)
// See note for CT_Row, span attribute about block optimization // See note for CT_Row, span attribute about block optimization
if (first_row_in_block) if (first_row_in_block)
{ {
// reset block column range
first_block_column = constants::max_column();
last_block_column = constants::min_column();
first_check_row = row; first_check_row = row;
// round up to the next multiple of 16 // round up to the next multiple of 16
last_check_row = ((row / 16) + 1) * 16; last_check_row = ((row / 16) + 1) * 16;
@ -2448,8 +2452,8 @@ void xlsx_producer::write_worksheet(const relationship &rel)
{ {
for (auto column = dimension.top_left().column(); column <= dimension.bottom_right().column(); ++column) for (auto column = dimension.top_left().column(); column <= dimension.bottom_right().column(); ++column)
{ {
if (!ws.has_cell(cell_reference(column, row))) continue; if (!ws.has_cell(cell_reference(column, check_row))) continue;
auto cell = ws.cell(cell_reference(column, row)); auto cell = ws.cell(cell_reference(column, check_row));
if (cell.garbage_collectible()) continue; if (cell.garbage_collectible()) continue;
first_block_column = std::min(first_block_column, cell.column()); first_block_column = std::min(first_block_column, cell.column());

View File

@ -577,7 +577,7 @@ column_t worksheet::highest_column_or_props() const
range_reference worksheet::calculate_dimension() const range_reference worksheet::calculate_dimension() const
{ {
return range_reference(lowest_column(), lowest_row(), return range_reference(lowest_column(), lowest_row_or_props(),
highest_column(), highest_row_or_props()); highest_column(), highest_row_or_props());
} }

Binary file not shown.

View File

@ -67,6 +67,7 @@ public:
register_test(test_id_gen); register_test(test_id_gen);
register_test(test_load_file); register_test(test_load_file);
register_test(test_Issue279); register_test(test_Issue279);
register_test(test_Issue353);
} }
void test_active_sheet() void test_active_sheet()
@ -495,5 +496,18 @@ public:
//save a copy file //save a copy file
wb.save("temp.xlsx"); wb.save("temp.xlsx");
} }
void test_Issue353()
{
xlnt::workbook wb1;
wb1.load(path_helper::test_file("Issue353_first_row_empty_w_properties.xlsx"));
wb1.save("temp_issue353.xlsx");
xlnt::workbook wb2;
wb2.load("temp_issue353.xlsx");
auto ws = wb2.active_sheet();
xlnt_assert_equals(ws.row_properties(1).spans.get(), "1:8");
xlnt_assert_equals(ws.row_properties(17).spans.get(), "2:7");
}
}; };
static workbook_test_suite x; static workbook_test_suite x;