Merge pull request #655 from musshorn/active_sheet

Added the ability to set the active sheet
This commit is contained in:
Thomas Fussell 2022-10-09 09:27:09 -05:00 committed by GitHub
commit d62b267448
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 25 additions and 0 deletions

View File

@ -203,6 +203,12 @@ public:
/// </summary>
worksheet active_sheet();
/// <summary>
/// Sets the worksheet that is determined to be active. An active
/// sheet is that which is initially shown by the spreadsheet editor.
/// </summary>
void active_sheet(std::size_t index);
/// <summary>
/// Returns the worksheet with the given name. This may throw an exception
/// if the sheet isn't found. Use workbook::contains(const std::string &)

View File

@ -2037,6 +2037,7 @@ void xlsx_consumer::read_office_document(const std::string &content_type) // CT_
if (parser().attribute_present("activeTab"))
{
view.active_tab = parser().attribute<std::size_t>("activeTab");
target_.d_->active_sheet_index_.set(view.active_tab.get());
}
target_.view(view);

View File

@ -743,6 +743,11 @@ worksheet workbook::active_sheet()
{
return sheet_by_index(d_->active_sheet_index_.is_set() ? d_->active_sheet_index_.get() : 0);
}
void workbook::active_sheet(std::size_t index)
{
d_->active_sheet_index_.set(index);
d_->view_.get().active_tab = index;
}
bool workbook::has_named_range(const std::string &name) const
{

Binary file not shown.

View File

@ -72,6 +72,7 @@ public:
register_test(test_Issue492_stream_empty_row);
register_test(test_Issue503_external_link_load);
register_test(test_formatting);
register_test(test_active_sheet);
}
bool workbook_matches_file(xlnt::workbook &wb, const xlnt::path &file)
@ -800,6 +801,13 @@ public:
assert_run(rt.runs()[10], " first line ", "Calibri", xlnt::theme_color(1), 12, true, false, xlnt::font::underline_style::none);
assert_run(rt.runs()[11], "Bold And Underline", "Calibri (Body)", xlnt::theme_color(1), 12, true, false, xlnt::font::underline_style::single);
}
void test_active_sheet()
{
xlnt::workbook wb;
wb.load(path_helper::test_file("20_active_sheet.xlsx"));
xlnt_assert_equals(wb.active_sheet(), wb[2]);
}
};
static serialization_test_suite x;

View File

@ -77,6 +77,11 @@ public:
{
xlnt::workbook wb;
xlnt_assert_equals(wb.active_sheet(), wb[0]);
wb.create_sheet();
wb.create_sheet();
wb.active_sheet(2);
xlnt_assert_equals(wb.active_sheet(), wb[2]);
}
void test_create_sheet()