mirror of
https://github.com/tfussell/xlnt.git
synced 2024-03-22 13:11:17 +08:00
remove some more extraneous worksheet methods
This commit is contained in:
parent
d8c9d14a98
commit
b914b064b7
|
@ -211,75 +211,62 @@ public:
|
|||
const class range range(const range_reference &reference) const;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// Returns a range encompassing all cells in this sheet which will
|
||||
/// be iterated upon in row-major order.
|
||||
/// </summary>
|
||||
class range rows() const;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
class range rows(const std::string &range_string) const;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
class range rows(int row_offset, int column_offset) const;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
class range rows(const std::string &range_string, int row_offset, int column_offset) const;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// Returns a range ecompassing all cells in this sheet which will
|
||||
/// be iterated upon in column-major order.
|
||||
/// </summary>
|
||||
class range columns() const;
|
||||
|
||||
// properties
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// Returns the column properties for the given column.
|
||||
/// </summary>
|
||||
xlnt::column_properties &column_properties(column_t column);
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// Returns the column properties for the given column.
|
||||
/// </summary>
|
||||
const xlnt::column_properties &column_properties(column_t column) const;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// Returns true if column properties have been set for the given column.
|
||||
/// </summary>
|
||||
bool has_column_properties(column_t column) const;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// Sets column properties for the given column to props.
|
||||
/// </summary>
|
||||
void add_column_properties(column_t column, const class column_properties &props);
|
||||
|
||||
/// <summary>
|
||||
/// Calculate the width of the given column. This will be the default column width if
|
||||
/// Calculates the width of the given column. This will be the default column width if
|
||||
/// a custom width is not set on this column's column_properties.
|
||||
/// </summary>
|
||||
double column_width(column_t column) const;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// Returns the row properties for the given row.
|
||||
/// </summary>
|
||||
xlnt::row_properties &row_properties(row_t row);
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// Returns the row properties for the given row.
|
||||
/// </summary>
|
||||
const xlnt::row_properties &row_properties(row_t row) const;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// Returns true if row properties have been set for the given row.
|
||||
/// </summary>
|
||||
bool has_row_properties(row_t row) const;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// Sets row properties for the given row to props.
|
||||
/// </summary>
|
||||
void add_row_properties(row_t row, const class row_properties &props);
|
||||
|
||||
|
@ -292,7 +279,7 @@ public:
|
|||
// positioning
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// Returns a reference to the cell at the given point coordinates.
|
||||
/// </summary>
|
||||
cell_reference point_pos(int left, int top) const;
|
||||
|
||||
|
@ -399,38 +386,6 @@ public:
|
|||
/// </summary>
|
||||
std::vector<range_reference> merged_ranges() const;
|
||||
|
||||
// append
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
void append();
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
void append(const std::vector<std::string> &cells);
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
void append(const std::vector<int> &cells);
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
void append(const std::unordered_map<std::string, std::string> &cells);
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
void append(const std::unordered_map<int, std::string> &cells);
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
void append(const std::vector<int>::const_iterator begin, const std::vector<int>::const_iterator end);
|
||||
|
||||
// operators
|
||||
|
||||
/// <summary>
|
||||
|
@ -459,27 +414,18 @@ public:
|
|||
void operator=(const worksheet &other);
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// Convenience method for worksheet::cell method.
|
||||
/// </summary>
|
||||
class cell operator[](const cell_reference &reference);
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// Convenience method for worksheet::cell method.
|
||||
/// </summary>
|
||||
const class cell operator[](const cell_reference &reference) const;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
class range operator()(const cell_reference &top_left, const cell_reference &bottom_right);
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
const class range operator()(const cell_reference &top_left, const cell_reference &bottom_right) const;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// Returns true if this worksheet is equal to other. If reference is true, the comparison
|
||||
/// will only check that both worksheets point to the same sheet in the same workbook.
|
||||
/// </summary>
|
||||
bool compare(const worksheet &other, bool reference) const;
|
||||
|
||||
|
|
|
@ -62,97 +62,7 @@ public:
|
|||
|
||||
TS_ASSERT_EQUALS(ws.rows()[row][column].reference(), coordinate);
|
||||
}
|
||||
|
||||
void test_iter_rows()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
auto ws = wb.active_sheet();
|
||||
|
||||
const std::vector<std::vector<std::string>> expected =
|
||||
{
|
||||
{ "A1", "B1", "C1" },
|
||||
{ "A2", "B2", "C2" },
|
||||
{ "A3", "B3", "C3" },
|
||||
{ "A4", "B4", "C4" }
|
||||
};
|
||||
|
||||
auto rows = ws.rows("A1:C4");
|
||||
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.reference(), *expected_cell_iter);
|
||||
expected_cell_iter++;
|
||||
}
|
||||
|
||||
expected_row_iter++;
|
||||
}
|
||||
}
|
||||
|
||||
void test_iter_rows_offset()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
auto ws = wb.active_sheet();
|
||||
auto rows = ws.rows("A1:C4", 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.reference(), *expected_cell_iter);
|
||||
expected_cell_iter++;
|
||||
}
|
||||
|
||||
expected_row_iter++;
|
||||
}
|
||||
}
|
||||
|
||||
void test_iter_rows_offset_int_int()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
auto ws = wb.active_sheet();
|
||||
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.reference(), *expected_cell_iter);
|
||||
expected_cell_iter++;
|
||||
}
|
||||
|
||||
expected_row_iter++;
|
||||
}
|
||||
}
|
||||
|
||||
void test_get_named_range()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
|
@ -228,91 +138,6 @@ public:
|
|||
TS_ASSERT_EQUALS("test", ws.cell("A1").value<std::string>());
|
||||
TS_ASSERT_EQUALS(ws.cell("A1").hyperlink(), "http://test.com");
|
||||
}
|
||||
|
||||
void test_append()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
auto ws = wb.active_sheet();
|
||||
ws.append(std::vector<std::string> {"value"});
|
||||
TS_ASSERT_EQUALS("value", ws.cell("A1").value<std::string>());
|
||||
}
|
||||
|
||||
void test_append_list()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
auto ws = wb.active_sheet();
|
||||
|
||||
ws.append(std::vector<std::string> {"This is A1", "This is B1"});
|
||||
|
||||
TS_ASSERT_EQUALS("This is A1", ws.cell("A1").value<std::string>());
|
||||
TS_ASSERT_EQUALS("This is B1", ws.cell("B1").value<std::string>());
|
||||
}
|
||||
|
||||
void test_append_dict_letter()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
auto ws = wb.active_sheet();
|
||||
|
||||
const std::unordered_map<std::string, std::string> dict_letter =
|
||||
{
|
||||
{ "A", "This is A1" },
|
||||
{ "C", "This is C1" }
|
||||
};
|
||||
|
||||
ws.append(dict_letter);
|
||||
|
||||
TS_ASSERT_EQUALS("This is A1", ws.cell("A1").value<std::string>());
|
||||
TS_ASSERT_EQUALS("This is C1", ws.cell("C1").value<std::string>());
|
||||
}
|
||||
|
||||
void test_append_dict_index()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
auto ws = wb.active_sheet();
|
||||
|
||||
const std::unordered_map<int, std::string> dict_index =
|
||||
{
|
||||
{ 1, "This is A1" },
|
||||
{ 3, "This is C1" }
|
||||
};
|
||||
|
||||
ws.append(dict_index);
|
||||
|
||||
TS_ASSERT_EQUALS("This is A1", ws.cell("A1").value<std::string>());
|
||||
TS_ASSERT_EQUALS("This is C1", ws.cell("C1").value<std::string>());
|
||||
}
|
||||
|
||||
void test_append_iterator()
|
||||
{
|
||||
std::vector<int> range;
|
||||
|
||||
for(int i = 0; i < 30; i++)
|
||||
{
|
||||
range.push_back(i);
|
||||
}
|
||||
|
||||
xlnt::workbook wb;
|
||||
auto ws = wb.active_sheet();
|
||||
ws.append(range.begin(), range.end());
|
||||
|
||||
TS_ASSERT_EQUALS(ws[xlnt::cell_reference("AD1")].value<int>(), 29);
|
||||
}
|
||||
|
||||
void test_append_2d_list()
|
||||
{
|
||||
xlnt::workbook wb;
|
||||
auto ws = wb.active_sheet();
|
||||
|
||||
ws.append(std::vector<std::string> {"This is A1", "This is B1"});
|
||||
ws.append(std::vector<std::string> {"This is A2", "This is B2"});
|
||||
|
||||
auto vals = ws.range("A1:B2");
|
||||
|
||||
TS_ASSERT_EQUALS(vals[0][0].value<std::string>(), "This is A1");
|
||||
TS_ASSERT_EQUALS(vals[0][1].value<std::string>(), "This is B1");
|
||||
TS_ASSERT_EQUALS(vals[1][0].value<std::string>(), "This is A2");
|
||||
TS_ASSERT_EQUALS(vals[1][1].value<std::string>(), "This is B2");
|
||||
}
|
||||
|
||||
void test_rows()
|
||||
{
|
||||
|
@ -418,7 +243,7 @@ public:
|
|||
{
|
||||
xlnt::workbook wb;
|
||||
auto ws = wb.active_sheet();
|
||||
auto cell_range = ws("A1", "B2");
|
||||
auto cell_range = ws.range("A1:B2");
|
||||
TS_ASSERT_EQUALS(cell_range[0][0], ws.cell("A1"));
|
||||
TS_ASSERT_EQUALS(cell_range[1][0], ws.cell("A2"));
|
||||
TS_ASSERT_EQUALS(cell_range[0][1], ws.cell("B1"));
|
||||
|
@ -637,10 +462,7 @@ public:
|
|||
{
|
||||
xlnt::workbook wb;
|
||||
auto ws = wb.active_sheet();
|
||||
ws.append();
|
||||
ws.append(std::vector<int> { 5 });
|
||||
ws.append();
|
||||
ws.append(std::vector<int> { 4 });
|
||||
ws.cell("D4").value("D4");
|
||||
TS_ASSERT_EQUALS(ws.highest_row(), 4);
|
||||
}
|
||||
|
||||
|
@ -649,8 +471,12 @@ public:
|
|||
xlnt::workbook wb;
|
||||
auto ws = wb.active_sheet();
|
||||
|
||||
ws.append({"A1", "B1", "C1"});
|
||||
ws.append({"A2", "B2", "C2"});
|
||||
ws.cell("A1").value("A1");
|
||||
ws.cell("B1").value("B1");
|
||||
ws.cell("C1").value("C1");
|
||||
ws.cell("A2").value("A2");
|
||||
ws.cell("B2").value("B2");
|
||||
ws.cell("C2").value("C2");
|
||||
|
||||
const xlnt::worksheet ws_const = ws;
|
||||
const auto rows = ws_const.rows();
|
||||
|
@ -677,8 +503,12 @@ public:
|
|||
xlnt::workbook wb;
|
||||
auto ws = wb.active_sheet();
|
||||
|
||||
ws.append({"A1", "B1", "C1"});
|
||||
ws.append({"A2", "B2", "C2"});
|
||||
ws.cell("A1").value("A1");
|
||||
ws.cell("B1").value("B1");
|
||||
ws.cell("C1").value("C1");
|
||||
ws.cell("A2").value("A2");
|
||||
ws.cell("B2").value("B2");
|
||||
ws.cell("C2").value("C2");
|
||||
|
||||
const xlnt::worksheet ws_const = ws;
|
||||
const auto rows = ws_const.rows();
|
||||
|
@ -712,8 +542,12 @@ public:
|
|||
xlnt::workbook wb;
|
||||
auto ws = wb.active_sheet();
|
||||
|
||||
ws.append({"A1", "B1", "C1"});
|
||||
ws.append({"A2", "B2", "C2"});
|
||||
ws.cell("A1").value("A1");
|
||||
ws.cell("B1").value("B1");
|
||||
ws.cell("C1").value("C1");
|
||||
ws.cell("A2").value("A2");
|
||||
ws.cell("B2").value("B2");
|
||||
ws.cell("C2").value("C2");
|
||||
|
||||
auto columns = ws.columns();
|
||||
|
||||
|
@ -751,8 +585,12 @@ public:
|
|||
xlnt::workbook wb;
|
||||
auto ws = wb.active_sheet();
|
||||
|
||||
ws.append({"A1", "B1", "C1"});
|
||||
ws.append({"A2", "B2", "C2"});
|
||||
ws.cell("A1").value("A1");
|
||||
ws.cell("B1").value("B1");
|
||||
ws.cell("C1").value("C1");
|
||||
ws.cell("A2").value("A2");
|
||||
ws.cell("B2").value("B2");
|
||||
ws.cell("C2").value("C2");
|
||||
|
||||
auto columns = ws.columns();
|
||||
|
||||
|
@ -793,8 +631,12 @@ public:
|
|||
xlnt::workbook wb;
|
||||
auto ws = wb.active_sheet();
|
||||
|
||||
ws.append({"A1", "B1", "C1"});
|
||||
ws.append({"A2", "B2", "C2"});
|
||||
ws.cell("A1").value("A1");
|
||||
ws.cell("B1").value("B1");
|
||||
ws.cell("C1").value("C1");
|
||||
ws.cell("A2").value("A2");
|
||||
ws.cell("B2").value("B2");
|
||||
ws.cell("C2").value("C2");
|
||||
|
||||
const xlnt::worksheet ws_const = ws;
|
||||
const auto columns = ws_const.columns();
|
||||
|
@ -830,8 +672,12 @@ public:
|
|||
xlnt::workbook wb;
|
||||
auto ws = wb.active_sheet();
|
||||
|
||||
ws.append({"A1", "B1", "C1"});
|
||||
ws.append({"A2", "B2", "C2"});
|
||||
ws.cell("A1").value("A1");
|
||||
ws.cell("B1").value("B1");
|
||||
ws.cell("C1").value("C1");
|
||||
ws.cell("A2").value("A2");
|
||||
ws.cell("B2").value("B2");
|
||||
ws.cell("C2").value("C2");
|
||||
|
||||
const xlnt::worksheet ws_const = ws;
|
||||
const auto columns = ws_const.columns();
|
||||
|
|
|
@ -111,11 +111,6 @@ void worksheet::create_named_range(const std::string &name, const range_referenc
|
|||
d_->named_ranges_[name] = xlnt::named_range(name, targets);
|
||||
}
|
||||
|
||||
range worksheet::operator()(const xlnt::cell_reference &top_left, const xlnt::cell_reference &bottom_right)
|
||||
{
|
||||
return range(range_reference(top_left, bottom_right));
|
||||
}
|
||||
|
||||
cell worksheet::operator[](const cell_reference &ref)
|
||||
{
|
||||
return cell(ref);
|
||||
|
@ -595,22 +590,6 @@ void worksheet::unmerge_cells(column_t start_column, row_t start_row, column_t e
|
|||
unmerge_cells(xlnt::range_reference(start_column, start_row, end_column, end_row));
|
||||
}
|
||||
|
||||
void worksheet::append()
|
||||
{
|
||||
cell(cell_reference(1, next_row()));
|
||||
}
|
||||
|
||||
void worksheet::append(const std::vector<std::string> &cells)
|
||||
{
|
||||
xlnt::cell_reference next(1, next_row());
|
||||
|
||||
for (auto cell : cells)
|
||||
{
|
||||
this->cell(next).value(cell);
|
||||
next.column_index(next.column_index() + 1);
|
||||
}
|
||||
}
|
||||
|
||||
row_t worksheet::next_row() const
|
||||
{
|
||||
auto row = highest_row() + 1;
|
||||
|
@ -623,70 +602,11 @@ row_t worksheet::next_row() const
|
|||
return row;
|
||||
}
|
||||
|
||||
void worksheet::append(const std::vector<int> &cells)
|
||||
{
|
||||
xlnt::cell_reference next(1, next_row());
|
||||
|
||||
for (auto cell : cells)
|
||||
{
|
||||
this->cell(next).value(static_cast<long double>(cell));
|
||||
next.column_index(next.column_index() + 1);
|
||||
}
|
||||
}
|
||||
|
||||
void worksheet::append(const std::unordered_map<std::string, std::string> &cells)
|
||||
{
|
||||
auto row = next_row();
|
||||
|
||||
for (auto cell : cells)
|
||||
{
|
||||
this->cell(cell_reference(cell.first, row)).value(cell.second);
|
||||
}
|
||||
}
|
||||
|
||||
void worksheet::append(const std::unordered_map<int, std::string> &cells)
|
||||
{
|
||||
auto row = next_row();
|
||||
|
||||
for (auto cell : cells)
|
||||
{
|
||||
this->cell(cell_reference(static_cast<column_t::index_t>(cell.first), row)).value(cell.second);
|
||||
}
|
||||
}
|
||||
|
||||
void worksheet::append(const std::vector<int>::const_iterator begin, const std::vector<int>::const_iterator end)
|
||||
{
|
||||
xlnt::cell_reference next(1, next_row());
|
||||
|
||||
for (auto i = begin; i != end; i++)
|
||||
{
|
||||
cell(next).value(static_cast<long double>(*i));
|
||||
next.column_index(next.column_index() + 1);
|
||||
}
|
||||
}
|
||||
|
||||
xlnt::range worksheet::rows() const
|
||||
{
|
||||
return range(calculate_dimension());
|
||||
}
|
||||
|
||||
xlnt::range worksheet::rows(const std::string &range_string) const
|
||||
{
|
||||
return range(range_reference(range_string));
|
||||
}
|
||||
|
||||
xlnt::range worksheet::rows(const std::string &range_string, int row_offset, int column_offset) const
|
||||
{
|
||||
range_reference reference(range_string);
|
||||
return 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 range(reference.make_offset(column_offset, row_offset));
|
||||
}
|
||||
|
||||
xlnt::range worksheet::columns() const
|
||||
{
|
||||
return xlnt::range(*this, calculate_dimension(), major_order::column);
|
||||
|
|
Loading…
Reference in New Issue
Block a user