fix some things

This commit is contained in:
Thomas Fussell 2014-07-19 16:59:05 -04:00
parent c7dbf12b51
commit ac5e29b125
26 changed files with 599 additions and 284 deletions

View File

@ -39,6 +39,7 @@ class worksheet;
struct date;
struct datetime;
struct time;
struct timedelta;
namespace detail {
struct cell_impl;
@ -152,6 +153,7 @@ public:
cell &operator=(const date &value);
cell &operator=(const time &value);
cell &operator=(const datetime &value);
cell &operator=(const timedelta &value);
bool operator==(const cell &comparand) const;
bool operator==(std::nullptr_t) const;
@ -163,6 +165,7 @@ public:
bool operator==(const date &comparand) const;
bool operator==(const time &comparand) const;
bool operator==(const datetime &comparand) const;
bool operator==(const timedelta &comparand) const;
friend bool operator==(std::nullptr_t, const cell &cell);
friend bool operator==(bool comparand, const cell &cell);

View File

@ -26,7 +26,7 @@
namespace xlnt {
enum calendar
enum class calendar
{
windows_1900,
mac_1904
@ -35,14 +35,14 @@ enum calendar
struct date
{
static date today();
static date from_number(int days_since_base_year, int base_year = 1900);
static date from_number(int days_since_base_year, calendar base_date);
date(int year, int month, int day)
: year(year), month(month), day(day)
{
}
int to_number(int base_year = 1900) const;
int to_number(calendar base_date) const;
bool operator==(const date &comparand) const;
int year;
@ -73,14 +73,14 @@ struct time
struct datetime
{
static datetime now();
static datetime from_number(long double number, int base_year = 1900);
static datetime from_number(long double number, calendar base_date);
datetime(int year, int month, int day, int hour = 0, int minute = 0, int second = 0, int microsecond = 0)
: year(year), month(month), day(day), hour(hour), minute(minute), second(second), microsecond(microsecond)
{
}
double to_number(int base_year = 1900) const;
double to_number(calendar base_date) const;
bool operator==(const datetime &comparand) const;
int year;
@ -92,4 +92,19 @@ struct datetime
int microsecond;
};
struct timedelta
{
timedelta(int days, int hours, int minutes, int seconds, int microseconds) : days(days), hours(hours), minutes(minutes), seconds(seconds), microseconds(microseconds)
{
}
double to_number() const;
int days;
int hours;
int minutes;
int seconds;
int microseconds;
};
} // namespace xlnt

View File

@ -89,7 +89,7 @@ public:
class invalid_file_exception : public std::runtime_error
{
public:
invalid_file_exception();
invalid_file_exception(const std::string &filename);
};
/// <summary>

View File

@ -106,6 +106,8 @@ public:
void flush(bool force_write = false);
std::string get_filename() const { return filename_; }
private:
void read_all();
void write_all();

View File

@ -40,14 +40,15 @@ class reader
{
public:
static std::vector<relationship> read_relationships(const std::string &content);
static std::pair<std::unordered_map<std::string, std::string>, std::unordered_map<std::string, std::string>> read_content_types(const std::string &content);
static std::string determine_document_type(const std::unordered_map<std::string, std::string> &override_types);
static std::vector<std::pair<std::string, std::string>> read_content_types(const zip_file &archive);
static std::string determine_document_type(const std::vector<std::pair<std::string, std::string>> &override_types);
static worksheet read_worksheet(std::istream &handle, workbook &wb, const std::string &title, const std::vector<std::string> &string_table);
static void read_worksheet(worksheet ws, const std::string &xml_string, const std::vector<std::string> &string_table, const std::vector<int> &number_format_ids);
static std::vector<std::string> read_shared_string(const std::string &xml_string);
static std::string read_dimension(const std::string &xml_string);
static document_properties read_properties_core(const std::string &xml_string);
static std::vector<std::pair<std::string,std::string>> read_sheets(const zip_file &archive);
static workbook load_workbook(const std::string &filename, bool guess_types = false);
};
} // namespace xlnt

View File

@ -33,6 +33,7 @@
namespace xlnt {
class document_properties;
class drawing;
class range;
class range_reference;
@ -40,7 +41,7 @@ class relationship;
class worksheet;
namespace detail {
struct workbook_impl;
struct workbook_impl;
} // namespace detail
struct content_type
@ -61,8 +62,8 @@ public:
workbook();
~workbook();
workbook &operator=(const workbook &) = delete;
workbook(const workbook &) = delete;
workbook &operator=(const workbook &);
workbook(const workbook &);
//void read_workbook_settings(const std::string &xml_source);
@ -142,7 +143,8 @@ public:
std::vector<std::string> get_sheet_names() const;
int get_base_year() const;
document_properties &get_properties();
const document_properties &get_properties() const;
//named ranges
void create_named_range(const std::string &name, worksheet worksheet, const range_reference &reference);
@ -158,6 +160,7 @@ public:
bool load(const std::istream &stream);
bool operator==(const workbook &rhs) const;
bool operator==(std::nullptr_t) const;
std::vector<content_type> get_content_types() const;
@ -167,7 +170,7 @@ public:
private:
friend class worksheet;
std::unique_ptr<detail::workbook_impl> d_;
std::shared_ptr<detail::workbook_impl> d_;
};
} // namespace xlnt

View File

@ -31,10 +31,10 @@
namespace xlnt {
class row
class cell_vector
{
public:
row(worksheet ws, const range_reference &ref);
cell_vector(worksheet ws, const range_reference &ref);
std::size_t num_cells() const;
@ -115,17 +115,17 @@ public:
~range();
row operator[](std::size_t row_index);
cell_vector operator[](std::size_t vector_index);
const row operator[](std::size_t row_index) const;
const cell_vector operator[](std::size_t vector_index) const;
bool operator==(const range &comparand) const;
bool operator!=(const range &comparand) const { return !(*this == comparand); }
row get_row(std::size_t row_index);
cell_vector get_vector(std::size_t vector_index);
const row get_row(std::size_t row_index) const;
const cell_vector get_vector(std::size_t vector_index) const;
cell get_cell(const cell_reference &ref);
@ -133,7 +133,7 @@ public:
range_reference get_reference() const;
std::size_t num_rows() const;
std::size_t length() const;
class iterator
{
@ -147,7 +147,7 @@ public:
iterator operator++(int);
iterator &operator++();
row operator*();
cell_vector operator*();
private:
worksheet ws_;
@ -170,7 +170,7 @@ public:
const_iterator operator++(int);
const_iterator &operator++();
const row operator*();
const cell_vector operator*();
private:
worksheet ws_;

View File

@ -60,6 +60,54 @@ class row_properties
int style_index;
};
class header
{
public:
header();
void set_text(const std::string &text) { text_ = text; }
void set_font_name(const std::string &font_name) { font_name_ = font_name; }
void set_font_size(std::size_t font_size) { font_size_ = font_size; }
void set_font_color(const std::string &font_color) { font_color_ = font_color; }
private:
std::string text_;
std::string font_name_;
std::size_t font_size_;
std::string font_color_;
};
class footer
{
public:
footer();
void set_text(const std::string &text) { text_ = text; }
void set_font_name(const std::string &font_name) { font_name_ = font_name; }
void set_font_size(std::size_t font_size) { font_size_ = font_size; }
void set_font_color(const std::string &font_color) { font_color_ = font_color; }
private:
std::string text_;
std::string font_name_;
std::size_t font_size_;
std::string font_color_;
};
class header_footer
{
public:
header_footer();
header &get_left_header() { return left_header_; }
header &get_center_header() { return center_header_; }
header &get_right_header() { return right_header_; }
footer &get_left_footer() { return left_footer_; }
footer &get_center_footer() { return center_footer_; }
footer &get_right_footer() { return right_footer_; }
private:
header left_header_, right_header_, center_header_;
footer left_footer_, right_footer_, center_footer_;
};
struct page_setup
{
enum class page_break
@ -254,6 +302,9 @@ public:
void reserve(std::size_t n);
header_footer &get_header_footer();
const header_footer &get_header_footer() const;
private:
friend class workbook;
friend class cell;

View File

@ -10,6 +10,7 @@
#include "detail/cell_impl.hpp"
#include "common/exceptions.hpp"
#include "workbook/workbook.hpp"
#include "workbook/document_properties.hpp"
namespace xlnt {
@ -256,6 +257,11 @@ bool cell::operator==(std::nullptr_t) const
return d_ == nullptr;
}
bool cell::operator==(bool value) const
{
return d_->type_ == type::boolean && (bool)d_->numeric_value == value;
}
bool cell::operator==(int comparand) const
{
return d_->type_ == type::numeric && d_->numeric_value == comparand;
@ -297,7 +303,7 @@ bool cell::operator==(const date &comparand) const
return false;
}
auto base_year = worksheet(d_->parent_).get_parent().get_base_year();
auto base_year = worksheet(d_->parent_).get_parent().get_properties().excel_base_date;
return date::from_number((int)d_->numeric_value, base_year) == comparand;
}
@ -308,7 +314,7 @@ bool cell::operator==(const datetime &comparand) const
return false;
}
auto base_year = worksheet(d_->parent_).get_parent().get_base_year();
auto base_year = worksheet(d_->parent_).get_parent().get_properties().excel_base_date;
return datetime::from_number(d_->numeric_value, base_year) == comparand;
}
@ -339,8 +345,8 @@ bool cell::operator==(const cell &comparand) const
case type::numeric:
if(is_date() && comparand.is_date())
{
auto base_year = worksheet(d_->parent_).get_parent().get_base_year();
auto other_base_year = worksheet(comparand.d_->parent_).get_parent().get_base_year();
auto base_year = worksheet(d_->parent_).get_parent().get_properties().excel_base_date;
auto other_base_year = worksheet(comparand.d_->parent_).get_parent().get_properties().excel_base_date;
return date::from_number((int)d_->numeric_value, base_year) == date::from_number((int)comparand.d_->numeric_value, other_base_year);
}
return d_->numeric_value == comparand.d_->numeric_value;
@ -349,6 +355,11 @@ bool cell::operator==(const cell &comparand) const
return false;
}
bool operator==(bool comparand, const xlnt::cell &cell)
{
return cell == comparand;
}
bool operator==(int comparand, const xlnt::cell &cell)
{
return cell == comparand;
@ -517,7 +528,7 @@ cell &cell::operator=(const time &value)
cell &cell::operator=(const date &value)
{
d_->type_ = type::numeric;
auto base_year = worksheet(d_->parent_).get_parent().get_base_year();
auto base_year = worksheet(d_->parent_).get_parent().get_properties().excel_base_date;
d_->numeric_value = value.to_number(base_year);
d_->is_date_ = true;
return *this;
@ -526,12 +537,20 @@ cell &cell::operator=(const date &value)
cell &cell::operator=(const datetime &value)
{
d_->type_ = type::numeric;
auto base_year = worksheet(d_->parent_).get_parent().get_base_year();
auto base_year = worksheet(d_->parent_).get_parent().get_properties().excel_base_date;
d_->numeric_value = value.to_number(base_year);
d_->is_date_ = true;
return *this;
}
cell &cell::operator=(const timedelta &value)
{
d_->type_ = type::numeric;
d_->numeric_value = value.to_number();
d_->is_date_ = true;
return *this;
}
std::string cell::to_string() const
{
return "<Cell " + worksheet(d_->parent_).get_title() + "." + get_reference().to_string() + ">";

View File

@ -38,11 +38,11 @@ time time::from_number(long double raw_time)
return result;
}
date date::from_number(int days_since_base_year, int base_year)
date date::from_number(int days_since_base_year, calendar base_date)
{
date result(0, 0, 0);
if(base_year == 1904)
if(base_date == calendar::mac_1904)
{
days_since_base_year += 1462;
}
@ -72,9 +72,9 @@ date date::from_number(int days_since_base_year, int base_year)
return result;
}
datetime datetime::from_number(long double raw_time, int base_year)
datetime datetime::from_number(long double raw_time, calendar base_date)
{
auto date_part = date::from_number((int)raw_time, base_year);
auto date_part = date::from_number((int)raw_time, base_date);
auto time_part = time::from_number(raw_time);
return datetime(date_part.year, date_part.month, date_part.day, time_part.hour, time_part.minute, time_part.second, time_part.microsecond);
}
@ -134,7 +134,7 @@ double time::to_number() const
return number;
}
int date::to_number(int base_year) const
int date::to_number(calendar base_date) const
{
if(day == 29 && month == 2 && year == 1900)
{
@ -151,7 +151,7 @@ int date::to_number(int base_year) const
days_since_1900--;
}
if(base_year == 1904)
if(base_date == calendar::mac_1904)
{
return days_since_1900 - 1462;
}
@ -159,9 +159,9 @@ int date::to_number(int base_year) const
return days_since_1900;
}
double datetime::to_number(int base_year) const
double datetime::to_number(calendar base_date) const
{
return date(year, month, day).to_number(base_year)
return date(year, month, day).to_number(base_date)
+ time(hour, minute, second, microsecond).to_number();
}
@ -179,4 +179,9 @@ datetime datetime::now()
return datetime(1900 + now.tm_year, now.tm_mon + 1, now.tm_mday, now.tm_hour, now.tm_min, now.tm_sec);
}
double timedelta::to_number() const
{
return days + hours / 24.0;
}
} // namespace xlnt

