File tree Expand file tree Collapse file tree
source/detail/serialization Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2365,16 +2365,24 @@ void xlsx_producer::write_worksheet(const relationship &rel)
23652365 write_start_element (xmlns, " sheetViews" );
23662366 write_start_element (xmlns, " sheetView" );
23672367
2368- const auto wb_view = source_.view ();
23692368 const auto view = ws.view ();
23702369
23712370 if (!view.show_grid_lines ())
23722371 {
23732372 write_attribute (" showGridLines" , write_bool (view.show_grid_lines ()));
23742373 }
23752374
2376- if ((wb_view.active_tab .is_set () && (ws.id () - 1 ) == wb_view.active_tab .get ())
2377- || (!wb_view.active_tab .is_set () && ws.id () == 1 ))
2375+ if (source_.has_view ())
2376+ {
2377+ const auto wb_view = source_.view ();
2378+
2379+ if ((wb_view.active_tab .is_set () && (ws.id () - 1 ) == wb_view.active_tab .get ())
2380+ || (!wb_view.active_tab .is_set () && ws.id () == 1 ))
2381+ {
2382+ write_attribute (" tabSelected" , write_bool (true ));
2383+ }
2384+ }
2385+ else if (ws.id () == 1 )
23782386 {
23792387 write_attribute (" tabSelected" , write_bool (true ));
23802388 }
Original file line number Diff line number Diff line change @@ -74,6 +74,7 @@ class serialization_test_suite : public test_suite
7474 register_test (test_formatting);
7575 register_test (test_active_sheet);
7676 register_test (test_locale_comma);
77+ register_test (test_Issue6_google_missing_workbookView);
7778 }
7879
7980 bool workbook_matches_file (xlnt::workbook &wb, const xlnt::path &file)
@@ -824,6 +825,13 @@ class serialization_test_suite : public test_suite
824825 xlnt_assert_equals (ws.cell (" A1" ).value <double >(), 1.9999999999 );
825826 xlnt_assert_equals (ws.cell (" A2" ).value <double >(), 1.1 );
826827 }
828+
829+ void test_Issue6_google_missing_workbookView ()
830+ {
831+ xlnt::workbook wb;
832+ wb.load (path_helper::test_file (" Issue6_google_missing_workbookView.xlsx" ));
833+ xlnt_assert_throws_nothing (wb.save (" temp.xlsx" ));
834+ }
827835};
828836
829837static serialization_test_suite x;
You can’t perform that action at this time.
0 commit comments