xlnt/tests/test_worksheet.hpp

406 lines
15 KiB
C++
Raw Normal View History

2014-05-09 03:32:12 +08:00
#pragma once
#include <iostream>
#include <cxxtest/TestSuite.h>
2014-05-14 02:40:28 +08:00
#include "pugixml.hpp"
2014-06-06 04:19:31 +08:00
#include <xlnt/xlnt.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()
{
2014-05-14 02:40:28 +08:00
xlnt::worksheet ws = wb.create_sheet();
TS_ASSERT(wb == ws.get_parent());
2014-05-09 03:32:12 +08:00
}
void test_new_sheet_name()
{
2014-05-14 02:40:28 +08:00
xlnt::workbook wb;
wb.remove_sheet(wb.get_active_sheet());
xlnt::worksheet ws = wb.create_sheet();
TS_ASSERT_EQUALS(ws.to_string(), "<Worksheet \"Sheet1\">");
2014-05-09 03:32:12 +08:00
}
void test_get_cell()
{
2014-05-14 02:40:28 +08:00
xlnt::worksheet ws(wb);
2014-05-21 22:20:30 +08:00
auto cell = ws.get_cell("A1");
TS_ASSERT_EQUALS(cell.get_reference().to_string(), "A1");
2014-05-09 03:32:12 +08:00
}
void test_set_bad_title()
{
2014-05-13 07:59:33 +08:00
std::string title(50, 'X');
2014-06-06 04:19:31 +08:00
TS_ASSERT_THROWS(wb.create_sheet(title), xlnt::sheet_title_exception);
2014-05-09 03:32:12 +08:00
}
void test_set_bad_title_character()
{
2014-06-06 04:19:31 +08:00
TS_ASSERT_THROWS(wb.create_sheet("["), xlnt::sheet_title_exception);
TS_ASSERT_THROWS(wb.create_sheet("]"), xlnt::sheet_title_exception);
TS_ASSERT_THROWS(wb.create_sheet("*"), xlnt::sheet_title_exception);
TS_ASSERT_THROWS(wb.create_sheet(":"), xlnt::sheet_title_exception);
TS_ASSERT_THROWS(wb.create_sheet("?"), xlnt::sheet_title_exception);
TS_ASSERT_THROWS(wb.create_sheet("/"), xlnt::sheet_title_exception);
TS_ASSERT_THROWS(wb.create_sheet("\\"), xlnt::sheet_title_exception);
2014-05-09 03:32:12 +08:00
}
void test_worksheet_dimension()
{
2014-05-14 02:40:28 +08:00
xlnt::worksheet ws(wb);
2014-05-21 22:20:30 +08:00
ws.get_cell("A1") = "AAA";
TS_ASSERT_EQUALS("A1", ws.calculate_dimension().to_string());
ws.get_cell("B12") = "AAA";
TS_ASSERT_EQUALS("A1:B12", ws.calculate_dimension().to_string());
2014-05-09 03:32:12 +08:00
}
void test_worksheet_range()
{
2014-05-14 02:40:28 +08:00
xlnt::worksheet ws(wb);
2014-05-21 22:20:30 +08:00
auto xlrange = ws.get_range("A1:C4");
2014-05-22 05:48:51 +08:00
TS_ASSERT_EQUALS(4, xlrange.num_rows());
TS_ASSERT_EQUALS(3, xlrange[0].num_cells());
2014-05-09 03:32:12 +08:00
}
void test_worksheet_named_range()
{
2014-05-14 02:40:28 +08:00
xlnt::worksheet ws(wb);
2014-05-13 01:42:28 +08:00
wb.create_named_range("test_range", ws, "C5");
2014-05-21 22:20:30 +08:00
auto xlrange = ws.get_named_range("test_range");
2014-05-22 05:48:51 +08:00
TS_ASSERT_EQUALS(1, xlrange.num_rows());
TS_ASSERT_EQUALS(1, xlrange[0].num_cells());
2014-05-14 02:40:28 +08:00
TS_ASSERT_EQUALS(5, xlrange[0][0].get_row());
2014-05-09 03:32:12 +08:00
}
void test_bad_named_range()
{
2014-05-14 02:40:28 +08:00
xlnt::worksheet ws(wb);
2014-05-21 22:20:30 +08:00
TS_ASSERT_THROWS_ANYTHING(ws.get_range("bad_range"));
2014-05-09 03:32:12 +08:00
}
void test_named_range_wrong_sheet()
{
2014-05-14 02:40:28 +08:00
xlnt::worksheet ws1(wb);
xlnt::worksheet ws2(wb);
2014-05-13 01:42:28 +08:00
wb.create_named_range("wrong_sheet_range", ws1, "C5");
2014-05-21 22:20:30 +08:00
TS_ASSERT_THROWS_ANYTHING(ws2.get_named_range("wrong_sheet_range"));
2014-05-09 03:32:12 +08:00
}
void test_cell_offset()
{
2014-05-14 02:40:28 +08:00
xlnt::worksheet ws(wb);
TS_ASSERT_EQUALS("C17", ws.get_cell(xlnt::cell_reference("B15").make_offset(1, 2)).get_reference().to_string());
2014-05-09 03:32:12 +08:00
}
void test_range_offset()
{
2014-05-14 02:40:28 +08:00
xlnt::worksheet ws(wb);
2014-05-21 22:20:30 +08:00
auto xlrange = ws.get_range(xlnt::range_reference("A1:C4").make_offset(3, 1));
2014-05-22 05:48:51 +08:00
TS_ASSERT_EQUALS(4, xlrange.num_rows());
TS_ASSERT_EQUALS(3, xlrange[0].num_cells());
2014-05-21 22:20:30 +08:00
TS_ASSERT_EQUALS("D2", xlrange[0][0].get_reference().to_string());
2014-05-09 03:32:12 +08:00
}
void test_cell_alternate_coordinates()
{
2014-05-14 02:40:28 +08:00
xlnt::worksheet ws(wb);
2014-05-21 22:20:30 +08:00
auto cell = ws.get_cell(xlnt::cell_reference(4, 8));
TS_ASSERT_EQUALS("E9", cell.get_reference().to_string());
2014-05-09 03:32:12 +08:00
}
void test_cell_range_name()
{
2014-05-14 02:40:28 +08:00
xlnt::worksheet ws(wb);
2014-05-13 01:42:28 +08:00
wb.create_named_range("test_range_single", ws, "B12");
2014-05-31 06:42:25 +08:00
TS_ASSERT_THROWS(ws.get_cell("test_range_single"), xlnt::cell_coordinates_exception);
2014-05-21 22:20:30 +08:00
auto c_range_name = ws.get_named_range("test_range_single");
auto c_range_coord = ws.get_range("B12");
auto c_cell = ws.get_cell("B12");
2014-05-13 01:42:28 +08:00
TS_ASSERT_EQUALS(c_range_coord, c_range_name);
TS_ASSERT(c_range_coord[0][0] == c_cell);
2014-05-09 03:32:12 +08:00
}
void test_garbage_collect()
{
2014-05-14 02:40:28 +08:00
xlnt::worksheet ws(wb);
2014-05-21 22:20:30 +08:00
ws.get_cell("A1") = "";
ws.get_cell("B2") = "0";
ws.get_cell("C4") = 0;
2014-05-14 02:40:28 +08:00
2014-05-13 01:42:28 +08:00
ws.garbage_collect();
2014-05-14 02:40:28 +08:00
2014-05-21 22:20:30 +08:00
std::list<xlnt::cell> comparison_cells = {ws.get_cell("B2"), ws.get_cell("C4")};
2014-05-14 02:40:28 +08:00
for(auto cell : ws.get_cell_collection())
2014-05-13 01:42:28 +08:00
{
2014-05-14 02:40:28 +08:00
auto match = std::find(comparison_cells.begin(), comparison_cells.end(), cell);
TS_ASSERT_DIFFERS(match, comparison_cells.end());
comparison_cells.erase(match);
2014-05-13 01:42:28 +08:00
}
2014-05-15 06:31:48 +08:00
TS_ASSERT(comparison_cells.empty());
2014-05-09 03:32:12 +08:00
}
void test_hyperlink_relationships()
{
2014-05-14 02:40:28 +08:00
xlnt::worksheet ws(wb);
TS_SKIP("test_hyperlink_relationships");
2014-05-14 02:40:28 +08:00
TS_ASSERT_EQUALS(ws.get_relationships().size(), 0);
2014-05-21 22:20:30 +08:00
ws.get_cell("A1").set_hyperlink("http:test.com");
2014-05-14 02:40:28 +08:00
TS_ASSERT_EQUALS(ws.get_relationships().size(), 1);
2014-05-31 06:42:25 +08:00
TS_ASSERT_EQUALS("rId1", ws.get_cell("A1").get_hyperlink());
2014-05-14 02:40:28 +08:00
TS_ASSERT_EQUALS("rId1", ws.get_relationships()[0].get_id());
TS_ASSERT_EQUALS("http:test.com", ws.get_relationships()[0].get_target_uri());
2014-05-15 06:31:48 +08:00
TS_ASSERT_EQUALS(xlnt::target_mode::external, ws.get_relationships()[0].get_target_mode());
2014-05-14 02:40:28 +08:00
2014-05-21 22:20:30 +08:00
ws.get_cell("A2").set_hyperlink("http:test2.com");
2014-05-14 02:40:28 +08:00
TS_ASSERT_EQUALS(ws.get_relationships().size(), 2);
2014-05-31 06:42:25 +08:00
TS_ASSERT_EQUALS("rId2", ws.get_cell("A2").get_hyperlink());
2014-05-14 02:40:28 +08:00
TS_ASSERT_EQUALS("rId2", ws.get_relationships()[1].get_id());
TS_ASSERT_EQUALS("http:test2.com", ws.get_relationships()[1].get_target_uri());
2014-05-15 06:31:48 +08:00
TS_ASSERT_EQUALS(xlnt::target_mode::external, ws.get_relationships()[1].get_target_mode());
2014-05-09 03:32:12 +08:00
}
void test_bad_relationship_type()
{
2014-05-14 02:40:28 +08:00
xlnt::relationship rel("bad_type");
2014-05-09 03:32:12 +08:00
}
void test_append_list()
{
2014-05-14 02:40:28 +08:00
xlnt::worksheet ws(wb);
2014-05-09 03:32:12 +08:00
2014-05-14 02:40:28 +08:00
ws.append(std::vector<std::string> {"This is A1", "This is B1"});
2014-05-09 03:32:12 +08:00
2014-05-21 22:20:30 +08:00
TS_ASSERT_EQUALS("This is A1", ws.get_cell("A1"));
TS_ASSERT_EQUALS("This is B1", ws.get_cell("B1"));
2014-05-09 03:32:12 +08:00
}
void test_append_dict_letter()
{
2014-05-14 02:40:28 +08:00
xlnt::worksheet ws(wb);
2014-05-09 03:32:12 +08:00
2014-05-14 02:40:28 +08:00
ws.append(std::unordered_map<std::string, std::string> {{"A", "This is A1"}, {"C", "This is C1"}});
2014-05-09 03:32:12 +08:00
2014-05-21 22:20:30 +08:00
TS_ASSERT_EQUALS("This is A1", ws.get_cell("A1"));
TS_ASSERT_EQUALS("This is C1", ws.get_cell("C1"));
2014-05-09 03:32:12 +08:00
}
void test_append_dict_index()
{
2014-05-14 02:40:28 +08:00
xlnt::worksheet ws(wb);
2014-05-09 03:32:12 +08:00
2014-05-14 02:40:28 +08:00
ws.append(std::unordered_map<int, std::string> {{0, "This is A1"}, {2, "This is C1"}});
2014-05-09 03:32:12 +08:00
2014-05-21 22:20:30 +08:00
TS_ASSERT_EQUALS("This is A1", ws.get_cell("A1"));
TS_ASSERT_EQUALS("This is C1", ws.get_cell("C1"));
2014-05-09 03:32:12 +08:00
}
void test_append_2d_list()
{
2014-05-14 02:40:28 +08:00
xlnt::worksheet ws(wb);
2014-05-09 03:32:12 +08:00
2014-05-14 02:40:28 +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"});
2014-05-09 03:32:12 +08:00
2014-05-21 22:20:30 +08:00
auto vals = ws.get_range("A1:B2");
2014-05-09 03:32:12 +08:00
2014-05-14 02:40:28 +08:00
TS_ASSERT_EQUALS(vals[0][0], "This is A1");
TS_ASSERT_EQUALS(vals[0][1], "This is B1");
TS_ASSERT_EQUALS(vals[1][0], "This is A2");
TS_ASSERT_EQUALS(vals[1][1], "This is B2");
2014-05-09 03:32:12 +08:00
}
void test_rows()
{
2014-05-14 02:40:28 +08:00
xlnt::worksheet ws(wb);
2014-05-09 03:32:12 +08:00
2014-05-21 22:20:30 +08:00
ws.get_cell("A1") = "first";
ws.get_cell("C9") = "last";
2014-05-09 03:32:12 +08:00
2014-05-14 02:40:28 +08:00
auto rows = ws.rows();
2014-05-09 03:32:12 +08:00
2014-05-22 05:48:51 +08:00
TS_ASSERT_EQUALS(rows.num_rows(), 9);
2014-05-09 03:32:12 +08:00
2014-05-14 02:40:28 +08:00
TS_ASSERT_EQUALS(rows[0][0], "first");
TS_ASSERT_EQUALS(rows[8][2], "last");
2014-05-09 03:32:12 +08:00
}
void test_auto_filter()
{
2014-05-14 02:40:28 +08:00
xlnt::worksheet ws(wb);
2014-06-05 06:42:17 +08:00
ws.auto_filter(ws.get_range("a1:f1"));
2014-05-20 08:47:15 +08:00
TS_ASSERT_EQUALS(ws.get_auto_filter(), "A1:F1");
2014-05-09 03:32:12 +08:00
2014-05-19 09:29:19 +08:00
ws.unset_auto_filter();
TS_ASSERT_EQUALS(ws.has_auto_filter(), false);
2014-05-09 03:32:12 +08:00
2014-06-05 06:42:17 +08:00
ws.auto_filter("c1:g9");
2014-05-19 09:29:19 +08:00
TS_ASSERT_EQUALS(ws.get_auto_filter(), "C1:G9");
2014-05-09 03:32:12 +08:00
}
void test_page_margins()
{
2014-05-14 02:40:28 +08:00
xlnt::worksheet ws(wb);
2014-05-19 09:29:19 +08:00
ws.get_page_margins().set_left(2.0);
2014-05-14 02:40:28 +08:00
ws.get_page_margins().set_right(2.0);
ws.get_page_margins().set_top(2.0);
ws.get_page_margins().set_bottom(2.0);
ws.get_page_margins().set_header(1.5);
2014-05-19 09:29:19 +08:00
ws.get_page_margins().set_footer(1.5);
auto xml_string = xlnt::writer::write_worksheet(ws);
pugi::xml_document doc;
doc.load(xml_string.c_str());
auto page_margins_node = doc.child("worksheet").child("pageMargins");
TS_ASSERT_DIFFERS(page_margins_node.attribute("left"), nullptr);
TS_ASSERT_EQUALS(page_margins_node.attribute("left").as_double(), 2.0);
TS_ASSERT_DIFFERS(page_margins_node.attribute("right"), nullptr);
TS_ASSERT_EQUALS(page_margins_node.attribute("right").as_double(), 2.0);
TS_ASSERT_DIFFERS(page_margins_node.attribute("top"), nullptr);
TS_ASSERT_EQUALS(page_margins_node.attribute("top").as_double(), 2.0);
TS_ASSERT_DIFFERS(page_margins_node.attribute("bottom"), nullptr);
TS_ASSERT_EQUALS(page_margins_node.attribute("bottom").as_double(), 2.0);
TS_ASSERT_DIFFERS(page_margins_node.attribute("header"), nullptr);
TS_ASSERT_EQUALS(page_margins_node.attribute("header").as_double(), 1.5);
TS_ASSERT_DIFFERS(page_margins_node.attribute("footer"), nullptr);
TS_ASSERT_EQUALS(page_margins_node.attribute("footer").as_double(), 1.5);
2014-05-14 02:40:28 +08:00
xlnt::worksheet ws2(wb);
2014-05-19 09:29:19 +08:00
xml_string = xlnt::writer::write_worksheet(ws2);
doc.load(xml_string.c_str());
TS_ASSERT_EQUALS(doc.child("worksheet").child("pageMargins"), nullptr);
2014-05-09 03:32:12 +08:00
}
void test_merge()
{
2014-05-14 02:40:28 +08:00
xlnt::worksheet ws(wb);
2014-05-20 08:47:15 +08:00
std::vector<std::string> string_table = {"Cell A1", "Cell B1"};
2014-05-13 01:42:28 +08:00
2014-05-21 22:20:30 +08:00
ws.get_cell("A1") = "Cell A1";
ws.get_cell("B1") = "Cell B1";
2014-05-19 09:29:19 +08:00
auto xml_string = xlnt::writer::write_worksheet(ws, string_table);
pugi::xml_document doc;
doc.load(xml_string.c_str());
2014-05-20 08:47:15 +08:00
auto sheet_data_node = doc.child("worksheet").child("sheetData");
auto row_node = sheet_data_node.find_child_by_attribute("row", "r", "1");
auto cell_node = row_node.find_child_by_attribute("c", "r", "A1");
2014-05-19 09:29:19 +08:00
TS_ASSERT_DIFFERS(cell_node, nullptr);
TS_ASSERT_DIFFERS(cell_node.attribute("r"), nullptr);
2014-05-20 08:47:15 +08:00
TS_ASSERT_EQUALS(std::string(cell_node.attribute("r").as_string()), "A1");
2014-05-19 09:29:19 +08:00
TS_ASSERT_DIFFERS(cell_node.attribute("t"), nullptr);
2014-05-20 08:47:15 +08:00
TS_ASSERT_EQUALS(std::string(cell_node.attribute("t").as_string()), "s");
2014-05-19 09:29:19 +08:00
TS_ASSERT_DIFFERS(cell_node.child("v"), nullptr);
2014-05-20 08:47:15 +08:00
TS_ASSERT_EQUALS(std::string(cell_node.child("v").text().as_string()), "0");
cell_node = row_node.find_child_by_attribute("c", "r", "B1");
TS_ASSERT_DIFFERS(cell_node, nullptr);
TS_ASSERT_DIFFERS(cell_node.attribute("r"), nullptr);
TS_ASSERT_EQUALS(std::string(cell_node.attribute("r").as_string()), "B1");
TS_ASSERT_DIFFERS(cell_node.attribute("t"), nullptr);
TS_ASSERT_EQUALS(std::string(cell_node.attribute("t").as_string()), "s");
TS_ASSERT_DIFFERS(cell_node.child("v"), nullptr);
TS_ASSERT_EQUALS(std::string(cell_node.child("v").text().as_string()), "1");
2014-05-13 01:42:28 +08:00
ws.merge_cells("A1:B1");
2014-05-19 09:29:19 +08:00
xml_string = xlnt::writer::write_worksheet(ws, string_table);
doc.load(xml_string.c_str());
2014-05-20 08:47:15 +08:00
sheet_data_node = doc.child("worksheet").child("sheetData");
row_node = sheet_data_node.find_child_by_attribute("row", "r", "1");
cell_node = row_node.find_child_by_attribute("c", "r", "A1");
TS_ASSERT_DIFFERS(cell_node, nullptr);
TS_ASSERT_DIFFERS(cell_node.attribute("r"), nullptr);
TS_ASSERT_EQUALS(std::string(cell_node.attribute("r").as_string()), "A1");
TS_ASSERT_DIFFERS(cell_node.attribute("t"), nullptr);
TS_ASSERT_EQUALS(std::string(cell_node.attribute("t").as_string()), "s");
TS_ASSERT_DIFFERS(cell_node.child("v"), nullptr);
TS_ASSERT_EQUALS(std::string(cell_node.child("v").text().as_string()), "0");
cell_node = row_node.find_child_by_attribute("c", "r", "B1");
TS_ASSERT_DIFFERS(cell_node, nullptr);
TS_ASSERT_EQUALS(cell_node.child("v"), nullptr);
2014-05-19 09:29:19 +08:00
auto merge_node = doc.child("worksheet").child("mergeCells").child("mergeCell");
2014-05-20 08:47:15 +08:00
TS_ASSERT_DIFFERS(merge_node, nullptr);
2014-05-19 09:29:19 +08:00
TS_ASSERT_EQUALS(std::string(merge_node.attribute("ref").as_string()), "A1:B1");
2014-05-13 01:42:28 +08:00
ws.unmerge_cells("A1:B1");
2014-05-19 09:29:19 +08:00
xml_string = xlnt::writer::write_worksheet(ws, string_table);
doc.load(xml_string.c_str());
2014-05-20 08:47:15 +08:00
sheet_data_node = doc.child("worksheet").child("sheetData");
row_node = sheet_data_node.find_child_by_attribute("row", "r", "1");
cell_node = row_node.find_child_by_attribute("c", "r", "A1");
TS_ASSERT_DIFFERS(cell_node, nullptr);
TS_ASSERT_DIFFERS(cell_node.attribute("r"), nullptr);
TS_ASSERT_EQUALS(std::string(cell_node.attribute("r").as_string()), "A1");
TS_ASSERT_DIFFERS(cell_node.attribute("t"), nullptr);
TS_ASSERT_EQUALS(std::string(cell_node.attribute("t").as_string()), "s");
TS_ASSERT_DIFFERS(cell_node.child("v"), nullptr);
TS_ASSERT_EQUALS(std::string(cell_node.child("v").text().as_string()), "0");
cell_node = row_node.find_child_by_attribute("c", "r", "B1");
TS_ASSERT_EQUALS(cell_node, nullptr);
2014-05-19 09:29:19 +08:00
merge_node = doc.child("worksheet").child("mergeCells").child("mergeCell");
TS_ASSERT_EQUALS(merge_node, nullptr);
2014-05-09 03:32:12 +08:00
}
void test_freeze()
{
2014-05-14 02:40:28 +08:00
xlnt::worksheet ws(wb);
2014-05-09 03:32:12 +08:00
2014-05-21 22:20:30 +08:00
ws.freeze_panes(ws.get_cell("b2"));
TS_ASSERT_EQUALS(ws.get_frozen_panes().to_string(), "B2");
2014-05-09 03:32:12 +08:00
2014-05-14 02:40:28 +08:00
ws.unfreeze_panes();
2014-05-21 22:20:30 +08:00
TS_ASSERT(!ws.has_frozen_panes());
2014-05-09 03:32:12 +08:00
2014-05-21 22:20:30 +08:00
ws.freeze_panes("c5");
TS_ASSERT_EQUALS(ws.get_frozen_panes().to_string(), "C5");
2014-05-14 02:40:28 +08:00
2014-05-21 22:20:30 +08:00
ws.freeze_panes(ws.get_cell("A1"));
TS_ASSERT(!ws.has_frozen_panes());
2014-05-09 03:32:12 +08:00
}
void test_printer_settings()
{
2014-05-14 02:40:28 +08:00
xlnt::worksheet ws(wb);
2014-05-20 08:47:15 +08:00
ws.get_page_setup().set_orientation(xlnt::page_setup::orientation::landscape);
2014-05-21 22:20:30 +08:00
ws.get_page_setup().set_paper_size(xlnt::page_setup::paper_size::tabloid);
2014-05-20 08:47:15 +08:00
ws.get_page_setup().set_fit_to_page(true);
ws.get_page_setup().set_fit_to_height(false);
ws.get_page_setup().set_fit_to_width(true);
2014-05-19 09:29:19 +08:00
auto xml_string = xlnt::writer::write_worksheet(ws);
2014-05-20 08:47:15 +08:00
2014-05-19 09:29:19 +08:00
pugi::xml_document doc;
doc.load(xml_string.c_str());
2014-05-20 08:47:15 +08:00
2014-05-19 09:29:19 +08:00
auto page_setup_node = doc.child("worksheet").child("pageSetup");
TS_ASSERT_DIFFERS(page_setup_node, nullptr);
TS_ASSERT_DIFFERS(page_setup_node.attribute("orientation"), nullptr);
2014-05-20 08:47:15 +08:00
TS_ASSERT_EQUALS(std::string(page_setup_node.attribute("orientation").as_string()), "landscape");
2014-05-19 09:29:19 +08:00
TS_ASSERT_DIFFERS(page_setup_node.attribute("paperSize"), nullptr);
2014-05-20 08:47:15 +08:00
TS_ASSERT_EQUALS(page_setup_node.attribute("paperSize").as_int(), 3);
2014-05-19 09:29:19 +08:00
TS_ASSERT_DIFFERS(page_setup_node.attribute("fitToHeight"), nullptr);
2014-05-20 08:47:15 +08:00
TS_ASSERT_EQUALS(page_setup_node.attribute("fitToHeight").as_int(), 0);
2014-05-19 09:29:19 +08:00
TS_ASSERT_DIFFERS(page_setup_node.attribute("fitToWidth"), nullptr);
2014-05-20 08:47:15 +08:00
TS_ASSERT_EQUALS(page_setup_node.attribute("fitToWidth").as_int(), 1);
2014-05-19 09:29:19 +08:00
TS_ASSERT_DIFFERS(doc.child("worksheet").child("pageSetUpPr").attribute("fitToPage"), nullptr);
2014-05-20 08:47:15 +08:00
TS_ASSERT_EQUALS(doc.child("worksheet").child("pageSetUpPr").attribute("fitToPage").as_int(), 1);
2014-05-14 02:40:28 +08:00
xlnt::worksheet ws2(wb);
2014-05-19 09:29:19 +08:00
xml_string = xlnt::writer::write_worksheet(ws2);
doc.load(xml_string.c_str());
TS_ASSERT_EQUALS(doc.child("worksheet").child("pageSetup"), nullptr);
TS_ASSERT_EQUALS(doc.child("worksheet").child("pageSetUpPr"), nullptr);
2014-05-09 03:32:12 +08:00
}
2014-05-14 02:40:28 +08:00
private:
xlnt::workbook wb;
2014-05-09 03:32:12 +08:00
};