mirror of
https://github.com/tfussell/xlnt.git
synced 2024-03-22 13:11:17 +08:00
Merge pull request #655 from musshorn/active_sheet
Added the ability to set the active sheet
This commit is contained in:
commit
d62b267448
|
@ -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 &)
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
BIN
tests/data/20_active_sheet.xlsx
Normal file
BIN
tests/data/20_active_sheet.xlsx
Normal file
Binary file not shown.
|
@ -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;
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue
Block a user