fix some things

This commit is contained in:
Thomas Fussell 2014-06-10 00:29:49 -04:00
parent b2ddc13a95
commit 05e2bf251b
10 changed files with 165 additions and 68 deletions

View File

@ -17,7 +17,7 @@ project "xlnt.test"
"$(cxxtest_prefix)" "$(cxxtest_prefix)"
} }
files { files {
"../tests/*.h", "../tests/*.hpp",
"../tests/runner-autogen.cpp" "../tests/runner-autogen.cpp"
} }
links { links {
@ -25,7 +25,7 @@ project "xlnt.test"
"xlnt", "xlnt",
"zlib" "zlib"
} }
prebuildcommands { "cxxtestgen --runner=ErrorPrinter -o ../../tests/runner-autogen.cpp ../../tests/*.h" } prebuildcommands { "/usr/local/Cellar/cxxtest/4.3/bin/cxxtestgen --runner=ErrorPrinter -o /Users/thomas/Development/xlnt/tests/runner-autogen.cpp /Users/thomas/Development/xlnt/tests/*.hpp" }
flags { flags {
"Unicode", "Unicode",
"NoEditAndContinue", "NoEditAndContinue",
@ -60,8 +60,9 @@ project "xlnt"
"../third-party/zlib/contrib/minizip" "../third-party/zlib/contrib/minizip"
} }
files { files {
"../source/*.cpp", "../source/**.cpp",
"../include/xlnt/*.h" "../source/**.hpp",
"../include/xlnt/**.hpp"
} }
flags { flags {
"Unicode", "Unicode",

View File

@ -102,7 +102,7 @@ public:
page_break get_break() const { return break_; } page_break get_break() const { return break_; }
void set_break(page_break b) { default_ = false; break_ = b; } void set_break(page_break b) { default_ = false; break_ = b; }
sheet_state get_sheet_state() const { return sheet_state_; } sheet_state get_sheet_state() const { return sheet_state_; }
void set_sheet_state(sheet_state sheet_state) { default_ = false; sheet_state_ = sheet_state; } void set_sheet_state(sheet_state sheet_state) { sheet_state_ = sheet_state; }
paper_size get_paper_size() const { return paper_size_; } paper_size get_paper_size() const { return paper_size_; }
void set_paper_size(paper_size paper_size) { default_ = false; paper_size_ = paper_size; } void set_paper_size(paper_size paper_size) { default_ = false; paper_size_ = paper_size; }
orientation get_orientation() const { return orientation_; } orientation get_orientation() const { return orientation_; }

View File

@ -40,10 +40,10 @@ public:
static std::string write_worksheet(worksheet ws, const std::vector<std::string> &string_table, const std::unordered_map<std::size_t, std::string> &style_table); static std::string write_worksheet(worksheet ws, const std::vector<std::string> &string_table, const std::unordered_map<std::size_t, std::string> &style_table);
static std::string write_theme(); static std::string write_theme();
static std::string write_content_types(const std::pair<std::unordered_map<std::string, std::string>, std::unordered_map<std::string, std::string>> &content_types); static std::string write_content_types(const std::pair<std::unordered_map<std::string, std::string>, std::unordered_map<std::string, std::string>> &content_types);
static std::string write_relationships(const std::unordered_map<std::string, std::pair<std::string, std::string>> &relationships); static std::string write_relationships(const std::vector<std::pair<std::string, std::pair<std::string, std::string>>> &relationships);
static std::string write_workbook_rels(const workbook &wb); static std::string write_workbook_rels(const workbook &wb);
static std::string write_worksheet_rels(worksheet ws, int n); static std::string write_worksheet_rels(worksheet ws, int n);
static std::string write_string_table(const std::unordered_map<std::string, int> &string_table); static std::string write_string_table(const std::vector<std::string> &string_table);
}; };
} // namespace xlnt } // namespace xlnt

View File

@ -52,7 +52,7 @@ std::string cell::get_value() const
case type::string: case type::string:
return d_->string_value; return d_->string_value;
case type::numeric: case type::numeric:
return std::to_string(d_->numeric_value); return std::floor(d_->numeric_value) == d_->numeric_value ? std::to_string((int)d_->numeric_value) : std::to_string(d_->numeric_value);
case type::formula: case type::formula:
return d_->string_value; return d_->string_value;
case type::error: case type::error:
@ -60,7 +60,7 @@ std::string cell::get_value() const
case type::null: case type::null:
return ""; return "";
case type::boolean: case type::boolean:
return d_->numeric_value != 0 ? "TRUE" : "FALSE"; return d_->numeric_value != 0 ? "1" : "0";
default: default:
throw std::runtime_error("bad enum"); throw std::runtime_error("bad enum");
} }

View File

@ -15,6 +15,12 @@ struct worksheet_impl
worksheet_impl(workbook *parent_workbook, const std::string &title) worksheet_impl(workbook *parent_workbook, const std::string &title)
: parent_(parent_workbook), title_(title), freeze_panes_("A1") : parent_(parent_workbook), title_(title), freeze_panes_("A1")
{ {
page_margins_.set_left(0.75);
page_margins_.set_right(0.75);
page_margins_.set_top(1);
page_margins_.set_bottom(1);
page_margins_.set_header(0.5);
page_margins_.set_footer(0.5);
} }
worksheet_impl(const worksheet_impl &other) worksheet_impl(const worksheet_impl &other)

