diff --git a/benchmarks/spreadsheet-load.cpp b/benchmarks/spreadsheet-load.cpp index 0caadb025..041be63a9 100644 --- a/benchmarks/spreadsheet-load.cpp +++ b/benchmarks/spreadsheet-load.cpp @@ -5,7 +5,7 @@ namespace { using milliseconds_d = std::chrono::duration; -void run_test(const xlnt::path &file, int runs = 10) +void run_load_test(const xlnt::path &file, int runs = 10) { std::cout << file.string() << "\n\n"; @@ -24,10 +24,35 @@ void run_test(const xlnt::path &file, int runs = 10) std::cout << milliseconds_d(test_timings.back()).count() << " ms\n"; } } + +void run_save_test(const xlnt::path &file, int runs = 10) +{ + std::cout << file.string() << "\n\n"; + + xlnt::workbook wb; + wb.load(file); + const xlnt::path save_path(file.filename()); + + std::vector test_timings; + + for (int i = 0; i < runs; ++i) + { + auto start = std::chrono::steady_clock::now(); + + wb.save(save_path); + + auto end = std::chrono::steady_clock::now(); + test_timings.push_back(end - start); + std::cout << milliseconds_d(test_timings.back()).count() << " ms\n"; + } +} } // namespace int main() { run_test(path_helper::benchmark_file("large.xlsx")); run_test(path_helper::benchmark_file("very_large.xlsx")); + + run_save_test(path_helper::benchmark_file("large.xlsx")); + run_save_test(path_helper::benchmark_file("very_large.xlsx")); } \ No newline at end of file diff --git a/source/detail/serialization/xlsx_producer.cpp b/source/detail/serialization/xlsx_producer.cpp index e0a52870e..743839ac2 100644 --- a/source/detail/serialization/xlsx_producer.cpp +++ b/source/detail/serialization/xlsx_producer.cpp @@ -2267,16 +2267,18 @@ void xlsx_producer::write_worksheet(const relationship &rel) { write_attribute("enableFormatConditionsCalculation", props.enable_format_condition_calculation.get()); } - + // outlinePr is optional in the spec but is being written every time? write_start_element(xmlns, "outlinePr"); write_attribute("summaryBelow", "1"); write_attribute("summaryRight", "1"); write_end_element(xmlns, "outlinePr"); - write_start_element(xmlns, "pageSetUpPr"); - write_attribute("fitToPage", write_bool(ws.page_setup().fit_to_page())); - write_end_element(xmlns, "pageSetUpPr"); - + if (ws.has_page_setup()) + { + write_start_element(xmlns, "pageSetUpPr"); + write_attribute("fitToPage", write_bool(ws.page_setup().fit_to_page())); + write_end_element(xmlns, "pageSetUpPr"); + } write_end_element(xmlns, "sheetPr"); }