still fixing things

This commit is contained in:
Thomas Fussell 2014-06-10 17:12:15 -04:00
parent 05e2bf251b
commit 98f2c5f10a
25 changed files with 1486 additions and 956 deletions

View File

@ -20,7 +20,7 @@ project "xlnt.test"
"$(cxxtest_prefix)" "$(cxxtest_prefix)"
} }
files { files {
"../tests/*.h", "../tests/*.hpp",
"../tests/runner-autogen.cpp" "../tests/runner-autogen.cpp"
} }
links { links {
@ -29,7 +29,6 @@ project "xlnt.test"
"zlib" "zlib"
} }
prebuildcommands { "cxxtestgen --runner=ErrorPrinter -o ../../tests/runner-autogen.cpp ../../tests/*.hpp" } prebuildcommands { "cxxtestgen --runner=ErrorPrinter -o ../../tests/runner-autogen.cpp ../../tests/*.hpp" }
postbuildcommands { "../../bin/xlnt.test" }
flags { flags {
"Unicode", "Unicode",
"NoEditAndContinue", "NoEditAndContinue",
@ -44,7 +43,9 @@ project "xlnt.test"
configuration "windows" configuration "windows"
defines { "WIN32" } defines { "WIN32" }
links { "Shlwapi" } links { "Shlwapi" }
postbuildcommands { "..\\..\\bin\\xlnt.test" }
configuration "not windows" configuration "not windows"
postbuildcommands { "../../bin/xlnt.test" }
buildoptions { buildoptions {
"-std=c++11", "-std=c++11",
"-Wno-unknown-pragmas" "-Wno-unknown-pragmas"
@ -69,8 +70,8 @@ project "xlnt"
} }
files { files {
"../source/**.cpp", "../source/**.cpp",
"../source/**.h", "../source/**.hpp",
"../include/xlnt/**.h" "../include/xlnt/**.hpp"
} }
flags { flags {
"Unicode", "Unicode",
@ -81,7 +82,10 @@ project "xlnt"
configuration "Debug" configuration "Debug"
flags { "FatalWarnings" } flags { "FatalWarnings" }
configuration "windows" configuration "windows"
defines { "WIN32" } defines {
"WIN32",
"_CRT_SECURE_NO_WARNINGS"
}
configuration "not windows" configuration "not windows"
buildoptions { buildoptions {
"-std=c++11", "-std=c++11",

View File

@ -33,6 +33,7 @@
namespace xlnt { namespace xlnt {
class cell_reference; class cell_reference;
class relationship;
class worksheet; class worksheet;
struct date; struct date;
@ -94,8 +95,9 @@ public:
bool is_merged() const; bool is_merged() const;
void set_merged(bool merged); void set_merged(bool merged);
std::string get_hyperlink() const; relationship get_hyperlink() const;
void set_hyperlink(const std::string &value); void set_hyperlink(const std::string &value);
bool has_hyperlink() const;
void set_number_format(const std::string &format_code); void set_number_format(const std::string &format_code);
@ -128,6 +130,7 @@ public:
cell &operator=(int value); cell &operator=(int value);
cell &operator=(double value); cell &operator=(double value);
cell &operator=(long int value); cell &operator=(long int value);
cell &operator=(long long value);
cell &operator=(long double value); cell &operator=(long double value);
cell &operator=(const std::string &value); cell &operator=(const std::string &value);
cell &operator=(const char *value); cell &operator=(const char *value);

View File

@ -48,6 +48,7 @@ enum class target_mode
class relationship class relationship
{ {
public: public:
relationship();
relationship(const std::string &type, const std::string &r_id = "", const std::string &target_uri = ""); relationship(const std::string &type, const std::string &r_id = "", const std::string &target_uri = "");
/// <summary> /// <summary>

View File

@ -88,12 +88,14 @@ public:
int get_index(worksheet worksheet); int get_index(worksheet worksheet);
worksheet operator[](const std::string &name); worksheet operator[](const std::string &name);
worksheet operator[](int index); worksheet operator[](std::size_t index);
class iterator class iterator
{ {
public: public:
iterator(workbook &wb, std::size_t index); iterator(workbook &wb, std::size_t index);
iterator(const iterator &);
iterator &operator=(const iterator &);
worksheet operator*(); worksheet operator*();
bool operator==(const iterator &comparand) const; bool operator==(const iterator &comparand) const;
bool operator!=(const iterator &comparand) const { return !(*this == comparand); } bool operator!=(const iterator &comparand) const { return !(*this == comparand); }
@ -112,6 +114,8 @@ public:
{ {
public: public:
const_iterator(const workbook &wb, std::size_t index); const_iterator(const workbook &wb, std::size_t index);
const_iterator(const const_iterator &);
const_iterator &operator=(const const_iterator &);
const worksheet operator*(); const worksheet operator*();
bool operator==(const const_iterator &comparand) const; bool operator==(const const_iterator &comparand) const;
bool operator!=(const const_iterator &comparand) const { return !(*this == comparand); } bool operator!=(const const_iterator &comparand) const { return !(*this == comparand); }
@ -150,6 +154,7 @@ public:
private: private:
friend class worksheet; friend class worksheet;
bool get_already_saved() const;
detail::workbook_impl *d_; detail::workbook_impl *d_;
}; };

View File

@ -49,9 +49,9 @@ struct worksheet_impl;
class row_properties class row_properties
{ {
public: public:
void set_height(int height) { this->height = height; } void set_height(double height) { this->height = height; }
int row_index; int row_index;
int height; double height;
bool visible; bool visible;
int outline_level; int outline_level;
bool collapsed; bool collapsed;
@ -183,6 +183,7 @@ public:
const range get_range(const range_reference &reference) const; const range get_range(const range_reference &reference) const;
row_properties &get_row_properties(row_t row); row_properties &get_row_properties(row_t row);
const row_properties &get_row_properties(row_t row) const; const row_properties &get_row_properties(row_t row) const;
bool has_row_properties(row_t row) const;
range rows() const; range rows() const;
range columns() const; range columns() const;
std::list<cell> get_cell_collection(); std::list<cell> get_cell_collection();

View File

@ -37,6 +37,8 @@ class style_writer
{ {
public: public:
style_writer(workbook &wb); style_writer(workbook &wb);
style_writer(const style_writer &);
style_writer &operator=(const style_writer &);
std::unordered_map<std::size_t, std::string> get_style_by_hash() const; std::unordered_map<std::size_t, std::string> get_style_by_hash() const;
std::string write_table() const; std::string write_table() const;

View File

@ -42,7 +42,7 @@ public:
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::vector<std::pair<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 drawing_id, int comments_id);
static std::string write_string_table(const std::vector<std::string> &string_table); static std::string write_string_table(const std::vector<std::string> &string_table);
}; };

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::floor(d_->numeric_value) == d_->numeric_value ? std::to_string((int)d_->numeric_value) : std::to_string(d_->numeric_value); return std::floor(d_->numeric_value) == d_->numeric_value ? std::to_string((long long)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:
@ -247,7 +247,7 @@ bool cell::operator==(double comparand) const
bool cell::operator==(const std::string &comparand) const bool cell::operator==(const std::string &comparand) const
{ {
if(d_->type_ == type::string) if(d_->type_ == type::string || d_->type_ == type::formula)
{ {
return d_->string_value == comparand; return d_->string_value == comparand;
} }
@ -357,6 +357,14 @@ cell &cell::operator=(long int value)
return *this; return *this;
} }
cell &cell::operator=(long long value)
{
d_->is_date_ = false;
d_->type_ = type::numeric;
d_->numeric_value = (long double)value;
return *this;
}
cell &cell::operator=(long double value) cell &cell::operator=(long double value)
{ {
d_->is_date_ = false; d_->is_date_ = false;
@ -446,9 +454,19 @@ std::string cell::to_string() const
return "<Cell " + worksheet(d_->parent_).get_title() + "." + get_reference().to_string() + ">"; return "<Cell " + worksheet(d_->parent_).get_title() + "." + get_reference().to_string() + ">";
} }
std::string cell::get_hyperlink() const relationship cell::get_hyperlink() const
{ {
return ""; if(!d_->has_hyperlink_)
{
throw std::runtime_error("no hyperlink set");
}
return d_->hyperlink_;
}
bool cell::has_hyperlink() const
{
return d_->has_hyperlink_;
} }
void cell::set_hyperlink(const std::string &hyperlink) void cell::set_hyperlink(const std::string &hyperlink)
@ -457,9 +475,15 @@ std::string cell::to_string() const
{ {
throw data_type_exception(); throw data_type_exception();
} }
d_->hyperlink_ = hyperlink;
d_->has_hyperlink_ = true;
d_->hyperlink_ = worksheet(d_->parent_).create_relationship("hyperlink", hyperlink);
if(d_->type_ == type::null)
{
*this = hyperlink; *this = hyperlink;
} }
}
void cell::set_null() void cell::set_null()
{ {
@ -472,6 +496,7 @@ std::string cell::to_string() const
{ {
throw data_type_exception(); throw data_type_exception();
} }
d_->type_ = type::formula; d_->type_ = type::formula;
d_->string_value = formula; d_->string_value = formula;
} }
@ -482,6 +507,7 @@ std::string cell::to_string() const
{ {
throw data_type_exception(); throw data_type_exception();
} }
d_->type_ = type::error; d_->type_ = type::error;
d_->string_value = error; d_->string_value = error;
} }

View File

@ -8,7 +8,7 @@ namespace xlnt {
time::time(long double raw_time) : hour(0), minute(0), second(0), microsecond(0) time::time(long double raw_time) : hour(0), minute(0), second(0), microsecond(0)
{ {
double integer_part; double integer_part;
double fractional_part = std::modf(raw_time, &integer_part); double fractional_part = std::modf((double)raw_time, &integer_part);
fractional_part *= 24; fractional_part *= 24;
hour = (int)fractional_part; hour = (int)fractional_part;
fractional_part = 60 * (fractional_part - hour); fractional_part = 60 * (fractional_part - hour);

View File

@ -4,11 +4,11 @@
namespace xlnt { namespace xlnt {
namespace detail { namespace detail {
cell_impl::cell_impl() : parent_(nullptr), type_(cell::type::null), column(0), row(0), style_(nullptr) cell_impl::cell_impl() : parent_(nullptr), type_(cell::type::null), column(0), row(0), style_(nullptr), merged(false)
{ {
} }
cell_impl::cell_impl(worksheet_impl *parent, int column_index, int row_index) : parent_(parent), type_(cell::type::null), column(column_index), row(row_index), style_(nullptr) cell_impl::cell_impl(worksheet_impl *parent, int column_index, int row_index) : parent_(parent), type_(cell::type::null), column(column_index), row(row_index), style_(nullptr), merged(false)
{ {
} }

View File

@ -21,7 +21,8 @@ struct cell_impl
cell::type type_; cell::type type_;
long double numeric_value; long double numeric_value;
std::string string_value; std::string string_value;
std::string hyperlink_; bool has_hyperlink_;
relationship hyperlink_;
column_t column; column_t column;
row_t row; row_t row;
bool merged; bool merged;

View File

@ -8,6 +8,7 @@ namespace detail {
struct workbook_impl struct workbook_impl
{ {
workbook_impl(optimization o); workbook_impl(optimization o);
bool already_saved_;
bool optimized_read_; bool optimized_read_;
bool optimized_write_; bool optimized_write_;
bool guess_types_; bool guess_types_;

View File

@ -32,4 +32,10 @@ cell_coordinates_exception::cell_coordinates_exception(const std::string &coord_
} }
workbook_already_saved::workbook_already_saved()
: std::runtime_error("")
{
}
} // namespace xlnt } // namespace xlnt

View File

@ -24,7 +24,7 @@ std::unordered_map<std::string, std::pair<std::string, std::string>> reader::rea
std::string id = relationship.attribute("Id").as_string(); std::string id = relationship.attribute("Id").as_string();
std::string type = relationship.attribute("Type").as_string(); std::string type = relationship.attribute("Type").as_string();
std::string target = relationship.attribute("Target").as_string(); std::string target = relationship.attribute("Target").as_string();
relationships[id] = std::make_pair(type, target); relationships[id] = std::make_pair(target, type);
} }
return relationships; return relationships;
@ -59,12 +59,12 @@ std::string reader::determine_document_type(const std::unordered_map<std::string
{ {
auto relationship_match = std::find_if(root_relationships.begin(), root_relationships.end(), auto relationship_match = std::find_if(root_relationships.begin(), root_relationships.end(),
[](const std::pair<std::string, std::pair<std::string, std::string>> &v) [](const std::pair<std::string, std::pair<std::string, std::string>> &v)
{ return v.second.first == "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument"; }); { return v.second.second == "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument"; });
std::string type; std::string type;
if(relationship_match != root_relationships.end()) if(relationship_match != root_relationships.end())
{ {
std::string office_document_relationship = relationship_match->second.second; std::string office_document_relationship = relationship_match->second.first;
if(office_document_relationship[0] != '/') if(office_document_relationship[0] != '/')
{ {

View File

@ -11,4 +11,8 @@ relationship::relationship(const std::string &t, const std::string &r_id, const
} }
} }
relationship::relationship() : id_(""), source_uri_(""), target_uri_("")
{
}
} // namespace xlnt } // namespace xlnt

View File

@ -1,8 +1,11 @@
#include <algorithm> #include <algorithm>
#include <array>
#include <fstream> #include <fstream>
#include <sstream> #include <sstream>
#include <pugixml.hpp> #include <pugixml.hpp>
#include <Windows.h>
#include "workbook/workbook.hpp" #include "workbook/workbook.hpp"
#include "common/exceptions.hpp" #include "common/exceptions.hpp"
#include "drawing/drawing.hpp" #include "drawing/drawing.hpp"
@ -16,9 +19,29 @@
#include "detail/workbook_impl.hpp" #include "detail/workbook_impl.hpp"
#include "detail/worksheet_impl.hpp" #include "detail/worksheet_impl.hpp"
static std::string CreateTemporaryFilename()
{
#ifdef _WIN32
std::array<TCHAR, MAX_PATH> buffer;
DWORD result = GetTempPath(static_cast<DWORD>(buffer.size()), buffer.data());
if(result > MAX_PATH)
{
throw std::runtime_error("buffer is too small");
}
if(result == 0)
{
throw std::runtime_error("GetTempPath failed");
}
std::string directory(buffer.begin(), buffer.begin() + result);
return directory + "xlnt.xlsx";
#else
return "/tmp/xlsx.xlnt";
#endif
}
namespace xlnt { namespace xlnt {
namespace detail { namespace detail {
workbook_impl::workbook_impl(optimization o) : optimized_read_(o == optimization::read), optimized_write_(o == optimization::write), active_sheet_index_(0) workbook_impl::workbook_impl(optimization o) : already_saved_(false), optimized_read_(o == optimization::read), optimized_write_(o == optimization::write), active_sheet_index_(0)
{ {
} }
@ -42,6 +65,11 @@ workbook::iterator::iterator(workbook &wb, std::size_t index) : wb_(wb), index_(
} }
workbook::iterator::iterator(const iterator &rhs) : wb_(rhs.wb_), index_(rhs.index_)
{
}
worksheet workbook::iterator::operator*() worksheet workbook::iterator::operator*()
{ {
return wb_[index_]; return wb_[index_];
@ -70,6 +98,11 @@ workbook::const_iterator::const_iterator(const workbook &wb, std::size_t index)
} }
workbook::const_iterator::const_iterator(const const_iterator &rhs) : wb_(rhs.wb_), index_(rhs.index_)
{
}
const worksheet workbook::const_iterator::operator*() const worksheet workbook::const_iterator::operator*()
{ {
return wb_.get_sheet_by_index(index_); return wb_.get_sheet_by_index(index_);
@ -121,6 +154,11 @@ 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)
@ -150,7 +188,6 @@ worksheet workbook::create_sheet()
d_->worksheets_.emplace_back(this, title); d_->worksheets_.emplace_back(this, title);
worksheet ws(&d_->worksheets_.back()); worksheet ws(&d_->worksheets_.back());
ws.get_cell("A1");
return ws; return ws;
} }
@ -233,13 +270,17 @@ range workbook::get_named_range(const std::string &name)
bool workbook::load(const std::vector<unsigned char> &data) bool workbook::load(const std::vector<unsigned char> &data)
{ {
std::string temp_file = CreateTemporaryFilename();
std::ofstream tmp; std::ofstream tmp;
tmp.open("/tmp/xlnt.xlsx", std::ios::out); tmp.open(temp_file, std::ios::out | std::ios::binary);
for(auto c : data) for(auto c : data)
{ {
tmp.put(c); tmp.put(c);
} }
load("/tmp/xlnt.xlsx"); tmp.close();
load(temp_file);
std::remove(temp_file.c_str());
return true; return true;
} }
@ -279,7 +320,7 @@ bool workbook::load(const std::string &filename)
auto relation_id = sheet_node.attribute("r:id").as_string(); auto relation_id = sheet_node.attribute("r:id").as_string();
auto ws = create_sheet(sheet_node.attribute("name").as_string()); auto ws = create_sheet(sheet_node.attribute("name").as_string());
std::string sheet_filename("xl/"); std::string sheet_filename("xl/");
sheet_filename += workbook_relationships[relation_id].second; sheet_filename += workbook_relationships[relation_id].first;
xlnt::reader::read_worksheet(ws, f.get_file_contents(sheet_filename).c_str(), shared_strings); xlnt::reader::read_worksheet(ws, f.get_file_contents(sheet_filename).c_str(), shared_strings);
} }
@ -380,7 +421,7 @@ worksheet workbook::operator[](const std::string &name)
return get_sheet_by_name(name); return get_sheet_by_name(name);
} }
worksheet workbook::operator[](int index) worksheet workbook::operator[](std::size_t index)
{ {
return worksheet(&d_->worksheets_[index]); return worksheet(&d_->worksheets_[index]);
} }
@ -390,20 +431,38 @@ 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)
{ {
save("/tmp/xlnt.xlsx"); auto temp_file = CreateTemporaryFilename();
save(temp_file);
std::ifstream tmp; std::ifstream tmp;
tmp.open("/tmp/xlnt.xlsx"); tmp.open(temp_file, std::ios::in | std::ios::binary);
auto char_data = std::vector<char>((std::istreambuf_iterator<char>(tmp)), auto char_data = std::vector<char>((std::istreambuf_iterator<char>(tmp)),
std::istreambuf_iterator<char>()); std::istreambuf_iterator<char>());
data = std::vector<unsigned char>(char_data.begin(), char_data.end()); data = std::vector<unsigned char>(char_data.begin(), char_data.end());
tmp.close();
std::remove(temp_file.c_str());
return true; return true;
} }
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 = std::pair<std::unordered_map<std::string, std::string>, std::unordered_map<std::string, std::string>> content_types =
@ -426,17 +485,17 @@ bool workbook::save(const std::string &filename)
std::vector<std::pair<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", {"docProps/app.xml", "http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties"}},
{"rId2", {"http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties", "docProps/core.xml"}}, {"rId2", {"docProps/core.xml", "http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties"}},
{"rId1", {"http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument", "xl/workbook.xml"}} {"rId1", {"xl/workbook.xml", "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument"}}
}; };
f.set_file_contents("_rels/.rels", writer::write_relationships(root_rels)); 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 = 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", {"worksheets/sheet1.xml", "http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet"}},
{"rId2", {"http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles", "styles.xml"}}, {"rId2", {"styles.xml", "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles"}},
{"rId3", {"http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme", "theme/theme1.xml"}} {"rId3", {"theme/theme1.xml", "http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme"}}
}; };
f.set_file_contents("xl/_rels/workbook.xml.rels", writer::write_relationships(workbook_rels)); f.set_file_contents("xl/_rels/workbook.xml.rels", writer::write_relationships(workbook_rels));

View File

@ -8,6 +8,7 @@
#include "common/relationship.hpp" #include "common/relationship.hpp"
#include "workbook/workbook.hpp" #include "workbook/workbook.hpp"
#include "detail/worksheet_impl.hpp" #include "detail/worksheet_impl.hpp"
#include "common/exceptions.hpp"
namespace xlnt { namespace xlnt {
@ -193,6 +194,11 @@ row_properties &worksheet::get_row_properties(row_t row)
return d_->row_properties_[row]; return d_->row_properties_[row];
} }
bool worksheet::has_row_properties(row_t row) const
{
return d_->row_properties_.find(row) != d_->row_properties_.end();
}
range worksheet::get_named_range(const std::string &name) range worksheet::get_named_range(const std::string &name)
{ {
if(!has_named_range(name)) if(!has_named_range(name))
@ -341,6 +347,11 @@ 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)
@ -358,6 +369,11 @@ 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)
@ -375,6 +391,11 @@ 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)
@ -392,6 +413,11 @@ 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())
{
throw workbook_already_saved();
}
int row = get_highest_row() - 1; int row = get_highest_row() - 1;
if(d_->cell_map_.size() != 0) if(d_->cell_map_.size() != 0)
@ -407,6 +433,11 @@ 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())
{
throw workbook_already_saved();
}
int row = get_highest_row() - 1; int row = get_highest_row() - 1;
if(d_->cell_map_.size() != 0) if(d_->cell_map_.size() != 0)

File diff suppressed because it is too large Load Diff

View File

@ -59,7 +59,7 @@ public:
#elif defined(_WIN32) #elif defined(_WIN32)
std::array<TCHAR, MAX_PATH> buffer; std::array<TCHAR, MAX_PATH> buffer;
DWORD result = GetModuleFileName(nullptr, buffer.data(), buffer.size()); DWORD result = GetModuleFileName(nullptr, buffer.data(), (DWORD)buffer.size());
if(result == 0 || result == buffer.size()) if(result == 0 || result == buffer.size())
{ {

View File

@ -21,12 +21,12 @@ int main( int argc, char *argv[] ) {
return status; return status;
} }
bool suite_test_cell_init = false; bool suite_test_cell_init = false;
#include "/Users/thomas/Development/xlnt/tests/test_cell.hpp" #include "C:\Users\taf656\Development\xlnt\tests\test_cell.hpp"
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( "/Users/thomas/Development/xlnt/tests/test_cell.hpp", 9, "test_cell", suite_test_cell, Tests_test_cell ); CxxTest::StaticSuiteDescription suiteDescription_test_cell( "../../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:
@ -184,12 +184,12 @@ public:
void runTest() { suite_test_cell.test_is_not_date_color_format(); } void runTest() { suite_test_cell.test_is_not_date_color_format(); }
} testDescription_suite_test_cell_test_is_not_date_color_format; } testDescription_suite_test_cell_test_is_not_date_color_format;
#include "/Users/thomas/Development/xlnt/tests/test_chart.hpp" #include "C:\Users\taf656\Development\xlnt\tests\test_chart.hpp"
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( "/Users/thomas/Development/xlnt/tests/test_chart.hpp", 8, "test_chart", suite_test_chart, Tests_test_chart ); CxxTest::StaticSuiteDescription suiteDescription_test_chart( "../../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:
@ -275,49 +275,49 @@ 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 "/Users/thomas/Development/xlnt/tests/test_dump.hpp" #include "C:\Users\taf656\Development\xlnt\tests\test_dump.hpp"
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( "/Users/thomas/Development/xlnt/tests/test_dump.hpp", 9, "test_dump", suite_test_dump, Tests_test_dump ); 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 { static class TestDescription_suite_test_dump_test_dump_sheet_title : public CxxTest::RealTestDescription {
public: public:
TestDescription_suite_test_dump_test_dump_sheet_title() : CxxTest::RealTestDescription( Tests_test_dump, suiteDescription_test_dump, 17, "test_dump_sheet_title" ) {} 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(); } void runTest() { suite_test_dump.test_dump_sheet_title(); }
} testDescription_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 { static class TestDescription_suite_test_dump_test_dump_sheet : public CxxTest::RealTestDescription {
public: public:
TestDescription_suite_test_dump_test_dump_sheet() : CxxTest::RealTestDescription( Tests_test_dump, suiteDescription_test_dump, 28, "test_dump_sheet" ) {} 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(); } void runTest() { suite_test_dump.test_dump_sheet(); }
} testDescription_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 { static class TestDescription_suite_test_dump_test_table_builder : public CxxTest::RealTestDescription {
public: public:
TestDescription_suite_test_dump_test_table_builder() : CxxTest::RealTestDescription( Tests_test_dump, suiteDescription_test_dump, 120, "test_table_builder" ) {} 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(); } void runTest() { suite_test_dump.test_table_builder(); }
} testDescription_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 { static class TestDescription_suite_test_dump_test_dump_twice : public CxxTest::RealTestDescription {
public: public:
TestDescription_suite_test_dump_test_dump_twice() : CxxTest::RealTestDescription( Tests_test_dump, suiteDescription_test_dump, 141, "test_dump_twice" ) {} 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(); } void runTest() { suite_test_dump.test_dump_twice(); }
} testDescription_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 { static class TestDescription_suite_test_dump_test_append_after_save : public CxxTest::RealTestDescription {
public: public:
TestDescription_suite_test_dump_test_append_after_save() : CxxTest::RealTestDescription( Tests_test_dump, suiteDescription_test_dump, 156, "test_append_after_save" ) {} 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(); } void runTest() { suite_test_dump.test_append_after_save(); }
} testDescription_suite_test_dump_test_append_after_save; } testDescription_suite_test_dump_test_append_after_save;
#include "/Users/thomas/Development/xlnt/tests/test_named_range.hpp" #include "C:\Users\taf656\Development\xlnt\tests\test_named_range.hpp"
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( "/Users/thomas/Development/xlnt/tests/test_named_range.hpp", 8, "test_named_range", suite_test_named_range, Tests_test_named_range ); CxxTest::StaticSuiteDescription suiteDescription_test_named_range( "../../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:
@ -403,12 +403,12 @@ public:
void runTest() { suite_test_named_range.test_can_be_saved(); } void runTest() { suite_test_named_range.test_can_be_saved(); }
} testDescription_suite_test_named_range_test_can_be_saved; } testDescription_suite_test_named_range_test_can_be_saved;
#include "/Users/thomas/Development/xlnt/tests/test_number_format.hpp" #include "C:\Users\taf656\Development\xlnt\tests\test_number_format.hpp"
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( "/Users/thomas/Development/xlnt/tests/test_number_format.hpp", 8, "test_number_format", suite_test_number_format, Tests_test_number_format ); CxxTest::StaticSuiteDescription suiteDescription_test_number_format( "../../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:
@ -506,12 +506,12 @@ public:
void runTest() { suite_test_number_format.test_mac_date(); } void runTest() { suite_test_number_format.test_mac_date(); }
} testDescription_suite_test_number_format_test_mac_date; } testDescription_suite_test_number_format_test_mac_date;
#include "/Users/thomas/Development/xlnt/tests/test_props.hpp" #include "C:\Users\taf656\Development\xlnt\tests\test_props.hpp"
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( "/Users/thomas/Development/xlnt/tests/test_props.hpp", 8, "test_props", suite_test_props, Tests_test_props ); CxxTest::StaticSuiteDescription suiteDescription_test_props( "../../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:
@ -549,12 +549,12 @@ public:
void runTest() { suite_test_props.test_write_properties_app(); } void runTest() { suite_test_props.test_write_properties_app(); }
} testDescription_suite_test_props_test_write_properties_app; } testDescription_suite_test_props_test_write_properties_app;
#include "/Users/thomas/Development/xlnt/tests/test_read.hpp" #include "C:\Users\taf656\Development\xlnt\tests\test_read.hpp"
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( "/Users/thomas/Development/xlnt/tests/test_read.hpp", 10, "test_read", suite_test_read, Tests_test_read ); CxxTest::StaticSuiteDescription suiteDescription_test_read( "../../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:
@ -682,12 +682,12 @@ public:
void runTest() { suite_test_read.test_read_date_value(); } void runTest() { suite_test_read.test_read_date_value(); }
} testDescription_suite_test_read_test_read_date_value; } testDescription_suite_test_read_test_read_date_value;
#include "/Users/thomas/Development/xlnt/tests/test_strings.hpp" #include "C:\Users\taf656\Development\xlnt\tests\test_strings.hpp"
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( "/Users/thomas/Development/xlnt/tests/test_strings.hpp", 8, "test_strings", suite_test_strings, Tests_test_strings ); CxxTest::StaticSuiteDescription suiteDescription_test_strings( "../../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:
@ -713,12 +713,12 @@ public:
void runTest() { suite_test_strings.test_formatted_string_table(); } void runTest() { suite_test_strings.test_formatted_string_table(); }
} testDescription_suite_test_strings_test_formatted_string_table; } testDescription_suite_test_strings_test_formatted_string_table;
#include "/Users/thomas/Development/xlnt/tests/test_style.hpp" #include "C:\Users\taf656\Development\xlnt\tests\test_style.hpp"
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( "/Users/thomas/Development/xlnt/tests/test_style.hpp", 8, "test_style", suite_test_style, Tests_test_style ); CxxTest::StaticSuiteDescription suiteDescription_test_style( "../../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:
@ -810,25 +810,25 @@ public:
void runTest() { suite_test_style.test_read_cell_style(); } void runTest() { suite_test_style.test_read_cell_style(); }
} testDescription_suite_test_style_test_read_cell_style; } testDescription_suite_test_style_test_read_cell_style;
#include "/Users/thomas/Development/xlnt/tests/test_theme.hpp" #include "C:\Users\taf656\Development\xlnt\tests\test_theme.hpp"
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( "/Users/thomas/Development/xlnt/tests/test_theme.hpp", 9, "test_theme", suite_test_theme, Tests_test_theme ); CxxTest::StaticSuiteDescription suiteDescription_test_theme( "../../tests/test_theme.hpp", 10, "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:
TestDescription_suite_test_theme_test_write_theme() : CxxTest::RealTestDescription( Tests_test_theme, suiteDescription_test_theme, 12, "test_write_theme" ) {} TestDescription_suite_test_theme_test_write_theme() : CxxTest::RealTestDescription( Tests_test_theme, suiteDescription_test_theme, 13, "test_write_theme" ) {}
void runTest() { suite_test_theme.test_write_theme(); } void runTest() { suite_test_theme.test_write_theme(); }
} testDescription_suite_test_theme_test_write_theme; } testDescription_suite_test_theme_test_write_theme;
#include "/Users/thomas/Development/xlnt/tests/test_workbook.hpp" #include "C:\Users\taf656\Development\xlnt\tests\test_workbook.hpp"
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( "/Users/thomas/Development/xlnt/tests/test_workbook.hpp", 9, "test_workbook", suite_test_workbook, Tests_test_workbook ); CxxTest::StaticSuiteDescription suiteDescription_test_workbook( "../../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:
@ -950,12 +950,12 @@ public:
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;
#include "/Users/thomas/Development/xlnt/tests/test_worksheet.hpp" #include "C:\Users\taf656\Development\xlnt\tests\test_worksheet.hpp"
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( "/Users/thomas/Development/xlnt/tests/test_worksheet.hpp", 9, "test_worksheet", suite_test_worksheet, Tests_test_worksheet ); CxxTest::StaticSuiteDescription suiteDescription_test_worksheet( "../../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:
@ -1055,76 +1055,76 @@ public:
static class TestDescription_suite_test_worksheet_test_bad_relationship_type : public CxxTest::RealTestDescription { static class TestDescription_suite_test_worksheet_test_bad_relationship_type : public CxxTest::RealTestDescription {
public: public:
TestDescription_suite_test_worksheet_test_bad_relationship_type() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 168, "test_bad_relationship_type" ) {} TestDescription_suite_test_worksheet_test_bad_relationship_type() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 167, "test_bad_relationship_type" ) {}
void runTest() { suite_test_worksheet.test_bad_relationship_type(); } void runTest() { suite_test_worksheet.test_bad_relationship_type(); }
} testDescription_suite_test_worksheet_test_bad_relationship_type; } testDescription_suite_test_worksheet_test_bad_relationship_type;
static class TestDescription_suite_test_worksheet_test_append_list : public CxxTest::RealTestDescription { static class TestDescription_suite_test_worksheet_test_append_list : public CxxTest::RealTestDescription {
public: public:
TestDescription_suite_test_worksheet_test_append_list() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 173, "test_append_list" ) {} TestDescription_suite_test_worksheet_test_append_list() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 172, "test_append_list" ) {}
void runTest() { suite_test_worksheet.test_append_list(); } void runTest() { suite_test_worksheet.test_append_list(); }
} testDescription_suite_test_worksheet_test_append_list; } testDescription_suite_test_worksheet_test_append_list;
static class TestDescription_suite_test_worksheet_test_append_dict_letter : public CxxTest::RealTestDescription { static class TestDescription_suite_test_worksheet_test_append_dict_letter : public CxxTest::RealTestDescription {
public: public:
TestDescription_suite_test_worksheet_test_append_dict_letter() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 183, "test_append_dict_letter" ) {} TestDescription_suite_test_worksheet_test_append_dict_letter() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 182, "test_append_dict_letter" ) {}
void runTest() { suite_test_worksheet.test_append_dict_letter(); } void runTest() { suite_test_worksheet.test_append_dict_letter(); }
} testDescription_suite_test_worksheet_test_append_dict_letter; } testDescription_suite_test_worksheet_test_append_dict_letter;
static class TestDescription_suite_test_worksheet_test_append_dict_index : public CxxTest::RealTestDescription { static class TestDescription_suite_test_worksheet_test_append_dict_index : public CxxTest::RealTestDescription {
public: public:
TestDescription_suite_test_worksheet_test_append_dict_index() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 193, "test_append_dict_index" ) {} TestDescription_suite_test_worksheet_test_append_dict_index() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 192, "test_append_dict_index" ) {}
void runTest() { suite_test_worksheet.test_append_dict_index(); } void runTest() { suite_test_worksheet.test_append_dict_index(); }
} testDescription_suite_test_worksheet_test_append_dict_index; } testDescription_suite_test_worksheet_test_append_dict_index;
static class TestDescription_suite_test_worksheet_test_append_2d_list : public CxxTest::RealTestDescription { static class TestDescription_suite_test_worksheet_test_append_2d_list : public CxxTest::RealTestDescription {
public: public:
TestDescription_suite_test_worksheet_test_append_2d_list() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 203, "test_append_2d_list" ) {} TestDescription_suite_test_worksheet_test_append_2d_list() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 202, "test_append_2d_list" ) {}
void runTest() { suite_test_worksheet.test_append_2d_list(); } void runTest() { suite_test_worksheet.test_append_2d_list(); }
} testDescription_suite_test_worksheet_test_append_2d_list; } testDescription_suite_test_worksheet_test_append_2d_list;
static class TestDescription_suite_test_worksheet_test_rows : public CxxTest::RealTestDescription { static class TestDescription_suite_test_worksheet_test_rows : public CxxTest::RealTestDescription {
public: public:
TestDescription_suite_test_worksheet_test_rows() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 218, "test_rows" ) {} TestDescription_suite_test_worksheet_test_rows() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 217, "test_rows" ) {}
void runTest() { suite_test_worksheet.test_rows(); } void runTest() { suite_test_worksheet.test_rows(); }
} testDescription_suite_test_worksheet_test_rows; } testDescription_suite_test_worksheet_test_rows;
static class TestDescription_suite_test_worksheet_test_auto_filter : public CxxTest::RealTestDescription { static class TestDescription_suite_test_worksheet_test_auto_filter : public CxxTest::RealTestDescription {
public: public:
TestDescription_suite_test_worksheet_test_auto_filter() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 233, "test_auto_filter" ) {} TestDescription_suite_test_worksheet_test_auto_filter() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 232, "test_auto_filter" ) {}
void runTest() { suite_test_worksheet.test_auto_filter(); } void runTest() { suite_test_worksheet.test_auto_filter(); }
} testDescription_suite_test_worksheet_test_auto_filter; } testDescription_suite_test_worksheet_test_auto_filter;
static class TestDescription_suite_test_worksheet_test_page_margins : public CxxTest::RealTestDescription { static class TestDescription_suite_test_worksheet_test_page_margins : public CxxTest::RealTestDescription {
public: public:
TestDescription_suite_test_worksheet_test_page_margins() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 247, "test_page_margins" ) {} TestDescription_suite_test_worksheet_test_page_margins() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 246, "test_page_margins" ) {}
void runTest() { suite_test_worksheet.test_page_margins(); } void runTest() { suite_test_worksheet.test_page_margins(); }
} testDescription_suite_test_worksheet_test_page_margins; } testDescription_suite_test_worksheet_test_page_margins;
static class TestDescription_suite_test_worksheet_test_merge : public CxxTest::RealTestDescription { static class TestDescription_suite_test_worksheet_test_merge : public CxxTest::RealTestDescription {
public: public:
TestDescription_suite_test_worksheet_test_merge() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 282, "test_merge" ) {} TestDescription_suite_test_worksheet_test_merge() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 292, "test_merge" ) {}
void runTest() { suite_test_worksheet.test_merge(); } void runTest() { suite_test_worksheet.test_merge(); }
} testDescription_suite_test_worksheet_test_merge; } testDescription_suite_test_worksheet_test_merge;
static class TestDescription_suite_test_worksheet_test_freeze : public CxxTest::RealTestDescription { static class TestDescription_suite_test_worksheet_test_freeze : public CxxTest::RealTestDescription {
public: public:
TestDescription_suite_test_worksheet_test_freeze() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 351, "test_freeze" ) {} TestDescription_suite_test_worksheet_test_freeze() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 361, "test_freeze" ) {}
void runTest() { suite_test_worksheet.test_freeze(); } void runTest() { suite_test_worksheet.test_freeze(); }
} testDescription_suite_test_worksheet_test_freeze; } testDescription_suite_test_worksheet_test_freeze;
static class TestDescription_suite_test_worksheet_test_printer_settings : public CxxTest::RealTestDescription { static class TestDescription_suite_test_worksheet_test_printer_settings : public CxxTest::RealTestDescription {
public: public:
TestDescription_suite_test_worksheet_test_printer_settings() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 368, "test_printer_settings" ) {} TestDescription_suite_test_worksheet_test_printer_settings() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 378, "test_printer_settings" ) {}
void runTest() { suite_test_worksheet.test_printer_settings(); } void runTest() { suite_test_worksheet.test_printer_settings(); }
} testDescription_suite_test_worksheet_test_printer_settings; } testDescription_suite_test_worksheet_test_printer_settings;
#include "/Users/thomas/Development/xlnt/tests/test_write.hpp" #include "C:\Users\taf656\Development\xlnt\tests\test_write.hpp"
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( "/Users/thomas/Development/xlnt/tests/test_write.hpp", 11, "test_write", suite_test_write, Tests_test_write ); CxxTest::StaticSuiteDescription suiteDescription_test_write( "../../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:
@ -1140,79 +1140,79 @@ public:
static class TestDescription_suite_test_write_test_write_workbook_rels : public CxxTest::RealTestDescription { static class TestDescription_suite_test_write_test_write_workbook_rels : public CxxTest::RealTestDescription {
public: public:
TestDescription_suite_test_write_test_write_workbook_rels() : CxxTest::RealTestDescription( Tests_test_write, suiteDescription_test_write, 36, "test_write_workbook_rels" ) {} TestDescription_suite_test_write_test_write_workbook_rels() : CxxTest::RealTestDescription( Tests_test_write, suiteDescription_test_write, 35, "test_write_workbook_rels" ) {}
void runTest() { suite_test_write.test_write_workbook_rels(); } void runTest() { suite_test_write.test_write_workbook_rels(); }
} testDescription_suite_test_write_test_write_workbook_rels; } testDescription_suite_test_write_test_write_workbook_rels;
static class TestDescription_suite_test_write_test_write_workbook : public CxxTest::RealTestDescription { static class TestDescription_suite_test_write_test_write_workbook : public CxxTest::RealTestDescription {
public: public:
TestDescription_suite_test_write_test_write_workbook() : CxxTest::RealTestDescription( Tests_test_write, suiteDescription_test_write, 44, "test_write_workbook" ) {} TestDescription_suite_test_write_test_write_workbook() : CxxTest::RealTestDescription( Tests_test_write, suiteDescription_test_write, 43, "test_write_workbook" ) {}
void runTest() { suite_test_write.test_write_workbook(); } void runTest() { suite_test_write.test_write_workbook(); }
} testDescription_suite_test_write_test_write_workbook; } testDescription_suite_test_write_test_write_workbook;
static class TestDescription_suite_test_write_test_write_string_table : public CxxTest::RealTestDescription { static class TestDescription_suite_test_write_test_write_string_table : public CxxTest::RealTestDescription {
public: public:
TestDescription_suite_test_write_test_write_string_table() : CxxTest::RealTestDescription( Tests_test_write, suiteDescription_test_write, 53, "test_write_string_table" ) {} TestDescription_suite_test_write_test_write_string_table() : CxxTest::RealTestDescription( Tests_test_write, suiteDescription_test_write, 51, "test_write_string_table" ) {}
void runTest() { suite_test_write.test_write_string_table(); } void runTest() { suite_test_write.test_write_string_table(); }
} testDescription_suite_test_write_test_write_string_table; } testDescription_suite_test_write_test_write_string_table;
static class TestDescription_suite_test_write_test_write_worksheet : public CxxTest::RealTestDescription { static class TestDescription_suite_test_write_test_write_worksheet : public CxxTest::RealTestDescription {
public: public:
TestDescription_suite_test_write_test_write_worksheet() : CxxTest::RealTestDescription( Tests_test_write, suiteDescription_test_write, 60, "test_write_worksheet" ) {} TestDescription_suite_test_write_test_write_worksheet() : CxxTest::RealTestDescription( Tests_test_write, suiteDescription_test_write, 58, "test_write_worksheet" ) {}
void runTest() { suite_test_write.test_write_worksheet(); } void runTest() { suite_test_write.test_write_worksheet(); }
} testDescription_suite_test_write_test_write_worksheet; } testDescription_suite_test_write_test_write_worksheet;
static class TestDescription_suite_test_write_test_write_hidden_worksheet : public CxxTest::RealTestDescription { static class TestDescription_suite_test_write_test_write_hidden_worksheet : public CxxTest::RealTestDescription {
public: public:
TestDescription_suite_test_write_test_write_hidden_worksheet() : CxxTest::RealTestDescription( Tests_test_write, suiteDescription_test_write, 68, "test_write_hidden_worksheet" ) {} TestDescription_suite_test_write_test_write_hidden_worksheet() : CxxTest::RealTestDescription( Tests_test_write, suiteDescription_test_write, 66, "test_write_hidden_worksheet" ) {}
void runTest() { suite_test_write.test_write_hidden_worksheet(); } void runTest() { suite_test_write.test_write_hidden_worksheet(); }
} testDescription_suite_test_write_test_write_hidden_worksheet; } testDescription_suite_test_write_test_write_hidden_worksheet;
static class TestDescription_suite_test_write_test_write_bool : public CxxTest::RealTestDescription { static class TestDescription_suite_test_write_test_write_bool : public CxxTest::RealTestDescription {
public: public:
TestDescription_suite_test_write_test_write_bool() : CxxTest::RealTestDescription( Tests_test_write, suiteDescription_test_write, 77, "test_write_bool" ) {} TestDescription_suite_test_write_test_write_bool() : CxxTest::RealTestDescription( Tests_test_write, suiteDescription_test_write, 75, "test_write_bool" ) {}
void runTest() { suite_test_write.test_write_bool(); } void runTest() { suite_test_write.test_write_bool(); }
} testDescription_suite_test_write_test_write_bool; } testDescription_suite_test_write_test_write_bool;
static class TestDescription_suite_test_write_test_write_formula : public CxxTest::RealTestDescription { static class TestDescription_suite_test_write_test_write_formula : public CxxTest::RealTestDescription {
public: public:
TestDescription_suite_test_write_test_write_formula() : CxxTest::RealTestDescription( Tests_test_write, suiteDescription_test_write, 86, "test_write_formula" ) {} TestDescription_suite_test_write_test_write_formula() : CxxTest::RealTestDescription( Tests_test_write, suiteDescription_test_write, 84, "test_write_formula" ) {}
void runTest() { suite_test_write.test_write_formula(); } void runTest() { suite_test_write.test_write_formula(); }
} testDescription_suite_test_write_test_write_formula; } testDescription_suite_test_write_test_write_formula;
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, 100, "test_write_style" ) {} TestDescription_suite_test_write_test_write_style() : CxxTest::RealTestDescription( Tests_test_write, suiteDescription_test_write, 98, "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, 109, "test_write_height" ) {} TestDescription_suite_test_write_test_write_height() : CxxTest::RealTestDescription( Tests_test_write, suiteDescription_test_write, 108, "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, 118, "test_write_hyperlink" ) {} TestDescription_suite_test_write_test_write_hyperlink() : CxxTest::RealTestDescription( Tests_test_write, suiteDescription_test_write, 117, "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, 127, "test_write_hyperlink_rels" ) {} TestDescription_suite_test_write_test_write_hyperlink_rels() : CxxTest::RealTestDescription( Tests_test_write, suiteDescription_test_write, 126, "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, 141, "test_hyperlink_value" ) {} TestDescription_suite_test_write_test_hyperlink_value() : CxxTest::RealTestDescription( Tests_test_write, suiteDescription_test_write, 140, "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, 150, "test_write_auto_filter" ) {} TestDescription_suite_test_write_test_write_auto_filter() : CxxTest::RealTestDescription( Tests_test_write, suiteDescription_test_write, 149, "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;

View File

@ -1,18 +1,18 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<worksheet xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"> <worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">
<sheetPr> <sheetPr>
<outlinePr summaryRight="1" summaryBelow="1"/> <outlinePr summaryBelow="1" summaryRight="1" />
</sheetPr> </sheetPr>
<dimension ref="A1:F42"/> <dimension ref="A1:F42"/>
<sheetViews> <sheetViews>
<sheetView workbookViewId="0"> <sheetView workbookViewId="0">
<selection sqref="A1" activeCell="A1"/> <selection activeCell="A1" sqref="A1" />
</sheetView> </sheetView>
</sheetViews> </sheetViews>
<sheetFormatPr baseColWidth="10" defaultRowHeight="15" /> <sheetFormatPr baseColWidth="10" defaultRowHeight="15" />
<sheetData> <sheetData>
<row spans="1:6" r="42"> <row r="42" spans="1:6">
<c t="s" r="F42"> <c r="F42" t="s">
<v>0</v> <v>0</v>
</c> </c>
</row> </row>

View File

@ -9,13 +9,9 @@
class test_dump : public CxxTest::TestSuite class test_dump : public CxxTest::TestSuite
{ {
public: public:
test_dump() : wb(xlnt::optimization::write)
{
}
void test_dump_sheet_title() void test_dump_sheet_title()
{ {
xlnt::workbook wb(xlnt::optimization::write);
auto ws = wb.create_sheet("Test1"); auto ws = wb.create_sheet("Test1");
wb.save(temp_file.GetFilename()); wb.save(temp_file.GetFilename());
xlnt::workbook wb2; xlnt::workbook wb2;
@ -27,9 +23,8 @@ public:
void test_dump_sheet() void test_dump_sheet()
{ {
TS_SKIP(""); xlnt::workbook wb(xlnt::optimization::write);
auto test_filename = temp_file.GetFilename(); auto ws = wb.create_sheet("test");
auto ws = wb.create_sheet();
std::vector<std::string> letters; std::vector<std::string> letters;
for(int i = 0; i < 20; i++) for(int i = 0; i < 20; i++)
@ -52,7 +47,7 @@ public:
std::vector<int> current_row; std::vector<int> current_row;
for(auto letter : letters) for(auto letter : letters)
{ {
current_row.push_back(row + 1); current_row.push_back(row + 21);
} }
ws.append(current_row); ws.append(current_row);
} }
@ -72,16 +67,17 @@ public:
std::vector<std::string> current_row; std::vector<std::string> current_row;
for(auto letter : letters) for(auto letter : letters)
{ {
current_row.push_back("=" + letter + std::to_string(row + 1)); current_row.push_back("=" + letter + std::to_string(row + 51));
} }
ws.append(current_row); ws.append(current_row);
} }
auto test_filename = temp_file.GetFilename();
wb.save(test_filename); wb.save(test_filename);
xlnt::workbook wb2; xlnt::workbook wb2;
wb2.load(test_filename); wb2.load(test_filename);
ws = wb[2]; ws = wb.get_sheet_by_name("test");
for(auto row : ws.rows()) for(auto row : ws.rows())
{ {
@ -140,6 +136,7 @@ public:
void test_dump_twice() void test_dump_twice()
{ {
xlnt::workbook wb(xlnt::optimization::write);
auto test_filename = temp_file.GetFilename(); auto test_filename = temp_file.GetFilename();
auto ws = wb.create_sheet(); auto ws = wb.create_sheet();
@ -155,6 +152,7 @@ public:
void test_append_after_save() void test_append_after_save()
{ {
xlnt::workbook wb(xlnt::optimization::write);
auto ws = wb.create_sheet(); auto ws = wb.create_sheet();
std::vector<std::string> to_append = {"hello"}; std::vector<std::string> to_append = {"hello"};
@ -167,6 +165,5 @@ public:
} }
private: private:
xlnt::workbook wb;
TemporaryFile temp_file; TemporaryFile temp_file;
}; };

View File

@ -5,21 +5,14 @@
#include <xlnt/xlnt.hpp> #include <xlnt/xlnt.hpp>
#include "helpers/path_helper.hpp" #include "helpers/path_helper.hpp"
#include "helpers/helper.hpp"
class test_theme : public CxxTest::TestSuite class test_theme : public CxxTest::TestSuite
{ {
public: public:
void test_write_theme() void test_write_theme()
{ {
TS_SKIP("");
auto content = xlnt::writer::write_theme(); auto content = xlnt::writer::write_theme();
TS_ASSERT(Helper::EqualsFileContent(PathHelper::GetDataDirectory() + "/writer/expected/theme1.xml", content));
std::string comparison_file = PathHelper::GetDataDirectory() + "/writer/expected/theme1.xml";
std::ifstream t(comparison_file);
std::stringstream buffer;
buffer << t.rdbuf();
std::string expected = buffer.str();
TS_ASSERT_EQUALS(buffer.str(), content);
} }
}; };

View File

@ -51,7 +51,7 @@ public:
{ {
xlnt::worksheet ws(wb); xlnt::worksheet ws(wb);
ws.get_cell("A1") = "AAA"; ws.get_cell("A1") = "AAA";
TS_ASSERT_EQUALS("A1", ws.calculate_dimension().to_string()); TS_ASSERT_EQUALS("A1:A1", ws.calculate_dimension().to_string());
ws.get_cell("B12") = "AAA"; ws.get_cell("B12") = "AAA";
TS_ASSERT_EQUALS("A1:B12", ws.calculate_dimension().to_string()); TS_ASSERT_EQUALS("A1:B12", ws.calculate_dimension().to_string());
} }
@ -147,21 +147,20 @@ public:
void test_hyperlink_relationships() void test_hyperlink_relationships()
{ {
xlnt::worksheet ws(wb); xlnt::worksheet ws(wb);
TS_SKIP("test_hyperlink_relationships");
TS_ASSERT_EQUALS(ws.get_relationships().size(), 0); TS_ASSERT_EQUALS(ws.get_relationships().size(), 0);
ws.get_cell("A1").set_hyperlink("http:test.com"); ws.get_cell("A1").set_hyperlink("http://test.com");
TS_ASSERT_EQUALS(ws.get_relationships().size(), 1); TS_ASSERT_EQUALS(ws.get_relationships().size(), 1);
TS_ASSERT_EQUALS("rId1", ws.get_cell("A1").get_hyperlink()); TS_ASSERT_EQUALS("rId1", ws.get_cell("A1").get_hyperlink().get_id());
TS_ASSERT_EQUALS("rId1", ws.get_relationships()[0].get_id()); TS_ASSERT_EQUALS("rId1", ws.get_relationships()[0].get_id());
TS_ASSERT_EQUALS("http:test.com", ws.get_relationships()[0].get_target_uri()); TS_ASSERT_EQUALS("http://test.com", ws.get_relationships()[0].get_target_uri());
TS_ASSERT_EQUALS(xlnt::target_mode::external, ws.get_relationships()[0].get_target_mode()); TS_ASSERT_EQUALS(xlnt::target_mode::external, ws.get_relationships()[0].get_target_mode());
ws.get_cell("A2").set_hyperlink("http:test2.com"); ws.get_cell("A2").set_hyperlink("http://test2.com");
TS_ASSERT_EQUALS(ws.get_relationships().size(), 2); TS_ASSERT_EQUALS(ws.get_relationships().size(), 2);
TS_ASSERT_EQUALS("rId2", ws.get_cell("A2").get_hyperlink()); TS_ASSERT_EQUALS("rId2", ws.get_cell("A2").get_hyperlink().get_id());
TS_ASSERT_EQUALS("rId2", ws.get_relationships()[1].get_id()); TS_ASSERT_EQUALS("rId2", ws.get_relationships()[1].get_id());
TS_ASSERT_EQUALS("http:test2.com", ws.get_relationships()[1].get_target_uri()); TS_ASSERT_EQUALS("http://test2.com", ws.get_relationships()[1].get_target_uri());
TS_ASSERT_EQUALS(xlnt::target_mode::external, ws.get_relationships()[1].get_target_mode()); TS_ASSERT_EQUALS(xlnt::target_mode::external, ws.get_relationships()[1].get_target_mode());
} }
@ -276,7 +275,18 @@ public:
xlnt::worksheet ws2(wb); xlnt::worksheet ws2(wb);
xml_string = xlnt::writer::write_worksheet(ws2); xml_string = xlnt::writer::write_worksheet(ws2);
doc.load(xml_string.c_str()); doc.load(xml_string.c_str());
TS_ASSERT_EQUALS(doc.child("worksheet").child("pageMargins"), nullptr); TS_ASSERT_DIFFERS(page_margins_node.attribute("left"), nullptr);
TS_ASSERT_EQUALS(page_margins_node.attribute("left").as_double(), 0.75);
TS_ASSERT_DIFFERS(page_margins_node.attribute("right"), nullptr);
TS_ASSERT_EQUALS(page_margins_node.attribute("right").as_double(), 0.75);
TS_ASSERT_DIFFERS(page_margins_node.attribute("top"), nullptr);
TS_ASSERT_EQUALS(page_margins_node.attribute("top").as_double(), 1);
TS_ASSERT_DIFFERS(page_margins_node.attribute("bottom"), nullptr);
TS_ASSERT_EQUALS(page_margins_node.attribute("bottom").as_double(), 1);
TS_ASSERT_DIFFERS(page_margins_node.attribute("header"), nullptr);
TS_ASSERT_EQUALS(page_margins_node.attribute("header").as_double(), 0.5);
TS_ASSERT_DIFFERS(page_margins_node.attribute("footer"), nullptr);
TS_ASSERT_EQUALS(page_margins_node.attribute("footer").as_double(), 0.5);
} }
void test_merge() void test_merge()

View File

@ -25,7 +25,6 @@ public:
void test_write_virtual_workbook() void test_write_virtual_workbook()
{ {
TS_SKIP("");
xlnt::workbook old_wb; xlnt::workbook old_wb;
std::vector<unsigned char> saved_wb; std::vector<unsigned char> saved_wb;
TS_ASSERT(old_wb.save(saved_wb)); TS_ASSERT(old_wb.save(saved_wb));
@ -49,7 +48,6 @@ public:
TS_ASSERT(Helper::EqualsFileContent(PathHelper::GetDataDirectory() + "/writer/expected/workbook.xml", content)); TS_ASSERT(Helper::EqualsFileContent(PathHelper::GetDataDirectory() + "/writer/expected/workbook.xml", content));
} }
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"};
@ -99,6 +97,7 @@ public:
void test_write_style() void test_write_style()
{ {
TS_SKIP("");
auto ws = wb.create_sheet(); auto ws = wb.create_sheet();
ws.get_cell("F1") = "13%"; ws.get_cell("F1") = "13%";
auto style_id_by_hash = xlnt::style_writer(wb).get_style_by_hash(); auto style_id_by_hash = xlnt::style_writer(wb).get_style_by_hash();
@ -119,8 +118,8 @@ public:
{ {
auto ws = wb.create_sheet(); auto ws = wb.create_sheet();
ws.get_cell("A1") = "test"; ws.get_cell("A1") = "test";
ws.get_cell("A1").set_hyperlink("http:test.com"); ws.get_cell("A1").set_hyperlink("http://test.com");
auto content = xlnt::writer::write_worksheet(ws, {{"test", 0}}, {}); auto content = xlnt::writer::write_worksheet(ws, {"test"}, {});
TS_ASSERT(Helper::EqualsFileContent(PathHelper::GetDataDirectory() + "/writer/expected/sheet1_hyperlink.xml", content)); TS_ASSERT(Helper::EqualsFileContent(PathHelper::GetDataDirectory() + "/writer/expected/sheet1_hyperlink.xml", content));
} }
@ -129,12 +128,12 @@ public:
auto ws = wb.create_sheet(); auto ws = wb.create_sheet();
TS_ASSERT_EQUALS(0, ws.get_relationships().size()); TS_ASSERT_EQUALS(0, ws.get_relationships().size());
ws.get_cell("A1") = "test"; ws.get_cell("A1") = "test";
ws.get_cell("A1").set_hyperlink("http:test.com/"); ws.get_cell("A1").set_hyperlink("http://test.com/");
TS_ASSERT_EQUALS(1, ws.get_relationships().size()); TS_ASSERT_EQUALS(1, ws.get_relationships().size());
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); auto content = xlnt::writer::write_worksheet_rels(ws, 1, 1);
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));
} }
@ -149,10 +148,11 @@ public:
void test_write_auto_filter() void test_write_auto_filter()
{ {
auto ws = wb.create_sheet(); xlnt::workbook wb;
auto ws = wb.get_sheet_by_index(0);
ws.get_cell("F42") = "hello"; ws.get_cell("F42") = "hello";
ws.auto_filter("A1:F1"); ws.auto_filter("A1:F1");
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_auto_filter.xml", content)); TS_ASSERT(Helper::EqualsFileContent(PathHelper::GetDataDirectory() + "/writer/expected/sheet1_auto_filter.xml", content));
content = xlnt::writer::write_workbook(wb); content = xlnt::writer::write_workbook(wb);
@ -164,7 +164,7 @@ public:
auto ws = wb.create_sheet(); auto ws = wb.create_sheet();
ws.get_cell("F42") = "hello"; ws.get_cell("F42") = "hello";
ws.freeze_panes("A4"); ws.freeze_panes("A4");
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_freeze_panes_horiz.xml", content)); TS_ASSERT(Helper::EqualsFileContent(PathHelper::GetDataDirectory() + "/writer/expected/sheet1_freeze_panes_horiz.xml", content));
} }
@ -173,7 +173,7 @@ public:
auto ws = wb.create_sheet(); auto ws = wb.create_sheet();
ws.get_cell("F42") = "hello"; ws.get_cell("F42") = "hello";
ws.freeze_panes("D1"); ws.freeze_panes("D1");
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_freeze_panes_vert.xml", content)); TS_ASSERT(Helper::EqualsFileContent(PathHelper::GetDataDirectory() + "/writer/expected/sheet1_freeze_panes_vert.xml", content));
} }
@ -182,7 +182,7 @@ public:
auto ws = wb.create_sheet(); auto ws = wb.create_sheet();
ws.get_cell("F42") = "hello"; ws.get_cell("F42") = "hello";
ws.freeze_panes("D4"); ws.freeze_panes("D4");
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_freeze_panes_both.xml", content)); TS_ASSERT(Helper::EqualsFileContent(PathHelper::GetDataDirectory() + "/writer/expected/sheet1_freeze_panes_both.xml", content));
} }