2014-05-09 03:32:12 +08:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <ctime>
|
|
|
|
#include <iostream>
|
|
|
|
#include <cxxtest/TestSuite.h>
|
|
|
|
|
2015-10-19 03:30:46 +08:00
|
|
|
#include <xlnt/cell/cell.hpp>
|
|
|
|
#include <xlnt/cell/cell_reference.hpp>
|
|
|
|
#include <xlnt/cell/comment.hpp>
|
|
|
|
#include <xlnt/common/datetime.hpp>
|
|
|
|
#include <xlnt/common/exceptions.hpp>
|
|
|
|
#include <xlnt/styles/alignment.hpp>
|
2015-10-21 11:30:10 +08:00
|
|
|
#include <xlnt/styles/border.hpp>
|
2015-10-19 03:30:46 +08:00
|
|
|
#include <xlnt/styles/font.hpp>
|
|
|
|
#include <xlnt/styles/fill.hpp>
|
|
|
|
#include <xlnt/styles/number_format.hpp>
|
|
|
|
#include <xlnt/styles/protection.hpp>
|
|
|
|
#include <xlnt/worksheet/range.hpp>
|
|
|
|
#include <xlnt/worksheet/worksheet.hpp>
|
|
|
|
#include <xlnt/workbook/workbook.hpp>
|
2014-05-09 03:32:12 +08:00
|
|
|
|
2015-10-24 02:42:36 +08:00
|
|
|
#include <xlnt/writer/excel_writer.hpp>
|
|
|
|
#include <xlnt/reader/excel_reader.hpp>
|
|
|
|
|
2014-06-06 04:19:31 +08:00
|
|
|
class test_cell : public CxxTest::TestSuite
|
2014-05-09 03:32:12 +08:00
|
|
|
{
|
2015-10-14 01:56:07 +08:00
|
|
|
private:
|
|
|
|
xlnt::workbook wb, wb_guess_types;
|
|
|
|
|
2014-05-09 03:32:12 +08:00
|
|
|
public:
|
2015-10-14 01:56:07 +08:00
|
|
|
test_cell()
|
|
|
|
{
|
|
|
|
wb_guess_types.set_guess_types(true);
|
|
|
|
}
|
2015-10-17 06:35:11 +08:00
|
|
|
|
2015-10-02 11:09:25 +08:00
|
|
|
void test_infer_numeric()
|
|
|
|
{
|
2015-10-07 00:31:49 +08:00
|
|
|
auto ws = wb_guess_types.create_sheet();
|
2015-10-14 01:56:07 +08:00
|
|
|
auto cell = ws.get_cell("A1");
|
2015-10-02 11:09:25 +08:00
|
|
|
|
|
|
|
cell.set_value("4.2");
|
2015-10-14 01:56:07 +08:00
|
|
|
TS_ASSERT(cell.get_value<long double>() == 4.2L);
|
2015-10-02 11:09:25 +08:00
|
|
|
|
|
|
|
cell.set_value("-42.000");
|
2015-10-14 01:56:07 +08:00
|
|
|
TS_ASSERT(cell.get_value<int>() == -42);
|
2015-10-02 11:09:25 +08:00
|
|
|
|
|
|
|
cell.set_value("0");
|
2015-10-14 01:56:07 +08:00
|
|
|
TS_ASSERT(cell.get_value<int>() == 0);
|
2015-10-02 11:09:25 +08:00
|
|
|
|
|
|
|
cell.set_value("0.9999");
|
2015-10-14 01:56:07 +08:00
|
|
|
TS_ASSERT(cell.get_value<long double>() == 0.9999L);
|
2015-10-02 11:09:25 +08:00
|
|
|
|
|
|
|
cell.set_value("99E-02");
|
2015-10-14 01:56:07 +08:00
|
|
|
TS_ASSERT(cell.get_value<long double>() == 0.99L);
|
2015-10-02 11:09:25 +08:00
|
|
|
|
|
|
|
cell.set_value("4");
|
2015-10-14 01:56:07 +08:00
|
|
|
TS_ASSERT(cell.get_value<int>() == 4);
|
2015-10-02 11:09:25 +08:00
|
|
|
|
|
|
|
cell.set_value("-1E3");
|
2015-10-14 01:56:07 +08:00
|
|
|
TS_ASSERT(cell.get_value<int>() == -1000);
|
2015-10-02 11:09:25 +08:00
|
|
|
|
|
|
|
cell.set_value("2e+2");
|
2015-10-14 01:56:07 +08:00
|
|
|
TS_ASSERT(cell.get_value<int>() == 200);
|
2015-10-02 11:09:25 +08:00
|
|
|
|
|
|
|
cell.set_value("3.1%");
|
2015-10-14 01:56:07 +08:00
|
|
|
TS_ASSERT(cell.get_value<long double>() == 0.031L);
|
2015-10-02 11:09:25 +08:00
|
|
|
|
|
|
|
cell.set_value("03:40:16");
|
2015-10-14 01:56:07 +08:00
|
|
|
TS_ASSERT(cell.get_value<xlnt::time>() == xlnt::time(3, 40, 16));
|
2015-10-02 11:09:25 +08:00
|
|
|
|
|
|
|
cell.set_value("03:40");
|
2015-10-14 01:56:07 +08:00
|
|
|
TS_ASSERT(cell.get_value<xlnt::time>() == xlnt::time(3, 40));
|
2015-10-02 11:09:25 +08:00
|
|
|
|
|
|
|
cell.set_value("30:33.865633336");
|
2015-10-14 01:56:07 +08:00
|
|
|
TS_ASSERT(cell.get_value<xlnt::time>() == xlnt::time(0, 30, 33, 865633));
|
2015-10-02 11:09:25 +08:00
|
|
|
}
|
|
|
|
|
2015-10-07 00:31:49 +08:00
|
|
|
void test_ctor()
|
|
|
|
{
|
|
|
|
auto ws = wb.create_sheet();
|
2015-10-14 01:56:07 +08:00
|
|
|
auto cell = ws.get_cell(xlnt::cell_reference("A", 1));
|
2015-10-07 00:31:49 +08:00
|
|
|
|
2015-10-14 01:56:07 +08:00
|
|
|
TS_ASSERT(cell.get_data_type() == xlnt::cell::type::null);
|
2015-10-07 00:31:49 +08:00
|
|
|
TS_ASSERT(cell.get_column() == "A");
|
|
|
|
TS_ASSERT(cell.get_row() == 1);
|
|
|
|
TS_ASSERT(cell.get_reference() == "A1");
|
2015-10-14 01:56:07 +08:00
|
|
|
TS_ASSERT(!cell.has_value());
|
|
|
|
TS_ASSERT(cell.get_xf_index() == 0);
|
2015-10-07 00:31:49 +08:00
|
|
|
TS_ASSERT(!cell.has_comment());
|
|
|
|
}
|
|
|
|
|
2015-10-14 01:56:07 +08:00
|
|
|
|
|
|
|
void test_null()
|
2014-05-09 03:32:12 +08:00
|
|
|
{
|
2015-10-14 01:56:07 +08:00
|
|
|
auto datatypes =
|
|
|
|
{
|
|
|
|
xlnt::cell::type::null
|
|
|
|
};
|
|
|
|
|
|
|
|
for(auto datatype : datatypes)
|
|
|
|
{
|
|
|
|
auto ws = wb.create_sheet();
|
|
|
|
auto cell = ws.get_cell(xlnt::cell_reference(1, 1));
|
|
|
|
|
|
|
|
cell.set_data_type(datatype);
|
|
|
|
TS_ASSERT(cell.get_data_type() == datatype);
|
|
|
|
cell.clear_value();
|
|
|
|
TS_ASSERT(cell.get_data_type() == xlnt::cell::type::null);
|
|
|
|
}
|
2014-05-09 03:32:12 +08:00
|
|
|
}
|
2015-10-14 01:56:07 +08:00
|
|
|
|
|
|
|
void test_string()
|
2014-05-09 03:32:12 +08:00
|
|
|
{
|
2015-10-14 01:56:07 +08:00
|
|
|
auto ws = wb.create_sheet();
|
|
|
|
auto cell = ws.get_cell(xlnt::cell_reference(1, 1));
|
|
|
|
|
|
|
|
cell.set_value("hello");
|
|
|
|
TS_ASSERT(cell.get_data_type() == xlnt::cell::type::string);
|
|
|
|
|
|
|
|
cell.set_value(".");
|
|
|
|
TS_ASSERT(cell.get_data_type() == xlnt::cell::type::string);
|
|
|
|
|
|
|
|
cell.set_value("0800");
|
|
|
|
TS_ASSERT(cell.get_data_type() == xlnt::cell::type::string);
|
2014-05-09 03:32:12 +08:00
|
|
|
}
|
2015-10-14 01:56:07 +08:00
|
|
|
|
|
|
|
void test_formula1()
|
2014-05-09 03:32:12 +08:00
|
|
|
{
|
2015-10-14 01:56:07 +08:00
|
|
|
auto ws = wb_guess_types.create_sheet();
|
|
|
|
auto cell = ws.get_cell(xlnt::cell_reference(1, 1));
|
|
|
|
|
|
|
|
cell.set_value("=42");
|
|
|
|
TS_ASSERT(cell.get_data_type() == xlnt::cell::type::formula);
|
2014-05-09 03:32:12 +08:00
|
|
|
}
|
2015-10-14 01:56:07 +08:00
|
|
|
|
|
|
|
void test_formula2()
|
2014-05-09 03:32:12 +08:00
|
|
|
{
|
2015-10-14 01:56:07 +08:00
|
|
|
auto ws = wb.create_sheet();
|
|
|
|
auto cell = ws.get_cell(xlnt::cell_reference(1, 1));
|
|
|
|
|
|
|
|
cell.set_value("=if(A1<4;-1;1)");
|
|
|
|
TS_ASSERT(cell.get_data_type() == xlnt::cell::type::formula);
|
2014-05-09 03:32:12 +08:00
|
|
|
}
|
2015-10-14 01:56:07 +08:00
|
|
|
|
|
|
|
void test_not_formula()
|
2014-05-09 03:32:12 +08:00
|
|
|
{
|
2015-10-14 01:56:07 +08:00
|
|
|
auto ws = wb.create_sheet();
|
|
|
|
auto cell = ws.get_cell(xlnt::cell_reference(1, 1));
|
|
|
|
|
|
|
|
cell.set_value("=");
|
|
|
|
TS_ASSERT(cell.get_data_type() == xlnt::cell::type::string);
|
|
|
|
TS_ASSERT(cell.get_value<std::string>() == "=");
|
|
|
|
TS_ASSERT(!cell.has_formula());
|
2014-05-09 03:32:12 +08:00
|
|
|
}
|
2015-10-14 01:56:07 +08:00
|
|
|
|
|
|
|
void test_boolean()
|
2014-05-09 03:32:12 +08:00
|
|
|
{
|
2015-10-14 01:56:07 +08:00
|
|
|
auto ws = wb.create_sheet();
|
|
|
|
auto cell = ws.get_cell(xlnt::cell_reference(1, 1));
|
|
|
|
|
|
|
|
for(auto value : {true, false})
|
2014-05-30 08:52:14 +08:00
|
|
|
{
|
2015-10-14 01:56:07 +08:00
|
|
|
cell.set_value(value);
|
|
|
|
TS_ASSERT(cell.get_data_type() == xlnt::cell::type::boolean);
|
2014-05-30 08:52:14 +08:00
|
|
|
}
|
2014-05-09 03:32:12 +08:00
|
|
|
}
|
2015-10-14 01:56:07 +08:00
|
|
|
|
|
|
|
void test_error_codes()
|
2014-05-09 03:32:12 +08:00
|
|
|
{
|
2015-10-14 01:56:07 +08:00
|
|
|
auto ws = wb_guess_types.create_sheet();
|
|
|
|
auto cell = ws.get_cell(xlnt::cell_reference(1, 1));
|
|
|
|
|
|
|
|
for(auto error_code : xlnt::cell::ErrorCodes)
|
2014-05-09 03:32:12 +08:00
|
|
|
{
|
2015-10-14 01:56:07 +08:00
|
|
|
cell.set_value(error_code.first);
|
|
|
|
TS_ASSERT(cell.get_data_type() == xlnt::cell::type::error);
|
2014-05-09 03:32:12 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-14 01:56:07 +08:00
|
|
|
void test_insert_datetime()
|
2014-05-09 03:32:12 +08:00
|
|
|
{
|
2015-10-14 01:56:07 +08:00
|
|
|
auto ws = wb.create_sheet();
|
|
|
|
auto cell = ws.get_cell(xlnt::cell_reference(1, 1));
|
|
|
|
|
|
|
|
cell.set_value(xlnt::datetime(2010, 7, 13, 6, 37, 41));
|
|
|
|
TS_ASSERT(cell.get_data_type() == xlnt::cell::type::numeric);
|
|
|
|
TS_ASSERT(cell.get_value<long double>() == 40372.27616898148L);
|
|
|
|
TS_ASSERT(cell.is_date());
|
2015-10-19 03:30:46 +08:00
|
|
|
TS_ASSERT(cell.get_number_format().get_format_string() == "yyyy-mm-dd h:mm:ss");
|
2014-05-09 03:32:12 +08:00
|
|
|
}
|
2015-10-14 01:56:07 +08:00
|
|
|
|
|
|
|
void test_insert_date()
|
2014-06-11 06:36:31 +08:00
|
|
|
{
|
2015-10-14 01:56:07 +08:00
|
|
|
auto ws = wb.create_sheet();
|
|
|
|
auto cell = ws.get_cell(xlnt::cell_reference(1, 1));
|
|
|
|
|
|
|
|
cell.set_value(xlnt::date(2010, 7, 13));
|
|
|
|
TS_ASSERT(cell.get_data_type() == xlnt::cell::type::numeric);
|
|
|
|
TS_ASSERT(cell.get_value<long double>() == 40372.L);
|
|
|
|
TS_ASSERT(cell.is_date());
|
2015-10-19 03:30:46 +08:00
|
|
|
TS_ASSERT(cell.get_number_format().get_format_string() == "yyyy-mm-dd");
|
2014-06-11 06:36:31 +08:00
|
|
|
}
|
2015-10-14 01:56:07 +08:00
|
|
|
|
|
|
|
void test_insert_time()
|
2014-05-09 03:32:12 +08:00
|
|
|
{
|
2015-10-14 01:56:07 +08:00
|
|
|
auto ws = wb.create_sheet();
|
|
|
|
auto cell = ws.get_cell(xlnt::cell_reference(1, 1));
|
|
|
|
|
|
|
|
cell.set_value(xlnt::time(1, 3));
|
|
|
|
TS_ASSERT(cell.get_data_type() == xlnt::cell::type::numeric);
|
|
|
|
TS_ASSERT(cell.get_value<long double>() == 0.04375L);
|
|
|
|
TS_ASSERT(cell.is_date());
|
2015-10-19 03:30:46 +08:00
|
|
|
TS_ASSERT(cell.get_number_format().get_format_string() == "h:mm:ss");
|
2014-05-09 03:32:12 +08:00
|
|
|
}
|
2015-10-14 01:56:07 +08:00
|
|
|
|
|
|
|
void test_cell_formatted_as_date1()
|
2014-05-09 03:32:12 +08:00
|
|
|
{
|
2015-10-14 01:56:07 +08:00
|
|
|
auto ws = wb.create_sheet();
|
|
|
|
auto cell = ws.get_cell(xlnt::cell_reference(1, 1));
|
|
|
|
|
|
|
|
cell.set_value(xlnt::datetime::today());
|
|
|
|
cell.clear_value();
|
2015-10-17 06:35:11 +08:00
|
|
|
TS_ASSERT(!cell.is_date()); // disagree with openpyxl
|
2015-10-14 01:56:07 +08:00
|
|
|
TS_ASSERT(!cell.has_value());
|
2014-05-09 03:32:12 +08:00
|
|
|
}
|
2015-10-14 01:56:07 +08:00
|
|
|
|
|
|
|
void test_cell_formatted_as_date2()
|
2014-05-09 03:32:12 +08:00
|
|
|
{
|
2015-10-14 01:56:07 +08:00
|
|
|
auto ws = wb.create_sheet();
|
|
|
|
auto cell = ws.get_cell(xlnt::cell_reference(1, 1));
|
|
|
|
|
|
|
|
cell.set_value(xlnt::datetime::today());
|
|
|
|
cell.set_value("testme");
|
|
|
|
TS_ASSERT(!cell.is_date());
|
|
|
|
TS_ASSERT(cell.get_value<std::string>() == "testme");
|
2014-05-09 03:32:12 +08:00
|
|
|
}
|
2015-10-14 01:56:07 +08:00
|
|
|
|
|
|
|
void test_cell_formatted_as_date3()
|
2014-05-09 03:32:12 +08:00
|
|
|
{
|
2015-10-14 01:56:07 +08:00
|
|
|
auto ws = wb.create_sheet();
|
|
|
|
auto cell = ws.get_cell(xlnt::cell_reference(1, 1));
|
|
|
|
|
|
|
|
cell.set_value(xlnt::datetime::today());
|
2014-07-26 04:39:25 +08:00
|
|
|
cell.set_value(true);
|
2015-10-14 01:56:07 +08:00
|
|
|
TS_ASSERT(!cell.is_date());
|
|
|
|
TS_ASSERT(cell.get_value<bool>() == true);
|
2014-05-09 03:32:12 +08:00
|
|
|
}
|
2015-10-14 01:56:07 +08:00
|
|
|
|
|
|
|
void test_illegal_chacters()
|
2014-05-09 03:32:12 +08:00
|
|
|
{
|
2015-10-14 01:56:07 +08:00
|
|
|
auto ws = wb.create_sheet();
|
|
|
|
auto cell = ws.get_cell(xlnt::cell_reference(1, 1));
|
|
|
|
|
|
|
|
// The bytes 0x00 through 0x1F inclusive must be manually escaped in values.
|
|
|
|
auto illegal_chrs = {0, 1, 2, 3, 4, 5, 6, 7, 8, 11, 12, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31};
|
|
|
|
|
|
|
|
for(auto i : illegal_chrs)
|
2014-05-13 01:42:28 +08:00
|
|
|
{
|
2015-10-14 01:56:07 +08:00
|
|
|
std::string str(1, i);
|
|
|
|
TS_ASSERT_THROWS(cell.set_value(str), xlnt::illegal_character_error);
|
2014-05-13 01:42:28 +08:00
|
|
|
}
|
2015-10-14 01:56:07 +08:00
|
|
|
|
|
|
|
cell.set_value(std::string(1, 33));
|
|
|
|
cell.set_value(std::string(1, 9)); // Tab
|
|
|
|
cell.set_value(std::string(1, 10)); // Newline
|
|
|
|
cell.set_value(std::string(1, 13)); // Carriage return
|
|
|
|
cell.set_value(" Leading and trailing spaces are legal ");
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
values = (
|
|
|
|
('30:33.865633336', [('', '', '', '30', '33', '865633')]),
|
|
|
|
('03:40:16', [('03', '40', '16', '', '', '')]),
|
|
|
|
('03:40', [('03', '40', '', '', '', '')]),
|
|
|
|
('55:72:12', []),
|
|
|
|
)
|
|
|
|
@pytest.mark.parametrize("value, expected",
|
|
|
|
values)
|
|
|
|
*/
|
|
|
|
void test_time_regex()
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
from openpyxl.cell.cell import TIME_REGEX;
|
|
|
|
m = TIME_REGEX.findall(value);
|
|
|
|
TS_ASSERT(m == expected;
|
|
|
|
*/
|
2014-05-09 03:32:12 +08:00
|
|
|
}
|
2015-10-14 01:56:07 +08:00
|
|
|
|
|
|
|
void test_timedelta()
|
2014-06-11 06:36:31 +08:00
|
|
|
{
|
2015-10-14 01:56:07 +08:00
|
|
|
auto ws = wb.create_sheet();
|
|
|
|
auto cell = ws.get_cell(xlnt::cell_reference(1, 1));
|
|
|
|
|
|
|
|
cell.set_value(xlnt::timedelta(1, 3));
|
|
|
|
TS_ASSERT(cell.get_value<long double>() == 1.125);
|
|
|
|
TS_ASSERT(cell.get_data_type() == xlnt::cell::type::numeric);
|
|
|
|
TS_ASSERT(!cell.is_date());
|
2015-10-19 03:30:46 +08:00
|
|
|
TS_ASSERT(cell.get_number_format().get_format_string() == "[hh]:mm:ss");
|
2014-06-11 06:36:31 +08:00
|
|
|
}
|
2015-10-14 01:56:07 +08:00
|
|
|
|
|
|
|
void test_repr()
|
2014-06-11 06:36:31 +08:00
|
|
|
{
|
2015-10-14 01:56:07 +08:00
|
|
|
auto ws = wb[1];
|
|
|
|
auto cell = ws.get_cell(xlnt::cell_reference(1, 1));
|
|
|
|
|
2015-10-17 06:35:11 +08:00
|
|
|
TS_ASSERT(cell.to_repr() == "<Cell Sheet1.A1>");
|
2014-06-11 06:36:31 +08:00
|
|
|
}
|
2015-10-14 01:56:07 +08:00
|
|
|
|
|
|
|
void test_comment_assignment()
|
2014-06-11 06:36:31 +08:00
|
|
|
{
|
2015-10-14 01:56:07 +08:00
|
|
|
auto ws = wb.create_sheet();
|
|
|
|
auto cell = ws.get_cell(xlnt::cell_reference(1, 1));
|
|
|
|
|
|
|
|
TS_ASSERT(!cell.has_comment());
|
|
|
|
xlnt::comment comm(cell, "text", "author");
|
|
|
|
TS_ASSERT(cell.get_comment() == comm);
|
2014-06-11 06:36:31 +08:00
|
|
|
}
|
2015-10-14 01:56:07 +08:00
|
|
|
|
|
|
|
void test_comment_count()
|
|
|
|
{
|
|
|
|
auto ws = wb.create_sheet();
|
|
|
|
auto cell = ws.get_cell(xlnt::cell_reference(1, 1));
|
2014-06-11 06:36:31 +08:00
|
|
|
|
2015-10-14 01:56:07 +08:00
|
|
|
TS_ASSERT(ws.get_comment_count() == 0);
|
|
|
|
xlnt::comment(cell, "text", "author");
|
|
|
|
TS_ASSERT(ws.get_comment_count() == 1);
|
|
|
|
xlnt::comment(cell, "text", "author");
|
|
|
|
TS_ASSERT(ws.get_comment_count() == 1);
|
|
|
|
cell.clear_comment();
|
|
|
|
TS_ASSERT(ws.get_comment_count() == 0);
|
|
|
|
cell.clear_comment();
|
|
|
|
TS_ASSERT(ws.get_comment_count() == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void test_only_one_cell_per_comment()
|
2014-06-11 06:36:31 +08:00
|
|
|
{
|
2015-10-14 01:56:07 +08:00
|
|
|
auto ws = wb.create_sheet();
|
|
|
|
auto cell = ws.get_cell(xlnt::cell_reference(1, 1));
|
|
|
|
xlnt::comment comm(cell, "text", "author");
|
|
|
|
|
|
|
|
auto c2 = ws.get_cell(xlnt::cell_reference(1, 2));
|
|
|
|
TS_ASSERT_THROWS(c2.set_comment(comm), xlnt::attribute_error);
|
2014-06-11 06:36:31 +08:00
|
|
|
}
|
2015-10-14 01:56:07 +08:00
|
|
|
|
|
|
|
void test_remove_comment()
|
2014-05-09 03:32:12 +08:00
|
|
|
{
|
2015-10-14 01:56:07 +08:00
|
|
|
auto ws = wb.create_sheet();
|
|
|
|
auto cell = ws.get_cell(xlnt::cell_reference(1, 1));
|
2015-10-07 00:31:49 +08:00
|
|
|
|
2015-10-14 01:56:07 +08:00
|
|
|
xlnt::comment comm(cell, "text", "author");
|
|
|
|
cell.clear_comment();
|
|
|
|
TS_ASSERT(!cell.has_comment());
|
2014-05-09 03:32:12 +08:00
|
|
|
}
|
2015-10-14 01:56:07 +08:00
|
|
|
|
|
|
|
void test_cell_offset()
|
2014-05-09 03:32:12 +08:00
|
|
|
{
|
2015-10-14 01:56:07 +08:00
|
|
|
/*
|
|
|
|
auto ws = wb.create_sheet();
|
|
|
|
auto cell = ws.get_cell(xlnt::cell_reference(1, 1));
|
|
|
|
TS_ASSERT(cell.offset(2, 1).get_reference() == "B3");
|
|
|
|
*/
|
2014-05-09 03:32:12 +08:00
|
|
|
}
|
2015-10-14 01:56:07 +08:00
|
|
|
|
|
|
|
void test_bad_encoding()
|
2014-05-09 03:32:12 +08:00
|
|
|
{
|
2015-10-14 01:56:07 +08:00
|
|
|
/*
|
|
|
|
unsigned char pound = 163;
|
|
|
|
auto test_string = "Compount Value (" + std::string(pound) + ")";
|
|
|
|
auto ws = wb.create_sheet();
|
|
|
|
cell = ws[xlnt::cell_reference("A1")];
|
|
|
|
TS_ASSERT_THROWS(cell.check_string(test_string), xlnt::unicode_decode_error);
|
|
|
|
TS_ASSERT_THROWS(cell.set_value(test_string), xlnt::unicode_decode_error);
|
|
|
|
*/
|
2014-05-09 03:32:12 +08:00
|
|
|
}
|
2014-07-20 02:43:48 +08:00
|
|
|
|
2015-10-14 01:56:07 +08:00
|
|
|
void test_good_encoding()
|
2014-07-20 02:43:48 +08:00
|
|
|
{
|
2015-10-14 01:56:07 +08:00
|
|
|
/*
|
|
|
|
auto wb = xlnt::workbook(xlnt::encoding::latin1);
|
|
|
|
auto ws = wb.get_active_sheet();
|
|
|
|
auto cell = ws[xlnt::cell_reference("A1")];
|
|
|
|
cell.set_value(test_string);
|
|
|
|
*/
|
2014-07-20 02:43:48 +08:00
|
|
|
}
|
2015-10-14 01:56:07 +08:00
|
|
|
|
2015-10-15 06:05:13 +08:00
|
|
|
void _test_font()
|
2014-05-09 03:32:12 +08:00
|
|
|
{
|
2015-10-14 01:56:07 +08:00
|
|
|
xlnt::font font;
|
|
|
|
font.set_bold(true);
|
|
|
|
auto ws = wb.create_sheet();
|
|
|
|
ws.get_parent().add_font(font);
|
|
|
|
|
|
|
|
auto cell = xlnt::cell(ws, "A1");
|
2015-10-14 04:35:22 +08:00
|
|
|
TS_ASSERT_EQUALS(cell.get_font(), font);
|
2014-05-09 03:32:12 +08:00
|
|
|
}
|
2015-10-14 01:56:07 +08:00
|
|
|
|
2015-10-15 06:05:13 +08:00
|
|
|
void _test_fill()
|
2014-05-09 03:32:12 +08:00
|
|
|
{
|
2015-10-24 02:42:36 +08:00
|
|
|
xlnt::fill f;
|
|
|
|
f.set_type(xlnt::fill::type::solid);
|
|
|
|
// f.set_foreground_color("FF0000");
|
2015-10-14 01:56:07 +08:00
|
|
|
auto ws = wb.create_sheet();
|
2015-10-24 02:42:36 +08:00
|
|
|
ws.get_parent().add_fill(f);
|
2015-10-14 01:56:07 +08:00
|
|
|
|
2014-05-30 08:52:14 +08:00
|
|
|
xlnt::cell cell(ws, "A1");
|
2015-10-24 02:42:36 +08:00
|
|
|
TS_ASSERT(cell.get_fill() == f);
|
2014-05-09 03:32:12 +08:00
|
|
|
}
|
2015-10-14 01:56:07 +08:00
|
|
|
|
2015-10-15 06:05:13 +08:00
|
|
|
void _test_border()
|
2014-05-09 03:32:12 +08:00
|
|
|
{
|
2015-10-14 01:56:07 +08:00
|
|
|
xlnt::border border;
|
|
|
|
auto ws = wb.create_sheet();
|
|
|
|
ws.get_parent().add_border(border);
|
|
|
|
|
|
|
|
auto cell = ws.get_cell(xlnt::cell_reference(1, 1));
|
|
|
|
TS_ASSERT(cell.get_border() == border);
|
2014-05-09 03:32:12 +08:00
|
|
|
}
|
2015-10-14 01:56:07 +08:00
|
|
|
|
2015-10-15 06:05:13 +08:00
|
|
|
void _test_number_format()
|
2014-05-09 03:32:12 +08:00
|
|
|
{
|
2015-10-14 01:56:07 +08:00
|
|
|
auto ws = wb.create_sheet();
|
2015-10-24 02:42:36 +08:00
|
|
|
ws.get_parent().add_number_format(xlnt::number_format("dd--hh--mm"));
|
2015-10-14 01:56:07 +08:00
|
|
|
|
2014-05-30 08:52:14 +08:00
|
|
|
xlnt::cell cell(ws, "A1");
|
2015-10-19 03:30:46 +08:00
|
|
|
cell.set_number_format(xlnt::number_format("dd--hh--mm"));
|
|
|
|
TS_ASSERT(cell.get_number_format().get_format_string() == "dd--hh--mm");
|
2014-05-09 03:32:12 +08:00
|
|
|
}
|
2015-10-14 01:56:07 +08:00
|
|
|
|
2015-10-15 06:05:13 +08:00
|
|
|
void _test_alignment()
|
2014-05-09 03:32:12 +08:00
|
|
|
{
|
2015-10-14 01:56:07 +08:00
|
|
|
xlnt::alignment align;
|
|
|
|
align.set_wrap_text(true);
|
|
|
|
|
|
|
|
auto ws = wb.create_sheet();
|
|
|
|
ws.get_parent().add_alignment(align);
|
|
|
|
|
2014-05-30 08:52:14 +08:00
|
|
|
xlnt::cell cell(ws, "A1");
|
2015-10-14 01:56:07 +08:00
|
|
|
TS_ASSERT(cell.get_alignment() == align);
|
2014-05-09 03:32:12 +08:00
|
|
|
}
|
2014-07-20 02:43:48 +08:00
|
|
|
|
2015-10-15 06:05:13 +08:00
|
|
|
void _test_protection()
|
2014-07-20 02:43:48 +08:00
|
|
|
{
|
2015-10-14 01:56:07 +08:00
|
|
|
xlnt::protection prot;
|
2015-10-24 02:42:36 +08:00
|
|
|
prot.set_locked(xlnt::protection::type::protected_);
|
2015-10-14 01:56:07 +08:00
|
|
|
|
|
|
|
auto ws = wb.create_sheet();
|
|
|
|
ws.get_parent().add_protection(prot);
|
|
|
|
|
2014-07-20 02:43:48 +08:00
|
|
|
xlnt::cell cell(ws, "A1");
|
2015-10-14 01:56:07 +08:00
|
|
|
TS_ASSERT(cell.get_protection() == prot);
|
|
|
|
}
|
|
|
|
|
2015-10-15 06:05:13 +08:00
|
|
|
void _test_pivot_button()
|
2015-10-14 01:56:07 +08:00
|
|
|
{
|
|
|
|
auto ws = wb.create_sheet();
|
2014-07-20 02:43:48 +08:00
|
|
|
|
2015-10-14 01:56:07 +08:00
|
|
|
xlnt::cell cell(ws, "A1");
|
2015-10-19 03:30:46 +08:00
|
|
|
cell.set_pivot_button(true);
|
2015-10-14 01:56:07 +08:00
|
|
|
TS_ASSERT(cell.pivot_button());
|
2014-07-20 02:43:48 +08:00
|
|
|
}
|
|
|
|
|
2015-10-15 06:05:13 +08:00
|
|
|
void _test_quote_prefix()
|
2014-07-20 02:43:48 +08:00
|
|
|
{
|
2015-10-14 01:56:07 +08:00
|
|
|
auto ws = wb.create_sheet();
|
|
|
|
|
|
|
|
xlnt::cell cell(ws, "A1");
|
2015-10-19 03:30:46 +08:00
|
|
|
cell.set_quote_prefix(true);
|
2015-10-14 01:56:07 +08:00
|
|
|
TS_ASSERT(cell.quote_prefix());
|
2014-07-20 02:43:48 +08:00
|
|
|
}
|
2014-05-09 03:32:12 +08:00
|
|
|
};
|