2014-05-09 03:32:12 +08:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <cxxtest/TestSuite.h>
|
|
|
|
|
2016-06-14 11:36:26 +08:00
|
|
|
#include <xlnt/worksheet/header_footer.hpp>
|
2015-10-30 11:16:31 +08:00
|
|
|
#include <xlnt/worksheet/worksheet.hpp>
|
2016-08-02 06:33:43 +08:00
|
|
|
#include <xlnt/workbook/workbook.hpp>
|
2014-05-09 03:32:12 +08:00
|
|
|
|
2014-06-06 04:19:31 +08:00
|
|
|
class test_worksheet : public CxxTest::TestSuite
|
2014-05-09 03:32:12 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
void test_new_worksheet()
|
|
|
|
{
|
2016-03-08 15:45:35 +08:00
|
|
|
xlnt::workbook wb;
|
2016-12-02 21:37:50 +08:00
|
|
|
auto ws = wb.active_sheet();
|
|
|
|
TS_ASSERT(ws.workbook() == wb);
|
2014-05-09 03:32:12 +08:00
|
|
|
}
|
2015-10-14 01:56:07 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
void test_cell()
|
2014-05-09 03:32:12 +08:00
|
|
|
{
|
2016-03-08 15:45:35 +08:00
|
|
|
xlnt::workbook wb;
|
2016-12-02 21:37:50 +08:00
|
|
|
auto ws = wb.active_sheet();
|
|
|
|
auto cell = ws.cell(xlnt::cell_reference(1, 1));
|
|
|
|
TS_ASSERT_EQUALS(cell.reference(), "A1");
|
2014-05-09 03:32:12 +08:00
|
|
|
}
|
2016-03-08 15:45:35 +08:00
|
|
|
|
|
|
|
void test_invalid_cell()
|
2015-12-24 14:58:11 +08:00
|
|
|
{
|
2016-08-12 12:22:14 +08:00
|
|
|
TS_ASSERT_THROWS(xlnt::cell_reference(xlnt::column_t((xlnt::column_t::index_t)0), 0),
|
|
|
|
xlnt::invalid_cell_reference);
|
2015-12-24 14:58:11 +08:00
|
|
|
}
|
2015-10-14 01:56:07 +08:00
|
|
|
|
|
|
|
void test_worksheet_dimension()
|
2014-05-09 03:32:12 +08:00
|
|
|
{
|
2016-03-08 15:45:35 +08:00
|
|
|
xlnt::workbook wb;
|
2016-12-02 21:37:50 +08:00
|
|
|
auto ws = wb.active_sheet();
|
2015-10-14 01:56:07 +08:00
|
|
|
|
|
|
|
TS_ASSERT_EQUALS("A1:A1", ws.calculate_dimension());
|
2016-12-02 21:37:50 +08:00
|
|
|
ws.cell("B12").value("AAA");
|
2015-10-14 01:56:07 +08:00
|
|
|
TS_ASSERT_EQUALS("B12:B12", ws.calculate_dimension());
|
2014-07-19 04:20:41 +08:00
|
|
|
}
|
|
|
|
|
2016-03-08 15:45:35 +08:00
|
|
|
void test_fill_rows()
|
2014-05-09 03:32:12 +08:00
|
|
|
{
|
2015-11-04 03:53:48 +08:00
|
|
|
std::size_t row = 0;
|
|
|
|
std::size_t column = 0;
|
2015-11-11 07:58:54 +08:00
|
|
|
std::string coordinate = "A1";
|
2015-10-14 01:56:07 +08:00
|
|
|
|
2016-03-08 15:45:35 +08:00
|
|
|
xlnt::workbook wb;
|
2016-12-02 21:37:50 +08:00
|
|
|
auto ws = wb.active_sheet();
|
2015-10-14 01:56:07 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
ws.cell("A1").value("first");
|
|
|
|
ws.cell("C9").value("last");
|
2015-10-14 01:56:07 +08:00
|
|
|
|
|
|
|
TS_ASSERT_EQUALS(ws.calculate_dimension(), "A1:C9");
|
2016-12-02 21:37:50 +08:00
|
|
|
TS_ASSERT_EQUALS(ws.rows()[row][column].reference(), coordinate);
|
2015-10-14 01:56:07 +08:00
|
|
|
|
|
|
|
row = 8;
|
|
|
|
column = 2;
|
|
|
|
coordinate = "C9";
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
TS_ASSERT_EQUALS(ws.rows()[row][column].reference(), coordinate);
|
2014-05-09 03:32:12 +08:00
|
|
|
}
|
2014-07-27 04:19:15 +08:00
|
|
|
|
2016-03-08 15:45:35 +08:00
|
|
|
void test_iter_rows()
|
2014-07-27 04:19:15 +08:00
|
|
|
{
|
2016-03-08 15:45:35 +08:00
|
|
|
xlnt::workbook wb;
|
2016-12-02 21:37:50 +08:00
|
|
|
auto ws = wb.active_sheet();
|
2015-10-14 01:56:07 +08:00
|
|
|
|
2015-11-11 07:58:54 +08:00
|
|
|
const std::vector<std::vector<std::string>> expected =
|
2015-10-14 01:56:07 +08:00
|
|
|
{
|
|
|
|
{ "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)
|
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
TS_ASSERT_EQUALS(cell.reference(), *expected_cell_iter);
|
2015-10-14 01:56:07 +08:00
|
|
|
expected_cell_iter++;
|
|
|
|
}
|
|
|
|
|
|
|
|
expected_row_iter++;
|
|
|
|
}
|
2014-07-27 04:19:15 +08:00
|
|
|
}
|
2015-10-14 01:56:07 +08:00
|
|
|
|
|
|
|
void test_iter_rows_offset()
|
2014-05-09 03:32:12 +08:00
|
|
|
{
|
2016-03-08 15:45:35 +08:00
|
|
|
xlnt::workbook wb;
|
2016-12-02 21:37:50 +08:00
|
|
|
auto ws = wb.active_sheet();
|
2015-10-14 01:56:07 +08:00
|
|
|
auto rows = ws.rows("A1:C4", 1, 3);
|
|
|
|
|
2015-11-11 07:58:54 +08:00
|
|
|
const std::vector<std::vector<std::string>> expected =
|
2015-10-14 01:56:07 +08:00
|
|
|
{
|
|
|
|
{ "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)
|
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
TS_ASSERT_EQUALS(cell.reference(), *expected_cell_iter);
|
2015-10-14 01:56:07 +08:00
|
|
|
expected_cell_iter++;
|
|
|
|
}
|
|
|
|
|
|
|
|
expected_row_iter++;
|
|
|
|
}
|
2014-05-09 03:32:12 +08:00
|
|
|
}
|
2016-05-26 10:55:50 +08:00
|
|
|
|
|
|
|
void test_iter_rows_offset_int_int()
|
|
|
|
{
|
|
|
|
xlnt::workbook wb;
|
2016-12-02 21:37:50 +08:00
|
|
|
auto ws = wb.active_sheet();
|
2016-05-26 10:55:50 +08:00
|
|
|
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)
|
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
TS_ASSERT_EQUALS(cell.reference(), *expected_cell_iter);
|
2016-05-26 10:55:50 +08:00
|
|
|
expected_cell_iter++;
|
|
|
|
}
|
|
|
|
|
|
|
|
expected_row_iter++;
|
|
|
|
}
|
|
|
|
}
|
2015-10-14 01:56:07 +08:00
|
|
|
|
|
|
|
void test_get_named_range()
|
2014-05-09 03:32:12 +08:00
|
|
|
{
|
2016-03-08 15:45:35 +08:00
|
|
|
xlnt::workbook wb;
|
2016-12-02 21:37:50 +08:00
|
|
|
auto ws = wb.active_sheet();
|
2016-03-08 15:45:35 +08:00
|
|
|
wb.create_named_range("test_range", ws, "C5");
|
2016-12-02 21:37:50 +08:00
|
|
|
auto xlrange = ws.named_range("test_range");
|
2014-07-20 04:59:05 +08:00
|
|
|
TS_ASSERT_EQUALS(1, xlrange.length());
|
2016-12-02 21:37:50 +08:00
|
|
|
TS_ASSERT_EQUALS(1, xlrange[0].length());
|
|
|
|
TS_ASSERT_EQUALS(5, xlrange[0][0].row());
|
2016-06-23 16:33:10 +08:00
|
|
|
|
|
|
|
ws.create_named_range("test_range2", "C6");
|
2016-12-02 21:37:50 +08:00
|
|
|
auto xlrange2 = ws.named_range("test_range2");
|
2016-06-23 16:33:10 +08:00
|
|
|
TS_ASSERT_EQUALS(1, xlrange2.length());
|
2016-12-02 21:37:50 +08:00
|
|
|
TS_ASSERT_EQUALS(1, xlrange2[0].length());
|
|
|
|
TS_ASSERT_EQUALS(6, xlrange2[0][0].row());
|
2014-05-09 03:32:12 +08:00
|
|
|
}
|
2015-10-14 01:56:07 +08:00
|
|
|
|
|
|
|
void test_get_bad_named_range()
|
2014-05-09 03:32:12 +08:00
|
|
|
{
|
2016-03-08 15:45:35 +08:00
|
|
|
xlnt::workbook wb;
|
2016-12-02 21:37:50 +08:00
|
|
|
auto ws = wb.active_sheet();
|
|
|
|
TS_ASSERT_THROWS(ws.named_range("bad_range"), xlnt::key_not_found);
|
2014-05-09 03:32:12 +08:00
|
|
|
}
|
2015-10-14 01:56:07 +08:00
|
|
|
|
|
|
|
void test_get_named_range_wrong_sheet()
|
2014-05-09 03:32:12 +08:00
|
|
|
{
|
2016-03-08 15:45:35 +08:00
|
|
|
xlnt::workbook wb;
|
2016-03-09 16:14:57 +08:00
|
|
|
wb.create_sheet();
|
|
|
|
wb.create_sheet();
|
|
|
|
auto ws1 = wb[0];
|
|
|
|
auto ws2 = wb[1];
|
2016-03-08 15:45:35 +08:00
|
|
|
wb.create_named_range("wrong_sheet_range", ws1, "C5");
|
2016-12-02 21:37:50 +08:00
|
|
|
TS_ASSERT_THROWS(ws2.named_range("wrong_sheet_range"), xlnt::key_not_found);
|
2014-05-09 03:32:12 +08:00
|
|
|
}
|
2015-10-14 01:56:07 +08:00
|
|
|
|
2016-06-23 16:33:10 +08:00
|
|
|
void test_remove_named_range_bad()
|
|
|
|
{
|
|
|
|
xlnt::workbook wb;
|
2016-12-02 21:37:50 +08:00
|
|
|
auto ws = wb.active_sheet();
|
2016-06-23 16:33:10 +08:00
|
|
|
TS_ASSERT_THROWS(ws.remove_named_range("bad_range"), std::runtime_error);
|
|
|
|
}
|
|
|
|
|
2014-05-09 03:32:12 +08:00
|
|
|
void test_cell_alternate_coordinates()
|
|
|
|
{
|
2016-03-08 15:45:35 +08:00
|
|
|
xlnt::workbook wb;
|
2016-12-02 21:37:50 +08:00
|
|
|
auto ws = wb.active_sheet();
|
|
|
|
auto cell = ws.cell(xlnt::cell_reference(4, 8));
|
|
|
|
TS_ASSERT_EQUALS(cell.reference(), "D8");
|
2014-05-09 03:32:12 +08:00
|
|
|
}
|
2015-10-14 01:56:07 +08:00
|
|
|
|
2016-03-08 15:45:35 +08:00
|
|
|
// void test_cell_insufficient_coordinates() {}
|
|
|
|
|
2014-05-09 03:32:12 +08:00
|
|
|
void test_cell_range_name()
|
|
|
|
{
|
2016-03-08 15:45:35 +08:00
|
|
|
xlnt::workbook wb;
|
2016-12-02 21:37:50 +08:00
|
|
|
auto ws = wb.active_sheet();
|
2016-03-08 15:45:35 +08:00
|
|
|
wb.create_named_range("test_range_single", ws, "B12");
|
2016-12-02 21:37:50 +08:00
|
|
|
auto c_range_name = ws.named_range("test_range_single");
|
|
|
|
auto c_range_coord = ws.range("B12");
|
|
|
|
auto c_cell = ws.cell("B12");
|
2014-05-13 01:42:28 +08:00
|
|
|
TS_ASSERT_EQUALS(c_range_coord, c_range_name);
|
2014-05-14 04:32:33 +08:00
|
|
|
TS_ASSERT(c_range_coord[0][0] == c_cell);
|
2014-05-09 03:32:12 +08:00
|
|
|
}
|
2015-10-14 01:56:07 +08:00
|
|
|
|
|
|
|
void test_hyperlink_value()
|
|
|
|
{
|
2016-03-08 15:45:35 +08:00
|
|
|
xlnt::workbook wb;
|
2016-12-02 21:37:50 +08:00
|
|
|
auto ws = wb.active_sheet();
|
|
|
|
ws.cell("A1").hyperlink("http://test.com");
|
2017-02-18 13:11:06 +08:00
|
|
|
TS_ASSERT_EQUALS(ws.cell("A1").hyperlink(), "http://test.com");
|
|
|
|
TS_ASSERT_EQUALS(ws.cell("A1").value<std::string>(), "");
|
2016-12-02 21:37:50 +08:00
|
|
|
ws.cell("A1").value("test");
|
|
|
|
TS_ASSERT_EQUALS("test", ws.cell("A1").value<std::string>());
|
|
|
|
TS_ASSERT_EQUALS(ws.cell("A1").hyperlink(), "http://test.com");
|
2015-10-14 01:56:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void test_append()
|
2014-05-09 03:32:12 +08:00
|
|
|
{
|
2016-03-08 15:45:35 +08:00
|
|
|
xlnt::workbook wb;
|
2016-12-02 21:37:50 +08:00
|
|
|
auto ws = wb.active_sheet();
|
2015-11-11 07:58:54 +08:00
|
|
|
ws.append(std::vector<std::string> {"value"});
|
2016-12-02 21:37:50 +08:00
|
|
|
TS_ASSERT_EQUALS("value", ws.cell("A1").value<std::string>());
|
2014-05-09 03:32:12 +08:00
|
|
|
}
|
2015-10-14 01:56:07 +08:00
|
|
|
|
2014-05-09 03:32:12 +08:00
|
|
|
void test_append_list()
|
|
|
|
{
|
2016-03-08 15:45:35 +08:00
|
|
|
xlnt::workbook wb;
|
2016-12-02 21:37:50 +08:00
|
|
|
auto ws = wb.active_sheet();
|
2015-10-14 01:56:07 +08:00
|
|
|
|
2015-11-11 07:58:54 +08:00
|
|
|
ws.append(std::vector<std::string> {"This is A1", "This is B1"});
|
2015-10-14 01:56:07 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
TS_ASSERT_EQUALS("This is A1", ws.cell("A1").value<std::string>());
|
|
|
|
TS_ASSERT_EQUALS("This is B1", ws.cell("B1").value<std::string>());
|
2014-05-09 03:32:12 +08:00
|
|
|
}
|
2015-10-14 01:56:07 +08:00
|
|
|
|
2014-05-09 03:32:12 +08:00
|
|
|
void test_append_dict_letter()
|
|
|
|
{
|
2016-03-08 15:45:35 +08:00
|
|
|
xlnt::workbook wb;
|
2016-12-02 21:37:50 +08:00
|
|
|
auto ws = wb.active_sheet();
|
2015-10-14 01:56:07 +08:00
|
|
|
|
2015-11-11 07:58:54 +08:00
|
|
|
const std::unordered_map<std::string, std::string> dict_letter =
|
2015-10-14 01:56:07 +08:00
|
|
|
{
|
|
|
|
{ "A", "This is A1" },
|
|
|
|
{ "C", "This is C1" }
|
|
|
|
};
|
|
|
|
|
|
|
|
ws.append(dict_letter);
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
TS_ASSERT_EQUALS("This is A1", ws.cell("A1").value<std::string>());
|
|
|
|
TS_ASSERT_EQUALS("This is C1", ws.cell("C1").value<std::string>());
|
2014-05-09 03:32:12 +08:00
|
|
|
}
|
2015-10-14 01:56:07 +08:00
|
|
|
|
2014-05-09 03:32:12 +08:00
|
|
|
void test_append_dict_index()
|
|
|
|
{
|
2016-03-08 15:45:35 +08:00
|
|
|
xlnt::workbook wb;
|
2016-12-02 21:37:50 +08:00
|
|
|
auto ws = wb.active_sheet();
|
2015-10-14 01:56:07 +08:00
|
|
|
|
2015-11-11 07:58:54 +08:00
|
|
|
const std::unordered_map<int, std::string> dict_index =
|
2015-10-14 01:56:07 +08:00
|
|
|
{
|
|
|
|
{ 1, "This is A1" },
|
|
|
|
{ 3, "This is C1" }
|
|
|
|
};
|
|
|
|
|
|
|
|
ws.append(dict_index);
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
TS_ASSERT_EQUALS("This is A1", ws.cell("A1").value<std::string>());
|
|
|
|
TS_ASSERT_EQUALS("This is C1", ws.cell("C1").value<std::string>());
|
2015-10-14 01:56:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void test_append_iterator()
|
|
|
|
{
|
|
|
|
std::vector<int> range;
|
|
|
|
|
|
|
|
for(int i = 0; i < 30; i++)
|
|
|
|
{
|
|
|
|
range.push_back(i);
|
|
|
|
}
|
|
|
|
|
2016-03-08 15:45:35 +08:00
|
|
|
xlnt::workbook wb;
|
2016-12-02 21:37:50 +08:00
|
|
|
auto ws = wb.active_sheet();
|
2015-10-14 01:56:07 +08:00
|
|
|
ws.append(range.begin(), range.end());
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
TS_ASSERT_EQUALS(ws[xlnt::cell_reference("AD1")].value<int>(), 29);
|
2015-10-14 01:56:07 +08:00
|
|
|
}
|
|
|
|
|
2014-05-09 03:32:12 +08:00
|
|
|
void test_append_2d_list()
|
|
|
|
{
|
2016-03-08 15:45:35 +08:00
|
|
|
xlnt::workbook wb;
|
2016-12-02 21:37:50 +08:00
|
|
|
auto ws = wb.active_sheet();
|
2015-10-14 01:56:07 +08:00
|
|
|
|
2015-11-11 07:58:54 +08:00
|
|
|
ws.append(std::vector<std::string> {"This is A1", "This is B1"});
|
|
|
|
ws.append(std::vector<std::string> {"This is A2", "This is B2"});
|
2015-10-14 01:56:07 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
auto vals = ws.range("A1:B2");
|
2015-10-14 01:56:07 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
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");
|
2014-05-09 03:32:12 +08:00
|
|
|
}
|
2016-08-02 06:33:43 +08:00
|
|
|
|
2014-05-09 03:32:12 +08:00
|
|
|
void test_rows()
|
|
|
|
{
|
2016-03-08 15:45:35 +08:00
|
|
|
xlnt::workbook wb;
|
2016-12-02 21:37:50 +08:00
|
|
|
auto ws = wb.active_sheet();
|
2015-10-14 01:56:07 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
ws.cell("A1").value("first");
|
|
|
|
ws.cell("C9").value("last");
|
2015-10-14 01:56:07 +08:00
|
|
|
|
2014-05-14 02:40:28 +08:00
|
|
|
auto rows = ws.rows();
|
2015-10-14 01:56:07 +08:00
|
|
|
|
2014-07-19 04:20:41 +08:00
|
|
|
TS_ASSERT_EQUALS(rows.length(), 9);
|
2015-10-14 01:56:07 +08:00
|
|
|
|
|
|
|
auto first_row = rows[0];
|
|
|
|
auto last_row = rows[8];
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
TS_ASSERT_EQUALS(first_row[0].value<std::string>(), "first");
|
|
|
|
TS_ASSERT_EQUALS(first_row[0].reference(), "A1");
|
|
|
|
TS_ASSERT_EQUALS(last_row[2].value<std::string>(), "last");
|
2015-10-14 01:56:07 +08:00
|
|
|
}
|
|
|
|
|
2016-03-08 15:45:35 +08:00
|
|
|
void test_no_rows()
|
|
|
|
{
|
|
|
|
xlnt::workbook wb;
|
2016-12-02 21:37:50 +08:00
|
|
|
auto ws = wb.active_sheet();
|
2016-03-08 15:45:35 +08:00
|
|
|
|
|
|
|
TS_ASSERT_EQUALS(ws.rows().length(), 1);
|
|
|
|
TS_ASSERT_EQUALS(ws.rows()[0].length(), 1);
|
|
|
|
}
|
|
|
|
|
2015-10-14 01:56:07 +08:00
|
|
|
void test_no_cols()
|
|
|
|
{
|
2016-03-08 15:45:35 +08:00
|
|
|
xlnt::workbook wb;
|
2016-12-02 21:37:50 +08:00
|
|
|
auto ws = wb.active_sheet();
|
2016-03-08 15:45:35 +08:00
|
|
|
|
|
|
|
TS_ASSERT_EQUALS(ws.columns().length(), 1);
|
|
|
|
TS_ASSERT_EQUALS(ws.columns()[0].length(), 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void test_one_cell()
|
|
|
|
{
|
|
|
|
xlnt::workbook wb;
|
2016-12-02 21:37:50 +08:00
|
|
|
auto ws = wb.active_sheet();
|
2016-03-08 15:45:35 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
auto cell = ws.cell("A1");
|
2015-10-14 01:56:07 +08:00
|
|
|
|
|
|
|
TS_ASSERT_EQUALS(ws.columns().length(), 1);
|
|
|
|
TS_ASSERT_EQUALS(ws.columns()[0].length(), 1);
|
2016-03-08 15:45:35 +08:00
|
|
|
TS_ASSERT_EQUALS(ws.columns()[0][0], cell);
|
2014-05-09 03:32:12 +08:00
|
|
|
}
|
2014-07-19 04:20:41 +08:00
|
|
|
|
2016-03-08 15:45:35 +08:00
|
|
|
// void test_by_col() {}
|
|
|
|
|
2014-07-19 04:20:41 +08:00
|
|
|
void test_cols()
|
|
|
|
{
|
2016-03-08 15:45:35 +08:00
|
|
|
xlnt::workbook wb;
|
2016-12-02 21:37:50 +08:00
|
|
|
auto ws = wb.active_sheet();
|
2015-10-14 01:56:07 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
ws.cell("A1").value("first");
|
|
|
|
ws.cell("C9").value("last");
|
2015-10-14 01:56:07 +08:00
|
|
|
|
2014-07-19 04:20:41 +08:00
|
|
|
auto cols = ws.columns();
|
2015-10-14 01:56:07 +08:00
|
|
|
|
2014-07-19 04:20:41 +08:00
|
|
|
TS_ASSERT_EQUALS(cols.length(), 3);
|
2015-10-14 01:56:07 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
TS_ASSERT_EQUALS(cols[0][0].value<std::string>(), "first");
|
|
|
|
TS_ASSERT_EQUALS(cols[2][8].value<std::string>(), "last");
|
2014-07-19 04:20:41 +08:00
|
|
|
}
|
2015-10-14 01:56:07 +08:00
|
|
|
|
2014-05-09 03:32:12 +08:00
|
|
|
void test_auto_filter()
|
|
|
|
{
|
2016-03-08 15:45:35 +08:00
|
|
|
xlnt::workbook wb;
|
2016-12-02 21:37:50 +08:00
|
|
|
auto ws = wb.active_sheet();
|
2015-10-14 01:56:07 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
ws.auto_filter(ws.range("a1:f1"));
|
|
|
|
TS_ASSERT_EQUALS(ws.auto_filter(), "A1:F1");
|
2015-10-14 01:56:07 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
ws.clear_auto_filter();
|
2016-12-10 08:18:50 +08:00
|
|
|
TS_ASSERT(!ws.has_auto_filter());
|
2015-10-14 01:56:07 +08:00
|
|
|
|
2014-06-05 06:42:17 +08:00
|
|
|
ws.auto_filter("c1:g9");
|
2016-12-02 21:37:50 +08:00
|
|
|
TS_ASSERT_EQUALS(ws.auto_filter(), "C1:G9");
|
2014-05-09 03:32:12 +08:00
|
|
|
}
|
2014-07-27 04:19:15 +08:00
|
|
|
|
|
|
|
void test_getitem()
|
|
|
|
{
|
2016-03-08 15:45:35 +08:00
|
|
|
xlnt::workbook wb;
|
2016-12-02 21:37:50 +08:00
|
|
|
auto ws = wb.active_sheet();
|
2014-07-27 04:19:15 +08:00
|
|
|
xlnt::cell cell = ws[xlnt::cell_reference("A1")];
|
2016-12-02 21:37:50 +08:00
|
|
|
TS_ASSERT_EQUALS(cell.reference().to_string(), "A1");
|
|
|
|
TS_ASSERT_EQUALS(cell.data_type(), xlnt::cell::type::null);
|
2014-07-27 04:19:15 +08:00
|
|
|
}
|
2016-08-02 06:33:43 +08:00
|
|
|
|
2014-07-27 04:19:15 +08:00
|
|
|
void test_setitem()
|
|
|
|
{
|
2016-03-08 15:45:35 +08:00
|
|
|
xlnt::workbook wb;
|
2016-12-02 21:37:50 +08:00
|
|
|
auto ws = wb.active_sheet();
|
|
|
|
ws[xlnt::cell_reference("A12")].value(5);
|
|
|
|
TS_ASSERT(ws[xlnt::cell_reference("A12")].value<int>() == 5);
|
2014-07-27 04:19:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void test_getslice()
|
|
|
|
{
|
2016-03-08 15:45:35 +08:00
|
|
|
xlnt::workbook wb;
|
2016-12-02 21:37:50 +08:00
|
|
|
auto ws = wb.active_sheet();
|
2014-07-27 04:19:15 +08:00
|
|
|
auto cell_range = ws("A1", "B2");
|
2016-12-02 21:37:50 +08:00
|
|
|
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"));
|
|
|
|
TS_ASSERT_EQUALS(cell_range[1][1], ws.cell("B2"));
|
2014-07-27 04:19:15 +08:00
|
|
|
}
|
2016-08-02 06:33:43 +08:00
|
|
|
|
2014-07-19 04:20:41 +08:00
|
|
|
void test_freeze()
|
2014-05-09 03:32:12 +08:00
|
|
|
{
|
2016-03-08 15:45:35 +08:00
|
|
|
xlnt::workbook wb;
|
2016-12-02 21:37:50 +08:00
|
|
|
auto ws = wb.active_sheet();
|
2015-10-14 01:56:07 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
ws.freeze_panes(ws.cell("b2"));
|
|
|
|
TS_ASSERT_EQUALS(ws.frozen_panes(), "B2");
|
2015-10-14 01:56:07 +08:00
|
|
|
|
2014-07-19 04:20:41 +08:00
|
|
|
ws.unfreeze_panes();
|
|
|
|
TS_ASSERT(!ws.has_frozen_panes());
|
2015-10-14 01:56:07 +08:00
|
|
|
|
2014-07-19 04:20:41 +08:00
|
|
|
ws.freeze_panes("c5");
|
2016-12-02 21:37:50 +08:00
|
|
|
TS_ASSERT_EQUALS(ws.frozen_panes(), "C5");
|
2015-10-14 01:56:07 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
ws.freeze_panes(ws.cell("A1"));
|
2014-07-19 04:20:41 +08:00
|
|
|
TS_ASSERT(!ws.has_frozen_panes());
|
2014-05-09 03:32:12 +08:00
|
|
|
}
|
2015-10-14 01:56:07 +08:00
|
|
|
|
|
|
|
void test_merged_cells_lookup()
|
|
|
|
{
|
2016-03-08 15:45:35 +08:00
|
|
|
xlnt::workbook wb;
|
2016-12-02 21:37:50 +08:00
|
|
|
auto ws = wb.active_sheet();
|
|
|
|
ws.cell("A2").value("test");
|
2015-10-14 01:56:07 +08:00
|
|
|
ws.merge_cells("A1:N50");
|
2016-12-02 21:37:50 +08:00
|
|
|
auto all_merged = ws.merged_ranges();
|
2015-10-14 01:56:07 +08:00
|
|
|
TS_ASSERT_EQUALS(all_merged.size(), 1);
|
2016-12-02 21:37:50 +08:00
|
|
|
auto merged = ws.range(all_merged[0]);
|
2015-10-14 01:56:07 +08:00
|
|
|
TS_ASSERT(merged.contains("A1"));
|
|
|
|
TS_ASSERT(merged.contains("N50"));
|
|
|
|
TS_ASSERT(!merged.contains("A51"));
|
|
|
|
TS_ASSERT(!merged.contains("O1"));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void test_merged_cell_ranges()
|
|
|
|
{
|
2016-03-08 15:45:35 +08:00
|
|
|
xlnt::workbook wb;
|
2016-12-02 21:37:50 +08:00
|
|
|
auto ws = wb.active_sheet();
|
|
|
|
TS_ASSERT_EQUALS(ws.merged_ranges().size(), 0);
|
2015-10-14 01:56:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void test_merge_range_string()
|
|
|
|
{
|
2016-03-08 15:45:35 +08:00
|
|
|
xlnt::workbook wb;
|
2016-12-02 21:37:50 +08:00
|
|
|
auto ws = wb.active_sheet();
|
|
|
|
ws.cell("A1").value(1);
|
|
|
|
ws.cell("D4").value(16);
|
2015-10-14 01:56:07 +08:00
|
|
|
ws.merge_cells("A1:D4");
|
|
|
|
std::vector<xlnt::range_reference> expected = { xlnt::range_reference("A1:D4") };
|
2016-12-02 21:37:50 +08:00
|
|
|
TS_ASSERT_EQUALS(ws.merged_ranges(), expected);
|
|
|
|
TS_ASSERT(!ws.cell("D4").has_value());
|
2015-10-14 01:56:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void test_merge_coordinate()
|
|
|
|
{
|
2016-03-08 15:45:35 +08:00
|
|
|
xlnt::workbook wb;
|
2016-12-02 21:37:50 +08:00
|
|
|
auto ws = wb.active_sheet();
|
2015-10-14 01:56:07 +08:00
|
|
|
ws.merge_cells(1, 1, 4, 4);
|
|
|
|
std::vector<xlnt::range_reference> expected = { xlnt::range_reference("A1:D4") };
|
2016-12-02 21:37:50 +08:00
|
|
|
TS_ASSERT_EQUALS(ws.merged_ranges(), expected);
|
2015-10-14 01:56:07 +08:00
|
|
|
}
|
|
|
|
|
2016-06-23 16:33:10 +08:00
|
|
|
void test_unmerge_bad()
|
|
|
|
{
|
|
|
|
xlnt::workbook wb;
|
2016-12-02 21:37:50 +08:00
|
|
|
auto ws = wb.active_sheet();
|
2016-06-23 16:33:10 +08:00
|
|
|
|
|
|
|
TS_ASSERT_THROWS(ws.unmerge_cells("A1:D3"), std::runtime_error);
|
|
|
|
}
|
|
|
|
|
2015-10-14 01:56:07 +08:00
|
|
|
void test_unmerge_range_string()
|
|
|
|
{
|
2016-03-08 15:45:35 +08:00
|
|
|
xlnt::workbook wb;
|
2016-12-02 21:37:50 +08:00
|
|
|
auto ws = wb.active_sheet();
|
2015-10-14 01:56:07 +08:00
|
|
|
ws.merge_cells("A1:D4");
|
2016-12-02 21:37:50 +08:00
|
|
|
TS_ASSERT_EQUALS(ws.merged_ranges().size(), 1);
|
2015-10-14 01:56:07 +08:00
|
|
|
ws.unmerge_cells("A1:D4");
|
2016-12-02 21:37:50 +08:00
|
|
|
TS_ASSERT_EQUALS(ws.merged_ranges().size(), 0);
|
2015-10-14 01:56:07 +08:00
|
|
|
}
|
2016-06-23 16:33:10 +08:00
|
|
|
|
2015-10-14 01:56:07 +08:00
|
|
|
void test_unmerge_coordinate()
|
|
|
|
{
|
2016-03-08 15:45:35 +08:00
|
|
|
xlnt::workbook wb;
|
2016-12-02 21:37:50 +08:00
|
|
|
auto ws = wb.active_sheet();
|
2015-10-14 01:56:07 +08:00
|
|
|
ws.merge_cells("A1:D4");
|
2016-12-02 21:37:50 +08:00
|
|
|
TS_ASSERT_EQUALS(ws.merged_ranges().size(), 1);
|
2015-10-14 01:56:07 +08:00
|
|
|
ws.unmerge_cells(1, 1, 4, 4);
|
2016-12-02 21:37:50 +08:00
|
|
|
TS_ASSERT_EQUALS(ws.merged_ranges().size(), 0);
|
2015-10-14 01:56:07 +08:00
|
|
|
}
|
2016-06-23 16:33:10 +08:00
|
|
|
|
2016-03-08 15:45:35 +08:00
|
|
|
void test_print_titles_old()
|
2015-10-14 01:56:07 +08:00
|
|
|
{
|
2016-03-08 15:45:35 +08:00
|
|
|
xlnt::workbook wb;
|
2016-08-06 22:40:17 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
auto ws = wb.active_sheet();
|
|
|
|
ws.print_title_rows(3);
|
|
|
|
TS_ASSERT_EQUALS(ws.print_titles(), "Sheet1!1:3");
|
2016-03-08 15:45:35 +08:00
|
|
|
|
2016-08-06 22:40:17 +08:00
|
|
|
auto ws2 = wb.create_sheet();
|
2016-12-02 21:37:50 +08:00
|
|
|
ws2.print_title_cols(4);
|
|
|
|
TS_ASSERT_EQUALS(ws2.print_titles(), "Sheet2!A:D");
|
2015-10-14 01:56:07 +08:00
|
|
|
}
|
|
|
|
|
2016-03-08 15:45:35 +08:00
|
|
|
void test_print_titles_new()
|
2015-10-14 01:56:07 +08:00
|
|
|
{
|
2016-03-08 15:45:35 +08:00
|
|
|
xlnt::workbook wb;
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
auto ws = wb.active_sheet();
|
|
|
|
ws.print_title_rows(4);
|
|
|
|
TS_ASSERT_EQUALS(ws.print_titles(), "Sheet1!1:4");
|
2016-03-08 15:45:35 +08:00
|
|
|
|
2016-08-06 22:40:17 +08:00
|
|
|
auto ws2 = wb.create_sheet();
|
2016-12-02 21:37:50 +08:00
|
|
|
ws2.print_title_cols("F");
|
|
|
|
TS_ASSERT_EQUALS(ws2.print_titles(), "Sheet2!A:F");
|
2016-08-06 22:40:17 +08:00
|
|
|
|
|
|
|
auto ws3 = wb.create_sheet();
|
2016-12-02 21:37:50 +08:00
|
|
|
ws3.print_title_rows(2, 3);
|
|
|
|
ws3.print_title_cols("C", "D");
|
|
|
|
TS_ASSERT_EQUALS(ws3.print_titles(), "Sheet3!2:3,Sheet3!C:D");
|
2015-10-14 01:56:07 +08:00
|
|
|
}
|
|
|
|
|
2016-03-08 15:45:35 +08:00
|
|
|
void test_print_area()
|
2015-10-14 01:56:07 +08:00
|
|
|
{
|
2016-03-08 15:45:35 +08:00
|
|
|
xlnt::workbook wb;
|
2016-12-02 21:37:50 +08:00
|
|
|
auto ws = wb.active_sheet();
|
|
|
|
ws.print_area("A1:F5");
|
|
|
|
TS_ASSERT_EQUALS(ws.print_area(), "$A$1:$F$5");
|
2015-10-14 01:56:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void test_freeze_panes_horiz()
|
|
|
|
{
|
2016-03-08 15:45:35 +08:00
|
|
|
xlnt::workbook wb;
|
2016-12-02 21:37:50 +08:00
|
|
|
auto ws = wb.active_sheet();
|
2015-10-14 01:56:07 +08:00
|
|
|
ws.freeze_panes("A4");
|
2016-03-08 15:45:35 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
auto view = ws.view();
|
|
|
|
TS_ASSERT_EQUALS(view.selections().size(), 2);
|
|
|
|
TS_ASSERT_EQUALS(view.selections()[0].active_cell(), "A3");
|
|
|
|
TS_ASSERT_EQUALS(view.selections()[0].pane(), xlnt::pane_corner::bottom_left);
|
|
|
|
TS_ASSERT_EQUALS(view.selections()[0].sqref(), "A1");
|
|
|
|
TS_ASSERT_EQUALS(view.pane().active_pane, xlnt::pane_corner::bottom_left);
|
|
|
|
TS_ASSERT_EQUALS(view.pane().state, xlnt::pane_state::frozen);
|
|
|
|
TS_ASSERT_EQUALS(view.pane().top_left_cell.get(), "A4");
|
|
|
|
TS_ASSERT_EQUALS(view.pane().y_split, 3);
|
2015-10-14 01:56:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void test_freeze_panes_vert()
|
|
|
|
{
|
2016-03-08 15:45:35 +08:00
|
|
|
xlnt::workbook wb;
|
2016-12-02 21:37:50 +08:00
|
|
|
auto ws = wb.active_sheet();
|
2015-10-14 01:56:07 +08:00
|
|
|
ws.freeze_panes("D1");
|
2016-03-08 15:45:35 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
auto view = ws.view();
|
|
|
|
TS_ASSERT_EQUALS(view.selections().size(), 2);
|
|
|
|
TS_ASSERT_EQUALS(view.selections()[0].active_cell(), "C1");
|
|
|
|
TS_ASSERT_EQUALS(view.selections()[0].pane(), xlnt::pane_corner::top_right);
|
|
|
|
TS_ASSERT_EQUALS(view.selections()[0].sqref(), "A1");
|
|
|
|
TS_ASSERT_EQUALS(view.pane().active_pane, xlnt::pane_corner::top_right);
|
|
|
|
TS_ASSERT_EQUALS(view.pane().state, xlnt::pane_state::frozen);
|
|
|
|
TS_ASSERT_EQUALS(view.pane().top_left_cell.get(), "D1");
|
|
|
|
TS_ASSERT_EQUALS(view.pane().x_split, 3);
|
2015-10-14 01:56:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void test_freeze_panes_both()
|
|
|
|
{
|
2016-03-08 15:45:35 +08:00
|
|
|
xlnt::workbook wb;
|
2016-12-02 21:37:50 +08:00
|
|
|
auto ws = wb.active_sheet();
|
2015-10-14 01:56:07 +08:00
|
|
|
ws.freeze_panes("D4");
|
2016-03-08 15:45:35 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
auto view = ws.view();
|
|
|
|
TS_ASSERT_EQUALS(view.selections().size(), 3);
|
|
|
|
TS_ASSERT_EQUALS(view.selections()[0].pane(), xlnt::pane_corner::top_right);
|
|
|
|
TS_ASSERT_EQUALS(view.selections()[1].pane(), xlnt::pane_corner::bottom_left);
|
|
|
|
TS_ASSERT_EQUALS(view.selections()[2].active_cell(), "D4");
|
|
|
|
TS_ASSERT_EQUALS(view.selections()[2].pane(), xlnt::pane_corner::bottom_right);
|
|
|
|
TS_ASSERT_EQUALS(view.selections()[2].sqref(), "A1");
|
|
|
|
TS_ASSERT_EQUALS(view.pane().active_pane, xlnt::pane_corner::bottom_right);
|
|
|
|
TS_ASSERT_EQUALS(view.pane().state, xlnt::pane_state::frozen);
|
|
|
|
TS_ASSERT_EQUALS(view.pane().top_left_cell.get(), "D4");
|
|
|
|
TS_ASSERT_EQUALS(view.pane().x_split, 3);
|
|
|
|
TS_ASSERT_EQUALS(view.pane().y_split, 3);
|
2015-10-14 01:56:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void test_min_column()
|
|
|
|
{
|
2016-03-08 15:45:35 +08:00
|
|
|
xlnt::workbook wb;
|
2016-12-02 21:37:50 +08:00
|
|
|
auto ws = wb.active_sheet();
|
|
|
|
TS_ASSERT_EQUALS(ws.lowest_column(), 1);
|
2015-10-14 01:56:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void test_max_column()
|
|
|
|
{
|
2016-03-08 15:45:35 +08:00
|
|
|
xlnt::workbook wb;
|
2016-12-02 21:37:50 +08:00
|
|
|
auto ws = wb.active_sheet();
|
|
|
|
ws[xlnt::cell_reference("F1")].value(10);
|
|
|
|
ws[xlnt::cell_reference("F2")].value(32);
|
|
|
|
ws[xlnt::cell_reference("F3")].formula("=F1+F2");
|
|
|
|
ws[xlnt::cell_reference("A4")].formula("=A1+A2+A3");
|
|
|
|
TS_ASSERT_EQUALS(ws.highest_column(), 6);
|
2015-10-14 01:56:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void test_min_row()
|
|
|
|
{
|
2016-03-08 15:45:35 +08:00
|
|
|
xlnt::workbook wb;
|
2016-12-02 21:37:50 +08:00
|
|
|
auto ws = wb.active_sheet();
|
|
|
|
TS_ASSERT_EQUALS(ws.lowest_row(), 1);
|
2015-10-14 01:56:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void test_max_row()
|
|
|
|
{
|
2016-03-08 15:45:35 +08:00
|
|
|
xlnt::workbook wb;
|
2016-12-02 21:37:50 +08:00
|
|
|
auto ws = wb.active_sheet();
|
2015-10-14 04:35:22 +08:00
|
|
|
ws.append();
|
|
|
|
ws.append(std::vector<int> { 5 });
|
|
|
|
ws.append();
|
|
|
|
ws.append(std::vector<int> { 4 });
|
2016-12-02 21:37:50 +08:00
|
|
|
TS_ASSERT_EQUALS(ws.highest_row(), 4);
|
2015-10-14 01:56:07 +08:00
|
|
|
}
|
2016-06-14 11:36:26 +08:00
|
|
|
|
|
|
|
void test_const_iterators()
|
|
|
|
{
|
|
|
|
xlnt::workbook wb;
|
2016-12-02 21:37:50 +08:00
|
|
|
auto ws = wb.active_sheet();
|
2016-06-14 11:36:26 +08:00
|
|
|
|
|
|
|
ws.append({"A1", "B1", "C1"});
|
|
|
|
ws.append({"A2", "B2", "C2"});
|
|
|
|
|
|
|
|
const xlnt::worksheet ws_const = ws;
|
|
|
|
const auto rows = ws_const.rows();
|
|
|
|
|
|
|
|
const auto first_row = *rows.begin();
|
|
|
|
const auto first_cell = *first_row.begin();
|
2016-12-02 21:37:50 +08:00
|
|
|
TS_ASSERT_EQUALS(first_cell.value<std::string>(), "A1");
|
2016-06-14 11:36:26 +08:00
|
|
|
|
|
|
|
const auto last_row = *(--rows.end());
|
|
|
|
const auto last_cell = *(--last_row.end());
|
2016-12-02 21:37:50 +08:00
|
|
|
TS_ASSERT_EQUALS(last_cell.value<std::string>(), "C2");
|
2016-06-14 11:36:26 +08:00
|
|
|
|
|
|
|
for (const auto row : rows)
|
|
|
|
{
|
|
|
|
for (const auto cell : row)
|
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
TS_ASSERT_EQUALS(cell.value<std::string>(), cell.reference().to_string());
|
2016-06-14 11:36:26 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void test_const_reverse_iterators()
|
|
|
|
{
|
|
|
|
xlnt::workbook wb;
|
2016-12-02 21:37:50 +08:00
|
|
|
auto ws = wb.active_sheet();
|
2016-06-14 11:36:26 +08:00
|
|
|
|
|
|
|
ws.append({"A1", "B1", "C1"});
|
|
|
|
ws.append({"A2", "B2", "C2"});
|
|
|
|
|
|
|
|
const xlnt::worksheet ws_const = ws;
|
|
|
|
const auto rows = ws_const.rows();
|
|
|
|
|
|
|
|
const auto first_row = *rows.rbegin();
|
|
|
|
const auto first_cell = *first_row.rbegin();
|
2016-12-02 21:37:50 +08:00
|
|
|
TS_ASSERT_EQUALS(first_cell.value<std::string>(), "C2");
|
2016-06-14 11:36:26 +08:00
|
|
|
|
2016-07-22 07:44:00 +08:00
|
|
|
auto row_iter = rows.rend();
|
|
|
|
row_iter--;
|
|
|
|
const auto last_row = *row_iter;
|
|
|
|
auto cell_iter = last_row.rend();
|
|
|
|
cell_iter--;
|
|
|
|
const auto last_cell = *cell_iter;
|
2016-12-02 21:37:50 +08:00
|
|
|
TS_ASSERT_EQUALS(last_cell.value<std::string>(), "A1");
|
2016-06-14 11:36:26 +08:00
|
|
|
|
2016-07-22 07:44:00 +08:00
|
|
|
for (auto ws_iter = rows.rbegin(); ws_iter != rows.rend(); ws_iter++)
|
2016-06-14 11:36:26 +08:00
|
|
|
{
|
|
|
|
const auto row = *ws_iter;
|
|
|
|
|
2016-07-22 07:44:00 +08:00
|
|
|
for (auto row_iter = row.rbegin(); row_iter != row.rend(); row_iter++)
|
2016-06-14 11:36:26 +08:00
|
|
|
{
|
|
|
|
const auto cell = *row_iter;
|
2016-12-02 21:37:50 +08:00
|
|
|
TS_ASSERT_EQUALS(cell.value<std::string>(), cell.reference().to_string());
|
2016-06-14 11:36:26 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-15 19:45:05 +08:00
|
|
|
void test_column_major_iterators()
|
|
|
|
{
|
|
|
|
xlnt::workbook wb;
|
2016-12-02 21:37:50 +08:00
|
|
|
auto ws = wb.active_sheet();
|
2016-06-15 19:45:05 +08:00
|
|
|
|
|
|
|
ws.append({"A1", "B1", "C1"});
|
|
|
|
ws.append({"A2", "B2", "C2"});
|
|
|
|
|
|
|
|
auto columns = ws.columns();
|
|
|
|
|
|
|
|
auto first_column = *columns.begin();
|
|
|
|
auto first_column_iter = first_column.begin();
|
|
|
|
auto first_cell = *first_column_iter;
|
2016-12-02 21:37:50 +08:00
|
|
|
TS_ASSERT_EQUALS(first_cell.value<std::string>(), "A1");
|
2016-06-15 19:45:05 +08:00
|
|
|
first_column_iter++;
|
|
|
|
auto second_cell = *first_column_iter;
|
2016-12-02 21:37:50 +08:00
|
|
|
TS_ASSERT_EQUALS(second_cell.value<std::string>(), "A2");
|
2016-06-15 19:45:05 +08:00
|
|
|
|
2016-07-24 09:24:25 +08:00
|
|
|
TS_ASSERT_EQUALS(first_cell, first_column.front());
|
|
|
|
TS_ASSERT_EQUALS(second_cell, first_column.back());
|
|
|
|
|
2016-06-15 19:45:05 +08:00
|
|
|
auto last_column = *(--columns.end());
|
|
|
|
auto last_column_iter = last_column.end();
|
|
|
|
last_column_iter--;
|
|
|
|
auto last_cell = *last_column_iter;
|
2016-12-02 21:37:50 +08:00
|
|
|
TS_ASSERT_EQUALS(last_cell.value<std::string>(), "C2");
|
2016-06-15 19:45:05 +08:00
|
|
|
last_column_iter--;
|
|
|
|
auto penultimate_cell = *last_column_iter;
|
2016-12-02 21:37:50 +08:00
|
|
|
TS_ASSERT_EQUALS(penultimate_cell.value<std::string>(), "C1");
|
2016-06-15 19:45:05 +08:00
|
|
|
|
|
|
|
for (auto column : columns)
|
|
|
|
{
|
|
|
|
for (auto cell : column)
|
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
TS_ASSERT_EQUALS(cell.value<std::string>(), cell.reference().to_string());
|
2016-06-15 19:45:05 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void test_reverse_column_major_iterators()
|
|
|
|
{
|
|
|
|
xlnt::workbook wb;
|
2016-12-02 21:37:50 +08:00
|
|
|
auto ws = wb.active_sheet();
|
2016-06-15 19:45:05 +08:00
|
|
|
|
|
|
|
ws.append({"A1", "B1", "C1"});
|
|
|
|
ws.append({"A2", "B2", "C2"});
|
|
|
|
|
|
|
|
auto columns = ws.columns();
|
|
|
|
|
|
|
|
auto column_iter = columns.rbegin();
|
2016-06-15 20:36:03 +08:00
|
|
|
auto first_column = *column_iter;
|
|
|
|
|
2016-06-15 19:45:05 +08:00
|
|
|
auto first_column_iter = first_column.rbegin();
|
2016-06-15 20:36:03 +08:00
|
|
|
auto first_cell = *first_column_iter;
|
2016-12-02 21:37:50 +08:00
|
|
|
TS_ASSERT_EQUALS(first_cell.value<std::string>(), "C2");
|
2016-06-15 19:45:05 +08:00
|
|
|
first_column_iter++;
|
2016-06-15 20:36:03 +08:00
|
|
|
auto second_cell = *first_column_iter;
|
2016-12-02 21:37:50 +08:00
|
|
|
TS_ASSERT_EQUALS(second_cell.value<std::string>(), "C1");
|
2016-06-15 19:45:05 +08:00
|
|
|
|
2016-06-15 20:36:03 +08:00
|
|
|
auto last_column = *(--columns.rend());
|
2016-06-15 19:45:05 +08:00
|
|
|
auto last_column_iter = last_column.rend();
|
|
|
|
last_column_iter--;
|
2016-06-15 20:36:03 +08:00
|
|
|
auto last_cell = *last_column_iter;
|
2016-12-02 21:37:50 +08:00
|
|
|
TS_ASSERT_EQUALS(last_cell.value<std::string>(), "A1");
|
2016-06-15 19:45:05 +08:00
|
|
|
last_column_iter--;
|
2016-06-15 20:36:03 +08:00
|
|
|
auto penultimate_cell = *last_column_iter;
|
2016-12-02 21:37:50 +08:00
|
|
|
TS_ASSERT_EQUALS(penultimate_cell.value<std::string>(), "A2");
|
2016-06-15 19:45:05 +08:00
|
|
|
|
|
|
|
for (auto column_iter = columns.rbegin(); column_iter != columns.rend(); ++column_iter)
|
|
|
|
{
|
|
|
|
auto column = *column_iter;
|
|
|
|
|
|
|
|
for (auto cell_iter = column.rbegin(); cell_iter != column.rend(); ++cell_iter)
|
|
|
|
{
|
|
|
|
auto cell = *cell_iter;
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
TS_ASSERT_EQUALS(cell.value<std::string>(), cell.reference().to_string());
|
2016-06-15 19:45:05 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void test_const_column_major_iterators()
|
|
|
|
{
|
|
|
|
xlnt::workbook wb;
|
2016-12-02 21:37:50 +08:00
|
|
|
auto ws = wb.active_sheet();
|
2016-06-15 19:45:05 +08:00
|
|
|
|
|
|
|
ws.append({"A1", "B1", "C1"});
|
|
|
|
ws.append({"A2", "B2", "C2"});
|
|
|
|
|
|
|
|
const xlnt::worksheet ws_const = ws;
|
|
|
|
const auto columns = ws_const.columns();
|
|
|
|
|
|
|
|
const auto first_column = *columns.begin();
|
|
|
|
auto first_column_iter = first_column.begin();
|
|
|
|
const auto first_cell = *first_column_iter;
|
2016-12-02 21:37:50 +08:00
|
|
|
TS_ASSERT_EQUALS(first_cell.value<std::string>(), "A1");
|
2016-06-15 19:45:05 +08:00
|
|
|
first_column_iter++;
|
|
|
|
const auto second_cell = *first_column_iter;
|
2016-12-02 21:37:50 +08:00
|
|
|
TS_ASSERT_EQUALS(second_cell.value<std::string>(), "A2");
|
2016-06-15 19:45:05 +08:00
|
|
|
|
|
|
|
const auto last_column = *(--columns.end());
|
|
|
|
auto last_column_iter = last_column.end();
|
|
|
|
last_column_iter--;
|
|
|
|
const auto last_cell = *last_column_iter;
|
2016-12-02 21:37:50 +08:00
|
|
|
TS_ASSERT_EQUALS(last_cell.value<std::string>(), "C2");
|
2016-06-15 19:45:05 +08:00
|
|
|
last_column_iter--;
|
|
|
|
const auto penultimate_cell = *last_column_iter;
|
2016-12-02 21:37:50 +08:00
|
|
|
TS_ASSERT_EQUALS(penultimate_cell.value<std::string>(), "C1");
|
2016-06-15 19:45:05 +08:00
|
|
|
|
|
|
|
for (const auto column : columns)
|
|
|
|
{
|
|
|
|
for (const auto cell : column)
|
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
TS_ASSERT_EQUALS(cell.value<std::string>(), cell.reference().to_string());
|
2016-06-15 19:45:05 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void test_const_reverse_column_major_iterators()
|
|
|
|
{
|
|
|
|
xlnt::workbook wb;
|
2016-12-02 21:37:50 +08:00
|
|
|
auto ws = wb.active_sheet();
|
2016-06-15 19:45:05 +08:00
|
|
|
|
|
|
|
ws.append({"A1", "B1", "C1"});
|
|
|
|
ws.append({"A2", "B2", "C2"});
|
|
|
|
|
|
|
|
const xlnt::worksheet ws_const = ws;
|
|
|
|
const auto columns = ws_const.columns();
|
|
|
|
|
|
|
|
const auto first_column = *columns.crbegin();
|
|
|
|
auto first_column_iter = first_column.crbegin();
|
|
|
|
const auto first_cell = *first_column_iter;
|
2016-12-02 21:37:50 +08:00
|
|
|
TS_ASSERT_EQUALS(first_cell.value<std::string>(), "C2");
|
2016-06-15 19:45:05 +08:00
|
|
|
first_column_iter++;
|
|
|
|
const auto second_cell = *first_column_iter;
|
2016-12-02 21:37:50 +08:00
|
|
|
TS_ASSERT_EQUALS(second_cell.value<std::string>(), "C1");
|
2016-06-15 19:45:05 +08:00
|
|
|
|
|
|
|
const auto last_column = *(--columns.crend());
|
|
|
|
auto last_column_iter = last_column.crend();
|
|
|
|
last_column_iter--;
|
|
|
|
const auto last_cell = *last_column_iter;
|
2016-12-02 21:37:50 +08:00
|
|
|
TS_ASSERT_EQUALS(last_cell.value<std::string>(), "A1");
|
2016-06-15 19:45:05 +08:00
|
|
|
last_column_iter--;
|
|
|
|
const auto penultimate_cell = *last_column_iter;
|
2016-12-02 21:37:50 +08:00
|
|
|
TS_ASSERT_EQUALS(penultimate_cell.value<std::string>(), "A2");
|
2016-06-15 19:45:05 +08:00
|
|
|
|
|
|
|
for (auto column_iter = columns.crbegin(); column_iter != columns.crend(); ++column_iter)
|
|
|
|
{
|
|
|
|
const auto column = *column_iter;
|
|
|
|
|
|
|
|
for (auto cell_iter = column.crbegin(); cell_iter != column.crend(); ++cell_iter)
|
|
|
|
{
|
|
|
|
const auto cell = *cell_iter;
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
TS_ASSERT_EQUALS(cell.value<std::string>(), cell.reference().to_string());
|
2016-06-15 19:45:05 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-14 11:36:26 +08:00
|
|
|
void test_header()
|
|
|
|
{
|
2016-12-10 08:18:50 +08:00
|
|
|
xlnt::header_footer hf;
|
|
|
|
using hf_loc = xlnt::header_footer::location;
|
2016-07-09 12:22:08 +08:00
|
|
|
|
2016-12-10 08:18:50 +08:00
|
|
|
for (auto location : { hf_loc::left, hf_loc::center, hf_loc::right })
|
2016-07-09 12:22:08 +08:00
|
|
|
{
|
2016-12-10 08:18:50 +08:00
|
|
|
TS_ASSERT(!hf.has_header(location));
|
|
|
|
TS_ASSERT(!hf.has_odd_even_header(location));
|
|
|
|
TS_ASSERT(!hf.has_first_page_header(location));
|
|
|
|
|
|
|
|
hf.header(location, "abc");
|
|
|
|
|
|
|
|
TS_ASSERT(hf.has_header(location));
|
|
|
|
TS_ASSERT(!hf.has_odd_even_header(location));
|
|
|
|
TS_ASSERT(!hf.has_first_page_header(location));
|
|
|
|
|
|
|
|
TS_ASSERT_EQUALS(hf.header(location), "abc");
|
|
|
|
|
|
|
|
hf.clear_header(location);
|
|
|
|
|
|
|
|
TS_ASSERT(!hf.has_header(location));
|
2016-07-09 12:22:08 +08:00
|
|
|
}
|
2016-06-14 11:36:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void test_footer()
|
|
|
|
{
|
2016-12-10 08:18:50 +08:00
|
|
|
xlnt::header_footer hf;
|
|
|
|
using hf_loc = xlnt::header_footer::location;
|
2016-07-09 12:22:08 +08:00
|
|
|
|
2016-12-10 08:18:50 +08:00
|
|
|
for (auto location : { hf_loc::left, hf_loc::center, hf_loc::right })
|
2016-07-09 12:22:08 +08:00
|
|
|
{
|
2016-12-10 08:18:50 +08:00
|
|
|
TS_ASSERT(!hf.has_footer(location));
|
|
|
|
TS_ASSERT(!hf.has_odd_even_footer(location));
|
|
|
|
TS_ASSERT(!hf.has_first_page_footer(location));
|
|
|
|
|
|
|
|
hf.footer(location, "abc");
|
|
|
|
|
|
|
|
TS_ASSERT(hf.has_footer(location));
|
|
|
|
TS_ASSERT(!hf.has_odd_even_footer(location));
|
|
|
|
TS_ASSERT(!hf.has_first_page_footer(location));
|
|
|
|
|
|
|
|
TS_ASSERT_EQUALS(hf.footer(location), "abc");
|
|
|
|
|
|
|
|
hf.clear_footer(location);
|
|
|
|
|
|
|
|
TS_ASSERT(!hf.has_footer(location));
|
2016-07-09 12:22:08 +08:00
|
|
|
}
|
2016-06-14 11:36:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void test_page_setup()
|
|
|
|
{
|
2016-08-14 02:45:26 +08:00
|
|
|
xlnt::page_setup setup;
|
2016-12-02 21:37:50 +08:00
|
|
|
setup.page_break(xlnt::page_break::column);
|
|
|
|
TS_ASSERT_EQUALS(setup.page_break(), xlnt::page_break::column);
|
|
|
|
setup.scale(1.23);
|
|
|
|
TS_ASSERT_EQUALS(setup.scale(), 1.23);
|
2016-06-14 11:36:26 +08:00
|
|
|
}
|
2016-06-23 16:33:10 +08:00
|
|
|
|
|
|
|
void test_unique_sheet_name()
|
|
|
|
{
|
|
|
|
xlnt::workbook wb;
|
2016-12-02 21:37:50 +08:00
|
|
|
auto ws = wb.active_sheet();
|
2016-06-23 16:33:10 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
auto active_name = ws.title();
|
2016-06-23 16:33:10 +08:00
|
|
|
auto next_name = ws.unique_sheet_name(active_name);
|
|
|
|
|
|
|
|
TS_ASSERT_DIFFERS(active_name, next_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
void test_page_margins()
|
|
|
|
{
|
|
|
|
xlnt::workbook wb;
|
2016-12-02 21:37:50 +08:00
|
|
|
auto ws = wb.active_sheet();
|
|
|
|
auto margins = ws.page_margins();
|
2016-07-17 03:57:50 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
margins.top(0);
|
|
|
|
margins.bottom(1);
|
|
|
|
margins.header(2);
|
|
|
|
margins.footer(3);
|
|
|
|
margins.left(4);
|
|
|
|
margins.right(5);
|
2016-06-23 16:33:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void test_garbage_collect()
|
|
|
|
{
|
|
|
|
xlnt::workbook wb;
|
2016-12-02 21:37:50 +08:00
|
|
|
auto ws = wb.active_sheet();
|
2016-06-23 16:33:10 +08:00
|
|
|
|
|
|
|
auto dimensions = ws.calculate_dimension();
|
|
|
|
TS_ASSERT_EQUALS(dimensions, xlnt::range_reference("A1", "A1"));
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
ws.cell("B2").value("text");
|
2016-06-23 16:33:10 +08:00
|
|
|
ws.garbage_collect();
|
|
|
|
|
|
|
|
dimensions = ws.calculate_dimension();
|
|
|
|
TS_ASSERT_EQUALS(dimensions, xlnt::range_reference("B2", "B2"));
|
|
|
|
}
|
|
|
|
|
|
|
|
void test_has_cell()
|
|
|
|
{
|
|
|
|
xlnt::workbook wb;
|
2016-12-02 21:37:50 +08:00
|
|
|
auto ws = wb.active_sheet();
|
2016-06-23 16:33:10 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
ws.cell("A3").value("test");
|
2016-06-23 16:33:10 +08:00
|
|
|
|
|
|
|
TS_ASSERT(!ws.has_cell("A2"));
|
|
|
|
TS_ASSERT(ws.has_cell("A3"));
|
|
|
|
}
|
|
|
|
|
|
|
|
void test_get_range_by_string()
|
|
|
|
{
|
|
|
|
xlnt::workbook wb;
|
2016-12-02 21:37:50 +08:00
|
|
|
auto ws = wb.active_sheet();
|
2016-06-23 16:33:10 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
ws.cell("A2").value(3.14);
|
|
|
|
ws.cell("A3").value(true);
|
|
|
|
ws.cell("B2").value("text");
|
|
|
|
ws.cell("B3").value(false);
|
2016-06-23 16:33:10 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
auto range = ws.range("A2:B3");
|
2016-07-17 07:40:20 +08:00
|
|
|
auto range_iter = range.begin();
|
|
|
|
auto row = *range_iter;
|
|
|
|
auto row_iter = row.begin();
|
2016-12-02 21:37:50 +08:00
|
|
|
TS_ASSERT_EQUALS((*row_iter).value<double>(), 3.14);
|
|
|
|
TS_ASSERT_EQUALS((*row_iter).reference(), "A2");
|
2016-07-24 09:24:25 +08:00
|
|
|
TS_ASSERT_EQUALS((*row_iter), row.front());
|
2016-07-17 08:06:39 +08:00
|
|
|
|
|
|
|
row_iter++;
|
2016-12-02 21:37:50 +08:00
|
|
|
TS_ASSERT_EQUALS((*row_iter).value<std::string>(), "text");
|
|
|
|
TS_ASSERT_EQUALS((*row_iter).reference(), "B2");
|
2016-07-24 09:24:25 +08:00
|
|
|
TS_ASSERT_EQUALS((*row_iter), row.back());
|
|
|
|
|
|
|
|
range_iter++;
|
|
|
|
row = *range_iter;
|
|
|
|
row_iter = row.begin();
|
2016-12-02 21:37:50 +08:00
|
|
|
TS_ASSERT_EQUALS((*row_iter).value<bool>(), true);
|
|
|
|
TS_ASSERT_EQUALS((*row_iter).reference(), "A3");
|
2016-07-17 07:40:20 +08:00
|
|
|
|
|
|
|
range_iter = range.end();
|
|
|
|
range_iter--;
|
|
|
|
row = *range_iter;
|
|
|
|
row_iter = row.end();
|
|
|
|
row_iter--;
|
2016-12-02 21:37:50 +08:00
|
|
|
TS_ASSERT_EQUALS((*row_iter).value<bool>(), false);
|
2016-06-23 16:33:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void test_operators()
|
|
|
|
{
|
|
|
|
xlnt::workbook wb;
|
|
|
|
|
|
|
|
wb.create_sheet();
|
|
|
|
wb.create_sheet();
|
|
|
|
|
|
|
|
auto ws1 = wb[1];
|
|
|
|
auto ws2 = wb[2];
|
|
|
|
|
|
|
|
TS_ASSERT_DIFFERS(ws1, ws2);
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
ws1[xlnt::cell_reference("A2")].value(true);
|
2016-06-23 16:33:10 +08:00
|
|
|
|
|
|
|
const auto ws1_const = ws1;
|
2016-12-02 21:37:50 +08:00
|
|
|
TS_ASSERT_EQUALS(ws1[xlnt::cell_reference("A2")].value<bool>(), true);
|
|
|
|
TS_ASSERT_EQUALS((*(*ws1[xlnt::range_reference("A2:A2")].begin()).begin()).value<bool>(), true);
|
2016-06-23 16:33:10 +08:00
|
|
|
|
|
|
|
ws1.create_named_range("rangey", "A2:A2");
|
2016-12-02 21:37:50 +08:00
|
|
|
TS_ASSERT_EQUALS(ws1[std::string("rangey")], ws1.range("A2:A2"));
|
|
|
|
TS_ASSERT_EQUALS(ws1[std::string("A2:A2")], ws1.range("A2:A2"));
|
|
|
|
TS_ASSERT(ws1[std::string("rangey")] != ws1.range("A2:A3"));
|
2016-07-17 03:57:50 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
TS_ASSERT_EQUALS(ws1[std::string("rangey")].cell("A1"), ws1.cell("A2"));
|
2016-06-23 16:33:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void test_reserve()
|
|
|
|
{
|
|
|
|
xlnt::workbook wb;
|
2016-12-02 21:37:50 +08:00
|
|
|
auto ws = wb.active_sheet();
|
2016-06-23 16:33:10 +08:00
|
|
|
|
|
|
|
ws.reserve(1000);
|
|
|
|
//TODO: actual tests go here
|
|
|
|
}
|
|
|
|
|
|
|
|
void test_iterate()
|
|
|
|
{
|
|
|
|
xlnt::workbook wb;
|
2016-12-02 21:37:50 +08:00
|
|
|
auto ws = wb.active_sheet();
|
2016-06-23 16:33:10 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
ws.cell("B3").value("B3");
|
|
|
|
ws.cell("C7").value("C7");
|
2016-06-23 16:33:10 +08:00
|
|
|
|
|
|
|
for (auto row : ws)
|
|
|
|
{
|
|
|
|
for (auto cell : row)
|
|
|
|
{
|
|
|
|
if (cell.has_value())
|
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
TS_ASSERT_EQUALS(cell.reference().to_string(), cell.value<std::string>());
|
2016-06-23 16:33:10 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto ws_const = ws;
|
|
|
|
|
|
|
|
for (auto row : ws_const)
|
|
|
|
{
|
|
|
|
for (auto cell : row)
|
|
|
|
{
|
|
|
|
if (cell.has_value())
|
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
TS_ASSERT_EQUALS(cell.reference().to_string(), cell.value<std::string>());
|
2016-06-23 16:33:10 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-07-23 08:26:02 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
const auto const_range = ws_const.range("B3:C7");
|
2016-07-23 11:21:53 +08:00
|
|
|
auto const_range_iter = const_range.cbegin();
|
2016-07-23 08:26:02 +08:00
|
|
|
const_range_iter++;
|
|
|
|
const_range_iter--;
|
|
|
|
TS_ASSERT_EQUALS(const_range_iter, const_range.begin());
|
2016-06-23 16:33:10 +08:00
|
|
|
}
|
2016-07-22 07:50:49 +08:00
|
|
|
|
|
|
|
void test_range_reference()
|
|
|
|
{
|
|
|
|
xlnt::range_reference ref1("A1:A1");
|
|
|
|
TS_ASSERT(ref1.is_single_cell());
|
|
|
|
xlnt::range_reference ref2("A1:B2");
|
|
|
|
|
|
|
|
TS_ASSERT(!ref2.is_single_cell());
|
|
|
|
TS_ASSERT(ref1 == xlnt::range_reference("A1:A1"));
|
|
|
|
TS_ASSERT(ref1 != ref2);
|
|
|
|
TS_ASSERT(ref1 == "A1:A1");
|
|
|
|
TS_ASSERT(ref1 == std::string("A1:A1"));
|
|
|
|
TS_ASSERT(std::string("A1:A1") == ref1);
|
|
|
|
TS_ASSERT("A1:A1" == ref1);
|
|
|
|
TS_ASSERT(ref1 != "A1:B2");
|
|
|
|
TS_ASSERT(ref1 != std::string("A1:B2"));
|
|
|
|
TS_ASSERT(std::string("A1:B2") != ref1);
|
|
|
|
TS_ASSERT("A1:B2" != ref1);
|
|
|
|
}
|
2016-07-23 11:50:27 +08:00
|
|
|
|
|
|
|
void test_get_point_pos()
|
|
|
|
{
|
|
|
|
xlnt::workbook wb;
|
2016-12-02 21:37:50 +08:00
|
|
|
auto ws = wb.active_sheet();
|
2016-07-23 11:50:27 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
TS_ASSERT_EQUALS(ws.point_pos({0, 0}), "A1");
|
2016-07-23 11:50:27 +08:00
|
|
|
}
|
2016-08-02 06:33:43 +08:00
|
|
|
|
|
|
|
void test_named_range_named_cell_reference()
|
|
|
|
{
|
|
|
|
xlnt::workbook wb;
|
2016-12-02 21:37:50 +08:00
|
|
|
auto ws = wb.active_sheet();
|
2016-08-16 12:23:49 +08:00
|
|
|
TS_ASSERT_THROWS(ws.create_named_range("A1", "A2"), xlnt::invalid_parameter);
|
|
|
|
TS_ASSERT_THROWS(ws.create_named_range("XFD1048576", "A2"), xlnt::invalid_parameter);
|
2016-08-02 06:33:43 +08:00
|
|
|
TS_ASSERT_THROWS_NOTHING(ws.create_named_range("XFE1048576", "A2"));
|
|
|
|
TS_ASSERT_THROWS_NOTHING(ws.create_named_range("XFD1048577", "A2"));
|
|
|
|
}
|
2016-11-10 08:52:18 +08:00
|
|
|
|
|
|
|
void test_iteration_skip_empty()
|
|
|
|
{
|
|
|
|
xlnt::workbook wb;
|
2016-12-02 21:37:50 +08:00
|
|
|
auto ws = wb.active_sheet();
|
|
|
|
ws.cell("A1").value("A1");
|
|
|
|
ws.cell("F6").value("F6");
|
2016-11-10 08:52:18 +08:00
|
|
|
|
|
|
|
{
|
|
|
|
std::vector<xlnt::cell> cells;
|
|
|
|
|
|
|
|
for (auto row : ws)
|
|
|
|
{
|
|
|
|
for (auto cell : row)
|
|
|
|
{
|
|
|
|
cells.push_back(cell);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TS_ASSERT_EQUALS(cells.size(), 2);
|
2016-12-02 21:37:50 +08:00
|
|
|
TS_ASSERT_EQUALS(cells[0].value<std::string>(), "A1");
|
|
|
|
TS_ASSERT_EQUALS(cells[1].value<std::string>(), "F6");
|
2016-11-10 08:52:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const auto ws_const = ws;
|
|
|
|
|
|
|
|
{
|
|
|
|
std::vector<xlnt::cell> cells;
|
|
|
|
|
|
|
|
for (auto row : ws_const)
|
|
|
|
{
|
|
|
|
for (auto cell : row)
|
|
|
|
{
|
|
|
|
cells.push_back(cell);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TS_ASSERT_EQUALS(cells.size(), 2);
|
2016-12-02 21:37:50 +08:00
|
|
|
TS_ASSERT_EQUALS(cells[0].value<std::string>(), "A1");
|
|
|
|
TS_ASSERT_EQUALS(cells[1].value<std::string>(), "F6");
|
2016-11-10 08:52:18 +08:00
|
|
|
}
|
|
|
|
}
|
2014-05-09 03:32:12 +08:00
|
|
|
};
|