2018-01-22 22:38:48 +08:00
|
|
|
// Copyright (c) 2014-2018 Thomas Fussell
|
2017-04-14 07:01:30 +08:00
|
|
|
//
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
// of this software and associated documentation files (the "Software"), to deal
|
|
|
|
// in the Software without restriction, including without limitation the rights
|
|
|
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
// copies of the Software, and to permit persons to whom the Software is
|
|
|
|
// furnished to do so, subject to the following conditions:
|
|
|
|
//
|
|
|
|
// The above copyright notice and this permission notice shall be included in
|
|
|
|
// all copies or substantial portions of the Software.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, WRISING FROM,
|
|
|
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
// THE SOFTWARE
|
|
|
|
//
|
|
|
|
// @license: http://www.opensource.org/licenses/mit-license.php
|
|
|
|
// @author: see AUTHORS file
|
|
|
|
|
2016-06-20 02:43:41 +08:00
|
|
|
#include <sstream>
|
2017-04-14 02:51:35 +08:00
|
|
|
|
2018-07-05 16:47:24 +08:00
|
|
|
#include <helpers/assertions.hpp>
|
|
|
|
#include <helpers/test_suite.hpp>
|
2014-05-09 03:32:12 +08:00
|
|
|
|
2018-07-05 17:26:29 +08:00
|
|
|
#include <xlnt/cell/cell.hpp>
|
|
|
|
#include <xlnt/cell/comment.hpp>
|
|
|
|
#include <xlnt/cell/hyperlink.hpp>
|
|
|
|
#include <xlnt/styles/number_format.hpp>
|
|
|
|
#include <xlnt/styles/alignment.hpp>
|
|
|
|
#include <xlnt/styles/border.hpp>
|
|
|
|
#include <xlnt/styles/fill.hpp>
|
|
|
|
#include <xlnt/styles/format.hpp>
|
|
|
|
#include <xlnt/styles/protection.hpp>
|
|
|
|
#include <xlnt/styles/style.hpp>
|
|
|
|
#include <xlnt/worksheet/worksheet.hpp>
|
|
|
|
#include <xlnt/utils/date.hpp>
|
|
|
|
#include <xlnt/utils/datetime.hpp>
|
|
|
|
#include <xlnt/utils/time.hpp>
|
|
|
|
#include <xlnt/utils/timedelta.hpp>
|
|
|
|
|
2017-04-14 02:51:35 +08:00
|
|
|
class cell_test_suite : public test_suite
|
2014-05-09 03:32:12 +08:00
|
|
|
{
|
|
|
|
public:
|
2017-04-14 02:51:35 +08:00
|
|
|
cell_test_suite()
|
|
|
|
{
|
2017-04-14 07:01:30 +08:00
|
|
|
register_test(test_infer_numeric);
|
|
|
|
register_test(test_constructor);
|
|
|
|
register_test(test_null);
|
|
|
|
register_test(test_string);
|
|
|
|
register_test(test_formula1);
|
|
|
|
register_test(test_formula2);
|
|
|
|
register_test(test_formula3);
|
|
|
|
register_test(test_not_formula);
|
|
|
|
register_test(test_boolean);
|
|
|
|
register_test(test_error_codes);
|
|
|
|
register_test(test_insert_datetime);
|
|
|
|
register_test(test_insert_date);
|
|
|
|
register_test(test_insert_time);
|
|
|
|
register_test(test_cell_formatted_as_date1);
|
|
|
|
register_test(test_cell_formatted_as_date2);
|
|
|
|
register_test(test_cell_formatted_as_date3);
|
|
|
|
register_test(test_illegal_characters);
|
|
|
|
register_test(test_timedelta);
|
|
|
|
register_test(test_cell_offset);
|
|
|
|
register_test(test_font);
|
|
|
|
register_test(test_fill);
|
|
|
|
register_test(test_border);
|
|
|
|
register_test(test_number_format);
|
|
|
|
register_test(test_alignment);
|
|
|
|
register_test(test_protection);
|
|
|
|
register_test(test_style);
|
|
|
|
register_test(test_print);
|
|
|
|
register_test(test_values);
|
|
|
|
register_test(test_reference);
|
|
|
|
register_test(test_anchor);
|
|
|
|
register_test(test_hyperlink);
|
|
|
|
register_test(test_comment);
|
2017-04-14 02:51:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void test_infer_numeric()
|
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
xlnt::workbook wb;
|
2017-04-14 07:01:30 +08:00
|
|
|
auto ws = wb.active_sheet();
|
2016-12-02 21:37:50 +08:00
|
|
|
auto cell = ws.cell("A1");
|
2015-10-02 11:09:25 +08:00
|
|
|
|
2017-04-14 07:01:30 +08:00
|
|
|
cell.value("4.2", true);
|
2017-09-09 09:05:34 +08:00
|
|
|
xlnt_assert_delta(cell.value<double>(), 4.2, 1E-9);
|
2015-10-02 11:09:25 +08:00
|
|
|
|
2017-04-14 07:01:30 +08:00
|
|
|
cell.value("-42.000", true);
|
2017-04-19 06:30:54 +08:00
|
|
|
xlnt_assert(cell.value<int>() == -42);
|
2015-10-02 11:09:25 +08:00
|
|
|
|
2017-04-14 07:01:30 +08:00
|
|
|
cell.value("0", true);
|
2017-04-19 06:30:54 +08:00
|
|
|
xlnt_assert(cell.value<int>() == 0);
|
2015-10-02 11:09:25 +08:00
|
|
|
|
2017-04-14 07:01:30 +08:00
|
|
|
cell.value("0.9999", true);
|
2017-09-09 09:05:34 +08:00
|
|
|
xlnt_assert(cell.value<double>() == 0.9999);
|
2015-10-02 11:09:25 +08:00
|
|
|
|
2017-04-14 07:01:30 +08:00
|
|
|
cell.value("99E-02", true);
|
2017-09-09 09:05:34 +08:00
|
|
|
xlnt_assert(cell.value<double>() == 0.99);
|
2015-10-02 11:09:25 +08:00
|
|
|
|
2017-04-14 07:01:30 +08:00
|
|
|
cell.value("4", true);
|
2017-04-19 06:30:54 +08:00
|
|
|
xlnt_assert(cell.value<int>() == 4);
|
2015-10-02 11:09:25 +08:00
|
|
|
|
2017-04-14 07:01:30 +08:00
|
|
|
cell.value("-1E3", true);
|
2017-04-19 06:30:54 +08:00
|
|
|
xlnt_assert(cell.value<int>() == -1000);
|
2015-10-02 11:09:25 +08:00
|
|
|
|
2017-04-14 07:01:30 +08:00
|
|
|
cell.value("2e+2", true);
|
2017-04-19 06:30:54 +08:00
|
|
|
xlnt_assert(cell.value<int>() == 200);
|
2015-10-02 11:09:25 +08:00
|
|
|
|
2017-04-14 07:01:30 +08:00
|
|
|
cell.value("3.1%", true);
|
2017-09-09 09:05:34 +08:00
|
|
|
xlnt_assert_delta(cell.value<double>(), 0.031, 1E-9);
|
2015-10-02 11:09:25 +08:00
|
|
|
|
2017-04-14 07:01:30 +08:00
|
|
|
cell.value("03:40:16", true);
|
2017-04-19 06:30:54 +08:00
|
|
|
xlnt_assert(cell.value<xlnt::time>() == xlnt::time(3, 40, 16));
|
2015-10-02 11:09:25 +08:00
|
|
|
|
2017-04-14 07:01:30 +08:00
|
|
|
cell.value("03:", true);
|
2017-04-19 06:30:54 +08:00
|
|
|
xlnt_assert_equals(cell.value<std::string>(), "03:");
|
2016-07-18 01:49:59 +08:00
|
|
|
|
2017-04-14 07:01:30 +08:00
|
|
|
cell.value("03:40", true);
|
2017-04-19 06:30:54 +08:00
|
|
|
xlnt_assert(cell.value<xlnt::time>() == xlnt::time(3, 40));
|
2015-10-02 11:09:25 +08:00
|
|
|
|
2017-04-14 07:01:30 +08:00
|
|
|
cell.value("30:33.865633336", true);
|
2017-04-19 06:30:54 +08:00
|
|
|
xlnt_assert(cell.value<xlnt::time>() == xlnt::time(0, 30, 33, 865633));
|
2017-04-14 02:51:35 +08:00
|
|
|
}
|
2015-10-02 11:09:25 +08:00
|
|
|
|
2017-03-31 11:52:57 +08:00
|
|
|
void test_constructor()
|
2015-10-07 00:31:49 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
xlnt::workbook wb;
|
|
|
|
auto ws = wb.active_sheet();
|
|
|
|
auto cell = ws.cell(xlnt::cell_reference("A", 1));
|
2017-04-14 07:01:30 +08:00
|
|
|
|
2017-05-10 20:44:25 +08:00
|
|
|
xlnt_assert(cell.data_type() == xlnt::cell::type::empty);
|
2017-04-19 06:30:54 +08:00
|
|
|
xlnt_assert(cell.column() == "A");
|
2018-07-03 09:16:33 +08:00
|
|
|
xlnt_assert(cell.column_index() == 1);
|
2017-04-19 06:30:54 +08:00
|
|
|
xlnt_assert(cell.row() == 1);
|
|
|
|
xlnt_assert(cell.reference() == "A1");
|
|
|
|
xlnt_assert(!cell.has_value());
|
2015-10-07 00:31:49 +08:00
|
|
|
}
|
|
|
|
|
2015-10-14 01:56:07 +08:00
|
|
|
void test_null()
|
2014-05-09 03:32:12 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
xlnt::workbook wb;
|
|
|
|
|
2016-03-14 11:46:01 +08:00
|
|
|
const auto datatypes =
|
2018-07-05 16:47:24 +08:00
|
|
|
{
|
|
|
|
xlnt::cell::type::empty,
|
|
|
|
xlnt::cell::type::boolean,
|
|
|
|
xlnt::cell::type::error,
|
|
|
|
xlnt::cell::type::formula_string,
|
|
|
|
xlnt::cell::type::number,
|
|
|
|
xlnt::cell::type::shared_string};
|
2017-04-14 07:01:30 +08:00
|
|
|
|
|
|
|
for (const auto &datatype : datatypes)
|
2015-10-14 01:56:07 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
auto ws = wb.active_sheet();
|
|
|
|
auto cell = ws.cell(xlnt::cell_reference(1, 1));
|
2017-04-14 07:01:30 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
cell.data_type(datatype);
|
2017-04-19 06:30:54 +08:00
|
|
|
xlnt_assert(cell.data_type() == datatype);
|
2015-10-14 01:56:07 +08:00
|
|
|
cell.clear_value();
|
2017-05-10 20:44:25 +08:00
|
|
|
xlnt_assert(cell.data_type() == xlnt::cell::type::empty);
|
2015-10-14 01:56:07 +08:00
|
|
|
}
|
2014-05-09 03:32:12 +08:00
|
|
|
}
|
2017-04-14 07:01:30 +08:00
|
|
|
|
2015-10-14 01:56:07 +08:00
|
|
|
void test_string()
|
2014-05-09 03:32:12 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
xlnt::workbook wb;
|
|
|
|
auto ws = wb.active_sheet();
|
|
|
|
auto cell = ws.cell(xlnt::cell_reference(1, 1));
|
2017-04-14 07:01:30 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
cell.value("hello");
|
2017-05-10 20:44:25 +08:00
|
|
|
xlnt_assert(cell.data_type() == xlnt::cell::type::shared_string);
|
2017-04-14 07:01:30 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
cell.value(".");
|
2017-05-10 20:44:25 +08:00
|
|
|
xlnt_assert(cell.data_type() == xlnt::cell::type::shared_string);
|
2017-04-14 07:01:30 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
cell.value("0800");
|
2017-05-10 20:44:25 +08:00
|
|
|
xlnt_assert(cell.data_type() == xlnt::cell::type::shared_string);
|
2014-05-09 03:32:12 +08:00
|
|
|
}
|
2017-04-14 07:01:30 +08:00
|
|
|
|
2015-10-14 01:56:07 +08:00
|
|
|
void test_formula1()
|
2014-05-09 03:32:12 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
xlnt::workbook wb;
|
|
|
|
auto ws = wb.active_sheet();
|
|
|
|
auto cell = ws.cell(xlnt::cell_reference(1, 1));
|
2016-07-24 07:15:17 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
cell.value("=42", true);
|
2018-03-17 09:21:16 +08:00
|
|
|
//xlnt_assert(cell.data_type() == xlnt::cell::type::number);
|
2017-05-10 20:44:25 +08:00
|
|
|
xlnt_assert(cell.has_formula());
|
2014-05-09 03:32:12 +08:00
|
|
|
}
|
2017-04-14 07:01:30 +08:00
|
|
|
|
2015-10-14 01:56:07 +08:00
|
|
|
void test_formula2()
|
2014-05-09 03:32:12 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
xlnt::workbook wb;
|
|
|
|
auto ws = wb.active_sheet();
|
|
|
|
auto cell = ws.cell(xlnt::cell_reference(1, 1));
|
2017-04-14 07:01:30 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
cell.value("=if(A1<4;-1;1)", true);
|
2018-03-17 09:21:16 +08:00
|
|
|
//xlnt_assert(cell.data_type() == xlnt::cell::type::number);
|
2017-05-10 20:44:25 +08:00
|
|
|
xlnt_assert(cell.has_formula());
|
2014-05-09 03:32:12 +08:00
|
|
|
}
|
2016-07-24 07:15:17 +08:00
|
|
|
|
|
|
|
void test_formula3()
|
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
xlnt::workbook wb;
|
|
|
|
auto ws = wb.active_sheet();
|
|
|
|
auto cell = ws.cell(xlnt::cell_reference(1, 1));
|
2016-07-24 07:15:17 +08:00
|
|
|
|
2017-04-19 06:30:54 +08:00
|
|
|
xlnt_assert(!cell.has_formula());
|
|
|
|
xlnt_assert_throws_nothing(cell.formula(""));
|
|
|
|
xlnt_assert(!cell.has_formula());
|
2016-12-02 21:37:50 +08:00
|
|
|
cell.formula("=42");
|
2017-04-19 06:30:54 +08:00
|
|
|
xlnt_assert(cell.has_formula());
|
|
|
|
xlnt_assert_equals(cell.formula(), "42");
|
2016-07-24 07:15:17 +08:00
|
|
|
cell.clear_formula();
|
2017-04-19 06:30:54 +08:00
|
|
|
xlnt_assert(!cell.has_formula());
|
2016-07-24 07:15:17 +08:00
|
|
|
}
|
|
|
|
|
2015-10-14 01:56:07 +08:00
|
|
|
void test_not_formula()
|
2014-05-09 03:32:12 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
xlnt::workbook wb;
|
|
|
|
auto ws = wb.active_sheet();
|
|
|
|
auto cell = ws.cell(xlnt::cell_reference(1, 1));
|
2017-04-14 07:01:30 +08:00
|
|
|
|
2017-05-10 20:44:25 +08:00
|
|
|
cell.value("=", true);
|
|
|
|
xlnt_assert(cell.data_type() == xlnt::cell::type::shared_string);
|
2017-04-19 06:30:54 +08:00
|
|
|
xlnt_assert(cell.value<std::string>() == "=");
|
|
|
|
xlnt_assert(!cell.has_formula());
|
2014-05-09 03:32:12 +08:00
|
|
|
}
|
2017-04-14 07:01:30 +08:00
|
|
|
|
2015-10-14 01:56:07 +08:00
|
|
|
void test_boolean()
|
2014-05-09 03:32:12 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
xlnt::workbook wb;
|
|
|
|
auto ws = wb.active_sheet();
|
|
|
|
auto cell = ws.cell(xlnt::cell_reference(1, 1));
|
2017-04-14 07:01:30 +08:00
|
|
|
|
2018-07-05 16:47:24 +08:00
|
|
|
for (auto value : {true, false})
|
2014-05-30 08:52:14 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
cell.value(value);
|
2017-04-19 06:30:54 +08:00
|
|
|
xlnt_assert(cell.data_type() == xlnt::cell::type::boolean);
|
2014-05-30 08:52:14 +08:00
|
|
|
}
|
2014-05-09 03:32:12 +08:00
|
|
|
}
|
2017-04-14 07:01:30 +08:00
|
|
|
|
2015-10-14 01:56:07 +08:00
|
|
|
void test_error_codes()
|
2014-05-09 03:32:12 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
xlnt::workbook wb;
|
|
|
|
auto ws = wb.active_sheet();
|
|
|
|
auto cell = ws.cell(xlnt::cell_reference(1, 1));
|
2017-04-14 07:01:30 +08:00
|
|
|
|
|
|
|
for (auto error_code : xlnt::cell::error_codes())
|
2014-05-09 03:32:12 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
cell.value(error_code.first, true);
|
2017-04-19 06:30:54 +08:00
|
|
|
xlnt_assert(cell.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
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
xlnt::workbook wb;
|
|
|
|
auto ws = wb.active_sheet();
|
|
|
|
auto cell = ws.cell(xlnt::cell_reference(1, 1));
|
2017-04-14 07:01:30 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
cell.value(xlnt::datetime(2010, 7, 13, 6, 37, 41));
|
2017-03-31 11:52:57 +08:00
|
|
|
|
2017-05-10 20:44:25 +08:00
|
|
|
xlnt_assert(cell.data_type() == xlnt::cell::type::number);
|
2017-09-09 09:05:34 +08:00
|
|
|
xlnt_assert_delta(cell.value<double>(), 40372.27616898148, 1E-9);
|
2017-04-19 06:30:54 +08:00
|
|
|
xlnt_assert(cell.is_date());
|
|
|
|
xlnt_assert(cell.number_format().format_string() == "yyyy-mm-dd h:mm:ss");
|
2014-05-09 03:32:12 +08:00
|
|
|
}
|
2017-04-14 07:01:30 +08:00
|
|
|
|
2015-10-14 01:56:07 +08:00
|
|
|
void test_insert_date()
|
2014-06-11 06:36:31 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
xlnt::workbook wb;
|
|
|
|
auto ws = wb.active_sheet();
|
|
|
|
auto cell = ws.cell(xlnt::cell_reference(1, 1));
|
2017-04-14 07:01:30 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
cell.value(xlnt::date(2010, 7, 13));
|
2017-05-10 20:44:25 +08:00
|
|
|
xlnt_assert(cell.data_type() == xlnt::cell::type::number);
|
2017-09-09 09:05:34 +08:00
|
|
|
xlnt_assert(cell.value<double>() == 40372.0);
|
2017-04-19 06:30:54 +08:00
|
|
|
xlnt_assert(cell.is_date());
|
|
|
|
xlnt_assert(cell.number_format().format_string() == "yyyy-mm-dd");
|
2014-06-11 06:36:31 +08:00
|
|
|
}
|
2017-04-14 07:01:30 +08:00
|
|
|
|
2015-10-14 01:56:07 +08:00
|
|
|
void test_insert_time()
|
2014-05-09 03:32:12 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
xlnt::workbook wb;
|
|
|
|
auto ws = wb.active_sheet();
|
|
|
|
auto cell = ws.cell(xlnt::cell_reference(1, 1));
|
2017-04-14 07:01:30 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
cell.value(xlnt::time(1, 3));
|
2017-05-10 20:44:25 +08:00
|
|
|
xlnt_assert(cell.data_type() == xlnt::cell::type::number);
|
2017-09-09 09:05:34 +08:00
|
|
|
xlnt_assert_delta(cell.value<double>(), 0.04375, 1E-9);
|
2017-04-19 06:30:54 +08:00
|
|
|
xlnt_assert(cell.is_date());
|
|
|
|
xlnt_assert(cell.number_format().format_string() == "h:mm:ss");
|
2014-05-09 03:32:12 +08:00
|
|
|
}
|
2017-04-14 07:01:30 +08:00
|
|
|
|
2015-10-14 01:56:07 +08:00
|
|
|
void test_cell_formatted_as_date1()
|
2014-05-09 03:32:12 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
xlnt::workbook wb;
|
|
|
|
auto ws = wb.active_sheet();
|
|
|
|
auto cell = ws.cell(xlnt::cell_reference(1, 1));
|
2017-04-14 07:01:30 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
cell.value(xlnt::datetime::today());
|
2015-10-14 01:56:07 +08:00
|
|
|
cell.clear_value();
|
2017-04-19 06:30:54 +08:00
|
|
|
xlnt_assert(!cell.is_date()); // disagree with openpyxl
|
|
|
|
xlnt_assert(!cell.has_value());
|
2014-05-09 03:32:12 +08:00
|
|
|
}
|
2017-04-14 07:01:30 +08:00
|
|
|
|
2015-10-14 01:56:07 +08:00
|
|
|
void test_cell_formatted_as_date2()
|
2014-05-09 03:32:12 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
xlnt::workbook wb;
|
|
|
|
auto ws = wb.active_sheet();
|
|
|
|
auto cell = ws.cell(xlnt::cell_reference(1, 1));
|
2017-04-14 07:01:30 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
cell.value(xlnt::datetime::today());
|
|
|
|
cell.value("testme");
|
2017-04-19 06:30:54 +08:00
|
|
|
xlnt_assert(!cell.is_date());
|
|
|
|
xlnt_assert(cell.value<std::string>() == "testme");
|
2014-05-09 03:32:12 +08:00
|
|
|
}
|
2017-04-14 07:01:30 +08:00
|
|
|
|
2015-10-14 01:56:07 +08:00
|
|
|
void test_cell_formatted_as_date3()
|
2014-05-09 03:32:12 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
xlnt::workbook wb;
|
|
|
|
auto ws = wb.active_sheet();
|
|
|
|
auto cell = ws.cell(xlnt::cell_reference(1, 1));
|
2017-04-14 07:01:30 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
cell.value(xlnt::datetime::today());
|
|
|
|
cell.value(true);
|
2017-04-19 06:30:54 +08:00
|
|
|
xlnt_assert(!cell.is_date());
|
|
|
|
xlnt_assert(cell.value<bool>() == true);
|
2014-05-09 03:32:12 +08:00
|
|
|
}
|
2017-04-14 07:01:30 +08:00
|
|
|
|
2016-03-14 11:46:01 +08:00
|
|
|
void test_illegal_characters()
|
2014-05-09 03:32:12 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
xlnt::workbook wb;
|
|
|
|
auto ws = wb.active_sheet();
|
|
|
|
auto cell = ws.cell(xlnt::cell_reference(1, 1));
|
2017-04-14 07:01:30 +08:00
|
|
|
|
2015-10-14 01:56:07 +08:00
|
|
|
// The bytes 0x00 through 0x1F inclusive must be manually escaped in values.
|
2018-07-05 16:47:24 +08:00
|
|
|
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};
|
2017-04-14 07:01:30 +08:00
|
|
|
|
|
|
|
for (auto i : illegal_chrs)
|
2014-05-13 01:42:28 +08:00
|
|
|
{
|
2015-11-11 07:58:54 +08:00
|
|
|
std::string str(1, i);
|
2017-04-19 06:30:54 +08:00
|
|
|
xlnt_assert_throws(cell.value(str), xlnt::illegal_character);
|
2014-05-13 01:42:28 +08:00
|
|
|
}
|
2017-04-14 07:01:30 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
cell.value(std::string(1, 33));
|
2018-07-05 16:47:24 +08:00
|
|
|
cell.value(std::string(1, 9)); // Tab
|
|
|
|
cell.value(std::string(1, 10)); // Newline
|
|
|
|
cell.value(std::string(1, 13)); // Carriage return
|
2016-12-02 21:37:50 +08:00
|
|
|
cell.value(" Leading and trailing spaces are legal ");
|
2015-10-14 01:56:07 +08:00
|
|
|
}
|
2017-04-14 07:01:30 +08:00
|
|
|
|
2016-03-14 11:46:01 +08:00
|
|
|
// void test_time_regex() {}
|
2017-04-14 07:01:30 +08:00
|
|
|
|
2015-10-14 01:56:07 +08:00
|
|
|
void test_timedelta()
|
2014-06-11 06:36:31 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
xlnt::workbook wb;
|
|
|
|
auto ws = wb.active_sheet();
|
|
|
|
auto cell = ws.cell(xlnt::cell_reference(1, 1));
|
2017-04-14 07:01:30 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
cell.value(xlnt::timedelta(1, 3, 0, 0, 0));
|
2015-11-23 01:41:27 +08:00
|
|
|
|
2017-09-09 09:05:34 +08:00
|
|
|
xlnt_assert(cell.value<double>() == 1.125);
|
2017-05-10 20:44:25 +08:00
|
|
|
xlnt_assert(cell.data_type() == xlnt::cell::type::number);
|
2017-04-19 06:30:54 +08:00
|
|
|
xlnt_assert(!cell.is_date());
|
|
|
|
xlnt_assert(cell.number_format().format_string() == "[hh]:mm:ss");
|
2014-06-11 06:36:31 +08:00
|
|
|
}
|
2016-12-10 08:18:50 +08:00
|
|
|
|
2015-10-14 01:56:07 +08:00
|
|
|
void test_cell_offset()
|
2014-05-09 03:32:12 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
xlnt::workbook wb;
|
|
|
|
auto ws = wb.active_sheet();
|
|
|
|
auto cell = ws.cell(xlnt::cell_reference(1, 1));
|
2017-04-19 06:30:54 +08:00
|
|
|
xlnt_assert(cell.offset(1, 2).reference() == "B3");
|
2015-11-23 01:41:27 +08:00
|
|
|
}
|
2017-04-14 07:01:30 +08:00
|
|
|
|
2015-11-23 01:41:27 +08:00
|
|
|
void test_font()
|
2014-05-09 03:32:12 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
xlnt::workbook wb;
|
2017-04-14 07:01:30 +08:00
|
|
|
auto ws = wb.active_sheet();
|
2016-12-02 21:37:50 +08:00
|
|
|
auto cell = ws.cell("A1");
|
2016-05-04 03:37:34 +08:00
|
|
|
|
2017-04-14 07:01:30 +08:00
|
|
|
auto font = xlnt::font().bold(true);
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
cell.font(font);
|
2017-04-14 07:01:30 +08:00
|
|
|
|
2017-04-19 06:30:54 +08:00
|
|
|
xlnt_assert(cell.has_format());
|
|
|
|
xlnt_assert(cell.format().font_applied());
|
|
|
|
xlnt_assert_equals(cell.font(), font);
|
2014-05-09 03:32:12 +08:00
|
|
|
}
|
2017-04-14 07:01:30 +08:00
|
|
|
|
2016-03-14 11:46:01 +08:00
|
|
|
void test_fill()
|
2014-05-09 03:32:12 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
xlnt::workbook wb;
|
|
|
|
auto ws = wb.active_sheet();
|
|
|
|
auto cell = ws.cell("A1");
|
2017-04-14 07:01:30 +08:00
|
|
|
|
|
|
|
xlnt::fill fill(xlnt::pattern_fill()
|
2018-07-05 16:47:24 +08:00
|
|
|
.type(xlnt::pattern_fill_type::solid)
|
|
|
|
.foreground(xlnt::color::red()));
|
2016-12-02 21:37:50 +08:00
|
|
|
cell.fill(fill);
|
2017-04-14 07:01:30 +08:00
|
|
|
|
2017-04-19 06:30:54 +08:00
|
|
|
xlnt_assert(cell.has_format());
|
|
|
|
xlnt_assert(cell.format().fill_applied());
|
|
|
|
xlnt_assert_equals(cell.fill(), fill);
|
2014-05-09 03:32:12 +08:00
|
|
|
}
|
2017-04-14 07:01:30 +08:00
|
|
|
|
2016-03-14 11:46:01 +08:00
|
|
|
void test_border()
|
2014-05-09 03:32:12 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
xlnt::workbook wb;
|
|
|
|
auto ws = wb.active_sheet();
|
|
|
|
auto cell = ws.cell("A1");
|
2017-04-14 07:01:30 +08:00
|
|
|
|
2016-05-04 03:37:34 +08:00
|
|
|
xlnt::border border;
|
2016-12-02 21:37:50 +08:00
|
|
|
cell.border(border);
|
2017-04-14 07:01:30 +08:00
|
|
|
|
2017-04-19 06:30:54 +08:00
|
|
|
xlnt_assert(cell.has_format());
|
|
|
|
xlnt_assert(cell.format().border_applied());
|
|
|
|
xlnt_assert_equals(cell.border(), border);
|
2014-05-09 03:32:12 +08:00
|
|
|
}
|
2017-04-14 07:01:30 +08:00
|
|
|
|
2016-03-14 11:46:01 +08:00
|
|
|
void test_number_format()
|
2014-05-09 03:32:12 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
xlnt::workbook wb;
|
|
|
|
auto ws = wb.active_sheet();
|
|
|
|
auto cell = ws.cell("A1");
|
2017-04-14 07:01:30 +08:00
|
|
|
|
2016-05-04 03:37:34 +08:00
|
|
|
xlnt::number_format format("dd--hh--mm");
|
2016-12-02 21:37:50 +08:00
|
|
|
cell.number_format(format);
|
2017-04-14 07:01:30 +08:00
|
|
|
|
2017-04-19 06:30:54 +08:00
|
|
|
xlnt_assert(cell.has_format());
|
|
|
|
xlnt_assert(cell.format().number_format_applied());
|
|
|
|
xlnt_assert_equals(cell.number_format().format_string(), "dd--hh--mm");
|
2014-05-09 03:32:12 +08:00
|
|
|
}
|
2017-04-14 07:01:30 +08:00
|
|
|
|
2016-03-14 11:46:01 +08:00
|
|
|
void test_alignment()
|
2014-05-09 03:32:12 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
xlnt::workbook wb;
|
|
|
|
auto ws = wb.active_sheet();
|
|
|
|
auto cell = ws.cell("A1");
|
2017-04-14 07:01:30 +08:00
|
|
|
|
2015-10-14 01:56:07 +08:00
|
|
|
xlnt::alignment align;
|
2016-08-18 19:34:18 +08:00
|
|
|
align.wrap(true);
|
2017-04-14 07:01:30 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
cell.alignment(align);
|
2017-04-14 07:01:30 +08:00
|
|
|
|
2017-04-19 06:30:54 +08:00
|
|
|
xlnt_assert(cell.has_format());
|
|
|
|
xlnt_assert(cell.format().alignment_applied());
|
|
|
|
xlnt_assert_equals(cell.alignment(), align);
|
2014-05-09 03:32:12 +08:00
|
|
|
}
|
2017-04-14 07:01:30 +08:00
|
|
|
|
2016-03-14 11:46:01 +08:00
|
|
|
void test_protection()
|
2014-07-20 02:43:48 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
xlnt::workbook wb;
|
|
|
|
auto ws = wb.active_sheet();
|
|
|
|
auto cell = ws.cell("A1");
|
2016-06-20 02:43:41 +08:00
|
|
|
|
2017-04-19 06:30:54 +08:00
|
|
|
xlnt_assert(!cell.has_format());
|
2016-06-20 02:43:41 +08:00
|
|
|
|
2017-04-14 07:01:30 +08:00
|
|
|
auto protection = xlnt::protection().locked(false).hidden(true);
|
2016-12-02 21:37:50 +08:00
|
|
|
cell.protection(protection);
|
2017-04-14 07:01:30 +08:00
|
|
|
|
2017-04-19 06:30:54 +08:00
|
|
|
xlnt_assert(cell.has_format());
|
|
|
|
xlnt_assert(cell.format().protection_applied());
|
|
|
|
xlnt_assert_equals(cell.protection(), protection);
|
2017-04-14 07:01:30 +08:00
|
|
|
|
2017-04-19 06:30:54 +08:00
|
|
|
xlnt_assert(cell.has_format());
|
2016-06-20 02:43:41 +08:00
|
|
|
cell.clear_format();
|
2017-04-19 06:30:54 +08:00
|
|
|
xlnt_assert(!cell.has_format());
|
2016-06-20 02:43:41 +08:00
|
|
|
}
|
2017-04-14 07:01:30 +08:00
|
|
|
|
2016-06-20 02:43:41 +08:00
|
|
|
void test_style()
|
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
xlnt::workbook wb;
|
|
|
|
auto ws = wb.active_sheet();
|
|
|
|
auto cell = ws.cell("A1");
|
2017-04-14 07:01:30 +08:00
|
|
|
|
2017-04-19 06:30:54 +08:00
|
|
|
xlnt_assert(!cell.has_style());
|
2017-04-14 07:01:30 +08:00
|
|
|
|
2016-11-08 10:11:30 +08:00
|
|
|
auto test_style = wb.create_style("test_style");
|
2016-08-18 19:34:18 +08:00
|
|
|
test_style.number_format(xlnt::number_format::date_ddmmyyyy(), true);
|
2017-04-14 07:01:30 +08:00
|
|
|
|
2016-11-08 10:11:30 +08:00
|
|
|
cell.style(test_style);
|
2017-04-19 06:30:54 +08:00
|
|
|
xlnt_assert(cell.has_style());
|
|
|
|
xlnt_assert_equals(cell.style().number_format(), xlnt::number_format::date_ddmmyyyy());
|
|
|
|
xlnt_assert_equals(cell.style(), test_style);
|
2016-06-20 02:43:41 +08:00
|
|
|
|
2016-11-08 10:11:30 +08:00
|
|
|
auto other_style = wb.create_style("other_style");
|
2016-08-18 19:34:18 +08:00
|
|
|
other_style.number_format(xlnt::number_format::date_time2(), true);
|
2017-04-14 07:01:30 +08:00
|
|
|
|
2016-11-08 10:11:30 +08:00
|
|
|
cell.style("other_style");
|
2017-04-19 06:30:54 +08:00
|
|
|
xlnt_assert_equals(cell.style().number_format(), xlnt::number_format::date_time2());
|
|
|
|
xlnt_assert_equals(cell.style(), other_style);
|
2017-04-14 07:01:30 +08:00
|
|
|
|
|
|
|
auto last_style = wb.create_style("last_style");
|
2016-08-18 19:34:18 +08:00
|
|
|
last_style.number_format(xlnt::number_format::percentage(), true);
|
2017-04-14 07:01:30 +08:00
|
|
|
|
2016-11-08 10:11:30 +08:00
|
|
|
cell.style(last_style);
|
2017-04-19 06:30:54 +08:00
|
|
|
xlnt_assert_equals(cell.style().number_format(), xlnt::number_format::percentage());
|
|
|
|
xlnt_assert_equals(cell.style(), last_style);
|
2017-04-14 07:01:30 +08:00
|
|
|
|
2017-04-19 06:30:54 +08:00
|
|
|
xlnt_assert_throws(cell.style("doesn't exist"), xlnt::key_not_found);
|
2017-04-14 07:01:30 +08:00
|
|
|
|
2016-06-20 02:43:41 +08:00
|
|
|
cell.clear_style();
|
2017-04-14 07:01:30 +08:00
|
|
|
|
2017-04-19 06:30:54 +08:00
|
|
|
xlnt_assert(!cell.has_style());
|
|
|
|
xlnt_assert_throws(cell.style(), xlnt::invalid_attribute);
|
2016-06-20 02:43:41 +08:00
|
|
|
}
|
2017-04-14 07:01:30 +08:00
|
|
|
|
2016-06-20 02:43:41 +08:00
|
|
|
void test_print()
|
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
xlnt::workbook wb;
|
|
|
|
auto ws = wb.active_sheet();
|
2016-06-20 02:43:41 +08:00
|
|
|
|
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
auto cell = ws.cell("A1");
|
2016-06-20 02:43:41 +08:00
|
|
|
|
|
|
|
std::stringstream ss;
|
|
|
|
ss << cell;
|
|
|
|
|
|
|
|
auto stream_string = ss.str();
|
|
|
|
|
2017-04-19 06:30:54 +08:00
|
|
|
xlnt_assert_equals(cell.to_string(), stream_string);
|
|
|
|
xlnt_assert_equals(stream_string, "");
|
2016-06-20 02:43:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
auto cell = ws.cell("A2");
|
2016-06-20 02:43:41 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
cell.value(false);
|
2016-06-20 02:43:41 +08:00
|
|
|
|
|
|
|
std::stringstream ss;
|
|
|
|
ss << cell;
|
|
|
|
|
|
|
|
auto stream_string = ss.str();
|
|
|
|
|
2017-04-19 06:30:54 +08:00
|
|
|
xlnt_assert_equals(cell.to_string(), stream_string);
|
|
|
|
xlnt_assert_equals(stream_string, "FALSE");
|
2016-06-20 02:43:41 +08:00
|
|
|
}
|
2017-04-14 07:01:30 +08:00
|
|
|
|
2016-06-20 02:43:41 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
auto cell = ws.cell("A3");
|
2016-06-20 02:43:41 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
cell.value(true);
|
2016-06-20 02:43:41 +08:00
|
|
|
|
|
|
|
std::stringstream ss;
|
|
|
|
ss << cell;
|
|
|
|
|
|
|
|
auto stream_string = ss.str();
|
|
|
|
|
2017-04-19 06:30:54 +08:00
|
|
|
xlnt_assert_equals(cell.to_string(), stream_string);
|
|
|
|
xlnt_assert_equals(stream_string, "TRUE");
|
2016-06-20 02:43:41 +08:00
|
|
|
}
|
2017-04-14 07:01:30 +08:00
|
|
|
|
2016-06-20 02:43:41 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
auto cell = ws.cell("A4");
|
2016-06-20 02:43:41 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
cell.value(1.234);
|
2016-06-20 02:43:41 +08:00
|
|
|
|
|
|
|
std::stringstream ss;
|
|
|
|
ss << cell;
|
|
|
|
|
|
|
|
auto stream_string = ss.str();
|
|
|
|
|
2017-04-19 06:30:54 +08:00
|
|
|
xlnt_assert_equals(cell.to_string(), stream_string);
|
|
|
|
xlnt_assert_equals(stream_string, "1.234");
|
2016-06-20 02:43:41 +08:00
|
|
|
}
|
2017-04-14 07:01:30 +08:00
|
|
|
|
2016-06-20 02:43:41 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
auto cell = ws.cell("A5");
|
2016-06-20 02:43:41 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
cell.error("#REF");
|
2016-06-20 02:43:41 +08:00
|
|
|
|
|
|
|
std::stringstream ss;
|
|
|
|
ss << cell;
|
|
|
|
|
|
|
|
auto stream_string = ss.str();
|
|
|
|
|
2017-04-19 06:30:54 +08:00
|
|
|
xlnt_assert_equals(cell.to_string(), stream_string);
|
|
|
|
xlnt_assert_equals(stream_string, "#REF");
|
2016-06-20 02:43:41 +08:00
|
|
|
}
|
2017-04-14 07:01:30 +08:00
|
|
|
|
2016-06-20 02:43:41 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
auto cell = ws.cell("A6");
|
2016-06-20 02:43:41 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
cell.value("test");
|
2016-06-20 02:43:41 +08:00
|
|
|
|
|
|
|
std::stringstream ss;
|
|
|
|
ss << cell;
|
|
|
|
|
|
|
|
auto stream_string = ss.str();
|
|
|
|
|
2017-04-19 06:30:54 +08:00
|
|
|
xlnt_assert_equals(cell.to_string(), stream_string);
|
|
|
|
xlnt_assert_equals(stream_string, "test");
|
2016-06-20 02:43:41 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void test_values()
|
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
xlnt::workbook wb;
|
|
|
|
auto ws = wb.active_sheet();
|
|
|
|
auto cell = ws.cell("A1");
|
2016-06-20 02:43:41 +08:00
|
|
|
|
2017-03-22 07:38:52 +08:00
|
|
|
cell.value(static_cast<int>(4));
|
2017-04-19 06:30:54 +08:00
|
|
|
xlnt_assert_equals(cell.value<int>(), 4);
|
2016-06-20 02:43:41 +08:00
|
|
|
|
2017-03-22 07:38:52 +08:00
|
|
|
cell.value(static_cast<unsigned int>(3));
|
2017-04-19 06:30:54 +08:00
|
|
|
xlnt_assert_equals(cell.value<unsigned>(), 3);
|
2016-06-20 02:43:41 +08:00
|
|
|
|
2017-03-22 07:38:52 +08:00
|
|
|
cell.value(static_cast<unsigned long long>(4));
|
2017-04-19 06:30:54 +08:00
|
|
|
xlnt_assert_equals(cell.value<unsigned long long>(), 4);
|
2016-06-20 02:43:41 +08:00
|
|
|
|
2017-03-22 07:38:52 +08:00
|
|
|
cell.value(static_cast<long long int>(3));
|
2017-04-19 06:30:54 +08:00
|
|
|
xlnt_assert_equals(cell.value<long long int>(), 3);
|
2016-06-20 02:43:41 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
cell.value(static_cast<float>(3.14));
|
2017-04-19 06:30:54 +08:00
|
|
|
xlnt_assert_delta(cell.value<float>(), 3.14, 0.001);
|
2016-06-20 02:43:41 +08:00
|
|
|
|
2017-09-09 09:05:34 +08:00
|
|
|
cell.value(static_cast<double>(3.141592));
|
|
|
|
xlnt_assert_equals(cell.value<double>(), 3.141592);
|
2016-06-20 02:43:41 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
auto cell2 = ws.cell("A2");
|
2017-07-03 10:15:42 +08:00
|
|
|
cell2.value(std::string(100000, 'a'));
|
2016-12-02 21:37:50 +08:00
|
|
|
cell.value(cell2);
|
2017-07-03 10:15:42 +08:00
|
|
|
xlnt_assert_equals(cell.value<std::string>(), std::string(32767, 'a'));
|
2014-07-20 02:43:48 +08:00
|
|
|
}
|
2016-06-20 02:49:41 +08:00
|
|
|
|
2016-07-19 09:38:16 +08:00
|
|
|
void test_reference()
|
|
|
|
{
|
|
|
|
xlnt::cell_reference_hash hash;
|
2017-04-19 06:30:54 +08:00
|
|
|
xlnt_assert_differs(hash(xlnt::cell_reference("A2")), hash(xlnt::cell_reference(1, 1)));
|
|
|
|
xlnt_assert_equals(hash(xlnt::cell_reference("A2")), hash(xlnt::cell_reference(1, 2)));
|
2016-07-19 09:38:16 +08:00
|
|
|
|
2017-04-19 06:30:54 +08:00
|
|
|
xlnt_assert_equals((xlnt::cell_reference("A1"), xlnt::cell_reference("B2")), xlnt::range_reference("A1:B2"));
|
2016-07-19 09:38:16 +08:00
|
|
|
|
2017-04-19 06:30:54 +08:00
|
|
|
xlnt_assert_throws(xlnt::cell_reference("A1&"), xlnt::invalid_cell_reference);
|
|
|
|
xlnt_assert_throws(xlnt::cell_reference("A"), xlnt::invalid_cell_reference);
|
2016-07-19 09:38:16 +08:00
|
|
|
|
|
|
|
auto ref = xlnt::cell_reference("$B$7");
|
2017-04-19 06:30:54 +08:00
|
|
|
xlnt_assert(ref.row_absolute());
|
|
|
|
xlnt_assert(ref.column_absolute());
|
2016-07-19 09:38:16 +08:00
|
|
|
|
2017-04-19 06:30:54 +08:00
|
|
|
xlnt_assert(xlnt::cell_reference("A1") == "A1");
|
|
|
|
xlnt_assert(xlnt::cell_reference("A1") != "A2");
|
2016-07-19 09:38:16 +08:00
|
|
|
}
|
2016-07-21 08:10:19 +08:00
|
|
|
|
|
|
|
void test_anchor()
|
|
|
|
{
|
|
|
|
xlnt::workbook wb;
|
2017-04-14 07:01:30 +08:00
|
|
|
auto cell = wb.active_sheet().cell("A1");
|
2016-12-02 21:37:50 +08:00
|
|
|
auto anchor = cell.anchor();
|
2017-04-19 06:30:54 +08:00
|
|
|
xlnt_assert_equals(anchor.first, 0);
|
|
|
|
xlnt_assert_equals(anchor.second, 0);
|
2016-07-21 08:10:19 +08:00
|
|
|
}
|
2016-07-24 07:15:17 +08:00
|
|
|
|
|
|
|
void test_hyperlink()
|
|
|
|
{
|
|
|
|
xlnt::workbook wb;
|
2017-04-14 07:01:30 +08:00
|
|
|
auto cell = wb.active_sheet().cell("A1");
|
2017-04-19 06:30:54 +08:00
|
|
|
xlnt_assert(!cell.has_hyperlink());
|
|
|
|
xlnt_assert_throws(cell.hyperlink(), xlnt::invalid_attribute);
|
|
|
|
xlnt_assert_throws(cell.hyperlink("notaurl"), xlnt::invalid_parameter);
|
|
|
|
xlnt_assert_throws(cell.hyperlink(""), xlnt::invalid_parameter);
|
2016-12-02 21:37:50 +08:00
|
|
|
cell.hyperlink("http://example.com");
|
2017-04-19 06:30:54 +08:00
|
|
|
xlnt_assert(cell.has_hyperlink());
|
2018-03-17 09:21:16 +08:00
|
|
|
xlnt_assert_equals(cell.hyperlink().relationship().target().to_string(), "http://example.com");
|
2016-07-24 07:15:17 +08:00
|
|
|
}
|
2016-10-29 22:23:04 +08:00
|
|
|
|
|
|
|
void test_comment()
|
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
xlnt::workbook wb;
|
|
|
|
auto ws = wb.active_sheet();
|
|
|
|
auto cell = ws.cell("A1");
|
2017-04-19 06:30:54 +08:00
|
|
|
xlnt_assert(!cell.has_comment());
|
|
|
|
xlnt_assert_throws(cell.comment(), xlnt::exception);
|
2016-12-02 21:37:50 +08:00
|
|
|
cell.comment(xlnt::comment("comment", "author"));
|
2017-04-19 06:30:54 +08:00
|
|
|
xlnt_assert(cell.has_comment());
|
|
|
|
xlnt_assert_equals(cell.comment(), xlnt::comment("comment", "author"));
|
2016-12-02 21:37:50 +08:00
|
|
|
cell.clear_comment();
|
2017-04-19 06:30:54 +08:00
|
|
|
xlnt_assert(!cell.has_comment());
|
|
|
|
xlnt_assert_throws(cell.comment(), xlnt::exception);
|
2016-10-29 22:23:04 +08:00
|
|
|
}
|
2014-05-09 03:32:12 +08:00
|
|
|
};
|
2018-07-05 16:47:24 +08:00
|
|
|
|
|
|
|
static cell_test_suite x{};
|