From 9f1edce3bc0fbb2ff4ba019593b6a53f59253f94 Mon Sep 17 00:00:00 2001 From: Xpol Wan Date: Thu, 26 May 2016 10:55:50 +0800 Subject: [PATCH] Add range worksheet::rows(int row_offset, int column_offset) const. --- source/worksheet/tests/test_worksheet.hpp | 30 +++++++++++++++++++++++ source/worksheet/worksheet.cpp | 6 +++++ 2 files changed, 36 insertions(+) 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 41af6b20..cc6c9209 100644 --- a/source/worksheet/worksheet.cpp +++ b/source/worksheet/worksheet.cpp @@ -626,6 +626,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);