diff --git a/AUTHORS.md b/AUTHORS.md index 1a6ad098..f4052fe3 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -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. \ No newline at end of file +Project logo designed by Thomas Fussell. diff --git a/source/workbook/tests/test_workbook.hpp b/source/workbook/tests/test_workbook.hpp index 6d354b93..e7647d14 100644 --- a/source/workbook/tests/test_workbook.hpp +++ b/source/workbook/tests/test_workbook.hpp @@ -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; diff --git a/source/workbook/workbook.cpp b/source/workbook/workbook.cpp index fa860494..0d848d6a 100644 --- a/source/workbook/workbook.cpp +++ b/source/workbook/workbook.cpp @@ -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(this)->get_sheet_by_name(name)); +} + worksheet workbook::get_sheet_by_index(std::size_t index) { return worksheet(&d_->worksheets_[index]); diff --git a/source/worksheet/tests/test_worksheet.hpp b/source/worksheet/tests/test_worksheet.hpp index 689f8153..5d0e63d2 100644 --- a/source/worksheet/tests/test_worksheet.hpp +++ b/source/worksheet/tests/test_worksheet.hpp @@ -152,6 +152,36 @@ public: expected_row_iter++; } } + + void test_iter_rows_offset_int_int() + { + xlnt::workbook wb; + xlnt::worksheet ws(wb); + auto rows = ws.rows(1, 3); + + const std::vector> 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() { diff --git a/source/worksheet/worksheet.cpp b/source/worksheet/worksheet.cpp index 965c2723..31336292 100644 --- a/source/worksheet/worksheet.cpp +++ b/source/worksheet/worksheet.cpp @@ -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);