mirror of
https://github.com/tfussell/xlnt.git
synced 2024-03-22 13:11:17 +08:00
Add the function of getting table hidden attributes.
This commit is contained in:
parent
3c7122a78c
commit
dafdfa3ebb
|
@ -241,6 +241,13 @@ public:
|
|||
/// </summary>
|
||||
const worksheet sheet_by_id(std::size_t id) const;
|
||||
|
||||
/// <summary>
|
||||
/// Returns the hidden identifier of the worksheet at the given index.
|
||||
/// This will throw an exception if index is greater than or equal to the
|
||||
/// number of sheets in this workbook.
|
||||
/// </summary>
|
||||
bool sheet_hidden_by_index(std::size_t index) const;
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if this workbook contains a sheet with the given title.
|
||||
/// </summary>
|
||||
|
|
|
@ -79,6 +79,7 @@ struct workbook_impl
|
|||
manifest_ = other.manifest_;
|
||||
|
||||
sheet_title_rel_id_map_ = other.sheet_title_rel_id_map_;
|
||||
sheet_hidden_ = other.sheet_hidden_;
|
||||
view_ = other.view_;
|
||||
code_name_ = other.code_name_;
|
||||
file_version_ = other.file_version_;
|
||||
|
@ -105,6 +106,7 @@ struct workbook_impl
|
|||
&& extended_properties_ == other.extended_properties_
|
||||
&& custom_properties_ == other.custom_properties_
|
||||
&& sheet_title_rel_id_map_ == other.sheet_title_rel_id_map_
|
||||
&& sheet_hidden_ == other.sheet_hidden_
|
||||
&& view_ == other.view_
|
||||
&& code_name_ == other.code_name_
|
||||
&& file_version_ == other.file_version_
|
||||
|
@ -134,6 +136,7 @@ struct workbook_impl
|
|||
std::vector<std::pair<std::string, variant>> custom_properties_;
|
||||
|
||||
std::unordered_map<std::string, std::string> sheet_title_rel_id_map_;
|
||||
std::vector<bool> sheet_hidden_;
|
||||
|
||||
optional<workbook_view> view_;
|
||||
optional<std::string> code_name_;
|
||||
|
|
|
@ -1883,12 +1883,14 @@ void xlsx_consumer::read_office_document(const std::string &content_type) // CT_
|
|||
expect_start_element(qn("spreadsheetml", "sheet"), xml::content::simple);
|
||||
|
||||
auto title = parser().attribute("name");
|
||||
skip_attribute("state");
|
||||
|
||||
sheet_title_index_map_[title] = index++;
|
||||
sheet_title_id_map_[title] = parser().attribute<std::size_t>("sheetId");
|
||||
target_.d_->sheet_title_rel_id_map_[title] = parser().attribute(qn("r", "id"));
|
||||
|
||||
bool hidden = parser().attribute<std::string>("state", "") == "hidden";
|
||||
target_.d_->sheet_hidden_.push_back(hidden);
|
||||
|
||||
expect_end_element(qn("spreadsheetml", "sheet"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -716,6 +716,16 @@ const worksheet workbook::sheet_by_id(std::size_t id) const
|
|||
throw key_not_found();
|
||||
}
|
||||
|
||||
bool workbook::sheet_hidden_by_index(std::size_t index) const
|
||||
{
|
||||
if (index >= d_->sheet_hidden_.size())
|
||||
{
|
||||
throw invalid_parameter();
|
||||
}
|
||||
|
||||
return d_->sheet_hidden_.at(index);
|
||||
}
|
||||
|
||||
worksheet workbook::active_sheet()
|
||||
{
|
||||
return sheet_by_index(d_->active_sheet_index_.is_set() ? d_->active_sheet_index_.get() : 0);
|
||||
|
|
BIN
tests/data/16_hidden_sheet.xlsx
Normal file
BIN
tests/data/16_hidden_sheet.xlsx
Normal file
Binary file not shown.
|
@ -112,6 +112,7 @@ public:
|
|||
register_test(test_delete_columns);
|
||||
register_test(test_insert_too_many);
|
||||
register_test(test_insert_delete_moves_merges);
|
||||
register_test(test_hidden_sheet);
|
||||
}
|
||||
|
||||
void test_new_worksheet()
|
||||
|
@ -1582,5 +1583,12 @@ public:
|
|||
xlnt_assert_equals(merged, expected);
|
||||
}
|
||||
}
|
||||
|
||||
void test_hidden_sheet()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
wb.load(path_helper::test_file("16_hidden_sheet.xlsx"));
|
||||
xlnt_assert_equals(wb.sheet_hidden_by_index(1), true);
|
||||
}
|
||||
};
|
||||
static worksheet_test_suite x;
|
||||
|
|
Loading…
Reference in New Issue
Block a user