View File

@ -13,10 +13,10 @@ struct workbook_impl
//bool guess_types_;
//bool data_only_;
int active_sheet_index_;
bool date_1904_;
std::vector<worksheet_impl> worksheets_;
std::vector<relationship> relationships_;
std::vector<drawing> drawings_;
document_properties properties_;
};
} // namespace detail

View File

@ -61,6 +61,7 @@ struct worksheet_impl
std::vector<range_reference> merged_cells_;
std::unordered_map<std::string, range_reference> named_ranges_;
std::vector<comment> comments_;
header_footer header_footer_;
};
} // namespace detail

View File

@ -20,6 +20,12 @@ data_type_exception::data_type_exception()
}
invalid_file_exception::invalid_file_exception(const std::string &filename)
: std::runtime_error(std::string("couldn't open file: (") + filename + ")")
{
}
cell_coordinates_exception::cell_coordinates_exception(int row, int column)
: std::runtime_error(std::string("bad cell coordinates: (") + std::to_string(row) + "," + std::to_string(column) + ")")
{

View File

@ -5,128 +5,128 @@
namespace xlnt {
row::iterator::iterator(worksheet ws, const cell_reference &start_cell)
cell_vector::iterator::iterator(worksheet ws, const cell_reference &start_cell)
: ws_(ws),
current_cell_(start_cell),
range_(start_cell.to_range())
{
}
row::iterator::~iterator()
cell_vector::iterator::~iterator()
{
}
bool row::iterator::operator==(const iterator &rhs)
bool cell_vector::iterator::operator==(const iterator &rhs)
{
return ws_ == rhs.ws_
&& current_cell_ == rhs.current_cell_;
}
row::iterator row::iterator::operator++(int)
cell_vector::iterator cell_vector::iterator::operator++(int)
{
iterator old = *this;
++*this;
return old;
}
row::iterator &row::iterator::operator++()
cell_vector::iterator &cell_vector::iterator::operator++()
{
current_cell_.set_column_index(current_cell_.get_column_index() + 1);
return *this;
}
cell row::iterator::operator*()
cell cell_vector::iterator::operator*()
{
return ws_[current_cell_];
}
row::const_iterator::const_iterator(worksheet ws, const cell_reference &start_cell)
cell_vector::const_iterator::const_iterator(worksheet ws, const cell_reference &start_cell)
: ws_(ws),
current_cell_(start_cell),
range_(start_cell.to_range())
{
}
row::const_iterator::~const_iterator()
cell_vector::const_iterator::~const_iterator()
{
}
bool row::const_iterator::operator==(const const_iterator &rhs)
bool cell_vector::const_iterator::operator==(const const_iterator &rhs)
{
return ws_ == rhs.ws_
&& rhs.current_cell_ == current_cell_;
}
row::const_iterator row::const_iterator::operator++(int)
cell_vector::const_iterator cell_vector::const_iterator::operator++(int)
{
const_iterator old = *this;
++*this;
return old;
}
row::const_iterator &row::const_iterator::operator++()
cell_vector::const_iterator &cell_vector::const_iterator::operator++()
{
current_cell_.set_column_index(current_cell_.get_column_index() + 1);
return *this;
}
const cell row::const_iterator::operator*()
const cell cell_vector::const_iterator::operator*()
{
const worksheet ws_const = ws_;
return ws_const[current_cell_];
}
row::iterator row::begin()
cell_vector::iterator cell_vector::begin()
{
return iterator(ws_, ref_.get_top_left());
}
row::iterator row::end()
cell_vector::iterator cell_vector::end()
{
auto past_end = ref_.get_bottom_right();
past_end.set_column_index(past_end.get_column_index() + 1);
return iterator(ws_, past_end);
}
row::const_iterator row::cbegin() const
cell_vector::const_iterator cell_vector::cbegin() const
{
return const_iterator(ws_, ref_.get_top_left());
}
row::const_iterator row::cend() const
cell_vector::const_iterator cell_vector::cend() const
{
auto past_end = ref_.get_top_left();
past_end.set_column_index(past_end.get_column_index() + 1);
return const_iterator(ws_, past_end);
}
cell row::operator[](std::size_t column_index)
cell cell_vector::operator[](std::size_t column_index)
{
return get_cell(column_index);
}
std::size_t row::num_cells() const
std::size_t cell_vector::num_cells() const
{
return ref_.get_width() + 1;
}
row::row(worksheet ws, const range_reference &reference)
cell_vector::cell_vector(worksheet ws, const range_reference &reference)
: ws_(ws),
ref_(reference)
{
}
cell row::front()
cell cell_vector::front()
{
return get_cell(ref_.get_top_left().get_column_index());
}
cell row::back()
cell cell_vector::back()
{
return get_cell(ref_.get_bottom_right().get_column_index());
}
cell row::get_cell(std::size_t column_index)
cell cell_vector::get_cell(std::size_t column_index)
{
return ws_.get_cell(ref_.get_top_left().make_offset((int)column_index, 0));
}
@ -142,9 +142,9 @@ range::~range()
{
}
row range::operator[](std::size_t row)
cell_vector range::operator[](std::size_t index)
{
return get_row(row);
return get_vector(index);
}
range_reference range::get_reference() const
@ -152,7 +152,7 @@ range_reference range::get_reference() const
return ref_;
}
std::size_t range::num_rows() const
std::size_t range::length() const
{
return ref_.get_bottom_right().get_row_index() - ref_.get_top_left().get_row_index() + 1;
}
@ -163,11 +163,11 @@ bool range::operator==(const range &comparand) const
&& ws_ == comparand.ws_;
}
row range::get_row(std::size_t row_)
cell_vector range::get_vector(std::size_t vector_index)
{
range_reference row_reference(ref_.get_top_left().get_column_index(), ref_.get_top_left().get_row_index() + (int)row_,
ref_.get_bottom_right().get_column_index(), ref_.get_top_left().get_row_index() + (int)row_);
return row(ws_, row_reference);
range_reference reference(ref_.get_top_left().get_column_index(), ref_.get_top_left().get_row_index() + (int)vector_index,
ref_.get_bottom_right().get_column_index(), ref_.get_top_left().get_row_index() + (int)vector_index);
return cell_vector(ws_, reference);
}
cell range::get_cell(const cell_reference &ref)
@ -237,13 +237,13 @@ range::iterator &range::iterator::operator++()
return *this;
}
row range::iterator::operator*()
cell_vector range::iterator::operator*()
{
range_reference row_range(range_.get_top_left().get_column_index(),
range_reference reference(range_.get_top_left().get_column_index(),
current_cell_.get_row_index(),
range_.get_bottom_right().get_column_index(),
current_cell_.get_row_index());
return row(ws_, row_range);
return cell_vector(ws_, reference);
}
range::const_iterator::const_iterator(worksheet ws, const range_reference &start_cell)
@ -276,13 +276,13 @@ range::const_iterator &range::const_iterator::operator++()
return *this;
}
const row range::const_iterator::operator*()
const cell_vector range::const_iterator::operator*()
{
range_reference row_range(range_.get_top_left().get_column_index(),
range_reference reference(range_.get_top_left().get_column_index(),
current_cell_.get_row_index(),
range_.get_bottom_right().get_column_index(),
current_cell_.get_row_index());
return row(ws_, row_range);
return cell_vector(ws_, reference);
}
} // namespace xlnt

View File

