mirror of
https://github.com/tfussell/xlnt.git
synced 2024-03-22 13:11:17 +08:00
correct off-by-one error in range dimension calculation, closes #213
This commit is contained in:
parent
0d125b1534
commit
7d0cf59286
|
@ -109,7 +109,7 @@ const cell cell_vector::back() const
|
|||
|
||||
std::size_t cell_vector::length() const
|
||||
{
|
||||
return order_ == major_order::row ? bounds_.width() + 1 : bounds_.height() + 1;
|
||||
return order_ == major_order::row ? bounds_.width() : bounds_.height();
|
||||
}
|
||||
|
||||
cell_vector::const_iterator cell_vector::begin() const
|
||||
|
|
|
@ -90,17 +90,17 @@ range_reference range_reference::make_offset(int column_offset, int row_offset)
|
|||
|
||||
std::size_t range_reference::height() const
|
||||
{
|
||||
return bottom_right_.row() - top_left_.row();
|
||||
return 1 + bottom_right_.row() - top_left_.row();
|
||||
}
|
||||
|
||||
std::size_t range_reference::width() const
|
||||
{
|
||||
return (bottom_right_.column() - top_left_.column()).index;
|
||||
return 1 + (bottom_right_.column() - top_left_.column()).index;
|
||||
}
|
||||
|
||||
bool range_reference::is_single_cell() const
|
||||
{
|
||||
return width() == 0 && height() == 0;
|
||||
return width() == 1 && height() == 1;
|
||||
}
|
||||
|
||||
std::string range_reference::to_string() const
|
||||
|
|
|
@ -93,6 +93,7 @@ public:
|
|||
register_test(test_get_point_pos);
|
||||
register_test(test_named_range_named_cell_reference);
|
||||
register_test(test_iteration_skip_empty);
|
||||
register_test(test_dimensions);
|
||||
}
|
||||
|
||||
void test_new_worksheet()
|
||||
|
@ -1088,4 +1089,17 @@ public:
|
|||
xlnt_assert_equals(cells[1].value<std::string>(), "F6");
|
||||
}
|
||||
}
|
||||
|
||||
void test_dimensions()
|
||||
{
|
||||
xlnt::workbook workbook;
|
||||
workbook.load(path_helper::test_file("4_every_style.xlsx"));
|
||||
|
||||
auto active_sheet = workbook.active_sheet();
|
||||
auto sheet_range = active_sheet.calculate_dimension();
|
||||
|
||||
xlnt_assert(!sheet_range.is_single_cell());
|
||||
xlnt_assert_equals(sheet_range.width(), 4);
|
||||
xlnt_assert_equals(sheet_range.height(), 35);
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue
Block a user