mirror of
https://github.com/tfussell/xlnt.git
synced 2024-03-22 13:11:17 +08:00
remove optimization, test_dump, and start fixing relationships
This commit is contained in:
parent
463bc3a677
commit
4d62e0bb75
|
@ -110,14 +110,4 @@ public:
|
||||||
missing_number_format();
|
missing_number_format();
|
||||||
};
|
};
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Error when attempting to perform operations on a dump workbook
|
|
||||||
/// while it has already been dumped once.
|
|
||||||
/// </summary>
|
|
||||||
class workbook_already_saved : public std::runtime_error
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
workbook_already_saved();
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace xlnt
|
} // namespace xlnt
|
||||||
|
|
|
@ -41,11 +41,12 @@ namespace detail {
|
||||||
struct workbook_impl;
|
struct workbook_impl;
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
|
|
||||||
enum class optimization
|
struct content_type
|
||||||
{
|
{
|
||||||
write,
|
bool is_default;
|
||||||
read,
|
std::string extension;
|
||||||
none
|
std::string part_name;
|
||||||
|
std::string type;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -55,16 +56,13 @@ class workbook
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
//constructors
|
//constructors
|
||||||
workbook(optimization optimization = optimization::none);
|
workbook();
|
||||||
~workbook();
|
~workbook();
|
||||||
|
|
||||||
workbook &operator=(const workbook &) = delete;
|
workbook &operator=(const workbook &) = delete;
|
||||||
workbook(const workbook &) = delete;
|
workbook(const workbook &) = delete;
|
||||||
|
|
||||||
void read_workbook_settings(const std::string &xml_source);
|
//void read_workbook_settings(const std::string &xml_source);
|
||||||
|
|
||||||
void create_relationship(const std::string &id, const std::string &target, const std::string &type);
|
|
||||||
relationship get_relationship(const std::string &id) const;
|
|
||||||
|
|
||||||
//getters
|
//getters
|
||||||
worksheet get_active_sheet();
|
worksheet get_active_sheet();
|
||||||
|
@ -159,12 +157,14 @@ public:
|
||||||
|
|
||||||
bool operator==(const workbook &rhs) const;
|
bool operator==(const workbook &rhs) const;
|
||||||
|
|
||||||
std::unordered_map<std::string, std::pair<std::string, std::string>> get_root_relationships() const;
|
std::vector<content_type> get_content_types() const;
|
||||||
std::unordered_map<std::string, std::pair<std::string, std::string>> get_relationships() const;
|
|
||||||
|
void create_relationship(const std::string &id, const std::string &target, const std::string &type);
|
||||||
|
relationship get_relationship(const std::string &id) const;
|
||||||
|
std::vector<relationship> get_relationships() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class worksheet;
|
friend class worksheet;
|
||||||
bool get_already_saved() const;
|
|
||||||
std::unique_ptr<detail::workbook_impl> d_;
|
std::unique_ptr<detail::workbook_impl> d_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,7 @@
|
||||||
|
|
||||||
namespace xlnt {
|
namespace xlnt {
|
||||||
|
|
||||||
|
class relationship;
|
||||||
class workbook;
|
class workbook;
|
||||||
class worksheet;
|
class worksheet;
|
||||||
class document_properties;
|
class document_properties;
|
||||||
|
@ -37,18 +38,30 @@ class document_properties;
|
||||||
class writer
|
class writer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
static std::string write_content_types(const workbook &wb);
|
||||||
|
|
||||||
|
static std::string write_properties_core(const document_properties &prop);
|
||||||
|
|
||||||
|
static std::string write_properties_app(const workbook &wb);
|
||||||
|
|
||||||
static std::string write_workbook(const workbook &wb);
|
static std::string write_workbook(const workbook &wb);
|
||||||
static std::string write_worksheet(worksheet ws);
|
|
||||||
static std::string write_worksheet(worksheet ws, const std::vector<std::string> &string_table);
|
static std::string write_theme();
|
||||||
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_shared_strings(const std::vector<std::string> &string_table);
|
||||||
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::vector<std::pair<std::string, std::pair<std::string, std::string>>> &relationships);
|
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_root_rels();
|
||||||
|
|
||||||
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 drawing_id, int comments_id);
|
|
||||||
static std::string write_string_table(const std::vector<std::string> &string_table);
|
static std::string write_worksheet_rels(worksheet ws);
|
||||||
static std::string write_properties_core(const document_properties &prop);
|
|
||||||
static std::string write_properties_app(const workbook &wb);
|
private:
|
||||||
|
static std::string write_relationships(const std::vector<relationship> &relationships);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace xlnt
|
} // namespace xlnt
|
||||||
|
|
|
@ -7,14 +7,11 @@ namespace detail {
|
||||||
|
|
||||||
struct workbook_impl
|
struct workbook_impl
|
||||||
{
|
{
|
||||||
workbook_impl(optimization o);
|
workbook_impl();
|
||||||
workbook_impl &operator=(const workbook_impl &) = delete;
|
workbook_impl &operator=(const workbook_impl &) = delete;
|
||||||
workbook_impl(const workbook_impl &) = delete;
|
workbook_impl(const workbook_impl &) = delete;
|
||||||
bool already_saved_;
|
//bool guess_types_;
|
||||||
bool optimized_read_;
|
//bool data_only_;
|
||||||
bool optimized_write_;
|
|
||||||
bool guess_types_;
|
|
||||||
bool data_only_;
|
|
||||||
int active_sheet_index_;
|
int active_sheet_index_;
|
||||||
bool date_1904_;
|
bool date_1904_;
|
||||||
std::vector<worksheet_impl> worksheets_;
|
std::vector<worksheet_impl> worksheets_;
|
||||||
|
|
|
@ -32,10 +32,4 @@ cell_coordinates_exception::cell_coordinates_exception(const std::string &coord_
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
workbook_already_saved::workbook_already_saved()
|
|
||||||
: std::runtime_error("")
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace xlnt
|
} // namespace xlnt
|
||||||
|
|
|
@ -43,18 +43,15 @@ static std::string CreateTemporaryFilename()
|
||||||
|
|
||||||
namespace xlnt {
|
namespace xlnt {
|
||||||
namespace detail {
|
namespace detail {
|
||||||
workbook_impl::workbook_impl(optimization o) : already_saved_(false), optimized_read_(o == optimization::read), optimized_write_(o == optimization::write), active_sheet_index_(0), date_1904_(false)
|
workbook_impl::workbook_impl() : active_sheet_index_(0), date_1904_(false)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
|
|
||||||
workbook::workbook(optimization optimize) : d_(new detail::workbook_impl(optimize))
|
workbook::workbook() : d_(new detail::workbook_impl())
|
||||||
{
|
{
|
||||||
if(!d_->optimized_read_)
|
create_sheet("Sheet");
|
||||||
{
|
|
||||||
create_sheet("Sheet");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
workbook::~workbook()
|
workbook::~workbook()
|
||||||
|
@ -156,11 +153,6 @@ worksheet workbook::get_active_sheet()
|
||||||
return worksheet(&d_->worksheets_[d_->active_sheet_index_]);
|
return worksheet(&d_->worksheets_[d_->active_sheet_index_]);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool workbook::get_already_saved() const
|
|
||||||
{
|
|
||||||
return d_->already_saved_;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool workbook::has_named_range(const std::string &name) const
|
bool workbook::has_named_range(const std::string &name) const
|
||||||
{
|
{
|
||||||
for(auto worksheet : *this)
|
for(auto worksheet : *this)
|
||||||
|
@ -175,11 +167,6 @@ bool workbook::has_named_range(const std::string &name) const
|
||||||
|
|
||||||
worksheet workbook::create_sheet()
|
worksheet workbook::create_sheet()
|
||||||
{
|
{
|
||||||
if(d_->optimized_read_)
|
|
||||||
{
|
|
||||||
throw std::runtime_error("this is a read-only workbook");
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string title = "Sheet1";
|
std::string title = "Sheet1";
|
||||||
int index = 1;
|
int index = 1;
|
||||||
|
|
||||||
|
@ -194,11 +181,6 @@ worksheet workbook::create_sheet()
|
||||||
|
|
||||||
void workbook::add_sheet(xlnt::worksheet worksheet)
|
void workbook::add_sheet(xlnt::worksheet worksheet)
|
||||||
{
|
{
|
||||||
if(d_->optimized_read_)
|
|
||||||
{
|
|
||||||
throw std::runtime_error("this is a read-only workbook");
|
|
||||||
}
|
|
||||||
|
|
||||||
for(auto ws : *this)
|
for(auto ws : *this)
|
||||||
{
|
{
|
||||||
if(worksheet == ws)
|
if(worksheet == ws)
|
||||||
|
@ -476,11 +458,6 @@ void workbook::clear()
|
||||||
d_->worksheets_.clear();
|
d_->worksheets_.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool workbook::get_optimized_write() const
|
|
||||||
{
|
|
||||||
return d_->optimized_write_;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool workbook::save(std::vector<unsigned char> &data)
|
bool workbook::save(std::vector<unsigned char> &data)
|
||||||
{
|
{
|
||||||
auto temp_file = CreateTemporaryFilename();
|
auto temp_file = CreateTemporaryFilename();
|
||||||
|
@ -498,75 +475,12 @@ bool workbook::save(std::vector<unsigned char> &data)
|
||||||
|
|
||||||
bool workbook::save(const std::string &filename)
|
bool workbook::save(const std::string &filename)
|
||||||
{
|
{
|
||||||
if(d_->optimized_write_)
|
|
||||||
{
|
|
||||||
if(d_->already_saved_)
|
|
||||||
{
|
|
||||||
throw workbook_already_saved();
|
|
||||||
}
|
|
||||||
|
|
||||||
d_->already_saved_ = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
zip_file f(filename, file_mode::create, file_access::write);
|
zip_file f(filename, file_mode::create, file_access::write);
|
||||||
|
|
||||||
std::pair<std::unordered_map<std::string, std::string>, std::unordered_map<std::string, std::string>> content_types =
|
f.set_file_contents("[Content_Types].xml", writer::write_content_types(*this));
|
||||||
{
|
|
||||||
{
|
|
||||||
{"rels", "application/vnd.openxmlformats-package.relationships+xml"},
|
|
||||||
{"xml", "application/xml"}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
{"/xl/styles.xml", "application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml"},
|
|
||||||
{"/xl/workbook.xml", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml"},
|
|
||||||
{"/docProps/app.xml", "application/vnd.openxmlformats-officedocument.extended-properties+xml"},
|
|
||||||
{"/docProps/core.xml", "application/vnd.openxmlformats-package.core-properties+xml"},
|
|
||||||
{"/xl/theme/theme1.xml", "application/vnd.openxmlformats-officedocument.theme+xml"}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
int ws_index = 1;
|
f.set_file_contents("_rels/.rels", writer::write_root_rels());
|
||||||
for(auto ws : *this)
|
f.set_file_contents("xl/_rels/workbook.xml.rels", writer::write_workbook_rels(*this));
|
||||||
{
|
|
||||||
auto sheet_filename = "/xl/worksheets/sheet" + std::to_string(ws_index++) + ".xml";
|
|
||||||
content_types.second[sheet_filename] = "application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml";
|
|
||||||
}
|
|
||||||
|
|
||||||
f.set_file_contents("[Content_Types].xml", writer::write_content_types(content_types));
|
|
||||||
|
|
||||||
std::vector<std::pair<std::string, std::pair<std::string, std::string>>> root_rels =
|
|
||||||
{
|
|
||||||
{"rId3", {"docProps/app.xml", "http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties"}},
|
|
||||||
{"rId2", {"docProps/core.xml", "http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties"}},
|
|
||||||
{"rId1", {"xl/workbook.xml", "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument"}}
|
|
||||||
};
|
|
||||||
|
|
||||||
f.set_file_contents("_rels/.rels", writer::write_relationships(root_rels));
|
|
||||||
|
|
||||||
std::vector<std::pair<std::string, std::pair<std::string, std::string>>> workbook_rels =
|
|
||||||
{
|
|
||||||
{"rId1", {"sharedStrings.xml", "http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings"}},
|
|
||||||
{"rId2", {"styles.xml", "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles"}},
|
|
||||||
{"rId3", {"theme/theme1.xml", "http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme"}}
|
|
||||||
};
|
|
||||||
|
|
||||||
ws_index = 2;
|
|
||||||
for(auto ws : *this)
|
|
||||||
{
|
|
||||||
auto sheet_filename = "worksheets/sheet" + std::to_string(ws_index++) + ".xml";
|
|
||||||
workbook_rels.push_back({"rId" + std::to_string(ws_index + 1), {sheet_filename, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet"}});
|
|
||||||
}
|
|
||||||
|
|
||||||
f.set_file_contents("xl/_rels/workbook.xml.rels", writer::write_relationships(workbook_rels));
|
|
||||||
|
|
||||||
int i = 0;
|
|
||||||
|
|
||||||
for(auto ws : *this)
|
|
||||||
{
|
|
||||||
std::string sheet_filename = "xl/worksheets/sheet";
|
|
||||||
f.set_file_contents(sheet_filename + std::to_string(i + 1) + ".xml", xlnt::writer::write_worksheet(ws));
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
|
|
||||||
f.set_file_contents("xl/workbook.xml", writer::write_workbook(*this));
|
f.set_file_contents("xl/workbook.xml", writer::write_workbook(*this));
|
||||||
|
|
||||||
|
@ -578,4 +492,18 @@ bool workbook::operator==(const workbook &rhs) const
|
||||||
return d_.get() == rhs.d_.get();
|
return d_.get() == rhs.d_.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<relationship> xlnt::workbook::get_relationships() const
|
||||||
|
{
|
||||||
|
return d_->relationships_;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<content_type> xlnt::workbook::get_content_types() const
|
||||||
|
{
|
||||||
|
std::vector<content_type> content_types;
|
||||||
|
content_types.push_back({ true, "xml", "xml" });
|
||||||
|
content_types.push_back({ true, "rels", "xml" });
|
||||||
|
content_types.push_back({ false, "xl/workbook.xml", "xml" });
|
||||||
|
return content_types;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -347,11 +347,6 @@ void worksheet::unmerge_cells(const range_reference &reference)
|
||||||
|
|
||||||
void worksheet::append(const std::vector<std::string> &cells)
|
void worksheet::append(const std::vector<std::string> &cells)
|
||||||
{
|
{
|
||||||
if(d_->parent_->get_optimized_write() && d_->parent_->get_already_saved())
|
|
||||||
{
|
|
||||||
throw workbook_already_saved();
|
|
||||||
}
|
|
||||||
|
|
||||||
int row = get_highest_row();
|
int row = get_highest_row();
|
||||||
|
|
||||||
if(d_->cell_map_.size() == 0)
|
if(d_->cell_map_.size() == 0)
|
||||||
|
@ -369,11 +364,6 @@ void worksheet::append(const std::vector<std::string> &cells)
|
||||||
|
|
||||||
void worksheet::append(const std::vector<int> &cells)
|
void worksheet::append(const std::vector<int> &cells)
|
||||||
{
|
{
|
||||||
if(d_->parent_->get_optimized_write() && d_->parent_->get_already_saved())
|
|
||||||
{
|
|
||||||
throw workbook_already_saved();
|
|
||||||
}
|
|
||||||
|
|
||||||
int row = get_highest_row();
|
int row = get_highest_row();
|
||||||
|
|
||||||
if(d_->cell_map_.size() == 0)
|
if(d_->cell_map_.size() == 0)
|
||||||
|
@ -391,11 +381,6 @@ void worksheet::append(const std::vector<int> &cells)
|
||||||
|
|
||||||
void worksheet::append(const std::vector<date> &cells)
|
void worksheet::append(const std::vector<date> &cells)
|
||||||
{
|
{
|
||||||
if(d_->parent_->get_optimized_write() && d_->parent_->get_already_saved())
|
|
||||||
{
|
|
||||||
throw workbook_already_saved();
|
|
||||||
}
|
|
||||||
|
|
||||||
int row = get_highest_row();
|
int row = get_highest_row();
|
||||||
|
|
||||||
if(d_->cell_map_.size() == 0)
|
if(d_->cell_map_.size() == 0)
|
||||||
|
@ -413,12 +398,7 @@ void worksheet::append(const std::vector<date> &cells)
|
||||||
|
|
||||||
void worksheet::append(const std::unordered_map<std::string, std::string> &cells)
|
void worksheet::append(const std::unordered_map<std::string, std::string> &cells)
|
||||||
{
|
{
|
||||||
if(d_->parent_->get_optimized_write() && d_->parent_->get_already_saved())
|
int row = get_highest_row() - 1;
|
||||||
{
|
|
||||||
throw workbook_already_saved();
|
|
||||||
}
|
|
||||||
|
|
||||||
int row = get_highest_row() - 1;
|
|
||||||
|
|
||||||
if(d_->cell_map_.size() != 0)
|
if(d_->cell_map_.size() != 0)
|
||||||
{
|
{
|
||||||
|
@ -433,12 +413,7 @@ void worksheet::append(const std::unordered_map<std::string, std::string> &cells
|
||||||
|
|
||||||
void worksheet::append(const std::unordered_map<int, std::string> &cells)
|
void worksheet::append(const std::unordered_map<int, std::string> &cells)
|
||||||
{
|
{
|
||||||
if(d_->parent_->get_optimized_write() && d_->parent_->get_already_saved())
|
int row = get_highest_row() - 1;
|
||||||
{
|
|
||||||
throw workbook_already_saved();
|
|
||||||
}
|
|
||||||
|
|
||||||
int row = get_highest_row() - 1;
|
|
||||||
|
|
||||||
if(d_->cell_map_.size() != 0)
|
if(d_->cell_map_.size() != 0)
|
||||||
{
|
{
|
||||||
|
|
1067
source/writer.cpp
1067
source/writer.cpp
File diff suppressed because it is too large
Load Diff
|
@ -329,43 +329,6 @@ public:
|
||||||
void runTest() { suite_test_chart.test_write_chart_scatter(); }
|
void runTest() { suite_test_chart.test_write_chart_scatter(); }
|
||||||
} testDescription_suite_test_chart_test_write_chart_scatter;
|
} testDescription_suite_test_chart_test_write_chart_scatter;
|
||||||
|
|
||||||
#include "C:\Users\Thomas\Development\xlnt\tests\test_dump.hpp"
|
|
||||||
|
|
||||||
static test_dump suite_test_dump;
|
|
||||||
|
|
||||||
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 );
|
|
||||||
|
|
||||||
static class TestDescription_suite_test_dump_test_dump_sheet_title : public CxxTest::RealTestDescription {
|
|
||||||
public:
|
|
||||||
TestDescription_suite_test_dump_test_dump_sheet_title() : CxxTest::RealTestDescription( Tests_test_dump, suiteDescription_test_dump, 12, "test_dump_sheet_title" ) {}
|
|
||||||
void runTest() { suite_test_dump.test_dump_sheet_title(); }
|
|
||||||
} testDescription_suite_test_dump_test_dump_sheet_title;
|
|
||||||
|
|
||||||
static class TestDescription_suite_test_dump_test_dump_sheet : public CxxTest::RealTestDescription {
|
|
||||||
public:
|
|
||||||
TestDescription_suite_test_dump_test_dump_sheet() : CxxTest::RealTestDescription( Tests_test_dump, suiteDescription_test_dump, 24, "test_dump_sheet" ) {}
|
|
||||||
void runTest() { suite_test_dump.test_dump_sheet(); }
|
|
||||||
} testDescription_suite_test_dump_test_dump_sheet;
|
|
||||||
|
|
||||||
static class TestDescription_suite_test_dump_test_table_builder : public CxxTest::RealTestDescription {
|
|
||||||
public:
|
|
||||||
TestDescription_suite_test_dump_test_table_builder() : CxxTest::RealTestDescription( Tests_test_dump, suiteDescription_test_dump, 116, "test_table_builder" ) {}
|
|
||||||
void runTest() { suite_test_dump.test_table_builder(); }
|
|
||||||
} testDescription_suite_test_dump_test_table_builder;
|
|
||||||
|
|
||||||
static class TestDescription_suite_test_dump_test_dump_twice : public CxxTest::RealTestDescription {
|
|
||||||
public:
|
|
||||||
TestDescription_suite_test_dump_test_dump_twice() : CxxTest::RealTestDescription( Tests_test_dump, suiteDescription_test_dump, 137, "test_dump_twice" ) {}
|
|
||||||
void runTest() { suite_test_dump.test_dump_twice(); }
|
|
||||||
} testDescription_suite_test_dump_test_dump_twice;
|
|
||||||
|
|
||||||
static class TestDescription_suite_test_dump_test_append_after_save : public CxxTest::RealTestDescription {
|
|
||||||
public:
|
|
||||||
TestDescription_suite_test_dump_test_append_after_save() : CxxTest::RealTestDescription( Tests_test_dump, suiteDescription_test_dump, 153, "test_append_after_save" ) {}
|
|
||||||
void runTest() { suite_test_dump.test_append_after_save(); }
|
|
||||||
} testDescription_suite_test_dump_test_append_after_save;
|
|
||||||
|
|
||||||
#include "C:\Users\Thomas\Development\xlnt\tests\test_named_range.hpp"
|
#include "C:\Users\Thomas\Development\xlnt\tests\test_named_range.hpp"
|
||||||
|
|
||||||
static test_named_range suite_test_named_range;
|
static test_named_range suite_test_named_range;
|
||||||
|
@ -882,125 +845,119 @@ 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( "../../tests/test_workbook.hpp", 10, "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:
|
||||||
TestDescription_suite_test_workbook_test_get_active_sheet() : CxxTest::RealTestDescription( Tests_test_workbook, suiteDescription_test_workbook, 12, "test_get_active_sheet" ) {}
|
TestDescription_suite_test_workbook_test_get_active_sheet() : CxxTest::RealTestDescription( Tests_test_workbook, suiteDescription_test_workbook, 13, "test_get_active_sheet" ) {}
|
||||||
void runTest() { suite_test_workbook.test_get_active_sheet(); }
|
void runTest() { suite_test_workbook.test_get_active_sheet(); }
|
||||||
} testDescription_suite_test_workbook_test_get_active_sheet;
|
} testDescription_suite_test_workbook_test_get_active_sheet;
|
||||||
|
|
||||||
static class TestDescription_suite_test_workbook_test_create_sheet : public CxxTest::RealTestDescription {
|
static class TestDescription_suite_test_workbook_test_create_sheet : public CxxTest::RealTestDescription {
|
||||||
public:
|
public:
|
||||||
TestDescription_suite_test_workbook_test_create_sheet() : CxxTest::RealTestDescription( Tests_test_workbook, suiteDescription_test_workbook, 19, "test_create_sheet" ) {}
|
TestDescription_suite_test_workbook_test_create_sheet() : CxxTest::RealTestDescription( Tests_test_workbook, suiteDescription_test_workbook, 20, "test_create_sheet" ) {}
|
||||||
void runTest() { suite_test_workbook.test_create_sheet(); }
|
void runTest() { suite_test_workbook.test_create_sheet(); }
|
||||||
} testDescription_suite_test_workbook_test_create_sheet;
|
} testDescription_suite_test_workbook_test_create_sheet;
|
||||||
|
|
||||||
static class TestDescription_suite_test_workbook_test_create_sheet_with_name : public CxxTest::RealTestDescription {
|
static class TestDescription_suite_test_workbook_test_create_sheet_with_name : public CxxTest::RealTestDescription {
|
||||||
public:
|
public:
|
||||||
TestDescription_suite_test_workbook_test_create_sheet_with_name() : CxxTest::RealTestDescription( Tests_test_workbook, suiteDescription_test_workbook, 26, "test_create_sheet_with_name" ) {}
|
TestDescription_suite_test_workbook_test_create_sheet_with_name() : CxxTest::RealTestDescription( Tests_test_workbook, suiteDescription_test_workbook, 27, "test_create_sheet_with_name" ) {}
|
||||||
void runTest() { suite_test_workbook.test_create_sheet_with_name(); }
|
void runTest() { suite_test_workbook.test_create_sheet_with_name(); }
|
||||||
} testDescription_suite_test_workbook_test_create_sheet_with_name;
|
} testDescription_suite_test_workbook_test_create_sheet_with_name;
|
||||||
|
|
||||||
static class TestDescription_suite_test_workbook_test_create_sheet_readonly : public CxxTest::RealTestDescription {
|
|
||||||
public:
|
|
||||||
TestDescription_suite_test_workbook_test_create_sheet_readonly() : CxxTest::RealTestDescription( Tests_test_workbook, suiteDescription_test_workbook, 33, "test_create_sheet_readonly" ) {}
|
|
||||||
void runTest() { suite_test_workbook.test_create_sheet_readonly(); }
|
|
||||||
} testDescription_suite_test_workbook_test_create_sheet_readonly;
|
|
||||||
|
|
||||||
static class TestDescription_suite_test_workbook_test_remove_sheet : public CxxTest::RealTestDescription {
|
static class TestDescription_suite_test_workbook_test_remove_sheet : public CxxTest::RealTestDescription {
|
||||||
public:
|
public:
|
||||||
TestDescription_suite_test_workbook_test_remove_sheet() : CxxTest::RealTestDescription( Tests_test_workbook, suiteDescription_test_workbook, 39, "test_remove_sheet" ) {}
|
TestDescription_suite_test_workbook_test_remove_sheet() : CxxTest::RealTestDescription( Tests_test_workbook, suiteDescription_test_workbook, 34, "test_remove_sheet" ) {}
|
||||||
void runTest() { suite_test_workbook.test_remove_sheet(); }
|
void runTest() { suite_test_workbook.test_remove_sheet(); }
|
||||||
} testDescription_suite_test_workbook_test_remove_sheet;
|
} testDescription_suite_test_workbook_test_remove_sheet;
|
||||||
|
|
||||||
static class TestDescription_suite_test_workbook_test_get_sheet_by_name : public CxxTest::RealTestDescription {
|
static class TestDescription_suite_test_workbook_test_get_sheet_by_name : public CxxTest::RealTestDescription {
|
||||||
public:
|
public:
|
||||||
TestDescription_suite_test_workbook_test_get_sheet_by_name() : CxxTest::RealTestDescription( Tests_test_workbook, suiteDescription_test_workbook, 51, "test_get_sheet_by_name" ) {}
|
TestDescription_suite_test_workbook_test_get_sheet_by_name() : CxxTest::RealTestDescription( Tests_test_workbook, suiteDescription_test_workbook, 46, "test_get_sheet_by_name" ) {}
|
||||||
void runTest() { suite_test_workbook.test_get_sheet_by_name(); }
|
void runTest() { suite_test_workbook.test_get_sheet_by_name(); }
|
||||||
} testDescription_suite_test_workbook_test_get_sheet_by_name;
|
} testDescription_suite_test_workbook_test_get_sheet_by_name;
|
||||||
|
|
||||||
static class TestDescription_suite_test_workbook_test_getitem : public CxxTest::RealTestDescription {
|
static class TestDescription_suite_test_workbook_test_getitem : public CxxTest::RealTestDescription {
|
||||||
public:
|
public:
|
||||||
TestDescription_suite_test_workbook_test_getitem() : CxxTest::RealTestDescription( Tests_test_workbook, suiteDescription_test_workbook, 61, "test_getitem" ) {}
|
TestDescription_suite_test_workbook_test_getitem() : CxxTest::RealTestDescription( Tests_test_workbook, suiteDescription_test_workbook, 56, "test_getitem" ) {}
|
||||||
void runTest() { suite_test_workbook.test_getitem(); }
|
void runTest() { suite_test_workbook.test_getitem(); }
|
||||||
} testDescription_suite_test_workbook_test_getitem;
|
} testDescription_suite_test_workbook_test_getitem;
|
||||||
|
|
||||||
static class TestDescription_suite_test_workbook_test_get_index2 : public CxxTest::RealTestDescription {
|
static class TestDescription_suite_test_workbook_test_get_index2 : public CxxTest::RealTestDescription {
|
||||||
public:
|
public:
|
||||||
TestDescription_suite_test_workbook_test_get_index2() : CxxTest::RealTestDescription( Tests_test_workbook, suiteDescription_test_workbook, 73, "test_get_index2" ) {}
|
TestDescription_suite_test_workbook_test_get_index2() : CxxTest::RealTestDescription( Tests_test_workbook, suiteDescription_test_workbook, 68, "test_get_index2" ) {}
|
||||||
void runTest() { suite_test_workbook.test_get_index2(); }
|
void runTest() { suite_test_workbook.test_get_index2(); }
|
||||||
} testDescription_suite_test_workbook_test_get_index2;
|
} testDescription_suite_test_workbook_test_get_index2;
|
||||||
|
|
||||||
static class TestDescription_suite_test_workbook_test_get_sheet_names : public CxxTest::RealTestDescription {
|
static class TestDescription_suite_test_workbook_test_get_sheet_names : public CxxTest::RealTestDescription {
|
||||||
public:
|
public:
|
||||||
TestDescription_suite_test_workbook_test_get_sheet_names() : CxxTest::RealTestDescription( Tests_test_workbook, suiteDescription_test_workbook, 81, "test_get_sheet_names" ) {}
|
TestDescription_suite_test_workbook_test_get_sheet_names() : CxxTest::RealTestDescription( Tests_test_workbook, suiteDescription_test_workbook, 76, "test_get_sheet_names" ) {}
|
||||||
void runTest() { suite_test_workbook.test_get_sheet_names(); }
|
void runTest() { suite_test_workbook.test_get_sheet_names(); }
|
||||||
} testDescription_suite_test_workbook_test_get_sheet_names;
|
} testDescription_suite_test_workbook_test_get_sheet_names;
|
||||||
|
|
||||||
static class TestDescription_suite_test_workbook_test_get_active_sheet2 : public CxxTest::RealTestDescription {
|
static class TestDescription_suite_test_workbook_test_get_active_sheet2 : public CxxTest::RealTestDescription {
|
||||||
public:
|
public:
|
||||||
TestDescription_suite_test_workbook_test_get_active_sheet2() : CxxTest::RealTestDescription( Tests_test_workbook, suiteDescription_test_workbook, 99, "test_get_active_sheet2" ) {}
|
TestDescription_suite_test_workbook_test_get_active_sheet2() : CxxTest::RealTestDescription( Tests_test_workbook, suiteDescription_test_workbook, 94, "test_get_active_sheet2" ) {}
|
||||||
void runTest() { suite_test_workbook.test_get_active_sheet2(); }
|
void runTest() { suite_test_workbook.test_get_active_sheet2(); }
|
||||||
} testDescription_suite_test_workbook_test_get_active_sheet2;
|
} testDescription_suite_test_workbook_test_get_active_sheet2;
|
||||||
|
|
||||||
static class TestDescription_suite_test_workbook_test_create_sheet2 : public CxxTest::RealTestDescription {
|
static class TestDescription_suite_test_workbook_test_create_sheet2 : public CxxTest::RealTestDescription {
|
||||||
public:
|
public:
|
||||||
TestDescription_suite_test_workbook_test_create_sheet2() : CxxTest::RealTestDescription( Tests_test_workbook, suiteDescription_test_workbook, 106, "test_create_sheet2" ) {}
|
TestDescription_suite_test_workbook_test_create_sheet2() : CxxTest::RealTestDescription( Tests_test_workbook, suiteDescription_test_workbook, 101, "test_create_sheet2" ) {}
|
||||||
void runTest() { suite_test_workbook.test_create_sheet2(); }
|
void runTest() { suite_test_workbook.test_create_sheet2(); }
|
||||||
} testDescription_suite_test_workbook_test_create_sheet2;
|
} testDescription_suite_test_workbook_test_create_sheet2;
|
||||||
|
|
||||||
static class TestDescription_suite_test_workbook_test_create_sheet_with_name2 : public CxxTest::RealTestDescription {
|
static class TestDescription_suite_test_workbook_test_create_sheet_with_name2 : public CxxTest::RealTestDescription {
|
||||||
public:
|
public:
|
||||||
TestDescription_suite_test_workbook_test_create_sheet_with_name2() : CxxTest::RealTestDescription( Tests_test_workbook, suiteDescription_test_workbook, 113, "test_create_sheet_with_name2" ) {}
|
TestDescription_suite_test_workbook_test_create_sheet_with_name2() : CxxTest::RealTestDescription( Tests_test_workbook, suiteDescription_test_workbook, 108, "test_create_sheet_with_name2" ) {}
|
||||||
void runTest() { suite_test_workbook.test_create_sheet_with_name2(); }
|
void runTest() { suite_test_workbook.test_create_sheet_with_name2(); }
|
||||||
} testDescription_suite_test_workbook_test_create_sheet_with_name2;
|
} testDescription_suite_test_workbook_test_create_sheet_with_name2;
|
||||||
|
|
||||||
static class TestDescription_suite_test_workbook_test_get_sheet_by_name2 : public CxxTest::RealTestDescription {
|
static class TestDescription_suite_test_workbook_test_get_sheet_by_name2 : public CxxTest::RealTestDescription {
|
||||||
public:
|
public:
|
||||||
TestDescription_suite_test_workbook_test_get_sheet_by_name2() : CxxTest::RealTestDescription( Tests_test_workbook, suiteDescription_test_workbook, 120, "test_get_sheet_by_name2" ) {}
|
TestDescription_suite_test_workbook_test_get_sheet_by_name2() : CxxTest::RealTestDescription( Tests_test_workbook, suiteDescription_test_workbook, 115, "test_get_sheet_by_name2" ) {}
|
||||||
void runTest() { suite_test_workbook.test_get_sheet_by_name2(); }
|
void runTest() { suite_test_workbook.test_get_sheet_by_name2(); }
|
||||||
} testDescription_suite_test_workbook_test_get_sheet_by_name2;
|
} testDescription_suite_test_workbook_test_get_sheet_by_name2;
|
||||||
|
|
||||||
static class TestDescription_suite_test_workbook_test_get_index : public CxxTest::RealTestDescription {
|
static class TestDescription_suite_test_workbook_test_get_index : public CxxTest::RealTestDescription {
|
||||||
public:
|
public:
|
||||||
TestDescription_suite_test_workbook_test_get_index() : CxxTest::RealTestDescription( Tests_test_workbook, suiteDescription_test_workbook, 130, "test_get_index" ) {}
|
TestDescription_suite_test_workbook_test_get_index() : CxxTest::RealTestDescription( Tests_test_workbook, suiteDescription_test_workbook, 125, "test_get_index" ) {}
|
||||||
void runTest() { suite_test_workbook.test_get_index(); }
|
void runTest() { suite_test_workbook.test_get_index(); }
|
||||||
} testDescription_suite_test_workbook_test_get_index;
|
} testDescription_suite_test_workbook_test_get_index;
|
||||||
|
|
||||||
static class TestDescription_suite_test_workbook_test_add_named_range : public CxxTest::RealTestDescription {
|
static class TestDescription_suite_test_workbook_test_add_named_range : public CxxTest::RealTestDescription {
|
||||||
public:
|
public:
|
||||||
TestDescription_suite_test_workbook_test_add_named_range() : CxxTest::RealTestDescription( Tests_test_workbook, suiteDescription_test_workbook, 138, "test_add_named_range" ) {}
|
TestDescription_suite_test_workbook_test_add_named_range() : CxxTest::RealTestDescription( Tests_test_workbook, suiteDescription_test_workbook, 133, "test_add_named_range" ) {}
|
||||||
void runTest() { suite_test_workbook.test_add_named_range(); }
|
void runTest() { suite_test_workbook.test_add_named_range(); }
|
||||||
} testDescription_suite_test_workbook_test_add_named_range;
|
} testDescription_suite_test_workbook_test_add_named_range;
|
||||||
|
|
||||||
static class TestDescription_suite_test_workbook_test_get_named_range2 : public CxxTest::RealTestDescription {
|
static class TestDescription_suite_test_workbook_test_get_named_range2 : public CxxTest::RealTestDescription {
|
||||||
public:
|
public:
|
||||||
TestDescription_suite_test_workbook_test_get_named_range2() : CxxTest::RealTestDescription( Tests_test_workbook, suiteDescription_test_workbook, 147, "test_get_named_range2" ) {}
|
TestDescription_suite_test_workbook_test_get_named_range2() : CxxTest::RealTestDescription( Tests_test_workbook, suiteDescription_test_workbook, 142, "test_get_named_range2" ) {}
|
||||||
void runTest() { suite_test_workbook.test_get_named_range2(); }
|
void runTest() { suite_test_workbook.test_get_named_range2(); }
|
||||||
} testDescription_suite_test_workbook_test_get_named_range2;
|
} testDescription_suite_test_workbook_test_get_named_range2;
|
||||||
|
|
||||||
static class TestDescription_suite_test_workbook_test_remove_named_range : public CxxTest::RealTestDescription {
|
static class TestDescription_suite_test_workbook_test_remove_named_range : public CxxTest::RealTestDescription {
|
||||||
public:
|
public:
|
||||||
TestDescription_suite_test_workbook_test_remove_named_range() : CxxTest::RealTestDescription( Tests_test_workbook, suiteDescription_test_workbook, 157, "test_remove_named_range" ) {}
|
TestDescription_suite_test_workbook_test_remove_named_range() : CxxTest::RealTestDescription( Tests_test_workbook, suiteDescription_test_workbook, 152, "test_remove_named_range" ) {}
|
||||||
void runTest() { suite_test_workbook.test_remove_named_range(); }
|
void runTest() { suite_test_workbook.test_remove_named_range(); }
|
||||||
} testDescription_suite_test_workbook_test_remove_named_range;
|
} testDescription_suite_test_workbook_test_remove_named_range;
|
||||||
|
|
||||||
static class TestDescription_suite_test_workbook_test_add_local_named_range : public CxxTest::RealTestDescription {
|
static class TestDescription_suite_test_workbook_test_add_local_named_range : public CxxTest::RealTestDescription {
|
||||||
public:
|
public:
|
||||||
TestDescription_suite_test_workbook_test_add_local_named_range() : CxxTest::RealTestDescription( Tests_test_workbook, suiteDescription_test_workbook, 167, "test_add_local_named_range" ) {}
|
TestDescription_suite_test_workbook_test_add_local_named_range() : CxxTest::RealTestDescription( Tests_test_workbook, suiteDescription_test_workbook, 162, "test_add_local_named_range" ) {}
|
||||||
void runTest() { suite_test_workbook.test_add_local_named_range(); }
|
void runTest() { suite_test_workbook.test_add_local_named_range(); }
|
||||||
} testDescription_suite_test_workbook_test_add_local_named_range;
|
} testDescription_suite_test_workbook_test_add_local_named_range;
|
||||||
|
|
||||||
static class TestDescription_suite_test_workbook_test_write_regular_date : public CxxTest::RealTestDescription {
|
static class TestDescription_suite_test_workbook_test_write_regular_date : public CxxTest::RealTestDescription {
|
||||||
public:
|
public:
|
||||||
TestDescription_suite_test_workbook_test_write_regular_date() : CxxTest::RealTestDescription( Tests_test_workbook, suiteDescription_test_workbook, 177, "test_write_regular_date" ) {}
|
TestDescription_suite_test_workbook_test_write_regular_date() : CxxTest::RealTestDescription( Tests_test_workbook, suiteDescription_test_workbook, 172, "test_write_regular_date" ) {}
|
||||||
void runTest() { suite_test_workbook.test_write_regular_date(); }
|
void runTest() { suite_test_workbook.test_write_regular_date(); }
|
||||||
} testDescription_suite_test_workbook_test_write_regular_date;
|
} testDescription_suite_test_workbook_test_write_regular_date;
|
||||||
|
|
||||||
static class TestDescription_suite_test_workbook_test_write_regular_float : public CxxTest::RealTestDescription {
|
static class TestDescription_suite_test_workbook_test_write_regular_float : public CxxTest::RealTestDescription {
|
||||||
public:
|
public:
|
||||||
TestDescription_suite_test_workbook_test_write_regular_float() : CxxTest::RealTestDescription( Tests_test_workbook, suiteDescription_test_workbook, 195, "test_write_regular_float" ) {}
|
TestDescription_suite_test_workbook_test_write_regular_float() : CxxTest::RealTestDescription( Tests_test_workbook, suiteDescription_test_workbook, 190, "test_write_regular_float" ) {}
|
||||||
void runTest() { suite_test_workbook.test_write_regular_float(); }
|
void runTest() { suite_test_workbook.test_write_regular_float(); }
|
||||||
} testDescription_suite_test_workbook_test_write_regular_float;
|
} testDescription_suite_test_workbook_test_write_regular_float;
|
||||||
|
|
||||||
|
|
|
@ -1,169 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <cxxtest/TestSuite.h>
|
|
||||||
|
|
||||||
#include "helpers/temporary_file.hpp"
|
|
||||||
#include <xlnt/xlnt.hpp>
|
|
||||||
|
|
||||||
class test_dump : public CxxTest::TestSuite
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
void test_dump_sheet_title()
|
|
||||||
{
|
|
||||||
xlnt::workbook wb(xlnt::optimization::write);
|
|
||||||
auto ws = wb.create_sheet("Test1");
|
|
||||||
wb.save(temp_file.GetFilename());
|
|
||||||
xlnt::workbook wb2;
|
|
||||||
wb2.load(temp_file.GetFilename());
|
|
||||||
ws = wb2.get_sheet_by_name("Test1");
|
|
||||||
TS_ASSERT_DIFFERS(ws, nullptr);
|
|
||||||
TS_ASSERT_EQUALS("Test1", ws.get_title());
|
|
||||||
}
|
|
||||||
|
|
||||||
void test_dump_sheet()
|
|
||||||
{
|
|
||||||
xlnt::workbook wb(xlnt::optimization::write);
|
|
||||||
auto ws = wb.create_sheet("test");
|
|
||||||
|
|
||||||
std::vector<std::string> letters;
|
|
||||||
for(int i = 0; i < 20; i++)
|
|
||||||
{
|
|
||||||
letters.push_back(xlnt::cell_reference::column_string_from_index(i + 1));
|
|
||||||
}
|
|
||||||
|
|
||||||
for(int row = 0; row < 20; row++)
|
|
||||||
{
|
|
||||||
std::vector<std::string> current_row;
|
|
||||||
for(auto letter : letters)
|
|
||||||
{
|
|
||||||
current_row.push_back(letter + std::to_string(row + 1));
|
|
||||||
}
|
|
||||||
ws.append(current_row);
|
|
||||||
}
|
|
||||||
|
|
||||||
for(int row = 0; row < 20; row++)
|
|
||||||
{
|
|
||||||
std::vector<int> current_row;
|
|
||||||
for(auto letter : letters)
|
|
||||||
{
|
|
||||||
current_row.push_back(row + 21);
|
|
||||||
}
|
|
||||||
ws.append(current_row);
|
|
||||||
}
|
|
||||||
|
|
||||||
for(int row = 0; row < 10; row++)
|
|
||||||
{
|
|
||||||
std::vector<xlnt::date> current_row;
|
|
||||||
for(std::size_t x = 0; x < letters.size(); x++)
|
|
||||||
{
|
|
||||||
current_row.push_back(xlnt::date(2010 + (int)x, 5, row + 1));
|
|
||||||
}
|
|
||||||
ws.append(current_row);
|
|
||||||
}
|
|
||||||
|
|
||||||
for(int row = 0; row < 20; row++)
|
|
||||||
{
|
|
||||||
std::vector<std::string> current_row;
|
|
||||||
for(auto letter : letters)
|
|
||||||
{
|
|
||||||
current_row.push_back("=" + letter + std::to_string(row + 51));
|
|
||||||
}
|
|
||||||
ws.append(current_row);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto test_filename = temp_file.GetFilename();
|
|
||||||
wb.save(test_filename);
|
|
||||||
|
|
||||||
xlnt::workbook wb2;
|
|
||||||
wb2.load(test_filename);
|
|
||||||
ws = wb.get_sheet_by_name("test");
|
|
||||||
|
|
||||||
for(auto row : ws.rows())
|
|
||||||
{
|
|
||||||
for(auto cell : row)
|
|
||||||
{
|
|
||||||
auto row_number = cell.get_row();
|
|
||||||
|
|
||||||
if (row_number <= 20)
|
|
||||||
{
|
|
||||||
std::string expected = cell.get_reference().to_string();
|
|
||||||
TS_ASSERT_EQUALS(cell.get_data_type(), xlnt::cell::type::string);
|
|
||||||
TS_ASSERT_EQUALS(cell, expected);
|
|
||||||
}
|
|
||||||
else if (row_number <= 40)
|
|
||||||
{
|
|
||||||
TS_ASSERT_EQUALS(cell.get_data_type(), xlnt::cell::type::numeric);
|
|
||||||
TS_ASSERT_EQUALS(cell, (int)row_number);
|
|
||||||
}
|
|
||||||
else if (row_number <= 50)
|
|
||||||
{
|
|
||||||
xlnt::date expected(2010 + cell.get_reference().get_column_index(), 5, row_number - 40);
|
|
||||||
TS_ASSERT_EQUALS(cell.get_data_type(), xlnt::cell::type::numeric);
|
|
||||||
TS_ASSERT(cell.is_date());
|
|
||||||
TS_ASSERT_EQUALS(cell, expected);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
std::string expected = "=" + cell.get_reference().to_string();
|
|
||||||
TS_ASSERT_EQUALS(cell.get_data_type(), xlnt::cell::type::formula);
|
|
||||||
TS_ASSERT_EQUALS(cell, expected);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void test_table_builder()
|
|
||||||
{
|
|
||||||
static const std::vector<std::pair<std::string, int>> result = {{"a", 0}, {"b", 1}, {"c", 2}, {"d", 3}};
|
|
||||||
xlnt::string_table_builder sb;
|
|
||||||
|
|
||||||
for(auto pair : result)
|
|
||||||
{
|
|
||||||
for(int i = 0; i < 5; i++)
|
|
||||||
{
|
|
||||||
sb.add(pair.first);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
auto table = sb.get_table();
|
|
||||||
|
|
||||||
for(auto pair : result)
|
|
||||||
{
|
|
||||||
TS_ASSERT_EQUALS(pair.second, table[pair.first]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void test_dump_twice()
|
|
||||||
{
|
|
||||||
xlnt::workbook wb(xlnt::optimization::write);
|
|
||||||
auto test_filename = temp_file.GetFilename();
|
|
||||||
|
|
||||||
auto ws = wb.create_sheet();
|
|
||||||
|
|
||||||
std::vector<std::string> to_append = {"hello"};
|
|
||||||
ws.append(to_append);
|
|
||||||
|
|
||||||
wb.save(test_filename);
|
|
||||||
std::remove(test_filename.c_str());
|
|
||||||
|
|
||||||
TS_ASSERT_THROWS(wb.save(test_filename), xlnt::workbook_already_saved);
|
|
||||||
}
|
|
||||||
|
|
||||||
void test_append_after_save()
|
|
||||||
{
|
|
||||||
xlnt::workbook wb(xlnt::optimization::write);
|
|
||||||
auto ws = wb.create_sheet();
|
|
||||||
|
|
||||||
std::vector<std::string> to_append = {"hello"};
|
|
||||||
ws.append(to_append);
|
|
||||||
|
|
||||||
wb.save(temp_file.GetFilename());
|
|
||||||
std::remove(temp_file.GetFilename().c_str());
|
|
||||||
|
|
||||||
TS_ASSERT_THROWS(ws.append(to_append), xlnt::workbook_already_saved);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
TemporaryFile temp_file;
|
|
||||||
};
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include <cxxtest/TestSuite.h>
|
#include <cxxtest/TestSuite.h>
|
||||||
|
|
||||||
#include <xlnt/xlnt.hpp>
|
#include <xlnt/xlnt.hpp>
|
||||||
|
#include "helpers\temporary_file.hpp"
|
||||||
|
|
||||||
class test_workbook : public CxxTest::TestSuite
|
class test_workbook : public CxxTest::TestSuite
|
||||||
{
|
{
|
||||||
|
@ -30,12 +31,6 @@ public:
|
||||||
TS_ASSERT_EQUALS(new_sheet, wb[0]);
|
TS_ASSERT_EQUALS(new_sheet, wb[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_create_sheet_readonly()
|
|
||||||
{
|
|
||||||
xlnt::workbook wb(xlnt::optimization::read);
|
|
||||||
TS_ASSERT_THROWS_ANYTHING(wb.create_sheet());
|
|
||||||
}
|
|
||||||
|
|
||||||
void test_remove_sheet()
|
void test_remove_sheet()
|
||||||
{
|
{
|
||||||
xlnt::workbook wb;
|
xlnt::workbook wb;
|
||||||
|
|
|
@ -51,7 +51,7 @@ public:
|
||||||
void test_write_string_table()
|
void test_write_string_table()
|
||||||
{
|
{
|
||||||
std::vector<std::string> table = {"hello", "world", "nice"};
|
std::vector<std::string> table = {"hello", "world", "nice"};
|
||||||
auto content = xlnt::writer::write_string_table(table);
|
auto content = xlnt::writer::write_shared_strings(table);
|
||||||
TS_ASSERT(Helper::EqualsFileContent(PathHelper::GetDataDirectory() + "/writer/expected/sharedStrings.xml", content));
|
TS_ASSERT(Helper::EqualsFileContent(PathHelper::GetDataDirectory() + "/writer/expected/sharedStrings.xml", content));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,7 +128,7 @@ public:
|
||||||
ws.get_cell("A2") = "test";
|
ws.get_cell("A2") = "test";
|
||||||
ws.get_cell("A2").set_hyperlink("http://test2.com/");
|
ws.get_cell("A2").set_hyperlink("http://test2.com/");
|
||||||
TS_ASSERT_EQUALS(2, ws.get_relationships().size());
|
TS_ASSERT_EQUALS(2, ws.get_relationships().size());
|
||||||
auto content = xlnt::writer::write_worksheet_rels(ws, 1, 1);
|
auto content = xlnt::writer::write_worksheet_rels(ws);
|
||||||
TS_ASSERT(Helper::EqualsFileContent(PathHelper::GetDataDirectory() + "/writer/expected/sheet1_hyperlink.xml.rels", content));
|
TS_ASSERT(Helper::EqualsFileContent(PathHelper::GetDataDirectory() + "/writer/expected/sheet1_hyperlink.xml.rels", content));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user