@ -10,6 +10,7 @@
#include "workbook/document_properties.hpp"
#include "common/relationship.hpp"
#include "common/zip_file.hpp"
#include "common/exceptions.hpp"
namespace xlnt {
@ -106,39 +107,44 @@ std::vector<relationship> reader::read_relationships(const std::string &content)
return relationships;
}
std::pair<std::unordered_map<std::string, std::string>, std::unordered_map<std::string, std::string>> reader::read_content_types(const std::string &content)
std::vector<std::pair<std::string, std::string>> reader::read_content_types(const zip_file &archive)
{
pugi::xml_document doc;
doc.load(content.c_str());
try
{
doc.load(archive.get_file_contents("[Content_Types].xml").c_str());
}
catch(std::out_of_range)
{
throw invalid_file_exception(archive.get_filename());
}
auto root_node = doc.child("Types");
std::unordered_map<std::string, std::string> default_types;
for(auto child : root_node.children("Default"))
{
default_types[child.attribute("Extension").as_string()] = child.attribute("ContentType").as_string();
}
std::unordered_map<std::string, std::string> override_types;
std::vector<std::pair<std::string, std::string>> override_types;
for(auto child : root_node.children("Override"))
{
override_types[child.attribute("PartName").as_string()] = child.attribute("ContentType").as_string();
std::string part_name = child.attribute("PartName").as_string();
std::string content_type = child.attribute("ContentType").as_string();
override_types.push_back({part_name, content_type});
}
return std::make_pair(default_types, override_types);
return override_types;
}
std::string reader::determine_document_type(const std::unordered_map<std::string, std::string> &override_types)
std::string reader::determine_document_type(const std::vector<std::pair<std::string, std::string>> &override_types)
{
std::string type;
auto match = std::find_if(override_types.begin(), override_types.end(), [](const std::pair<std::string, std::string> &p) { return p.first == "/xl/workbook.xml"; });
if(override_types.find("/xl/workbook.xml") != override_types.end())
if(match == override_types.end())
{
type = override_types.at("/xl/workbook.xml");
return "unsupported";
}
std::string type = match->second;
if(type == "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml")
{
return "excel";
@ -212,7 +218,7 @@ void read_worksheet_common(worksheet ws, const pugi::xml_node &root_node, const
}
else if(number_format_id == 14) // date
{
ws.get_cell(address) = datetime::from_number(cell_node.child("v").text().as_double(), ws.get_parent().get_base_year());
ws.get_cell(address) = datetime::from_number(cell_node.child("v").text().as_double(), ws.get_parent().get_properties().excel_base_date);
}
else if(number_format_id == 18) // time
{
@ -220,7 +226,7 @@ void read_worksheet_common(worksheet ws, const pugi::xml_node &root_node, const
}
else if(number_format_id == 22) // datetime
{
ws.get_cell(address) = datetime::from_number(cell_node.child("v").text().as_double(), 1900);
ws.get_cell(address) = datetime::from_number(cell_node.child("v").text().as_double(), ws.get_parent().get_properties().excel_base_date);
}
else if(number_format_id == 14) // decimal
{
@ -283,4 +289,11 @@ std::vector<std::string> reader::read_shared_string(const std::string &xml_strin
return shared_strings;
}
workbook reader::load_workbook(const std::string &filename, bool guess_types)
{
workbook wb;
wb.load(filename);
return wb;
}
} // namespace xlnt

View File

@ -17,6 +17,7 @@
#include "worksheet/worksheet.hpp"
#include "writer/writer.hpp"
#include "common/zip_file.hpp"
#include "workbook/document_properties.hpp"
#include "detail/cell_impl.hpp"
#include "detail/workbook_impl.hpp"
#include "detail/worksheet_impl.hpp"
@ -43,7 +44,7 @@ static std::string CreateTemporaryFilename()
namespace xlnt {
namespace detail {
workbook_impl::workbook_impl() : active_sheet_index_(0), date_1904_(false)
workbook_impl::workbook_impl() : active_sheet_index_(0)
{
}
@ -288,9 +289,9 @@ bool workbook::load(const std::string &filename)
zip_file f(filename, file_mode::open);
//auto core_properties = read_core_properties();
//auto app_properties = read_app_properties();
auto content_types = reader::read_content_types(f.get_file_contents("[Content_Types].xml"));
auto content_types = reader::read_content_types(f);
auto type = reader::determine_document_type(content_types.second);
auto type = reader::determine_document_type(content_types);
if(type != "excel")
{
@ -312,7 +313,7 @@ bool workbook::load(const std::string &filename)
auto root_node = doc.child("workbook");
auto workbook_pr_node = root_node.child("workbookPr");
d_->date_1904_ = workbook_pr_node.attribute("date1904") != nullptr && workbook_pr_node.attribute("date1904").as_int() != 0;
get_properties().excel_base_date = (workbook_pr_node.attribute("date1904") != nullptr && workbook_pr_node.attribute("date1904").as_int() != 0) ? calendar::mac_1904 : calendar::windows_1900;
auto sheets_node = root_node.child("sheets");
@ -367,11 +368,6 @@ relationship workbook::get_relationship(const std::string &id) const
throw std::runtime_error("");
}
int workbook::get_base_year() const
{
return d_->date_1904_ ? 1904 : 1900;
}
void workbook::remove_sheet(worksheet ws)
{
auto match_iter = std::find_if(d_->worksheets_.begin(), d_->worksheets_.end(), [=](detail::worksheet_impl &comp) { return worksheet(&comp) == ws; });
@ -418,13 +414,21 @@ worksheet workbook::create_sheet(const std::string &title)
throw sheet_title_exception(title);
}
if(std::find_if(d_->worksheets_.begin(), d_->worksheets_.end(), [&](detail::worksheet_impl &ws) { return worksheet(&ws).get_title() == title; }) != d_->worksheets_.end())
std::string unique_title = title;
if(std::find_if(d_->worksheets_.begin(), d_->worksheets_.end(), [&](detail::worksheet_impl &ws) { return worksheet(&ws).get_title() == unique_title; }) != d_->worksheets_.end())
{
throw std::runtime_error("sheet exists");
std::size_t suffix = 1;
while(std::find_if(d_->worksheets_.begin(), d_->worksheets_.end(), [&](detail::worksheet_impl &ws) { return worksheet(&ws).get_title() == unique_title; }) != d_->worksheets_.end())
{
unique_title = title + std::to_string(suffix);
suffix++;
}
}
auto ws = create_sheet();
ws.set_title(title);
ws.set_title(unique_title);
return ws;
}
@ -476,8 +480,8 @@ void workbook::clear()
d_->worksheets_.clear();
d_->relationships_.clear();
d_->active_sheet_index_ = 0;
d_->date_1904_ = false;
d_->drawings_.clear();
d_->properties_ = document_properties();
}
bool workbook::save(std::vector<unsigned char> &data)
@ -519,6 +523,11 @@ bool workbook::save(const std::string &filename)
return true;
}
bool workbook::operator==(std::nullptr_t) const
{
return d_.get() == nullptr;
}
bool workbook::operator==(const workbook &rhs) const
{
return d_.get() == rhs.d_.get();
@ -538,4 +547,19 @@ std::vector<content_type> xlnt::workbook::get_content_types() const
return content_types;
}
document_properties &workbook::get_properties()
{
return d_->properties_;
}
const document_properties &workbook::get_properties() const
{
return d_->properties_;
}
workbook::workbook(const workbook &other) : d_(other.d_)
{
}
}

View File

@ -431,6 +431,11 @@ xlnt::range worksheet::rows() const
return get_range(calculate_dimension());
}
xlnt::range worksheet::columns() const
{
return get_range(calculate_dimension());
}
bool worksheet::operator==(const worksheet &other) const
{
return d_ == other.d_;
@ -511,4 +516,29 @@ std::size_t worksheet::get_comment_count() const
return d_->comments_.size();
}
header_footer &worksheet::get_header_footer()
{
return d_->header_footer_;
}
const header_footer &worksheet::get_header_footer() const
{
return d_->header_footer_;
}
header_footer::header_footer()
{
}
header::header() : font_size_(12)
{
}
footer::footer() : font_size_(12)
{
}
} // namespace xlnt

View File

@ -2,6 +2,7 @@
#include <fstream>
#include "common/zip_file.hpp"
#include "common/exceptions.hpp"
namespace xlnt {
@ -321,7 +322,7 @@ void zip_file::start_read()
if(unzip_file_ == nullptr)
{
throw std::runtime_error("bad or non-existant file");
throw invalid_file_exception(filename_);
}
}

View File

@ -78,9 +78,9 @@ public:
}
static std::string GetDataDirectory()
static std::string GetDataDirectory(const std::string &append = "")
{
return GetExecutableDirectory() + "../tests/test_data";
return GetExecutableDirectory() + "../tests/test_data" + append;
}
static void CopyFile(const std::string &source, const std::string &destination, bool overwrite)

View File

