Merge branch 'master' of github.com:tfussell/xlnt

This commit is contained in:
Thomas Fussell 2016-06-11 01:12:30 -04:00
commit 8c7a7f7a6f
5 changed files with 55 additions and 2 deletions

View File

@ -5,5 +5,6 @@ It was initially inspired by the openpyxl library: https://openpyxl.readthedocs.
Thanks to everyone who has contributed to this project (in alphabetical order):
* Malvineous
* xpol
Project logo designed by Thomas Fussell.

View File

@ -76,6 +76,17 @@ public:
TS_ASSERT_EQUALS(new_sheet, found_sheet);
}
void test_get_sheet_by_name_const()
{
xlnt::workbook wb;
auto new_sheet = wb.create_sheet();
std::string title = "my sheet";
new_sheet.set_title(title);
const xlnt::workbook& wbconst = wb;
auto found_sheet = wbconst.get_sheet_by_name(title);
TS_ASSERT_EQUALS(new_sheet, found_sheet);
}
void test_index_operator() // test_getitem
{
xlnt::workbook wb;

View File

@ -98,7 +98,7 @@ workbook::workbook(encoding e) : workbook()
d_->encoding_ = e;
}
worksheet workbook::get_sheet_by_name(const std::string &name)
const worksheet workbook::get_sheet_by_name(const std::string &name) const
{
for (auto &impl : d_->worksheets_)
{
@ -111,6 +111,11 @@ worksheet workbook::get_sheet_by_name(const std::string &name)
return worksheet();
}
worksheet workbook::get_sheet_by_name(const std::string &name)
{
return worksheet(static_cast<const workbook*>(this)->get_sheet_by_name(name));
}
worksheet workbook::get_sheet_by_index(std::size_t index)
{
return worksheet(&d_->worksheets_[index]);

View File

@ -153,6 +153,36 @@ public:
}
}
void test_iter_rows_offset_int_int()
{
xlnt::workbook wb;
xlnt::worksheet ws(wb);
auto rows = ws.rows(1, 3);
const std::vector<std::vector<std::string>> expected =
{
{ "D2", "E2", "F2" },
{ "D3", "E3", "F3" },
{ "D4", "E4", "F4" },
{ "D5", "E5", "F5" }
};
auto expected_row_iter = expected.begin();
for (auto row : rows)
{
auto expected_cell_iter = (*expected_row_iter).begin();
for (auto cell : row)
{
TS_ASSERT_EQUALS(cell.get_reference(), *expected_cell_iter);
expected_cell_iter++;
}
expected_row_iter++;
}
}
void test_get_named_range()
{
xlnt::workbook wb;

View File

@ -627,6 +627,12 @@ xlnt::range worksheet::rows(const std::string &range_string, int row_offset, int
return get_range(reference.make_offset(column_offset, row_offset));
}
xlnt::range worksheet::rows(int row_offset, int column_offset) const
{
range_reference reference(calculate_dimension());
return get_range(reference.make_offset(column_offset, row_offset));
}
xlnt::range worksheet::columns() const
{
return range(*this, calculate_dimension(), major_order::column);