View File

@ -74,10 +74,6 @@ bool range_reference::is_single_cell() const
std::string range_reference::to_string() const std::string range_reference::to_string() const
{ {
if(is_single_cell())
{
return top_left_.to_string();
}
return top_left_.to_string() + ":" + bottom_right_.to_string(); return top_left_.to_string() + ":" + bottom_right_.to_string();
} }

View File

@ -28,7 +28,7 @@ workbook::workbook(optimization optimize) : d_(new detail::workbook_impl(optimiz
{ {
if(!d_->optimized_read_) if(!d_->optimized_read_)
{ {
create_sheet("Sheet1"); create_sheet("Sheet");
} }
} }
@ -149,7 +149,10 @@ worksheet workbook::create_sheet()
} }
d_->worksheets_.emplace_back(this, title); d_->worksheets_.emplace_back(this, title);
return worksheet(&d_->worksheets_.back()); worksheet ws(&d_->worksheets_.back());
ws.get_cell("A1");
return ws;
} }
void workbook::add_sheet(xlnt::worksheet worksheet) void workbook::add_sheet(xlnt::worksheet worksheet)
@ -421,7 +424,7 @@ bool workbook::save(const std::string &filename)
f.set_file_contents("[Content_Types].xml", writer::write_content_types(content_types)); f.set_file_contents("[Content_Types].xml", writer::write_content_types(content_types));
std::unordered_map<std::string, std::pair<std::string, std::string>> root_rels = std::vector<std::pair<std::string, std::pair<std::string, std::string>>> root_rels =
{ {
{"rId3", {"http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties", "docProps/app.xml"}}, {"rId3", {"http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties", "docProps/app.xml"}},
{"rId2", {"http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties", "docProps/core.xml"}}, {"rId2", {"http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties", "docProps/core.xml"}},
@ -429,7 +432,7 @@ bool workbook::save(const std::string &filename)
}; };
f.set_file_contents("_rels/.rels", writer::write_relationships(root_rels)); f.set_file_contents("_rels/.rels", writer::write_relationships(root_rels));
std::unordered_map<std::string, std::pair<std::string, std::string>> workbook_rels = std::vector<std::pair<std::string, std::pair<std::string, std::string>>> workbook_rels =
{ {
{"rId1", {"http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet", "worksheets/sheet1.xml"}}, {"rId1", {"http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet", "worksheets/sheet1.xml"}},
{"rId2", {"http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles", "styles.xml"}}, {"rId2", {"http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles", "styles.xml"}},

View File

@ -11,17 +11,39 @@
#include "worksheet/range.hpp" #include "worksheet/range.hpp"
#include "worksheet/range_reference.hpp" #include "worksheet/range_reference.hpp"
#include "worksheet/worksheet.hpp" #include "worksheet/worksheet.hpp"
#include "workbook/workbook.hpp"
namespace xlnt { namespace xlnt {
std::string writer::write_string_table(const std::unordered_map<std::string, int> &/*string_table*/) std::string writer::write_string_table(const std::vector<std::string> &string_table)
{ {
return ""; pugi::xml_document doc;
auto root_node = doc.append_child("sst");
root_node.append_attribute("xmlns").set_value("http://schemas.openxmlformats.org/spreadsheetml/2006/main");
root_node.append_attribute("uniqueCount").set_value((int)string_table.size());
for(auto string : string_table)
{
root_node.append_child("si").append_child("t").text().set(string.c_str());
}
std::stringstream ss;
doc.save(ss);
return ss.str();
} }
std::string writer::write_workbook_rels(const workbook &/*wb*/) std::string writer::write_workbook_rels(const workbook &/*wb*/)
{ {
return ""; static const std::vector<std::pair<std::string, std::pair<std::string, std::string>>> rels =
{
{"rId1", {"worksheets/sheet1.xml", "http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet"}},
{"rId2", {"sharedStrings.xml", "http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings"}},
{"rId3", {"styles.xml", "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles"}},
{"rId4", {"theme/theme1.xml", "http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme"}}
};
return write_relationships(rels);
} }
std::string writer::write_worksheet_rels(worksheet /*ws*/, int) std::string writer::write_worksheet_rels(worksheet /*ws*/, int)
@ -30,9 +52,58 @@ std::string writer::write_worksheet_rels(worksheet /*ws*/, int)
} }
std::string writer::write_workbook(const workbook &/*wb*/) std::string writer::write_workbook(const workbook &wb)
{ {
return ""; pugi::xml_document doc;
auto root_node = doc.append_child("workbook");
root_node.append_attribute("xmlns").set_value("http://schemas.openxmlformats.org/spreadsheetml/2006/main");
root_node.append_attribute("xmlns:r").set_value("http://schemas.openxmlformats.org/officeDocument/2006/relationships");
auto file_version_node = root_node.append_child("fileVersion");
file_version_node.append_attribute("appName").set_value("xl");
file_version_node.append_attribute("lastEdited").set_value("4");
file_version_node.append_attribute("lowestEdited").set_value("4");
file_version_node.append_attribute("rupBuild").set_value("4505");
auto workbook_pr_node = root_node.append_child("workbookPr");
workbook_pr_node.append_attribute("codeName").set_value("ThisWorkbook");
workbook_pr_node.append_attribute("defaultThemeVersion").set_value("124226");
auto book_views_node = root_node.append_child("bookViews");
auto workbook_view_node = book_views_node.append_child("workbookView");
workbook_view_node.append_attribute("activeTab").set_value("0");
workbook_view_node.append_attribute("autoFilterDateGrouping").set_value("1");
workbook_view_node.append_attribute("firstSheet").set_value("0");
workbook_view_node.append_attribute("minimized").set_value("0");
workbook_view_node.append_attribute("showHorizontalScroll").set_value("1");
workbook_view_node.append_attribute("showSheetTabs").set_value("1");
workbook_view_node.append_attribute("showVerticalScroll").set_value("1");
workbook_view_node.append_attribute("tabRatio").set_value("600");
workbook_view_node.append_attribute("visibility").set_value("visible");
auto sheets_node = root_node.append_child("sheets");
int i = 0;
for(auto ws : wb)
{
auto sheet_node = sheets_node.append_child("sheet");
sheet_node.append_attribute("name").set_value(ws.get_title().c_str());
sheet_node.append_attribute("r:id").set_value((std::string("rId") + std::to_string(i + 1)).c_str());
sheet_node.append_attribute("sheetId").set_value(std::to_string(i + 1).c_str());
i++;
}
root_node.append_child("definedNames");
auto calc_pr_node = root_node.append_child("calcPr");
calc_pr_node.append_attribute("calcId").set_value("124519");
calc_pr_node.append_attribute("calcMode").set_value("auto");
calc_pr_node.append_attribute("fullCalcOnLoad").set_value("1");
std::stringstream ss;
doc.save(ss);
return ss.str();
} }
std::string writer::write_worksheet(worksheet ws, const std::vector<std::string> &string_table) std::string writer::write_worksheet(worksheet ws, const std::vector<std::string> &string_table)
@ -46,20 +117,24 @@ std::string writer::write_worksheet(worksheet ws, const std::vector<std::string>
auto root_node = doc.append_child("worksheet"); auto root_node = doc.append_child("worksheet");
root_node.append_attribute("xmlns").set_value(constants::Namespaces.at("spreadsheetml").c_str()); root_node.append_attribute("xmlns").set_value(constants::Namespaces.at("spreadsheetml").c_str());
root_node.append_attribute("xmlns:r").set_value(constants::Namespaces.at("r").c_str()); root_node.append_attribute("xmlns:r").set_value(constants::Namespaces.at("r").c_str());
auto sheet_pr_node = root_node.append_child("sheetPr");
auto outline_pr_node = sheet_pr_node.append_child("outlinePr");
outline_pr_node.append_attribute("summaryBelow").set_value(1);
outline_pr_node.append_attribute("summaryRight").set_value(1);
auto dimension_node = root_node.append_child("dimension"); auto dimension_node = root_node.append_child("dimension");
dimension_node.append_attribute("ref").set_value(ws.calculate_dimension().to_string().c_str()); dimension_node.append_attribute("ref").set_value(ws.calculate_dimension().to_string().c_str());
auto sheet_views_node = root_node.append_child("sheetViews"); auto sheet_views_node = root_node.append_child("sheetViews");
auto sheet_view_node = sheet_views_node.append_child("sheetView"); auto sheet_view_node = sheet_views_node.append_child("sheetView");
sheet_view_node.append_attribute("tabSelected").set_value(1);
sheet_view_node.append_attribute("workbookViewId").set_value(0); sheet_view_node.append_attribute("workbookViewId").set_value(0);
auto selection_node = sheet_view_node.append_child("selection"); auto selection_node = sheet_view_node.append_child("selection");
std::string active_cell = "B2"; std::string active_cell = "A1";
selection_node.append_attribute("activeCell").set_value(active_cell.c_str()); selection_node.append_attribute("activeCell").set_value(active_cell.c_str());
selection_node.append_attribute("sqref").set_value(active_cell.c_str()); selection_node.append_attribute("sqref").set_value(active_cell.c_str());
auto sheet_format_pr_node = root_node.append_child("sheetFormatPr"); auto sheet_format_pr_node = root_node.append_child("sheetFormatPr");
sheet_format_pr_node.append_attribute("baseColWidth").set_value(10);
sheet_format_pr_node.append_attribute("defaultRowHeight").set_value(15); sheet_format_pr_node.append_attribute("defaultRowHeight").set_value(15);
auto sheet_data_node = root_node.append_child("sheetData"); auto sheet_data_node = root_node.append_child("sheetData");
@ -89,7 +164,7 @@ std::string writer::write_worksheet(worksheet ws, const std::vector<std::string>
row_node.append_attribute("r").set_value(row.front().get_row()); row_node.append_attribute("r").set_value(row.front().get_row());
row_node.append_attribute("spans").set_value((std::to_string(min) + ":" + std::to_string(max)).c_str()); row_node.append_attribute("spans").set_value((std::to_string(min) + ":" + std::to_string(max)).c_str());
row_node.append_attribute("x14ac:dyDescent").set_value(0.25); //row_node.append_attribute("x14ac:dyDescent").set_value(0.25);
for(auto cell : row) for(auto cell : row)
{ {
@ -127,9 +202,24 @@ std::string writer::write_worksheet(worksheet ws, const std::vector<std::string>
{ {
if(cell.get_data_type() != cell::type::null) if(cell.get_data_type() != cell::type::null)
{ {
if(cell.get_data_type() == cell::type::boolean)
{
cell_node.append_attribute("t").set_value("b");
auto value_node = cell_node.append_child("v"); auto value_node = cell_node.append_child("v");
value_node.text().set(cell.get_value().c_str()); value_node.text().set(cell.get_value().c_str());
} }
else if(cell.get_data_type() == cell::type::numeric)
{
cell_node.append_attribute("t").set_value("n");
auto value_node = cell_node.append_child("v");
value_node.text().set(cell.get_value().c_str());
}
else if(cell.get_data_type() == cell::type::formula)
{
cell_node.append_child("f").text().set(cell.get_value().substr(1).c_str());
cell_node.append_child("v");
}
}
} }
} }
} }
@ -147,8 +237,6 @@ std::string writer::write_worksheet(worksheet ws, const std::vector<std::string>
} }
} }
if(!ws.get_page_margins().is_default())
{
auto page_margins_node = root_node.append_child("pageMargins"); auto page_margins_node = root_node.append_child("pageMargins");
page_margins_node.append_attribute("left").set_value(ws.get_page_margins().get_left()); page_margins_node.append_attribute("left").set_value(ws.get_page_margins().get_left());
@ -157,7 +245,6 @@ std::string writer::write_worksheet(worksheet ws, const std::vector<std::string>
page_margins_node.append_attribute("bottom").set_value(ws.get_page_margins().get_bottom()); page_margins_node.append_attribute("bottom").set_value(ws.get_page_margins().get_bottom());
page_margins_node.append_attribute("header").set_value(ws.get_page_margins().get_header()); page_margins_node.append_attribute("header").set_value(ws.get_page_margins().get_header());
page_margins_node.append_attribute("footer").set_value(ws.get_page_margins().get_footer()); page_margins_node.append_attribute("footer").set_value(ws.get_page_margins().get_footer());
}
if(!ws.get_page_setup().is_default()) if(!ws.get_page_setup().is_default())
{ {
@ -307,7 +394,7 @@ std::string writer::write_content_types(const std::pair<std::unordered_map<std::
return ss.str(); return ss.str();
} }
std::string writer::write_relationships(const std::unordered_map<std::string, std::pair<std::string, std::string>> &relationships) std::string writer::write_relationships(const std::vector<std::pair<std::string, std::pair<std::string, std::string>>> &relationships)
{ {
pugi::xml_document doc; pugi::xml_document doc;
auto root_node = doc.append_child("Relationships"); auto root_node = doc.append_child("Relationships");
@ -317,8 +404,8 @@ std::string writer::write_relationships(const std::unordered_map<std::string, st
{ {
auto app_props_node = root_node.append_child("Relationship"); auto app_props_node = root_node.append_child("Relationship");
app_props_node.append_attribute("Id").set_value(relationship.first.c_str()); app_props_node.append_attribute("Id").set_value(relationship.first.c_str());
app_props_node.append_attribute("Type").set_value(relationship.second.first.c_str()); app_props_node.append_attribute("Target").set_value(relationship.second.first.c_str());
app_props_node.append_attribute("Target").set_value(relationship.second.second.c_str()); app_props_node.append_attribute("Type").set_value(relationship.second.second.c_str());
} }
std::stringstream ss; std::stringstream ss;

View File

@ -26,7 +26,7 @@ bool suite_test_cell_init = false;
static test_cell suite_test_cell; static test_cell suite_test_cell;
static CxxTest::List Tests_test_cell = { 0, 0 }; static CxxTest::List Tests_test_cell = { 0, 0 };
CxxTest::StaticSuiteDescription suiteDescription_test_cell( "../../tests/test_cell.hpp", 9, "test_cell", suite_test_cell, Tests_test_cell ); CxxTest::StaticSuiteDescription suiteDescription_test_cell( "/Users/thomas/Development/xlnt/tests/test_cell.hpp", 9, "test_cell", suite_test_cell, Tests_test_cell );
static class TestDescription_suite_test_cell_test_coordinates : public CxxTest::RealTestDescription { static class TestDescription_suite_test_cell_test_coordinates : public CxxTest::RealTestDescription {
public: public:
@ -189,7 +189,7 @@ public:
static test_chart suite_test_chart; static test_chart suite_test_chart;
static CxxTest::List Tests_test_chart = { 0, 0 }; static CxxTest::List Tests_test_chart = { 0, 0 };
CxxTest::StaticSuiteDescription suiteDescription_test_chart( "../../tests/test_chart.hpp", 8, "test_chart", suite_test_chart, Tests_test_chart ); CxxTest::StaticSuiteDescription suiteDescription_test_chart( "/Users/thomas/Development/xlnt/tests/test_chart.hpp", 8, "test_chart", suite_test_chart, Tests_test_chart );
static class TestDescription_suite_test_chart_test_write_title : public CxxTest::RealTestDescription { static class TestDescription_suite_test_chart_test_write_title : public CxxTest::RealTestDescription {
public: public:
@ -280,7 +280,7 @@ public:
static test_dump suite_test_dump; static test_dump suite_test_dump;
static CxxTest::List Tests_test_dump = { 0, 0 }; static CxxTest::List Tests_test_dump = { 0, 0 };
CxxTest::StaticSuiteDescription suiteDescription_test_dump( "../../tests/test_dump.hpp", 9, "test_dump", suite_test_dump, Tests_test_dump ); CxxTest::StaticSuiteDescription suiteDescription_test_dump( "/Users/thomas/Development/xlnt/tests/test_dump.hpp", 9, "test_dump", suite_test_dump, Tests_test_dump );
static class TestDescription_suite_test_dump_test_dump_sheet_title : public CxxTest::RealTestDescription { static class TestDescription_suite_test_dump_test_dump_sheet_title : public CxxTest::RealTestDescription {
public: public:
@ -317,7 +317,7 @@ public:
static test_named_range suite_test_named_range; static test_named_range suite_test_named_range;
static CxxTest::List Tests_test_named_range = { 0, 0 }; static CxxTest::List Tests_test_named_range = { 0, 0 };
CxxTest::StaticSuiteDescription suiteDescription_test_named_range( "../../tests/test_named_range.hpp", 8, "test_named_range", suite_test_named_range, Tests_test_named_range ); CxxTest::StaticSuiteDescription suiteDescription_test_named_range( "/Users/thomas/Development/xlnt/tests/test_named_range.hpp", 8, "test_named_range", suite_test_named_range, Tests_test_named_range );
static class TestDescription_suite_test_named_range_test_split : public CxxTest::RealTestDescription { static class TestDescription_suite_test_named_range_test_split : public CxxTest::RealTestDescription {
public: public:
@ -408,7 +408,7 @@ public:
static test_number_format suite_test_number_format; static test_number_format suite_test_number_format;
static CxxTest::List Tests_test_number_format = { 0, 0 }; static CxxTest::List Tests_test_number_format = { 0, 0 };
CxxTest::StaticSuiteDescription suiteDescription_test_number_format( "../../tests/test_number_format.hpp", 8, "test_number_format", suite_test_number_format, Tests_test_number_format ); CxxTest::StaticSuiteDescription suiteDescription_test_number_format( "/Users/thomas/Development/xlnt/tests/test_number_format.hpp", 8, "test_number_format", suite_test_number_format, Tests_test_number_format );
static class TestDescription_suite_test_number_format_test_convert_date_to_julian : public CxxTest::RealTestDescription { static class TestDescription_suite_test_number_format_test_convert_date_to_julian : public CxxTest::RealTestDescription {
public: public:
@ -511,7 +511,7 @@ public:
static test_props suite_test_props; static test_props suite_test_props;
static CxxTest::List Tests_test_props = { 0, 0 }; static CxxTest::List Tests_test_props = { 0, 0 };
CxxTest::StaticSuiteDescription suiteDescription_test_props( "../../tests/test_props.hpp", 8, "test_props", suite_test_props, Tests_test_props ); CxxTest::StaticSuiteDescription suiteDescription_test_props( "/Users/thomas/Development/xlnt/tests/test_props.hpp", 8, "test_props", suite_test_props, Tests_test_props );
static class TestDescription_suite_test_props_test_read_properties_core : public CxxTest::RealTestDescription { static class TestDescription_suite_test_props_test_read_properties_core : public CxxTest::RealTestDescription {
public: public:
@ -554,7 +554,7 @@ public:
static test_read suite_test_read; static test_read suite_test_read;
static CxxTest::List Tests_test_read = { 0, 0 }; static CxxTest::List Tests_test_read = { 0, 0 };
CxxTest::StaticSuiteDescription suiteDescription_test_read( "../../tests/test_read.hpp", 10, "test_read", suite_test_read, Tests_test_read ); CxxTest::StaticSuiteDescription suiteDescription_test_read( "/Users/thomas/Development/xlnt/tests/test_read.hpp", 10, "test_read", suite_test_read, Tests_test_read );
static class TestDescription_suite_test_read_test_read_standalone_worksheet : public CxxTest::RealTestDescription { static class TestDescription_suite_test_read_test_read_standalone_worksheet : public CxxTest::RealTestDescription {
public: public:
@ -687,7 +687,7 @@ public:
static test_strings suite_test_strings; static test_strings suite_test_strings;
static CxxTest::List Tests_test_strings = { 0, 0 }; static CxxTest::List Tests_test_strings = { 0, 0 };
CxxTest::StaticSuiteDescription suiteDescription_test_strings( "../../tests/test_strings.hpp", 8, "test_strings", suite_test_strings, Tests_test_strings ); CxxTest::StaticSuiteDescription suiteDescription_test_strings( "/Users/thomas/Development/xlnt/tests/test_strings.hpp", 8, "test_strings", suite_test_strings, Tests_test_strings );
static class TestDescription_suite_test_strings_test_create_string_table : public CxxTest::RealTestDescription { static class TestDescription_suite_test_strings_test_create_string_table : public CxxTest::RealTestDescription {
public: public:
@ -718,7 +718,7 @@ public:
static test_style suite_test_style; static test_style suite_test_style;
static CxxTest::List Tests_test_style = { 0, 0 }; static CxxTest::List Tests_test_style = { 0, 0 };
CxxTest::StaticSuiteDescription suiteDescription_test_style( "../../tests/test_style.hpp", 8, "test_style", suite_test_style, Tests_test_style ); CxxTest::StaticSuiteDescription suiteDescription_test_style( "/Users/thomas/Development/xlnt/tests/test_style.hpp", 8, "test_style", suite_test_style, Tests_test_style );
static class TestDescription_suite_test_style_test_create_style_table : public CxxTest::RealTestDescription { static class TestDescription_suite_test_style_test_create_style_table : public CxxTest::RealTestDescription {
public: public:
@ -815,7 +815,7 @@ public:
static test_theme suite_test_theme; static test_theme suite_test_theme;
static CxxTest::List Tests_test_theme = { 0, 0 }; static CxxTest::List Tests_test_theme = { 0, 0 };
CxxTest::StaticSuiteDescription suiteDescription_test_theme( "../../tests/test_theme.hpp", 9, "test_theme", suite_test_theme, Tests_test_theme ); CxxTest::StaticSuiteDescription suiteDescription_test_theme( "/Users/thomas/Development/xlnt/tests/test_theme.hpp", 9, "test_theme", suite_test_theme, Tests_test_theme );
static class TestDescription_suite_test_theme_test_write_theme : public CxxTest::RealTestDescription { static class TestDescription_suite_test_theme_test_write_theme : public CxxTest::RealTestDescription {
public: public:
@ -828,7 +828,7 @@ public:
static test_workbook suite_test_workbook; static test_workbook suite_test_workbook;
static CxxTest::List Tests_test_workbook = { 0, 0 }; static CxxTest::List Tests_test_workbook = { 0, 0 };
CxxTest::StaticSuiteDescription suiteDescription_test_workbook( "../../tests/test_workbook.hpp", 9, "test_workbook", suite_test_workbook, Tests_test_workbook ); CxxTest::StaticSuiteDescription suiteDescription_test_workbook( "/Users/thomas/Development/xlnt/tests/test_workbook.hpp", 9, "test_workbook", suite_test_workbook, Tests_test_workbook );
static class TestDescription_suite_test_workbook_test_get_active_sheet : public CxxTest::RealTestDescription { static class TestDescription_suite_test_workbook_test_get_active_sheet : public CxxTest::RealTestDescription {
public: public:
@ -955,7 +955,7 @@ public:
static test_worksheet suite_test_worksheet; static test_worksheet suite_test_worksheet;
static CxxTest::List Tests_test_worksheet = { 0, 0 }; static CxxTest::List Tests_test_worksheet = { 0, 0 };
CxxTest::StaticSuiteDescription suiteDescription_test_worksheet( "../../tests/test_worksheet.hpp", 9, "test_worksheet", suite_test_worksheet, Tests_test_worksheet ); CxxTest::StaticSuiteDescription suiteDescription_test_worksheet( "/Users/thomas/Development/xlnt/tests/test_worksheet.hpp", 9, "test_worksheet", suite_test_worksheet, Tests_test_worksheet );
static class TestDescription_suite_test_worksheet_test_new_worksheet : public CxxTest::RealTestDescription { static class TestDescription_suite_test_worksheet_test_new_worksheet : public CxxTest::RealTestDescription {
public: public:
@ -1124,7 +1124,7 @@ public:
static test_write suite_test_write; static test_write suite_test_write;
static CxxTest::List Tests_test_write = { 0, 0 }; static CxxTest::List Tests_test_write = { 0, 0 };
CxxTest::StaticSuiteDescription suiteDescription_test_write( "../../tests/test_write.hpp", 11, "test_write", suite_test_write, Tests_test_write ); CxxTest::StaticSuiteDescription suiteDescription_test_write( "/Users/thomas/Development/xlnt/tests/test_write.hpp", 11, "test_write", suite_test_write, Tests_test_write );
static class TestDescription_suite_test_write_test_write_empty_workbook : public CxxTest::RealTestDescription { static class TestDescription_suite_test_write_test_write_empty_workbook : public CxxTest::RealTestDescription {
public: public:
@ -1182,67 +1182,67 @@ public:
static class TestDescription_suite_test_write_test_write_style : public CxxTest::RealTestDescription { static class TestDescription_suite_test_write_test_write_style : public CxxTest::RealTestDescription {
public: public:
TestDescription_suite_test_write_test_write_style() : CxxTest::RealTestDescription( Tests_test_write, suiteDescription_test_write, 96, "test_write_style" ) {} TestDescription_suite_test_write_test_write_style() : CxxTest::RealTestDescription( Tests_test_write, suiteDescription_test_write, 100, "test_write_style" ) {}
void runTest() { suite_test_write.test_write_style(); } void runTest() { suite_test_write.test_write_style(); }
} testDescription_suite_test_write_test_write_style; } testDescription_suite_test_write_test_write_style;
static class TestDescription_suite_test_write_test_write_height : public CxxTest::RealTestDescription { static class TestDescription_suite_test_write_test_write_height : public CxxTest::RealTestDescription {
public: public:
TestDescription_suite_test_write_test_write_height() : CxxTest::RealTestDescription( Tests_test_write, suiteDescription_test_write, 105, "test_write_height" ) {} TestDescription_suite_test_write_test_write_height() : CxxTest::RealTestDescription( Tests_test_write, suiteDescription_test_write, 109, "test_write_height" ) {}
void runTest() { suite_test_write.test_write_height(); } void runTest() { suite_test_write.test_write_height(); }
} testDescription_suite_test_write_test_write_height; } testDescription_suite_test_write_test_write_height;
static class TestDescription_suite_test_write_test_write_hyperlink : public CxxTest::RealTestDescription { static class TestDescription_suite_test_write_test_write_hyperlink : public CxxTest::RealTestDescription {
public: public:
TestDescription_suite_test_write_test_write_hyperlink() : CxxTest::RealTestDescription( Tests_test_write, suiteDescription_test_write, 114, "test_write_hyperlink" ) {} TestDescription_suite_test_write_test_write_hyperlink() : CxxTest::RealTestDescription( Tests_test_write, suiteDescription_test_write, 118, "test_write_hyperlink" ) {}
void runTest() { suite_test_write.test_write_hyperlink(); } void runTest() { suite_test_write.test_write_hyperlink(); }
} testDescription_suite_test_write_test_write_hyperlink; } testDescription_suite_test_write_test_write_hyperlink;
static class TestDescription_suite_test_write_test_write_hyperlink_rels : public CxxTest::RealTestDescription { static class TestDescription_suite_test_write_test_write_hyperlink_rels : public CxxTest::RealTestDescription {
public: public:
TestDescription_suite_test_write_test_write_hyperlink_rels() : CxxTest::RealTestDescription( Tests_test_write, suiteDescription_test_write, 123, "test_write_hyperlink_rels" ) {} TestDescription_suite_test_write_test_write_hyperlink_rels() : CxxTest::RealTestDescription( Tests_test_write, suiteDescription_test_write, 127, "test_write_hyperlink_rels" ) {}
void runTest() { suite_test_write.test_write_hyperlink_rels(); } void runTest() { suite_test_write.test_write_hyperlink_rels(); }
} testDescription_suite_test_write_test_write_hyperlink_rels; } testDescription_suite_test_write_test_write_hyperlink_rels;
static class TestDescription_suite_test_write_test_hyperlink_value : public CxxTest::RealTestDescription { static class TestDescription_suite_test_write_test_hyperlink_value : public CxxTest::RealTestDescription {
public: public:
TestDescription_suite_test_write_test_hyperlink_value() : CxxTest::RealTestDescription( Tests_test_write, suiteDescription_test_write, 137, "test_hyperlink_value" ) {} TestDescription_suite_test_write_test_hyperlink_value() : CxxTest::RealTestDescription( Tests_test_write, suiteDescription_test_write, 141, "test_hyperlink_value" ) {}
void runTest() { suite_test_write.test_hyperlink_value(); } void runTest() { suite_test_write.test_hyperlink_value(); }
} testDescription_suite_test_write_test_hyperlink_value; } testDescription_suite_test_write_test_hyperlink_value;
static class TestDescription_suite_test_write_test_write_auto_filter : public CxxTest::RealTestDescription { static class TestDescription_suite_test_write_test_write_auto_filter : public CxxTest::RealTestDescription {
public: public:
TestDescription_suite_test_write_test_write_auto_filter() : CxxTest::RealTestDescription( Tests_test_write, suiteDescription_test_write, 146, "test_write_auto_filter" ) {} TestDescription_suite_test_write_test_write_auto_filter() : CxxTest::RealTestDescription( Tests_test_write, suiteDescription_test_write, 150, "test_write_auto_filter" ) {}
void runTest() { suite_test_write.test_write_auto_filter(); } void runTest() { suite_test_write.test_write_auto_filter(); }
} testDescription_suite_test_write_test_write_auto_filter; } testDescription_suite_test_write_test_write_auto_filter;
static class TestDescription_suite_test_write_test_freeze_panes_horiz : public CxxTest::RealTestDescription { static class TestDescription_suite_test_write_test_freeze_panes_horiz : public CxxTest::RealTestDescription {
public: public:
TestDescription_suite_test_write_test_freeze_panes_horiz() : CxxTest::RealTestDescription( Tests_test_write, suiteDescription_test_write, 158, "test_freeze_panes_horiz" ) {} TestDescription_suite_test_write_test_freeze_panes_horiz() : CxxTest::RealTestDescription( Tests_test_write, suiteDescription_test_write, 162, "test_freeze_panes_horiz" ) {}
void runTest() { suite_test_write.test_freeze_panes_horiz(); } void runTest() { suite_test_write.test_freeze_panes_horiz(); }
} testDescription_suite_test_write_test_freeze_panes_horiz; } testDescription_suite_test_write_test_freeze_panes_horiz;
static class TestDescription_suite_test_write_test_freeze_panes_vert : public CxxTest::RealTestDescription { static class TestDescription_suite_test_write_test_freeze_panes_vert : public CxxTest::RealTestDescription {
public: public:
TestDescription_suite_test_write_test_freeze_panes_vert() : CxxTest::RealTestDescription( Tests_test_write, suiteDescription_test_write, 167, "test_freeze_panes_vert" ) {} TestDescription_suite_test_write_test_freeze_panes_vert() : CxxTest::RealTestDescription( Tests_test_write, suiteDescription_test_write, 171, "test_freeze_panes_vert" ) {}
void runTest() { suite_test_write.test_freeze_panes_vert(); } void runTest() { suite_test_write.test_freeze_panes_vert(); }
} testDescription_suite_test_write_test_freeze_panes_vert; } testDescription_suite_test_write_test_freeze_panes_vert;
static class TestDescription_suite_test_write_test_freeze_panes_both : public CxxTest::RealTestDescription { static class TestDescription_suite_test_write_test_freeze_panes_both : public CxxTest::RealTestDescription {
public: public:
TestDescription_suite_test_write_test_freeze_panes_both() : CxxTest::RealTestDescription( Tests_test_write, suiteDescription_test_write, 176, "test_freeze_panes_both" ) {} TestDescription_suite_test_write_test_freeze_panes_both() : CxxTest::RealTestDescription( Tests_test_write, suiteDescription_test_write, 180, "test_freeze_panes_both" ) {}
void runTest() { suite_test_write.test_freeze_panes_both(); } void runTest() { suite_test_write.test_freeze_panes_both(); }
} testDescription_suite_test_write_test_freeze_panes_both; } testDescription_suite_test_write_test_freeze_panes_both;
static class TestDescription_suite_test_write_test_long_number : public CxxTest::RealTestDescription { static class TestDescription_suite_test_write_test_long_number : public CxxTest::RealTestDescription {
public: public:
TestDescription_suite_test_write_test_long_number() : CxxTest::RealTestDescription( Tests_test_write, suiteDescription_test_write, 185, "test_long_number" ) {} TestDescription_suite_test_write_test_long_number() : CxxTest::RealTestDescription( Tests_test_write, suiteDescription_test_write, 189, "test_long_number" ) {}
void runTest() { suite_test_write.test_long_number(); } void runTest() { suite_test_write.test_long_number(); }
} testDescription_suite_test_write_test_long_number; } testDescription_suite_test_write_test_long_number;
static class TestDescription_suite_test_write_test_short_number : public CxxTest::RealTestDescription { static class TestDescription_suite_test_write_test_short_number : public CxxTest::RealTestDescription {
public: public:
TestDescription_suite_test_write_test_short_number() : CxxTest::RealTestDescription( Tests_test_write, suiteDescription_test_write, 193, "test_short_number" ) {} TestDescription_suite_test_write_test_short_number() : CxxTest::RealTestDescription( Tests_test_write, suiteDescription_test_write, 197, "test_short_number" ) {}
void runTest() { suite_test_write.test_short_number(); } void runTest() { suite_test_write.test_short_number(); }
} testDescription_suite_test_write_test_short_number; } testDescription_suite_test_write_test_short_number;

View File

@ -52,7 +52,7 @@ public:
void test_write_string_table() void test_write_string_table()
{ {
std::unordered_map<std::string, int> table = {{"hello", 1}, {"world", 2}, {"nice", 3}}; std::vector<std::string> table = {"hello", "world", "nice"};
auto content = xlnt::writer::write_string_table(table); auto content = xlnt::writer::write_string_table(table);
TS_ASSERT(Helper::EqualsFileContent(PathHelper::GetDataDirectory() + "/writer/expected/sharedStrings.xml", content)); TS_ASSERT(Helper::EqualsFileContent(PathHelper::GetDataDirectory() + "/writer/expected/sharedStrings.xml", content));
} }
@ -61,7 +61,7 @@ public:
{ {
auto ws = wb.create_sheet(); auto ws = wb.create_sheet();
ws.get_cell("F42") = "hello"; ws.get_cell("F42") = "hello";
auto content = xlnt::writer::write_worksheet(ws, {{"hello", 0}}, {}); auto content = xlnt::writer::write_worksheet(ws, {"hello"}, {});
TS_ASSERT(Helper::EqualsFileContent(PathHelper::GetDataDirectory() + "/writer/expected/sheet1.xml", content)); TS_ASSERT(Helper::EqualsFileContent(PathHelper::GetDataDirectory() + "/writer/expected/sheet1.xml", content));
} }
@ -70,7 +70,7 @@ public:
auto ws = wb.create_sheet(); auto ws = wb.create_sheet();
ws.get_page_setup().set_sheet_state(xlnt::page_setup::sheet_state::hidden); ws.get_page_setup().set_sheet_state(xlnt::page_setup::sheet_state::hidden);
ws.get_cell("F42") = "hello"; ws.get_cell("F42") = "hello";
auto content = xlnt::writer::write_worksheet(ws, {{"hello", 0}}, {}); auto content = xlnt::writer::write_worksheet(ws, {"hello"}, {});
TS_ASSERT(Helper::EqualsFileContent(PathHelper::GetDataDirectory() + "/writer/expected/sheet1.xml", content)); TS_ASSERT(Helper::EqualsFileContent(PathHelper::GetDataDirectory() + "/writer/expected/sheet1.xml", content));
} }
@ -85,10 +85,14 @@ public:
void test_write_formula() void test_write_formula()
{ {
TS_SKIP("");
auto ws = wb.create_sheet(); auto ws = wb.create_sheet();
ws.get_cell("F1") = 10; ws.get_cell("F1") = 10;
ws.get_cell("F2") = 32; ws.get_cell("F2") = 32;
ws.get_cell("F3") = "=F1+F2"; ws.get_cell("F3") = "=F1+F2";
ws.get_cell("A4") = "=A1+A2+A3";
ws.get_cell("B4") = "=";
ws.get_cell("C4") = "=";
auto content = xlnt::writer::write_worksheet(ws, {}, {}); auto content = xlnt::writer::write_worksheet(ws, {}, {});
TS_ASSERT(Helper::EqualsFileContent(PathHelper::GetDataDirectory() + "/writer/expected/sheet1_formula.xml", content)); TS_ASSERT(Helper::EqualsFileContent(PathHelper::GetDataDirectory() + "/writer/expected/sheet1_formula.xml", content));
} }