Merge branch 'worksheet--has_cell'

This commit is contained in:
degaart 2015-12-24 10:00:56 +03:00
commit c53bfa53bc
3 changed files with 26 additions and 0 deletions

View File

@ -86,6 +86,7 @@ public:
// container
cell get_cell(const cell_reference &reference);
const cell get_cell(const cell_reference &reference) const;
bool has_cell(const cell_reference &reference) const;
range get_range(const std::string &reference_string);
range get_range(const range_reference &reference);
const range get_range(const std::string &reference_string) const;

View File

@ -21,6 +21,18 @@ public:
auto cell = ws.get_cell(xlnt::cell_reference(1, 1));
TS_ASSERT_EQUALS(cell.get_reference(), "A1");
}
void test_has_cell()
{
xlnt::worksheet ws(wb_);
const xlnt::worksheet& const_ws = ws;
TS_ASSERT_EQUALS(const_ws.has_cell(xlnt::cell_reference("A", 1)), false);
ws.get_cell("C10").set_value("value");
TS_ASSERT_EQUALS(const_ws.has_cell(xlnt::cell_reference("C", 9)), false);
TS_ASSERT_EQUALS(const_ws.has_cell(xlnt::cell_reference("C", 10)), true);
}
void test_worksheet_dimension()
{

View File

@ -229,6 +229,19 @@ const cell worksheet::get_cell(const cell_reference &reference) const
return cell(&d_->cell_map_.at(reference.get_row()).at(reference.get_column_index()));
}
bool worksheet::has_cell(const cell_reference &reference) const
{
const auto row = d_->cell_map_.find(reference.get_row());
if(row == d_->cell_map_.cend())
return false;
const auto col = row->second.find(reference.get_column_index());
if(col == row->second.cend())
return false;
return true;
}
bool worksheet::has_row_properties(row_t row) const
{
return d_->row_properties_.find(row) != d_->row_properties_.end();