@ -70,11 +70,11 @@ public:
void runTest() { suite_test_cell.test_bad_column_index(); }
} testDescription_suite_test_cell_test_bad_column_index;
static class TestDescription_suite_test_cell_test_column_letter_boundries : public CxxTest::RealTestDescription {
static class TestDescription_suite_test_cell_test_column_letter_boundaries : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_cell_test_column_letter_boundries() : CxxTest::RealTestDescription( Tests_test_cell, suiteDescription_test_cell, 79, "test_column_letter_boundries" ) {}
void runTest() { suite_test_cell.test_column_letter_boundries(); }
} testDescription_suite_test_cell_test_column_letter_boundries;
TestDescription_suite_test_cell_test_column_letter_boundaries() : CxxTest::RealTestDescription( Tests_test_cell, suiteDescription_test_cell, 79, "test_column_letter_boundaries" ) {}
void runTest() { suite_test_cell.test_column_letter_boundaries(); }
} testDescription_suite_test_cell_test_column_letter_boundaries;
static class TestDescription_suite_test_cell_test_column_letter : public CxxTest::RealTestDescription {
public:
@ -208,51 +208,57 @@ public:
void runTest() { suite_test_cell.test_time(); }
} testDescription_suite_test_cell_test_time;
static class TestDescription_suite_test_cell_test_timedelta : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_cell_test_timedelta() : CxxTest::RealTestDescription( Tests_test_cell, suiteDescription_test_cell, 340, "test_timedelta" ) {}
void runTest() { suite_test_cell.test_timedelta(); }
} testDescription_suite_test_cell_test_timedelta;
static class TestDescription_suite_test_cell_test_date_format_on_non_date : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_cell_test_date_format_on_non_date() : CxxTest::RealTestDescription( Tests_test_cell, suiteDescription_test_cell, 340, "test_date_format_on_non_date" ) {}
TestDescription_suite_test_cell_test_date_format_on_non_date() : CxxTest::RealTestDescription( Tests_test_cell, suiteDescription_test_cell, 350, "test_date_format_on_non_date" ) {}
void runTest() { suite_test_cell.test_date_format_on_non_date(); }
} testDescription_suite_test_cell_test_date_format_on_non_date;
static class TestDescription_suite_test_cell_test_set_get_date : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_cell_test_set_get_date() : CxxTest::RealTestDescription( Tests_test_cell, suiteDescription_test_cell, 350, "test_set_get_date" ) {}
TestDescription_suite_test_cell_test_set_get_date() : CxxTest::RealTestDescription( Tests_test_cell, suiteDescription_test_cell, 360, "test_set_get_date" ) {}
void runTest() { suite_test_cell.test_set_get_date(); }
} testDescription_suite_test_cell_test_set_get_date;
static class TestDescription_suite_test_cell_test_repr : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_cell_test_repr() : CxxTest::RealTestDescription( Tests_test_cell, suiteDescription_test_cell, 361, "test_repr" ) {}
TestDescription_suite_test_cell_test_repr() : CxxTest::RealTestDescription( Tests_test_cell, suiteDescription_test_cell, 371, "test_repr" ) {}
void runTest() { suite_test_cell.test_repr(); }
} testDescription_suite_test_cell_test_repr;
static class TestDescription_suite_test_cell_test_is_date : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_cell_test_is_date() : CxxTest::RealTestDescription( Tests_test_cell, suiteDescription_test_cell, 369, "test_is_date" ) {}
TestDescription_suite_test_cell_test_is_date() : CxxTest::RealTestDescription( Tests_test_cell, suiteDescription_test_cell, 379, "test_is_date" ) {}
void runTest() { suite_test_cell.test_is_date(); }
} testDescription_suite_test_cell_test_is_date;
static class TestDescription_suite_test_cell_test_is_not_date_color_format : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_cell_test_is_not_date_color_format() : CxxTest::RealTestDescription( Tests_test_cell, suiteDescription_test_cell, 383, "test_is_not_date_color_format" ) {}
TestDescription_suite_test_cell_test_is_not_date_color_format() : CxxTest::RealTestDescription( Tests_test_cell, suiteDescription_test_cell, 393, "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;
static class TestDescription_suite_test_cell_test_comment_count : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_cell_test_comment_count() : CxxTest::RealTestDescription( Tests_test_cell, suiteDescription_test_cell, 394, "test_comment_count" ) {}
TestDescription_suite_test_cell_test_comment_count() : CxxTest::RealTestDescription( Tests_test_cell, suiteDescription_test_cell, 404, "test_comment_count" ) {}
void runTest() { suite_test_cell.test_comment_count(); }
} testDescription_suite_test_cell_test_comment_count;
static class TestDescription_suite_test_cell_test_comment_assignment : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_cell_test_comment_assignment() : CxxTest::RealTestDescription( Tests_test_cell, suiteDescription_test_cell, 410, "test_comment_assignment" ) {}
TestDescription_suite_test_cell_test_comment_assignment() : CxxTest::RealTestDescription( Tests_test_cell, suiteDescription_test_cell, 420, "test_comment_assignment" ) {}
void runTest() { suite_test_cell.test_comment_assignment(); }
} testDescription_suite_test_cell_test_comment_assignment;
static class TestDescription_suite_test_cell_test_cell_offset : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_cell_test_cell_offset() : CxxTest::RealTestDescription( Tests_test_cell, suiteDescription_test_cell, 424, "test_cell_offset" ) {}
TestDescription_suite_test_cell_test_cell_offset() : CxxTest::RealTestDescription( Tests_test_cell, suiteDescription_test_cell, 434, "test_cell_offset" ) {}
void runTest() { suite_test_cell.test_cell_offset(); }
} testDescription_suite_test_cell_test_cell_offset;
@ -599,123 +605,189 @@ public:
static class TestDescription_suite_test_read_test_read_standard_workbook : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_read_test_read_standard_workbook() : CxxTest::RealTestDescription( Tests_test_read, suiteDescription_test_read, 31, "test_read_standard_workbook" ) {}
TestDescription_suite_test_read_test_read_standard_workbook() : CxxTest::RealTestDescription( Tests_test_read, suiteDescription_test_read, 37, "test_read_standard_workbook" ) {}
void runTest() { suite_test_read.test_read_standard_workbook(); }
} testDescription_suite_test_read_test_read_standard_workbook;
static class TestDescription_suite_test_read_test_read_standard_workbook_from_fileobj : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_read_test_read_standard_workbook_from_fileobj() : CxxTest::RealTestDescription( Tests_test_read, suiteDescription_test_read, 38, "test_read_standard_workbook_from_fileobj" ) {}
TestDescription_suite_test_read_test_read_standard_workbook_from_fileobj() : CxxTest::RealTestDescription( Tests_test_read, suiteDescription_test_read, 42, "test_read_standard_workbook_from_fileobj" ) {}
void runTest() { suite_test_read.test_read_standard_workbook_from_fileobj(); }
} testDescription_suite_test_read_test_read_standard_workbook_from_fileobj;
static class TestDescription_suite_test_read_test_read_worksheet : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_read_test_read_worksheet() : CxxTest::RealTestDescription( Tests_test_read, suiteDescription_test_read, 46, "test_read_worksheet" ) {}
TestDescription_suite_test_read_test_read_worksheet() : CxxTest::RealTestDescription( Tests_test_read, suiteDescription_test_read, 50, "test_read_worksheet" ) {}
void runTest() { suite_test_read.test_read_worksheet(); }
} testDescription_suite_test_read_test_read_worksheet;
static class TestDescription_suite_test_read_test_read_nostring_workbook : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_read_test_read_nostring_workbook() : CxxTest::RealTestDescription( Tests_test_read, suiteDescription_test_read, 57, "test_read_nostring_workbook" ) {}
TestDescription_suite_test_read_test_read_nostring_workbook() : CxxTest::RealTestDescription( Tests_test_read, suiteDescription_test_read, 61, "test_read_nostring_workbook" ) {}
void runTest() { suite_test_read.test_read_nostring_workbook(); }
} testDescription_suite_test_read_test_read_nostring_workbook;
static class TestDescription_suite_test_read_test_read_empty_file : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_read_test_read_empty_file() : CxxTest::RealTestDescription( Tests_test_read, suiteDescription_test_read, 64, "test_read_empty_file" ) {}
TestDescription_suite_test_read_test_read_empty_file() : CxxTest::RealTestDescription( Tests_test_read, suiteDescription_test_read, 68, "test_read_empty_file" ) {}
void runTest() { suite_test_read.test_read_empty_file(); }
} testDescription_suite_test_read_test_read_empty_file;
static class TestDescription_suite_test_read_test_read_empty_archive : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_read_test_read_empty_archive() : CxxTest::RealTestDescription( Tests_test_read, suiteDescription_test_read, 72, "test_read_empty_archive" ) {}
TestDescription_suite_test_read_test_read_empty_archive() : CxxTest::RealTestDescription( Tests_test_read, suiteDescription_test_read, 74, "test_read_empty_archive" ) {}
void runTest() { suite_test_read.test_read_empty_archive(); }
} testDescription_suite_test_read_test_read_empty_archive;
static class TestDescription_suite_test_read_test_read_dimension : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_read_test_read_dimension() : CxxTest::RealTestDescription( Tests_test_read, suiteDescription_test_read, 79, "test_read_dimension" ) {}
void runTest() { suite_test_read.test_read_dimension(); }
} testDescription_suite_test_read_test_read_dimension;
static class TestDescription_suite_test_read_test_calculate_dimension_iter : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_read_test_calculate_dimension_iter() : CxxTest::RealTestDescription( Tests_test_read, suiteDescription_test_read, 89, "test_calculate_dimension_iter" ) {}
void runTest() { suite_test_read.test_calculate_dimension_iter(); }
} testDescription_suite_test_read_test_calculate_dimension_iter;
static class TestDescription_suite_test_read_test_get_highest_row_iter : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_read_test_get_highest_row_iter() : CxxTest::RealTestDescription( Tests_test_read, suiteDescription_test_read, 99, "test_get_highest_row_iter" ) {}
void runTest() { suite_test_read.test_get_highest_row_iter(); }
} testDescription_suite_test_read_test_get_highest_row_iter;
static class TestDescription_suite_test_read_test_read_workbook_with_no_properties : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_read_test_read_workbook_with_no_properties() : CxxTest::RealTestDescription( Tests_test_read, suiteDescription_test_read, 109, "test_read_workbook_with_no_properties" ) {}
TestDescription_suite_test_read_test_read_workbook_with_no_properties() : CxxTest::RealTestDescription( Tests_test_read, suiteDescription_test_read, 80, "test_read_workbook_with_no_properties" ) {}
void runTest() { suite_test_read.test_read_workbook_with_no_properties(); }
} testDescription_suite_test_read_test_read_workbook_with_no_properties;
static class TestDescription_suite_test_read_test_read_general_style : public CxxTest::RealTestDescription {
static class TestDescription_suite_test_read_test_read_workbook_with_styles_general : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_read_test_read_general_style() : CxxTest::RealTestDescription( Tests_test_read, suiteDescription_test_read, 116, "test_read_general_style" ) {}
void runTest() { suite_test_read.test_read_general_style(); }
} testDescription_suite_test_read_test_read_general_style;
TestDescription_suite_test_read_test_read_workbook_with_styles_general() : CxxTest::RealTestDescription( Tests_test_read, suiteDescription_test_read, 92, "test_read_workbook_with_styles_general" ) {}
void runTest() { suite_test_read.test_read_workbook_with_styles_general(); }
} testDescription_suite_test_read_test_read_workbook_with_styles_general;
static class TestDescription_suite_test_read_test_read_date_style : public CxxTest::RealTestDescription {
static class TestDescription_suite_test_read_test_read_workbook_with_styles_date : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_read_test_read_date_style() : CxxTest::RealTestDescription( Tests_test_read, suiteDescription_test_read, 121, "test_read_date_style" ) {}
void runTest() { suite_test_read.test_read_date_style(); }
} testDescription_suite_test_read_test_read_date_style;
TestDescription_suite_test_read_test_read_workbook_with_styles_date() : CxxTest::RealTestDescription( Tests_test_read, suiteDescription_test_read, 99, "test_read_workbook_with_styles_date" ) {}
void runTest() { suite_test_read.test_read_workbook_with_styles_date(); }
} testDescription_suite_test_read_test_read_workbook_with_styles_date;
static class TestDescription_suite_test_read_test_read_number_style : public CxxTest::RealTestDescription {
static class TestDescription_suite_test_read_test_read_workbook_with_styles_number : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_read_test_read_number_style() : CxxTest::RealTestDescription( Tests_test_read, suiteDescription_test_read, 126, "test_read_number_style" ) {}
void runTest() { suite_test_read.test_read_number_style(); }
} testDescription_suite_test_read_test_read_number_style;
TestDescription_suite_test_read_test_read_workbook_with_styles_number() : CxxTest::RealTestDescription( Tests_test_read, suiteDescription_test_read, 106, "test_read_workbook_with_styles_number" ) {}
void runTest() { suite_test_read.test_read_workbook_with_styles_number(); }
} testDescription_suite_test_read_test_read_workbook_with_styles_number;
static class TestDescription_suite_test_read_test_read_time_style : public CxxTest::RealTestDescription {
static class TestDescription_suite_test_read_test_read_workbook_with_styles_time : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_read_test_read_time_style() : CxxTest::RealTestDescription( Tests_test_read, suiteDescription_test_read, 131, "test_read_time_style" ) {}
void runTest() { suite_test_read.test_read_time_style(); }
} testDescription_suite_test_read_test_read_time_style;
TestDescription_suite_test_read_test_read_workbook_with_styles_time() : CxxTest::RealTestDescription( Tests_test_read, suiteDescription_test_read, 113, "test_read_workbook_with_styles_time" ) {}
void runTest() { suite_test_read.test_read_workbook_with_styles_time(); }
} testDescription_suite_test_read_test_read_workbook_with_styles_time;
static class TestDescription_suite_test_read_test_read_percentage_style : public CxxTest::RealTestDescription {
static class TestDescription_suite_test_read_test_read_workbook_with_styles_percentage : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_read_test_read_percentage_style() : CxxTest::RealTestDescription( Tests_test_read, suiteDescription_test_read, 136, "test_read_percentage_style" ) {}
void runTest() { suite_test_read.test_read_percentage_style(); }
} testDescription_suite_test_read_test_read_percentage_style;
TestDescription_suite_test_read_test_read_workbook_with_styles_percentage() : CxxTest::RealTestDescription( Tests_test_read, suiteDescription_test_read, 120, "test_read_workbook_with_styles_percentage" ) {}
void runTest() { suite_test_read.test_read_workbook_with_styles_percentage(); }
} testDescription_suite_test_read_test_read_workbook_with_styles_percentage;
static class TestDescription_suite_test_read_test_read_win_base_date : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_read_test_read_win_base_date() : CxxTest::RealTestDescription( Tests_test_read, suiteDescription_test_read, 141, "test_read_win_base_date" ) {}
TestDescription_suite_test_read_test_read_win_base_date() : CxxTest::RealTestDescription( Tests_test_read, suiteDescription_test_read, 139, "test_read_win_base_date" ) {}
void runTest() { suite_test_read.test_read_win_base_date(); }
} testDescription_suite_test_read_test_read_win_base_date;
static class TestDescription_suite_test_read_test_read_mac_base_date : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_read_test_read_mac_base_date() : CxxTest::RealTestDescription( Tests_test_read, suiteDescription_test_read, 146, "test_read_mac_base_date" ) {}
TestDescription_suite_test_read_test_read_mac_base_date() : CxxTest::RealTestDescription( Tests_test_read, suiteDescription_test_read, 145, "test_read_mac_base_date" ) {}
void runTest() { suite_test_read.test_read_mac_base_date(); }
} testDescription_suite_test_read_test_read_mac_base_date;
static class TestDescription_suite_test_read_test_read_date_style_mac : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_read_test_read_date_style_mac() : CxxTest::RealTestDescription( Tests_test_read, suiteDescription_test_read, 151, "test_read_date_style_mac" ) {}
void runTest() { suite_test_read.test_read_date_style_mac(); }
} testDescription_suite_test_read_test_read_date_style_mac;
static class TestDescription_suite_test_read_test_read_date_style_win : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_read_test_read_date_style_win() : CxxTest::RealTestDescription( Tests_test_read, suiteDescription_test_read, 156, "test_read_date_style_win" ) {}
TestDescription_suite_test_read_test_read_date_style_win() : CxxTest::RealTestDescription( Tests_test_read, suiteDescription_test_read, 151, "test_read_date_style_win" ) {}
void runTest() { suite_test_read.test_read_date_style_win(); }
} testDescription_suite_test_read_test_read_date_style_win;
static class TestDescription_suite_test_read_test_read_date_value : public CxxTest::RealTestDescription {
static class TestDescription_suite_test_read_test_read_date_style_mac : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_read_test_read_date_value() : CxxTest::RealTestDescription( Tests_test_read, suiteDescription_test_read, 161, "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_style_mac() : CxxTest::RealTestDescription( Tests_test_read, suiteDescription_test_read, 158, "test_read_date_style_mac" ) {}
void runTest() { suite_test_read.test_read_date_style_mac(); }
} testDescription_suite_test_read_test_read_date_style_mac;
static class TestDescription_suite_test_read_test_read_compare_mac_win_dates : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_read_test_read_compare_mac_win_dates() : CxxTest::RealTestDescription( Tests_test_read, suiteDescription_test_read, 165, "test_read_compare_mac_win_dates" ) {}
void runTest() { suite_test_read.test_read_compare_mac_win_dates(); }
} testDescription_suite_test_read_test_read_compare_mac_win_dates;
static class TestDescription_suite_test_read_test_repair_central_directory : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_read_test_repair_central_directory() : CxxTest::RealTestDescription( Tests_test_read, suiteDescription_test_read, 177, "test_repair_central_directory" ) {}
void runTest() { suite_test_read.test_repair_central_directory(); }
} testDescription_suite_test_read_test_repair_central_directory;
static class TestDescription_suite_test_read_test_read_no_theme : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_read_test_read_no_theme() : CxxTest::RealTestDescription( Tests_test_read, suiteDescription_test_read, 192, "test_read_no_theme" ) {}
void runTest() { suite_test_read.test_read_no_theme(); }
} testDescription_suite_test_read_test_read_no_theme;
static class TestDescription_suite_test_read_test_read_cell_formulae : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_read_test_read_cell_formulae() : CxxTest::RealTestDescription( Tests_test_read, suiteDescription_test_read, 199, "test_read_cell_formulae" ) {}
void runTest() { suite_test_read.test_read_cell_formulae(); }
} testDescription_suite_test_read_test_read_cell_formulae;
static class TestDescription_suite_test_read_test_read_complex_formulae : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_read_test_read_complex_formulae() : CxxTest::RealTestDescription( Tests_test_read, suiteDescription_test_read, 219, "test_read_complex_formulae" ) {}
void runTest() { suite_test_read.test_read_complex_formulae(); }
} testDescription_suite_test_read_test_read_complex_formulae;
static class TestDescription_suite_test_read_test_data_only : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_read_test_data_only() : CxxTest::RealTestDescription( Tests_test_read, suiteDescription_test_read, 224, "test_data_only" ) {}
void runTest() { suite_test_read.test_data_only(); }
} testDescription_suite_test_read_test_data_only;
static class TestDescription_suite_test_read_test_detect_worksheets : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_read_test_detect_worksheets() : CxxTest::RealTestDescription( Tests_test_read, suiteDescription_test_read, 229, "test_detect_worksheets" ) {}
void runTest() { suite_test_read.test_detect_worksheets(); }
} testDescription_suite_test_read_test_detect_worksheets;
static class TestDescription_suite_test_read_test_read_rels : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_read_test_read_rels() : CxxTest::RealTestDescription( Tests_test_read, suiteDescription_test_read, 234, "test_read_rels" ) {}
void runTest() { suite_test_read.test_read_rels(); }
} testDescription_suite_test_read_test_read_rels;
static class TestDescription_suite_test_read_test_read_content_types : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_read_test_read_content_types() : CxxTest::RealTestDescription( Tests_test_read, suiteDescription_test_read, 239, "test_read_content_types" ) {}
void runTest() { suite_test_read.test_read_content_types(); }
} testDescription_suite_test_read_test_read_content_types;
static class TestDescription_suite_test_read_test_read_sheets : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_read_test_read_sheets() : CxxTest::RealTestDescription( Tests_test_read, suiteDescription_test_read, 269, "test_read_sheets" ) {}
void runTest() { suite_test_read.test_read_sheets(); }
} testDescription_suite_test_read_test_read_sheets;
static class TestDescription_suite_test_read_test_guess_types : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_read_test_guess_types() : CxxTest::RealTestDescription( Tests_test_read, suiteDescription_test_read, 290, "test_guess_types" ) {}
void runTest() { suite_test_read.test_guess_types(); }
} testDescription_suite_test_read_test_guess_types;
static class TestDescription_suite_test_read_test_read_autofilter : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_read_test_read_autofilter() : CxxTest::RealTestDescription( Tests_test_read, suiteDescription_test_read, 306, "test_read_autofilter" ) {}
void runTest() { suite_test_read.test_read_autofilter(); }
} testDescription_suite_test_read_test_read_autofilter;
static class TestDescription_suite_test_read_test_bad_formats_xlsb : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_read_test_bad_formats_xlsb() : CxxTest::RealTestDescription( Tests_test_read, suiteDescription_test_read, 314, "test_bad_formats_xlsb" ) {}
void runTest() { suite_test_read.test_bad_formats_xlsb(); }
} testDescription_suite_test_read_test_bad_formats_xlsb;
static class TestDescription_suite_test_read_test_bad_formats_xls : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_read_test_bad_formats_xls() : CxxTest::RealTestDescription( Tests_test_read, suiteDescription_test_read, 320, "test_bad_formats_xls" ) {}
void runTest() { suite_test_read.test_bad_formats_xls(); }
} testDescription_suite_test_read_test_bad_formats_xls;
static class TestDescription_suite_test_read_test_bad_formats_no : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_read_test_bad_formats_no() : CxxTest::RealTestDescription( Tests_test_read, suiteDescription_test_read, 326, "test_bad_formats_no" ) {}
void runTest() { suite_test_read.test_bad_formats_no(); }
} testDescription_suite_test_read_test_bad_formats_no;
#include "/Users/thomas/Development/xlnt/tests/test_strings.hpp"
@ -1010,144 +1082,192 @@ public:
void runTest() { suite_test_worksheet.test_set_bad_title(); }
} testDescription_suite_test_worksheet_test_set_bad_title;
static class TestDescription_suite_test_worksheet_test_increment_title : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_worksheet_test_increment_title() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 37, "test_increment_title" ) {}
void runTest() { suite_test_worksheet.test_increment_title(); }
} testDescription_suite_test_worksheet_test_increment_title;
static class TestDescription_suite_test_worksheet_test_set_bad_title_character : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_worksheet_test_set_bad_title_character() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 37, "test_set_bad_title_character" ) {}
TestDescription_suite_test_worksheet_test_set_bad_title_character() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 45, "test_set_bad_title_character" ) {}
void runTest() { suite_test_worksheet.test_set_bad_title_character(); }
} testDescription_suite_test_worksheet_test_set_bad_title_character;
static class TestDescription_suite_test_worksheet_test_worksheet_dimension : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_worksheet_test_worksheet_dimension() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 48, "test_worksheet_dimension" ) {}
TestDescription_suite_test_worksheet_test_worksheet_dimension() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 56, "test_worksheet_dimension" ) {}
void runTest() { suite_test_worksheet.test_worksheet_dimension(); }
} testDescription_suite_test_worksheet_test_worksheet_dimension;
static class TestDescription_suite_test_worksheet_test_worksheet_range : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_worksheet_test_worksheet_range() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 57, "test_worksheet_range" ) {}
TestDescription_suite_test_worksheet_test_worksheet_range() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 65, "test_worksheet_range" ) {}
void runTest() { suite_test_worksheet.test_worksheet_range(); }
} testDescription_suite_test_worksheet_test_worksheet_range;
static class TestDescription_suite_test_worksheet_test_worksheet_named_range : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_worksheet_test_worksheet_named_range() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 65, "test_worksheet_named_range" ) {}
TestDescription_suite_test_worksheet_test_worksheet_named_range() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 73, "test_worksheet_named_range" ) {}
void runTest() { suite_test_worksheet.test_worksheet_named_range(); }
} testDescription_suite_test_worksheet_test_worksheet_named_range;
static class TestDescription_suite_test_worksheet_test_bad_named_range : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_worksheet_test_bad_named_range() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 75, "test_bad_named_range" ) {}
TestDescription_suite_test_worksheet_test_bad_named_range() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 83, "test_bad_named_range" ) {}
void runTest() { suite_test_worksheet.test_bad_named_range(); }
} testDescription_suite_test_worksheet_test_bad_named_range;
static class TestDescription_suite_test_worksheet_test_named_range_wrong_sheet : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_worksheet_test_named_range_wrong_sheet() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 81, "test_named_range_wrong_sheet" ) {}
TestDescription_suite_test_worksheet_test_named_range_wrong_sheet() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 89, "test_named_range_wrong_sheet" ) {}
void runTest() { suite_test_worksheet.test_named_range_wrong_sheet(); }
} testDescription_suite_test_worksheet_test_named_range_wrong_sheet;
static class TestDescription_suite_test_worksheet_test_cell_offset : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_worksheet_test_cell_offset() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 89, "test_cell_offset" ) {}
TestDescription_suite_test_worksheet_test_cell_offset() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 97, "test_cell_offset" ) {}
void runTest() { suite_test_worksheet.test_cell_offset(); }
} testDescription_suite_test_worksheet_test_cell_offset;
static class TestDescription_suite_test_worksheet_test_range_offset : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_worksheet_test_range_offset() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 95, "test_range_offset" ) {}
TestDescription_suite_test_worksheet_test_range_offset() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 103, "test_range_offset" ) {}
void runTest() { suite_test_worksheet.test_range_offset(); }
} testDescription_suite_test_worksheet_test_range_offset;
static class TestDescription_suite_test_worksheet_test_cell_alternate_coordinates : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_worksheet_test_cell_alternate_coordinates() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 104, "test_cell_alternate_coordinates" ) {}
TestDescription_suite_test_worksheet_test_cell_alternate_coordinates() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 112, "test_cell_alternate_coordinates" ) {}
void runTest() { suite_test_worksheet.test_cell_alternate_coordinates(); }
} testDescription_suite_test_worksheet_test_cell_alternate_coordinates;
static class TestDescription_suite_test_worksheet_test_cell_range_name : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_worksheet_test_cell_range_name() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 111, "test_cell_range_name" ) {}
TestDescription_suite_test_worksheet_test_cell_range_name() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 119, "test_cell_range_name" ) {}
void runTest() { suite_test_worksheet.test_cell_range_name(); }
} testDescription_suite_test_worksheet_test_cell_range_name;
static class TestDescription_suite_test_worksheet_test_garbage_collect : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_worksheet_test_garbage_collect() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 123, "test_garbage_collect" ) {}
TestDescription_suite_test_worksheet_test_garbage_collect() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 131, "test_garbage_collect" ) {}
void runTest() { suite_test_worksheet.test_garbage_collect(); }
} testDescription_suite_test_worksheet_test_garbage_collect;
static class TestDescription_suite_test_worksheet_test_hyperlink_relationships : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_worksheet_test_hyperlink_relationships() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 145, "test_hyperlink_relationships" ) {}
TestDescription_suite_test_worksheet_test_hyperlink_relationships() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 153, "test_hyperlink_relationships" ) {}
void runTest() { suite_test_worksheet.test_hyperlink_relationships(); }
} testDescription_suite_test_worksheet_test_hyperlink_relationships;
static class TestDescription_suite_test_worksheet_test_bad_relationship_type : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_worksheet_test_bad_relationship_type() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 165, "test_bad_relationship_type" ) {}
TestDescription_suite_test_worksheet_test_bad_relationship_type() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 173, "test_bad_relationship_type" ) {}
void runTest() { 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 {
public:
TestDescription_suite_test_worksheet_test_append_list() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 170, "test_append_list" ) {}
TestDescription_suite_test_worksheet_test_append_list() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 178, "test_append_list" ) {}
void runTest() { 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 {
public:
TestDescription_suite_test_worksheet_test_append_dict_letter() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 180, "test_append_dict_letter" ) {}
TestDescription_suite_test_worksheet_test_append_dict_letter() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 188, "test_append_dict_letter" ) {}
void runTest() { 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 {
public:
TestDescription_suite_test_worksheet_test_append_dict_index() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 190, "test_append_dict_index" ) {}
TestDescription_suite_test_worksheet_test_append_dict_index() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 198, "test_append_dict_index" ) {}
void runTest() { 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 {
public:
TestDescription_suite_test_worksheet_test_append_2d_list() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 200, "test_append_2d_list" ) {}
TestDescription_suite_test_worksheet_test_append_2d_list() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 208, "test_append_2d_list" ) {}
void runTest() { 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 {
public:
TestDescription_suite_test_worksheet_test_rows() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 215, "test_rows" ) {}
TestDescription_suite_test_worksheet_test_rows() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 223, "test_rows" ) {}
void runTest() { suite_test_worksheet.test_rows(); }
} testDescription_suite_test_worksheet_test_rows;
static class TestDescription_suite_test_worksheet_test_cols : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_worksheet_test_cols() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 238, "test_cols" ) {}
void runTest() { suite_test_worksheet.test_cols(); }
} testDescription_suite_test_worksheet_test_cols;
static class TestDescription_suite_test_worksheet_test_auto_filter : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_worksheet_test_auto_filter() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 230, "test_auto_filter" ) {}
TestDescription_suite_test_worksheet_test_auto_filter() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 253, "test_auto_filter" ) {}
void runTest() { suite_test_worksheet.test_auto_filter(); }
} testDescription_suite_test_worksheet_test_auto_filter;
static class TestDescription_suite_test_worksheet_test_freeze : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_worksheet_test_freeze() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 267, "test_freeze" ) {}
void runTest() { suite_test_worksheet.test_freeze(); }
} testDescription_suite_test_worksheet_test_freeze;
static class TestDescription_suite_test_worksheet_test_write_empty : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_worksheet_test_write_empty() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 284, "test_write_empty" ) {}
void runTest() { suite_test_worksheet.test_write_empty(); }
} testDescription_suite_test_worksheet_test_write_empty;
static class TestDescription_suite_test_worksheet_test_page_margins : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_worksheet_test_page_margins() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 244, "test_page_margins" ) {}
TestDescription_suite_test_worksheet_test_page_margins() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 296, "test_page_margins" ) {}
void runTest() { suite_test_worksheet.test_page_margins(); }
} testDescription_suite_test_worksheet_test_page_margins;
static class TestDescription_suite_test_worksheet_test_merge : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_worksheet_test_merge() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 290, "test_merge" ) {}
TestDescription_suite_test_worksheet_test_merge() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 308, "test_merge" ) {}
void runTest() { suite_test_worksheet.test_merge(); }
} testDescription_suite_test_worksheet_test_merge;
static class TestDescription_suite_test_worksheet_test_freeze : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_worksheet_test_freeze() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 359, "test_freeze" ) {}
void runTest() { suite_test_worksheet.test_freeze(); }
} testDescription_suite_test_worksheet_test_freeze;
static class TestDescription_suite_test_worksheet_test_printer_settings : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_worksheet_test_printer_settings() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 376, "test_printer_settings" ) {}
TestDescription_suite_test_worksheet_test_printer_settings() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 320, "test_printer_settings" ) {}
void runTest() { suite_test_worksheet.test_printer_settings(); }
} testDescription_suite_test_worksheet_test_printer_settings;
static class TestDescription_suite_test_worksheet_test_header_footer : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_worksheet_test_header_footer() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 342, "test_header_footer" ) {}
void runTest() { suite_test_worksheet.test_header_footer(); }
} testDescription_suite_test_worksheet_test_header_footer;
static class TestDescription_suite_test_worksheet_test_positioning_point : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_worksheet_test_positioning_point() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 419, "test_positioning_point" ) {}
void runTest() { suite_test_worksheet.test_positioning_point(); }
} testDescription_suite_test_worksheet_test_positioning_point;
static class TestDescription_suite_test_worksheet_test_positioning_roundtrip : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_worksheet_test_positioning_roundtrip() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 427, "test_positioning_roundtrip" ) {}
void runTest() { suite_test_worksheet.test_positioning_roundtrip(); }
} testDescription_suite_test_worksheet_test_positioning_roundtrip;
static class TestDescription_suite_test_worksheet_test_page_setup : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_worksheet_test_page_setup() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 438, "test_page_setup" ) {}
void runTest() { suite_test_worksheet.test_page_setup(); }
} testDescription_suite_test_worksheet_test_page_setup;
static class TestDescription_suite_test_worksheet_test_page_options : public CxxTest::RealTestDescription {
public:
TestDescription_suite_test_worksheet_test_page_options() : CxxTest::RealTestDescription( Tests_test_worksheet, suiteDescription_test_worksheet, 449, "test_page_options" ) {}
void runTest() { suite_test_worksheet.test_page_options(); }
} testDescription_suite_test_worksheet_test_page_options;
#include "/Users/thomas/Development/xlnt/tests/test_write.hpp"
static test_write suite_test_write;

View File

@ -342,7 +342,7 @@ public:
xlnt::worksheet ws = wb.create_sheet();
xlnt::cell cell(ws, "A1");
cell = xlnt::timedelta().days(1).hours(3);
cell = xlnt::timedelta(1, 3, 0, 0, 0);
TS_ASSERT_EQUALS(cell, 1.125);
TS_ASSERT_EQUALS(cell.get_data_type(), xlnt::cell::type::numeric);
}

View File

View File

View File

View File

@ -12,7 +12,7 @@ class test_read : public CxxTest::TestSuite
public:
void test_read_standalone_worksheet()
{
auto path = PathHelper::GetDataDirectory() + "/reader/sheet2.xml";
auto path = PathHelper::GetDataDirectory("/reader/sheet2.xml");
xlnt::workbook wb;
xlnt::worksheet ws(wb);
{
@ -30,8 +30,8 @@ public:
xlnt::workbook standard_workbook()
{
auto path = PathHelper::GetDataDirectory("genuine/emtpy.xlsx");
return xlnt::load_workbook(path);
auto path = PathHelper::GetDataDirectory("/genuine/empty.xlsx");
return xlnt::reader::load_workbook(path);
}
void test_read_standard_workbook()
@ -41,15 +41,15 @@ public:
void test_read_standard_workbook_from_fileobj()
{
auto path = PathHelper::GetDataDirectory("genuine/emtpy.xlsx");
auto path = PathHelper::GetDataDirectory("/genuine/empty.xlsx");
std::ifstream fo(path, std::ios::binary);
auto wb = xlnt::load_workbook(path);
auto wb = xlnt::reader::load_workbook(path);
TS_ASSERT_DIFFERS(standard_workbook(), nullptr);
}
void test_read_worksheet()
{
auto wb = standard_workbook()
auto wb = standard_workbook();
auto sheet2 = wb.get_sheet_by_name("Sheet2 - Numbers");
TS_ASSERT_DIFFERS(sheet2, nullptr);
TS_ASSERT_EQUALS("This is cell G5", sheet2.get_cell("G5"));
@ -61,112 +61,112 @@ public:
void test_read_nostring_workbook()
{
auto path = PathHelper::GetDataDirectory("/genuine/empty-no-string.xlsx");
auto wb = xlnt::load_workbook(path);
auto wb = xlnt::reader::load_workbook(path);
TS_ASSERT_DIFFERS(standard_workbook(), nullptr);
}
void test_read_empty_file()
{
auto path = PathHelper::GetDataDirectory("/reader/null_file.xlsx";
TS_ASSERT_THROWS(xlnt::load_workbook(path), xlnt::invalid_file_exception);
auto path = PathHelper::GetDataDirectory("/reader/null_file.xlsx");
TS_ASSERT_THROWS(xlnt::reader::load_workbook(path), xlnt::invalid_file_exception);
}
void test_read_empty_archive()
{
auto path = PathHelper::GetDataDirectory("/reader/null_archive.xlsx");
TS_ASSERT_THROWS(xlnt::load_workbook(path), xlnt::invalid_file_exception);
TS_ASSERT_THROWS(xlnt::reader::load_workbook(path), xlnt::invalid_file_exception);
}
void test_read_workbook_with_no_properties()
{
auto path = PathHelper::GetDataDirectory("/reader/null_archive.xlsx");
xlnt::load_workbook(path);
auto path = PathHelper::GetDataDirectory("/genuine/empty_with_no_properties.xlsx");
xlnt::reader::load_workbook(path);
}
void workbook_with_styles()
xlnt::workbook workbook_with_styles()
{
auto path = PathHelper::GetDataDirectory("/reader/empty-with-styles.xlsx");
return xlnt::load_workbook(path);
auto path = PathHelper::GetDataDirectory("/genuine/empty-with-styles.xlsx");
return xlnt::reader::load_workbook(path);
}
void test_read_workbook_with_styles_general()
{
auto wb = workbook_with_styles();
auto ws = wb["Sheet1"];
TS_ASSERT(ws.get_cell("A1").get_style().get_number_format().get_format_code() == xlnt::number_format::known_formats::general);
TS_ASSERT_EQUALS(ws.get_cell("A1").get_style().get_number_format().get_format_code(), xlnt::number_format::format::general);
}
void test_read_workbook_with_styles_date()
{
auto wb = workbook_with_styles();
auto ws = wb["Sheet1"];
TS_ASSERT(ws.get_cell("A2").get_style().get_number_format().get_format_code() == xlnt::number_format::known_formats::date_xlsx14);
TS_ASSERT_EQUALS(ws.get_cell("A2").get_style().get_number_format().get_format_code(), xlnt::number_format::format::date_xlsx14);
}
void test_read_workbook_with_styles_number()
{
auto wb = workbook_with_styles();
auto ws = wb["Sheet1"];
TS_ASSERT(ws.get_cell("A3").get_style().get_number_format().get_format_code() == xlnt::number_format::known_formats::number00);
TS_ASSERT_EQUALS(ws.get_cell("A3").get_style().get_number_format().get_format_code(), xlnt::number_format::format::number00);
}
void test_read_workbook_with_styles_time()
{
auto wb = workbook_with_styles();
auto ws = wb["Sheet1"];
TS_ASSERT(ws.get_cell("A4").get_style().get_number_format().get_format_code() == xlnt::number_format::known_formats::date_time_3);
TS_ASSERT_EQUALS(ws.get_cell("A4").get_style().get_number_format().get_format_code(), xlnt::number_format::format::date_time3);
}
void test_read_workbook_with_styles_percentage()
{
auto wb = workbook_with_styles();
auto ws = wb["Sheet1"];
TS_ASSERT(ws.get_cell("A5").get_style().get_number_format().get_format_code() == xlnt::number_format::known_formats::percentage00);
TS_ASSERT_EQUALS(ws.get_cell("A5").get_style().get_number_format().get_format_code(), xlnt::number_format::format::percentage00);
}
void date_mac_1904()
xlnt::workbook date_mac_1904()
{
auto path = PathHelper::GetDataDirectory("/reader/date_1904.xlsx");
return xlnt::load_workbook(path);
return xlnt::reader::load_workbook(path);
}
void date_std_1900()
xlnt::workbook date_std_1900()
{
auto path = PathHelper::GetDataDirectory("/reader/date_1900.xlsx");
return xlnt::load_workbook(path);
return xlnt::reader::load_workbook(path);
}
void test_read_win_base_date()
{
auto wb = date_std_1900();
TS_ASSERT_EQUALS(wb.get_properties().get_excel_base_date(), xlnt::calendar::windows_1900);
TS_ASSERT_EQUALS(wb.get_properties().excel_base_date, xlnt::calendar::windows_1900);
}
void test_read_mac_base_date()
{
auto wb = date_mac_1904();
TS_ASSERT_EQUALS(wb.get_properties().get_excel_base_date(), xlnt::calendar::mac_1904);
TS_ASSERT_EQUALS(wb.get_properties().excel_base_date, xlnt::calendar::mac_1904);
}
void test_read_date_style_win()
{
auto wb = date_std_1900();
auto ws = wb["Sheet1"];
TS_ASSERT_EQUALS(ws.get_cell("A1").get_style().get_number_format().get_format_code() == xlnt::number_format::known_formats::date_xlsx14);
TS_ASSERT_EQUALS(ws.get_cell("A1").get_style().get_number_format().get_format_code(), xlnt::number_format::format::date_xlsx14);
}
void test_read_date_style_mac()
{
auto wb = date_mac_1904();
auto ws = wb["Sheet1"];
TS_ASSERT_EQUALS(ws.get_cell("A1").get_style().get_number_format().get_format_code() == xlnt::number_format::known_formats::date_xlsx14);
TS_ASSERT_EQUALS(ws.get_cell("A1").get_style().get_number_format().get_format_code(), xlnt::number_format::format::date_xlsx14);
}
void test_read_win_base_date()
void test_read_compare_mac_win_dates()
{
auto wb_mac = date_mac_1904();
auto ws_mac = wb_mac["Sheet1"];
auto wb_win = date_win_1900();
auto wb_win = date_std_1900();
auto ws_win = wb_win["Sheet1"];
xlnt::datetime dt(2011, 10, 31);
TS_ASSERT_EQUALS(ws_mac.get_cell("A1"), dt);
@ -192,17 +192,19 @@ public:
void test_read_no_theme()
{
auto path = PathHelper::GetDataDirectory("/genuine/libreoffice_nrt.xlsx");
auto wb = xlnt::load_workbook(path);
auto wb = xlnt::reader::load_workbook(path);
TS_ASSERT_DIFFERS(wb, nullptr);
}
void test_read_cell_formulae()
{
TS_ASSERT(false);
/*
xlnt::workbook wb;
auto ws = wb.get_active_sheet();
auto path = PathHelper::GetDataDirectory("/reader/worksheet_formula.xml");
std::ifstream ws_stream(path);
xlnt::fast_parse(ws, ws_stream, {"", ""}, {}, 0);
xlnt::reader::fast_parse(ws, ws_stream, {"", ""}, {}, 0);
auto b1 = ws.get_cell("B1");
TS_ASSERT_EQUALS(b1.get_data_type(), xlnt::cell::type::formula);
@ -211,6 +213,7 @@ public:
auto a6 = ws.get_cell("A6");
TS_ASSERT_EQUALS(a6.get_data_type(), xlnt::cell::type::formula);
TS_ASSERT_EQUALS(a6, "=SUM(A4:A5)");
*/
}
void test_read_complex_formulae()
@ -254,42 +257,47 @@ public:
};
auto path = PathHelper::GetDataDirectory("/reader/bug137.xlsx");
xlnt::zip_file f(path);
auto result = xlnt::workbook_reader::read_conent_types(f);
xlnt::zip_file f(path, xlnt::file_mode::open);
auto result = xlnt::reader::read_content_types(f);
TS_ASSERT_EQUALS(result, expected);
for(std::size_t i = 0; i < expected.size(); i++)
{
TS_ASSERT_EQUALS(result[i], expected[i]);
}
}
void test_read_sheets()
{
{
auto path = PathHelper::GetDataDirectory("/reader/bug137.xlsx");
xlnt::zip_file f(path);
auto sheets = xlnt::workbook_reader::read_sheets(f);
TS_ASSERT_EQUALS(sheets["rId1"], "Chart1");
TS_ASSERT_EQUALS(sheets["rId2"], "Sheet1");
xlnt::zip_file f(path, xlnt::file_mode::open);
auto sheets = xlnt::reader::read_sheets(f);
std::vector<std::pair<std::string, std::string>> expected =
{{"rId1", "Chart1"}, {"rId2", "Sheet1"}};
TS_ASSERT_EQUALS(sheets, expected);
}
{
auto path = PathHelper::GetDataDirectory("/reader/bug304.xlsx");
xlnt::zip_file f(path);
auto sheets = xlnt::workbook_reader::read_sheets(f);
TS_ASSERT_EQUALS(sheets["rId1"], "Sheet1");
TS_ASSERT_EQUALS(sheets["rId2"], "Sheet2");
TS_ASSERT_EQUALS(sheets["rId3"], "Sheet3");
xlnt::zip_file f(path, xlnt::file_mode::open);
auto sheets = xlnt::reader::read_sheets(f);
std::vector<std::pair<std::string, std::string>> expected =
{{"rId1", "Sheet1"}, {"rId2", "Sheet2"}, {"rId3", "Sheet3"}};
TS_ASSERT_EQUALS(sheets, expected);
}
}
void test_guess_types()
{
bool guess;
xlnt::cell:type dtype;
xlnt::cell::type dtype;
std::vector<std::pair<bool, xlnt::cell::type>> test_cases = {{true, xlnt::cell::type::numeric}, {false, xlnt::cell::type::string}};
for(const auto &expected : {true, xlnt::cell::type::number}, {false, xlnt::cell::type::string})
for(const auto &expected : test_cases)
{
std::tie(guess, dtype) = expected;
auto path = PathHelper::GetDataDirectory("/genuine/guess_types.xlsx");
auto wb = xlnt::load_workbook(path, guess);
auto wb = xlnt::reader::load_workbook(path, guess);
auto ws = wb.get_active_sheet();
TS_ASSERT_EQUALS(ws.get_cell("D2").get_data_type(), dtype);
}
@ -298,26 +306,26 @@ public:
void test_read_autofilter()
{
auto path = PathHelper::GetDataDirectory("/reader/bug275.xlsx");
auto wb = xlnt::load_workbook(path);
auto wb = xlnt::reader::load_workbook(path);
auto ws = wb.get_active_sheet();
TS_ASSERT_EQUALS(ws.get_auto_filter.get_reference(), "A1:B6");
TS_ASSERT_EQUALS(ws.get_auto_filter().to_string(), "A1:B6");
}
void test_bad_formats_xlsb()
{
auto path = PathHelper::GetDataDirectory("/genuine/a.xlsb");
TS_ASSERT_THROWS(xlnt::load_workbook(path), xlnt::invaid_file_exception);
TS_ASSERT_THROWS(xlnt::reader::load_workbook(path), xlnt::invalid_file_exception);
}
void test_bad_formats_xls()
{
auto path = PathHelper::GetDataDirectory("/genuine/a.xls");
TS_ASSERT_THROWS(xlnt::load_workbook(path), xlnt::invaid_file_exception);
TS_ASSERT_THROWS(xlnt::reader::load_workbook(path), xlnt::invalid_file_exception);
}
void test_bad_formats_no()
{
auto path = PathHelper::GetDataDirectory("/genuine/a.no-format");
TS_ASSERT_THROWS(xlnt::load_workbook(path), xlnt::invaid_file_exception);
TS_ASSERT_THROWS(xlnt::reader::load_workbook(path), xlnt::invalid_file_exception);
}
};

View File

@ -39,7 +39,7 @@ public:
auto ws1 = wb_.create_sheet("Test");
TS_ASSERT_EQUALS(ws1.get_title(), "Test");
auto ws2 = wb_.create_sheet("Test");
TS_ASSERT_EQUALS(ws1.get_title(), "Test1");
TS_ASSERT_EQUALS(ws2.get_title(), "Test1");
}
void test_set_bad_title_character()
@ -66,7 +66,7 @@ public:
{
xlnt::worksheet ws(wb_);
auto xlrange = ws.get_range("A1:C4");
TS_ASSERT_EQUALS(4, xlrange.num_rows());
TS_ASSERT_EQUALS(4, xlrange.length());
TS_ASSERT_EQUALS(3, xlrange[0].num_cells());
}
@ -75,7 +75,7 @@ public:
xlnt::worksheet ws(wb_);
wb_.create_named_range("test_range", ws, "C5");
auto xlrange = ws.get_named_range("test_range");
TS_ASSERT_EQUALS(1, xlrange.num_rows());
TS_ASSERT_EQUALS(1, xlrange.length());
TS_ASSERT_EQUALS(1, xlrange[0].num_cells());
TS_ASSERT_EQUALS(5, xlrange[0][0].get_row());
}
@ -104,7 +104,7 @@ public:
{
xlnt::worksheet ws(wb_);
auto xlrange = ws.get_range(xlnt::range_reference("A1:C4").make_offset(3, 1));
TS_ASSERT_EQUALS(4, xlrange.num_rows());
TS_ASSERT_EQUALS(4, xlrange.length());
TS_ASSERT_EQUALS(3, xlrange[0].num_cells());
TS_ASSERT_EQUALS("D2", xlrange[0][0].get_reference().to_string());
}
@ -246,8 +246,8 @@ public:
TS_ASSERT_EQUALS(cols.length(), 3);
TS_ASSERT_EQUALS(rows[0][0], "first");
TS_ASSERT_EQUALS(rows[2][8], "last");
TS_ASSERT_EQUALS(cols[0][0], "first");
TS_ASSERT_EQUALS(cols[2][8], "last");
}
void test_auto_filter()
@ -364,7 +364,7 @@ public:
ws.get_header_footer().get_right_footer().set_font_size(14);
ws.get_header_footer().get_right_footer().set_font_color("AABBCC");
auto expected_xml_string =
std::string expected_xml_string =
"<worksheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\">"
" <sheetPr>"
" <outlinePr summaryRight=\"1\" summaryBelow=\"1\"/>"
@ -384,66 +384,79 @@ public:
" </headerFooter>"
"</worksheet>";
pugi::xml_document doc;
doc.load(expected_xml_string.c_str());
pugi::xml_document expected_doc;
pugi::xml_document observed_doc;
TS_ASSERT(Helper::compare_xml(doc, xlnt::worksheet_writer::write_worksheet(ws, {}, {})));
expected_doc.load(expected_xml_string.c_str());
observed_doc.load(xlnt::writer::write_worksheet(ws, {}, {}).c_str());
auto ws = wb_.create_sheet();
TS_ASSERT(Helper::compare_xml(expected_doc, observed_doc));
ws = wb_.create_sheet();
expected_xml_string =
"<worksheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\">"
" <sheetPr>"
" <outlinePr summaryRight="1" summaryBelow="1"/>"
" <outlinePr summaryRight=\"1\" summaryBelow=\"1\"/>"
" </sheetPr>"
" <dimension ref="A1:A1"/>"
" <dimension ref=\"A1:A1\"/>"
" <sheetViews>"
" <sheetView workbookViewId="0">"
" <selection sqref="A1" activeCell="A1"/>"
" <sheetView workbookViewId=\"0\">"
" <selection sqref=\"A1\" activeCell=\"A1\"/>"
" </sheetView>"
" </sheetViews>"
" <sheetFormatPr baseColWidth="10" defaultRowHeight="15"/>"
" <sheetFormatPr baseColWidth=\"10\" defaultRowHeight=\"15\"/>"
" <sheetData/>"
" <pageMargins left="0.75" right="0.75" top="1" bottom="1" header="0.5" footer="0.5"/>"
" <pageMargins left=\"0.75\" right=\"0.75\" top=\"1\" bottom=\"1\" header=\"0.5\" footer=\"0.5\"/>"
"</worksheet>";
pugi::xml_document doc;
doc.load(expected_xml_string.c_str());
expected_doc.load(expected_xml_string.c_str());
observed_doc.load(xlnt::writer::write_worksheet(ws, {}, {}).c_str());
TS_ASSERT(Helper::compare_xml(doc, xlnt::worksheet_writer::write_worksheet(ws, {}, {})));
TS_ASSERT(Helper::compare_xml(expected_doc, observed_doc));
}
void test_positioning_point()
{
auto ws = wb_.create_sheet();
TS_ASSERT(false);
/*
auto ws = wb_.create_sheet();
*/
}
void test_positioning_roundtrip()
{
TS_ASSERT(false);
/*
auto ws = wb_.create_sheet();
TS_ASSERT_EQUALS(ws.get_point_pos(ws.get_cell("A1").get_anchor()), xlnt::cell_reference("A1"));
TS_ASSERT_EQUALS(ws.get_point_pos(ws.get_cell("D52").get_anchor()), xlnt::cell_reference("D52"));
TS_ASSERT_EQUALS(ws.get_point_pos(ws.get_cell("X11").get_anchor()), xlnt::cell_reference("X11"));
*/
}
void test_page_setup()
{
TS_ASSERT(false);
/*
xlnt::page_setup p;
TS_ASSERT(p.get_setup().empty());
TS_ASSERT(p.get_page_setup().empty());
p.set_scale(1);
TS_ASSERT_EQUALS(p.get_setup().at("scale"), 1);
TS_ASSERT_EQUALS(p.get_page_setup().at("scale"), 1);
*/
}
void test_page_options()
{
TS_ASSERT(false);
/*
xlnt::page_setup p;
TS_ASSERT(p.get_options().empty());
p.set_horizontal_centered(true);
p.set_vertical_centered(true);
TS_ASSERT_EQUALS(p.get_options().at("verticalCentered"), "1");
TS_ASSERT_EQUALS(p.get_options().at("horizontalCentered"), "1");
*/
}
private: