rename getters and setters to the property name, many breaking changes\!

This commit is contained in:
Thomas Fussell 2016-12-02 14:37:50 +01:00
parent a1ff8c0ed2
commit c55aac9ecf
88 changed files with 3564 additions and 3819 deletions

View File

@ -106,7 +106,7 @@ public:
/// as for std::string and xlnt datetime types: date, time, datetime, and timedelta.
/// </summary>
template <typename T>
T get_value() const;
T value() const;
/// <summary>
/// Make this cell have a value of type null.
@ -120,17 +120,23 @@ public:
/// as for std::string and xlnt datetime types: date, time, datetime, and timedelta.
/// </summary>
template <typename T>
void set_value(T value);
void value(T value);
/// <summary>
/// Analyze string_value to determine its type, convert it to that type,
/// and set the value of this cell to that converted value.
/// </summary>
void value(const std::string &string_value, bool infer_type);
/// <summary>
/// Return the type of this cell.
/// </summary>
type get_data_type() const;
type data_type() const;
/// <summary>
/// Set the type of this cell.
/// </summary>
void set_data_type(type t);
void data_type(type t);
// properties
@ -150,34 +156,34 @@ public:
/// <summary>
/// Return a cell_reference that points to the location of this cell.
/// </summary>
cell_reference get_reference() const;
cell_reference reference() const;
/// <summary>
/// Return the column of this cell.
/// </summary>
column_t get_column() const;
column_t column() const;
/// <summary>
/// Return the row of this cell.
/// </summary>
row_t get_row() const;
row_t row() const;
/// <summary>
/// Return the location of this cell as an ordered pair.
/// </summary>
std::pair<int, int> get_anchor() const;
std::pair<int, int> anchor() const;
// hyperlink
/// <summary>
/// Return the URL of this cell's hyperlink.
/// </summary>
std::string get_hyperlink() const;
std::string hyperlink() const;
/// <summary>
/// Add a hyperlink to this cell pointing to the URI of the given value.
/// </summary>
void set_hyperlink(const std::string &value);
void hyperlink(const std::string &value);
/// <summary>
/// Return true if this cell has a hyperlink set.
@ -187,32 +193,32 @@ public:
// computed formatting
/// <summary>
/// Returns the result of get_computed_format().get_alignment().
/// Returns the result of computed_format().alignment().
/// </summary>
alignment computed_alignment() const;
/// <summary>
/// Returns the result of get_computed_format().get_border().
/// Returns the result of computed_format().border().
/// </summary>
border computed_border() const;
/// <summary>
/// Returns the result of get_computed_format().get_fill().
/// Returns the result of computed_format().fill().
/// </summary>
fill computed_fill() const;
/// <summary>
/// Returns the result of get_computed_format().get_font().
/// Returns the result of computed_format().font().
/// </summary>
font computed_font() const;
/// <summary>
/// Returns the result of get_computed_format().get_number_format().
/// Returns the result of computed_format().number_format().
/// </summary>
number_format computed_number_format() const;
/// <summary>
/// Returns the result of get_computed_format().get_protection().
/// Returns the result of computed_format().protection().
/// </summary>
protection computed_protection() const;
@ -244,68 +250,68 @@ public:
/// <summary>
/// Returns the number format of this cell.
/// </summary>
number_format get_number_format() const;
number_format number_format() const;
/// <summary>
/// Creates a new format in the workbook, sets its number_format
/// to the given format, and applies the format to this cell.
/// </summary>
void set_number_format(const number_format &format);
void number_format(const class number_format &format);
/// <summary>
/// Returns the font applied to the text in this cell.
/// </summary>
font get_font() const;
font font() const;
/// <summary>
/// Creates a new format in the workbook, sets its font
/// to the given font, and applies the format to this cell.
/// </summary>
void set_font(const font &font_);
void font(const class font &font_);
/// <summary>
/// Returns the fill applied to this cell.
/// </summary>
fill get_fill() const;
fill fill() const;
/// <summary>
/// Creates a new format in the workbook, sets its fill
/// to the given fill, and applies the format to this cell.
/// </summary>
void set_fill(const fill &fill_);
void fill(const class fill &fill_);
/// <summary>
/// Returns the border of this cell.
/// </summary>
border get_border() const;
border border() const;
/// <summary>
/// Creates a new format in the workbook, sets its border
/// to the given border, and applies the format to this cell.
/// </summary>
void set_border(const border &border_);
void border(const class border &border_);
/// <summary>
/// Returns the alignment of the text in this cell.
/// </summary>
alignment get_alignment() const;
alignment alignment() const;
/// <summary>
/// Creates a new format in the workbook, sets its alignment
/// to the given alignment, and applies the format to this cell.
/// </summary>
void set_alignment(const alignment &alignment_);
void alignment(const class alignment &alignment_);
/// <summary>
/// Returns the protection of this cell.
/// </summary>
protection get_protection() const;
protection protection() const;
/// <summary>
/// Creates a new format in the workbook, sets its protection
/// to the given protection, and applies the format to this cell.
/// </summary>
void set_protection(const protection &protection_);
void protection(const class protection &protection_);
// style
@ -343,13 +349,13 @@ public:
/// <summary>
/// Returns the string representation of the formula applied to this cell.
/// </summary>
std::string get_formula() const;
std::string formula() const;
/// <summary>
/// Sets the formula of this cell to the given value.
/// This formula string should begin with '='.
/// </summary>
void set_formula(const std::string &formula);
void formula(const std::string &formula);
/// <summary>
/// Removes the formula from this cell. After this is called, has_formula() will return false.
@ -387,17 +393,17 @@ public:
/// Generally, this shouldn't be called directly. Instead,
/// use worksheet::merge_cells on its parent worksheet.
/// </summary>
void set_merged(bool merged);
void merged(bool merged);
/// <summary>
/// Return the error string that is stored in this cell.
/// </summary>
std::string get_error() const;
std::string error() const;
/// <summary>
/// Directly assign the value of this cell to be the given error.
/// </summary>
void set_error(const std::string &error);
void error(const std::string &error);
/// <summary>
/// Return a cell from this cell's parent workbook at
@ -408,28 +414,28 @@ public:
/// <summary>
/// Return the worksheet that owns this cell.
/// </summary>
worksheet get_worksheet();
worksheet worksheet();
/// <summary>
/// Return the worksheet that owns this cell.
/// </summary>
const worksheet get_worksheet() const;
const class worksheet worksheet() const;
/// <summary>
/// Return the workbook of the worksheet that owns this cell.
/// </summary>
workbook &get_workbook();
workbook &workbook();
/// <summary>
/// Return the workbook of the worksheet that owns this cell.
/// </summary>
const workbook &get_workbook() const;
const class workbook &workbook() const;
/// <summary>
/// Shortcut to return the base date of the parent workbook.
/// Equivalent to get_workbook().get_properties().excel_base_date
/// Equivalent to workbook().properties().excel_base_date
/// </summary>
calendar get_base_date() const;
calendar base_date() const;
/// <summary>
/// Return to_check after checking encoding, size, and illegal characters.
@ -489,12 +495,6 @@ private:
friend class detail::xlsx_producer;
friend struct detail::cell_impl;
/// <summary>
/// Helper function to guess the type of a string, convert it,
/// and then use the correct cell::get_value according to the type.
/// </summary>
void guess_type_and_set_value(const std::string &value);
/// <summary>
/// Returns a non-const reference to the format of this cell.
/// This is for internal use only.

View File

@ -139,32 +139,32 @@ public:
/// Return a string that identifies the column of this reference
/// (e.g. second column from left is "B")
/// </summary>
column_t get_column() const;
column_t column() const;
/// <summary>
/// Set the column of this reference from a string that identifies a particular column.
/// </summary>
void set_column(const std::string &column_string);
void column(const std::string &column_string);
/// <summary>
/// Return a 1-indexed numeric index of the column of this reference.
/// </summary>
column_t get_column_index() const;
column_t::index_t column_index() const;
/// <summary>
/// Set the column of this reference from a 1-indexed number that identifies a particular column.
/// </summary>
void set_column_index(column_t column);
void column_index(column_t column);
/// <summary>
/// Return a 1-indexed numeric index of the row of this reference.
/// </summary>
row_t get_row() const;
row_t row() const;
/// <summary>
/// Set the row of this reference from a 1-indexed number that identifies a particular row.
/// </summary>
void set_row(row_t row);
void row(row_t row);
/// <summary>
/// Return a cell_reference offset from this cell_reference by

View File

@ -26,6 +26,7 @@
#include <xlnt/xlnt_config.hpp>
#include <xlnt/styles/color.hpp>
#include <xlnt/styles/font.hpp>
#include <xlnt/utils/optional.hpp>
namespace xlnt {
@ -56,12 +57,12 @@ public:
/// <summary>
///
/// </summary>
std::string get_string() const;
std::string string() const;
/// <summary>
///
/// </summary>
void set_string(const std::string &string);
void string(const std::string &string);
/// <summary>
///
@ -71,12 +72,12 @@ public:
/// <summary>
///
/// </summary>
std::size_t get_size() const;
std::size_t size() const;
/// <summary>
///
/// </summary>
void set_size(std::size_t size);
void size(std::size_t size);
/// <summary>
///
@ -86,12 +87,12 @@ public:
/// <summary>
///
/// </summary>
color get_color() const;
color color() const;
/// <summary>
///
/// </summary>
void set_color(const color &new_color);
void color(const class color &new_color);
/// <summary>
///
@ -101,12 +102,12 @@ public:
/// <summary>
///
/// </summary>
std::string get_font() const;
std::string font() const;
/// <summary>
///
/// </summary>
void set_font(const std::string &font);
void font(const std::string &font);
/// <summary>
///
@ -116,12 +117,12 @@ public:
/// <summary>
///
/// </summary>
std::size_t get_family() const;
std::size_t family() const;
/// <summary>
///
/// </summary>
void set_family(std::size_t family);
void family(std::size_t family);
/// <summary>
///
@ -131,27 +132,42 @@ public:
/// <summary>
///
/// </summary>
std::string get_scheme() const;
std::string scheme() const;
/// <summary>
///
/// </summary>
void set_scheme(const std::string &scheme);
void scheme(const std::string &scheme);
/// <summary>
///
/// </summary>
bool bold_set() const;
bool bold() const;
/// <summary>
///
/// </summary>
bool is_bold() const;
void bold(bool bold);
/// <summary>
///
/// </summary>
void set_bold(bool bold);
bool underline_set() const;
/// <summary>
///
/// </summary>
bool underlined() const;
/// <summary>
///
/// </summary>
font::underline_style underline() const;
/// <summary>
///
/// </summary>
void underline(font::underline_style style);
private:
/// <summary>
@ -162,32 +178,7 @@ private:
/// <summary>
///
/// </summary>
optional<std::size_t> size_;
/// <summary>
///
/// </summary>
optional<color> color_;
/// <summary>
///
/// </summary>
optional<std::string> font_;
/// <summary>
///
/// </summary>
optional<std::size_t> family_;
/// <summary>
///
/// </summary>
optional<std::string> scheme_;
/// <summary>
///
/// </summary>
optional<bool> bold_;
optional<xlnt::font> font_;
};
} // namespace xlnt

View File

@ -48,14 +48,14 @@ public:
/// Returns the path to all internal package parts registered as a source
/// or target of a relationship.
/// </summary>
std::vector<path> get_parts() const;
std::vector<path> parts() const;
// Relationships
/// <summary>
/// Returns true if the manifest contains a relationship with the given type with part as the source.
/// </summary>
bool has_relationship(const path &source, relationship::type type) const;
bool has_relationship(const path &source, relationship_type type) const;
/// <summary>
/// Returns true if the manifest contains a relationship with the given type with part as the source.
@ -66,39 +66,39 @@ public:
/// Returns the relationship with "source" as the source and with a type of "type".
/// Throws a key_not_found exception if no such relationship is found.
/// </summary>
relationship get_relationship(const path &source, relationship::type type) const;
relationship relationship(const path &source, relationship_type type) const;
/// <summary>
/// Returns the relationship with "source" as the source and with an ID of "rel_id".
/// Throws a key_not_found exception if no such relationship is found.
/// </summary>
relationship get_relationship(const path &source, const std::string &rel_id) const;
class relationship relationship(const path &source, const std::string &rel_id) const;
/// <summary>
/// Returns all relationship with "source" as the source.
/// </summary>
std::vector<relationship> get_relationships(const path &source) const;
std::vector<xlnt::relationship> relationships(const path &source) const;
/// <summary>
/// Returns all relationships with "source" as the source and with a type of "type".
/// </summary>
std::vector<relationship> get_relationships(const path &source, relationship::type type) const;
std::vector<xlnt::relationship> relationships(const path &source, relationship_type type) const;
/// <summary>
/// Returns the canonical path of the chain of relationships by traversing through rels
/// and forming the absolute combined path.
/// </summary>
path canonicalize(const std::vector<relationship> &rels) const;
path canonicalize(const std::vector<xlnt::relationship> &rels) const;
/// <summary>
///
/// </summary>
std::string register_relationship(const uri &source, relationship::type type, const uri &target, target_mode mode);
std::string register_relationship(const uri &source, relationship_type type, const uri &target, target_mode mode);
/// <summary>
///
/// </summary>
std::string register_relationship(const uri &source, relationship::type type, const uri &target, target_mode mode, const std::string &rel_id);
std::string register_relationship(const uri &source, relationship_type type, const uri &target, target_mode mode, const std::string &rel_id);
/// <summary>
///
@ -110,7 +110,7 @@ public:
/// <summary>
/// Given the path to a part, returns the content type of the part as a string.
/// </summary>
std::string get_content_type(const path &part) const;
std::string content_type(const path &part) const;
// Default Content Types
@ -122,12 +122,12 @@ public:
/// <summary>
/// Returns a vector of all extensions with registered default content types.
/// </summary>
std::vector<std::string> get_extensions_with_default_types() const;
std::vector<std::string> extensions_with_default_types() const;
/// <summary>
/// Returns the registered default content type for parts of the given extension.
/// </summary>
std::string get_default_type(const std::string &extension) const;
std::string default_type(const std::string &extension) const;
/// <summary>
/// Associates the given extension with the given content type.
@ -151,12 +151,12 @@ public:
/// Returns the override content type registered for the given part.
/// Throws key_not_found exception if no override type was found.
/// </summary>
std::string get_override_type(const path &part) const;
std::string override_type(const path &part) const;
/// <summary>
/// Returns the path of every part in this manifest with an overriden content type.
/// </summary>
std::vector<path> get_parts_with_overriden_types() const;
std::vector<path> parts_with_overriden_types() const;
/// <summary>
/// Overrides any default type registered for the part's extension with the given content type.
@ -187,7 +187,7 @@ private:
/// <summary>
///
/// </summary>
std::unordered_map<path, std::unordered_map<std::string, relationship>> relationships_;
std::unordered_map<path, std::unordered_map<std::string, xlnt::relationship>> relationships_;
};
} // namespace xlnt

View File

@ -100,11 +100,6 @@ enum class XLNT_API relationship_type
class XLNT_API relationship
{
public:
/// <summary>
///
/// </summary>
using type = relationship_type;
/// <summary>
///
/// </summary>
@ -113,32 +108,32 @@ public:
/// <summary>
///
/// </summary>
relationship(const std::string &id, type t, const uri &source, const uri &target, target_mode mode);
relationship(const std::string &id, relationship_type t, const uri &source, const uri &target, target_mode mode);
/// <summary>
/// Returns a string of the form rId# that identifies the relationship.
/// </summary>
std::string get_id() const;
std::string id() const;
/// <summary>
/// Returns the type of this relationship.
/// </summary>
type get_type() const;
relationship_type type() const;
/// <summary>
/// Returns whether the target of the relationship is internal or external to the package.
/// </summary>
target_mode get_target_mode() const;
target_mode target_mode() const;
/// <summary>
/// Returns the URI of the package part this relationship points to.
/// </summary>
uri get_source() const;
uri source() const;
/// <summary>
/// Returns the URI of the package part this relationship points to.
/// </summary>
uri get_target() const;
uri target() const;
/// <summary>
/// Returns true if and only if rhs is equal to this relationship.
@ -159,7 +154,7 @@ private:
/// <summary>
///
/// </summary>
type type_;
relationship_type type_;
/// <summary>
///
@ -174,7 +169,7 @@ private:
/// <summary>
///
/// </summary>
target_mode mode_;
enum target_mode mode_;
};
} // namespace xlnt

View File

@ -68,12 +68,12 @@ public:
/// <summary>
///
/// </summary>
std::string get_scheme() const;
std::string scheme() const;
/// <summary>
///
/// </summary>
std::string get_authority() const;
std::string authority() const;
/// <summary>
///
@ -83,22 +83,22 @@ public:
/// <summary>
///
/// </summary>
std::string get_authentication() const;
std::string authentication() const;
/// <summary>
///
/// </summary>
std::string get_username() const;
std::string username() const;
/// <summary>
///
/// </summary>
std::string get_password() const;
std::string password() const;
/// <summary>
///
/// </summary>
std::string get_host() const;
std::string host() const;
/// <summary>
///
@ -108,12 +108,12 @@ public:
/// <summary>
///
/// </summary>
std::size_t get_port() const;
std::size_t port() const;
/// <summary>
///
/// </summary>
path get_path() const;
path path() const;
/// <summary>
///
@ -123,7 +123,7 @@ public:
/// <summary>
///
/// </summary>
std::string get_query() const;
std::string query() const;
/// <summary>
///
@ -133,7 +133,7 @@ public:
/// <summary>
///
/// </summary>
std::string get_fragment() const;
std::string fragment() const;
/// <summary>
///
@ -219,7 +219,7 @@ private:
/// <summary>
///
/// </summary>
path path_;
class path path_;
};
} // namespace xlnt

View File

@ -44,12 +44,12 @@ public:
/// <summary>
///
/// </summary>
std::size_t get_index() const;
std::size_t index() const;
/// <summary>
///
/// </summary>
void set_index(std::size_t index);
void index(std::size_t index);
private:
/// <summary>
@ -72,12 +72,12 @@ public:
/// <summary>
///
/// </summary>
std::size_t get_index() const;
std::size_t index() const;
/// <summary>
///
/// </summary>
void set_index(std::size_t index);
void index(std::size_t index);
private:
/// <summary>
@ -105,37 +105,37 @@ public:
/// <summary>
///
/// </summary>
std::string get_hex_string() const;
std::string hex_string() const;
/// <summary>
///
/// </summary>
std::uint8_t get_red() const;
std::uint8_t red() const;
/// <summary>
///
/// </summary>
std::uint8_t get_green() const;
std::uint8_t green() const;
/// <summary>
///
/// </summary>
std::uint8_t get_blue() const;
std::uint8_t blue() const;
/// <summary>
///
/// </summary>
std::uint8_t get_alpha() const;
std::uint8_t alpha() const;
/// <summary>
///
/// </summary>
std::array<std::uint8_t, 3> get_rgb() const;
std::array<std::uint8_t, 3> rgb() const;
/// <summary>
///
/// </summary>
std::array<std::uint8_t, 4> get_rgba() const;
std::array<std::uint8_t, 4> rgba() const;
private:
/// <summary>
@ -149,23 +149,22 @@ private:
std::array<std::uint8_t, 4> rgba_;
};
/// <summary>
/// Some colors are references to colors rather than having a particular RGB value.
/// </summary>
enum class color_type
{
indexed,
theme,
rgb
};
/// <summary>
/// Colors can be applied to many parts of a cell's style.
/// </summary>
class XLNT_API color
{
public:
/// <summary>
/// Some colors are references to colors rather than having a particular RGB value.
/// </summary>
enum class type
{
indexed,
theme,
rgb,
auto_
};
/// <summary>
///
/// </summary>
@ -239,7 +238,7 @@ public:
/// <summary>
///
/// </summary>
type get_type() const;
color_type type() const;
/// <summary>
///
@ -249,32 +248,32 @@ public:
/// <summary>
///
/// </summary>
void set_auto(bool value);
void auto_(bool value);
/// <summary>
///
/// </summary>
const rgb_color &get_rgb() const;
const rgb_color &rgb() const;
/// <summary>
///
/// </summary>
const indexed_color &get_indexed() const;
const indexed_color &indexed() const;
/// <summary>
///
/// </summary>
const theme_color &get_theme() const;
const theme_color &theme() const;
/// <summary>
///
/// </summary>
double get_tint() const;
double tint() const;
/// <summary>
///
/// </summary>
void set_tint(double tint);
void tint(double tint);
/// <summary>
///
@ -290,12 +289,12 @@ private:
/// <summary>
///
/// </summary>
void assert_type(type t) const;
void assert_type(color_type t) const;
/// <summary>
///
/// </summary>
type type_;
color_type type_;
/// <summary>
///
@ -316,6 +315,11 @@ private:
///
/// </summary>
double tint_;
/// <summary>
///
/// </summary>
bool auto__;
};
} // namespace xlnt

View File

@ -111,6 +111,11 @@ public:
/// </summary>
underline_style underline() const;
/// <summary>
///
/// </summary>
bool has_size() const;
/// <summary>
///
/// </summary>
@ -121,6 +126,11 @@ public:
/// </summary>
std::size_t size() const;
/// <summary>
///
/// </summary>
bool has_name() const;
/// <summary>
///
/// </summary>
@ -131,6 +141,11 @@ public:
/// </summary>
std::string name() const;
/// <summary>
///
/// </summary>
bool has_color() const;
/// <summary>
///
/// </summary>
@ -139,7 +154,12 @@ public:
/// <summary>
///
/// </summary>
optional<xlnt::color> color() const;
xlnt::color color() const;
/// <summary>
///
/// </summary>
bool has_family() const;
/// <summary>
///
@ -149,7 +169,12 @@ public:
/// <summary>
///
/// </summary>
optional<std::size_t> family() const;
std::size_t family() const;
/// <summary>
///
/// </summary>
bool has_scheme() const;
/// <summary>
///
@ -159,7 +184,7 @@ public:
/// <summary>
///
/// </summary>
optional<std::string> scheme() const;
std::string scheme() const;
/// <summary>
/// Returns true if left is exactly equal to right.
@ -177,12 +202,12 @@ private:
/// <summary>
///
/// </summary>
std::string name_ = "Calibri";
optional<std::string> name_;
/// <summary>
///
/// </summary>
std::size_t size_ = 12;
optional<std::size_t> size_;
/// <summary>
///

View File

@ -196,17 +196,17 @@ public:
/// <summary>
///
/// </summary>
void set_format_string(const std::string &format_code);
void format_string(const std::string &format_code);
/// <summary>
///
/// </summary>
void set_format_string(const std::string &format_code, std::size_t custom_id);
void format_string(const std::string &format_code, std::size_t custom_id);
/// <summary>
///
/// </summary>
std::string get_format_string() const;
std::string format_string() const;
/// <summary>
///
@ -216,12 +216,12 @@ public:
/// <summary>
///
/// </summary>
void set_id(std::size_t id);
void id(std::size_t id);
/// <summary>
///
/// </summary>
std::size_t get_id() const;
std::size_t id() const;
/// <summary>
///

View File

@ -55,6 +55,11 @@ struct XLNT_API datetime
/// </summary>
static datetime from_number(long double number, calendar base_date);
/// <summary>
///
/// </summary>
static datetime from_iso_string(const std::string &iso_string);
/// <summary>
///
/// </summary>
@ -70,6 +75,11 @@ struct XLNT_API datetime
/// </summary>
std::string to_string() const;
/// <summary>
///
/// </summary>
std::string to_iso_string() const;
/// <summary>
///
/// </summary>

View File

@ -55,7 +55,7 @@ public:
/// <summary>
///
/// </summary>
void set_message(const std::string &message);
void message(const std::string &message);
private:
/// <summary>

View File

@ -115,6 +115,13 @@ public:
/// </summary>
path resolve(const path &base_path) const;
/// <summary>
/// The inverse of path::resolve. Creates a relative path from an absolute
/// path by removing the common root between base_path and this path.
/// If the current path is already relative, return it unchanged.
/// </summary>
path relative_to(const path &base_path) const;
// filesystem attributes
/// <summary>

View File

@ -38,7 +38,7 @@ std::vector<std::pair<std::string, std::string>> XLNT_API split_named_range(cons
/// <summary>
/// A 2D range of cells in a worksheet that is referred to by name.
/// ws->get_range("A1:B2") could be replaced by ws->get_range("range1")
/// ws->range("A1:B2") could be replaced by ws->range("range1")
/// </summary>
class XLNT_API named_range
{
@ -66,12 +66,12 @@ public:
/// <summary>
///
/// </summary>
std::string get_name() const;
std::string name() const;
/// <summary>
///
/// </summary>
const std::vector<target> &get_targets() const;
const std::vector<target> &targets() const;
/// <summary>
///

View File

@ -150,31 +150,6 @@ public:
/// </summary>
~workbook();
// general properties
/// <summary>
/// Returns true if guess_types is enabled for this workbook.
/// </summary>
bool get_guess_types() const;
/// <summary>
/// Set to true to guess the type represented by a string set as the value
/// for a cell and then set the actual value of the cell to that type.
/// For example, cell.set_value("1") with guess_types enabled will set
/// type of the cell to numeric and it's value to the number 1.
/// </summary>
void set_guess_types(bool guess);
/// <summary>
/// ?
/// </summary>
bool get_data_only() const;
/// <summary>
/// ?
/// </summary>
void set_data_only(bool data_only);
// add worksheets
/// <summary>
@ -209,41 +184,41 @@ public:
/// This is also the sheet that will be shown when the workbook is opened
/// in the spreadsheet editor program.
/// </summary>
worksheet get_active_sheet();
worksheet active_sheet();
/// <summary>
/// Return the worksheet with the given name.
/// This may throw an exception if the sheet isn't found.
/// Use workbook::contains(const std::string &) to make sure the sheet exists.
/// </summary>
worksheet get_sheet_by_title(const std::string &sheet_name);
worksheet sheet_by_title(const std::string &sheet_name);
/// <summary>
/// Return the const worksheet with the given name.
/// This may throw an exception if the sheet isn't found.
/// Use workbook::contains(const std::string &) to make sure the sheet exists.
/// </summary>
const worksheet get_sheet_by_title(const std::string &sheet_name) const;
const worksheet sheet_by_title(const std::string &sheet_name) const;
/// <summary>
/// Return the worksheet at the given index.
/// </summary>
worksheet get_sheet_by_index(std::size_t index);
worksheet sheet_by_index(std::size_t index);
/// <summary>
/// Return the const worksheet at the given index.
/// </summary>
const worksheet get_sheet_by_index(std::size_t index) const;
const worksheet sheet_by_index(std::size_t index) const;
/// <summary>
/// Return the worksheet with a sheetId of id.
/// </summary>
worksheet get_sheet_by_id(std::size_t id);
worksheet sheet_by_id(std::size_t id);
/// <summary>
/// Return the const worksheet with a sheetId of id.
/// </summary>
const worksheet get_sheet_by_id(std::size_t id) const;
const worksheet sheet_by_id(std::size_t id) const;
/// <summary>
/// Return true if this workbook contains a sheet with the given name.
@ -254,7 +229,7 @@ public:
/// Return the index of the given worksheet.
/// The worksheet must be owned by this workbook.
/// </summary>
std::size_t get_index(worksheet worksheet);
std::size_t index(worksheet worksheet);
// remove worksheets
@ -317,159 +292,61 @@ public:
/// Returns a temporary vector containing the titles of each sheet in the order
/// of the sheets in the workbook.
/// </summary>
std::vector<std::string> get_sheet_titles() const;
std::vector<std::string> sheet_titles() const;
/// <summary>
/// Returns the number of sheets in this workbook.
/// </summary>
std::size_t get_sheet_count() const;
std::size_t sheet_count() const;
/// <summary>
/// Returns the name of the application that created this workbook.
/// Returns true if the workbook has the core property with the given name.
/// </summary>
std::string get_application() const;
/// <summary>
/// Sets the name of the application that created this workbook to "application".
/// </summary>
void set_application(const std::string &application);
bool has_core_property(const std::string &property_name) const;
/// <summary>
///
/// </summary>
calendar get_base_date() const;
template<typename T = std::string>
T core_property(const std::string &property_name) const;
/// <summary>
///
/// </summary>
void set_base_date(calendar base_date);
template<typename T = std::string>
void core_property(const std::string &property_name, const T value);
/// <summary>
///
/// </summary>
std::string get_creator() const;
calendar base_date() const;
/// <summary>
///
/// </summary>
void set_creator(const std::string &creator);
void base_date(calendar base_date);
/// <summary>
///
/// </summary>
std::string get_last_modified_by() const;
bool has_title() const;
/// <summary>
///
/// </summary>
void set_last_modified_by(const std::string &last_modified_by);
std::string title() const;
/// <summary>
///
/// </summary>
datetime get_created() const;
/// <summary>
///
/// </summary>
void set_created(const datetime &when);
/// <summary>
///
/// </summary>
datetime get_modified() const;
/// <summary>
///
/// </summary>
void set_modified(const datetime &when);
/// <summary>
///
/// </summary>
int get_doc_security() const;
/// <summary>
///
/// </summary>
void set_doc_security(int doc_security);
/// <summary>
///
/// </summary>
bool get_scale_crop() const;
/// <summary>
///
/// </summary>
void set_scale_crop(bool scale_crop);
/// <summary>
///
/// </summary>
std::string get_company() const;
/// <summary>
///
/// </summary>
void set_company(const std::string &company);
/// <summary>
///
/// </summary>
bool links_up_to_date() const;
/// <summary>
///
/// </summary>
void set_links_up_to_date(bool links_up_to_date);
/// <summary>
///
/// </summary>
bool is_shared_doc() const;
/// <summary>
///
/// </summary>
void set_shared_doc(bool shared_doc);
/// <summary>
///
/// </summary>
bool hyperlinks_changed() const;
/// <summary>
///
/// </summary>
void set_hyperlinks_changed(bool hyperlinks_changed);
/// <summary>
///
/// </summary>
std::string get_app_version() const;
/// <summary>
///
/// </summary>
void set_app_version(const std::string &version);
/// <summary>
///
/// </summary>
std::string get_title() const;
/// <summary>
///
/// </summary>
void set_title(const std::string &title);
void title(const std::string &title);
// named ranges
/// <summary>
///
/// </summary>
std::vector<named_range> get_named_ranges() const;
std::vector<named_range> named_ranges() const;
/// <summary>
///
@ -489,7 +366,7 @@ public:
/// <summary>
///
/// </summary>
range get_named_range(const std::string &name);
range named_range(const std::string &name);
/// <summary>
///
@ -608,12 +485,12 @@ public:
/// <summary>
///
/// </summary>
workbook_view get_view() const;
workbook_view view() const;
/// <summary>
///
/// </summary>
void set_view(const workbook_view &view);
void view(const workbook_view &view);
/// <summary>
///
@ -623,52 +500,12 @@ public:
/// <summary>
///
/// </summary>
std::string get_code_name() const;
std::string code_name() const;
/// <summary>
///
/// </summary>
void set_code_name(const std::string &code_name);
/// <summary>
///
/// </summary>
bool x15_enabled() const;
/// <summary>
///
/// </summary>
void enable_x15();
/// <summary>
///
/// </summary>
void disable_x15();
/// <summary>
///
/// </summary>
bool has_absolute_path() const;
/// <summary>
///
/// </summary>
path get_absolute_path() const;
/// <summary>
///
/// </summary>
void set_absolute_path(const path &absolute_path);
/// <summary>
///
/// </summary>
void clear_absolute_path();
/// <summary>
///
/// </summary>
bool has_properties() const;
void code_name(const std::string &code_name);
/// <summary>
///
@ -678,34 +515,22 @@ public:
/// <summary>
///
/// </summary>
std::string get_app_name() const;
std::string app_name() const;
/// <summary>
///
/// </summary>
std::size_t get_last_edited() const;
std::size_t last_edited() const;
/// <summary>
///
/// </summary>
std::size_t get_lowest_edited() const;
std::size_t lowest_edited() const;
/// <summary>
///
/// </summary>
std::size_t get_rup_build() const;
/// <summary>
///
/// </summary>
bool has_arch_id() const;
// calculation
/// <summary>
///
/// </summary>
bool has_calculation_properties() const;
std::size_t rup_build() const;
// theme
@ -717,29 +542,29 @@ public:
/// <summary>
///
/// </summary>
const theme &get_theme() const;
const theme &theme() const;
/// <summary>
///
/// </summary>
void set_theme(const theme &value);
void theme(const class theme &value);
// formats
/// <summary>
///
/// </summary>
format get_format(std::size_t format_index);
format format(std::size_t format_index);
/// <summary>
///
/// </summary>
const format get_format(std::size_t format_index) const;
const class format format(std::size_t format_index) const;
/// <summary>
///
/// </summary>
format create_format(bool default_format = false);
class format create_format(bool default_format = false);
/// <summary>
///
@ -778,12 +603,12 @@ public:
/// <summary>
///
/// </summary>
manifest &get_manifest();
manifest &manifest();
/// <summary>
///
/// </summary>
const manifest &get_manifest() const;
const class manifest &manifest() const;
// shared strings
@ -795,25 +620,25 @@ public:
/// <summary>
///
/// </summary>
std::vector<formatted_text> &get_shared_strings();
std::vector<formatted_text> &shared_strings();
/// <summary>
///
/// </summary>
const std::vector<formatted_text> &get_shared_strings() const;
const std::vector<formatted_text> &shared_strings() const;
// thumbnail
/// <summary>
///
/// </summary>
void set_thumbnail(const std::vector<std::uint8_t> &thumbnail,
void thumbnail(const std::vector<std::uint8_t> &thumbnail,
const std::string &extension, const std::string &content_type);
/// <summary>
///
/// </summary>
const std::vector<std::uint8_t> &get_thumbnail() const;
const std::vector<std::uint8_t> &thumbnail() const;
// operators

View File

@ -71,11 +71,6 @@ public:
/// </summary>
cell_vector(worksheet ws, const range_reference &ref, major_order order = major_order::row);
/// <summary>
///
/// </summary>
std::size_t num_cells() const;
/// <summary>
///
/// </summary>
@ -109,12 +104,12 @@ public:
/// <summary>
///
/// </summary>
cell get_cell(std::size_t column_index);
cell cell(std::size_t column_index);
/// <summary>
///
/// </summary>
const cell get_cell(std::size_t column_index) const;
const class cell cell(std::size_t column_index) const;
/// <summary>
///

View File

@ -44,22 +44,22 @@ public:
/// <summary>
///
/// </summary>
void set_text(const std::string &text);
void text(const std::string &text);
/// <summary>
///
/// </summary>
void set_font_name(const std::string &font_name);
void font_name(const std::string &font_name);
/// <summary>
///
/// </summary>
void set_font_size(std::size_t font_size);
void font_size(std::size_t font_size);
/// <summary>
///
/// </summary>
void set_font_color(const std::string &font_color);
void font_color(const std::string &font_color);
/// <summary>
///

View File

@ -44,22 +44,22 @@ public:
/// <summary>
///
/// </summary>
void set_text(const std::string &text);
void text(const std::string &text);
/// <summary>
///
/// </summary>
void set_font_name(const std::string &font_name);
void font_name(const std::string &font_name);
/// <summary>
///
/// </summary>
void set_font_size(std::size_t font_size);
void font_size(std::size_t font_size);
/// <summary>
///
/// </summary>
void set_font_color(const std::string &font_color);
void font_color(const std::string &font_color);
/// <summary>
///

View File

@ -46,32 +46,32 @@ public:
/// <summary>
///
/// </summary>
header &get_left_header();
header &left_header();
/// <summary>
///
/// </summary>
header &get_center_header();
header &center_header();
/// <summary>
///
/// </summary>
header &get_right_header();
header &right_header();
/// <summary>
///
/// </summary>
footer &get_left_footer();
footer &left_footer();
/// <summary>
///
/// </summary>
footer &get_center_footer();
footer &center_footer();
/// <summary>
///
/// </summary>
footer &get_right_footer();
footer &right_footer();
/// <summary>
///

View File

@ -41,62 +41,62 @@ public:
/// <summary>
///
/// </summary>
double get_top() const;
double top() const;
/// <summary>
///
/// </summary>
void set_top(double top);
void top(double top);
/// <summary>
///
/// </summary>
double get_left() const;
double left() const;
/// <summary>
///
/// </summary>
void set_left(double left);
void left(double left);
/// <summary>
///
/// </summary>
double get_bottom() const;
double bottom() const;
/// <summary>
///
/// </summary>
void set_bottom(double bottom);
void bottom(double bottom);
/// <summary>
///
/// </summary>
double get_right() const;
double right() const;
/// <summary>
///
/// </summary>
void set_right(double right);
void right(double right);
/// <summary>
///
/// </summary>
double get_header() const;
double header() const;
/// <summary>
///
/// </summary>
void set_header(double header);
void header(double header);
/// <summary>
///
/// </summary>
double get_footer() const;
double footer() const;
/// <summary>
///
/// </summary>
void set_footer(double footer);
void footer(double footer);
private:
/// <summary>

View File

@ -45,42 +45,42 @@ public:
/// <summary>
///
/// </summary>
page_break get_break() const;
page_break page_break() const;
/// <summary>
///
/// </summary>
void set_break(page_break b);
void page_break(enum page_break b);
/// <summary>
///
/// </summary>
sheet_state get_sheet_state() const;
sheet_state sheet_state() const;
/// <summary>
///
/// </summary>
void set_sheet_state(sheet_state sheet_state);
void sheet_state(enum sheet_state sheet_state);
/// <summary>
///
/// </summary>
paper_size get_paper_size() const;
paper_size paper_size() const;
/// <summary>
///
/// </summary>
void set_paper_size(paper_size paper_size);
void paper_size(enum paper_size paper_size);
/// <summary>
///
/// </summary>
orientation get_orientation() const;
orientation orientation() const;
/// <summary>
///
/// </summary>
void set_orientation(orientation orientation);
void orientation(enum orientation orientation);
/// <summary>
///
@ -90,7 +90,7 @@ public:
/// <summary>
///
/// </summary>
void set_fit_to_page(bool fit_to_page);
void fit_to_page(bool fit_to_page);
/// <summary>
///
@ -100,7 +100,7 @@ public:
/// <summary>
///
/// </summary>
void set_fit_to_height(bool fit_to_height);
void fit_to_height(bool fit_to_height);
/// <summary>
///
@ -110,58 +110,58 @@ public:
/// <summary>
///
/// </summary>
void set_fit_to_width(bool fit_to_width);
void fit_to_width(bool fit_to_width);
/// <summary>
///
/// </summary>
void set_horizontal_centered(bool horizontal_centered);
void horizontal_centered(bool horizontal_centered);
/// <summary>
///
/// </summary>
bool get_horizontal_centered() const;
bool horizontal_centered() const;
/// <summary>
///
/// </summary>
void set_vertical_centered(bool vertical_centered);
void vertical_centered(bool vertical_centered);
/// <summary>
///
/// </summary>
bool get_vertical_centered() const;
bool vertical_centered() const;
/// <summary>
///
/// </summary>
void set_scale(double scale);
void scale(double scale);
/// <summary>
///
/// </summary>
double get_scale() const;
double scale() const;
private:
/// <summary>
///
/// </summary>
page_break break_;
enum page_break break_;
/// <summary>
///
/// </summary>
sheet_state sheet_state_;
enum sheet_state sheet_state_;
/// <summary>
///
/// </summary>
paper_size paper_size_;
enum paper_size paper_size_;
/// <summary>
///
/// </summary>
orientation orientation_;
enum orientation orientation_;
/// <summary>
///

View File

@ -35,7 +35,8 @@ namespace xlnt {
enum class XLNT_API pane_state
{
frozen,
normal
frozen_split,
split
};
/// <summary>
@ -52,33 +53,41 @@ enum class XLNT_API pane_corner
/// <summary>
/// A fixed portion of a worksheet.
/// </summary>
class XLNT_API pane
struct XLNT_API pane
{
public:
/// <summary>
///
/// </summary>
cell_reference top_left_cell;
optional<cell_reference> top_left_cell;
/// <summary>
///
/// </summary>
pane_state state;
pane_state state = pane_state::split;
/// <summary>
///
/// </summary>
pane_corner active_pane;
pane_corner active_pane = pane_corner::top_left;
/// <summary>
///
/// </summary>
row_t y_split;
row_t y_split = 1;
/// <summary>
///
/// </summary>
column_t x_split;
column_t x_split = 1;
bool operator==(const pane &rhs) const
{
return top_left_cell == rhs.top_left_cell
&& state == rhs.state
&& active_pane == rhs.active_pane
&& y_split == rhs.y_split
&& x_split == rhs.x_split;
}
};
} // namespace xlnt

View File

@ -104,27 +104,27 @@ public:
/// <summary>
///
/// </summary>
cell_vector get_vector(std::size_t vector_index);
cell_vector vector(std::size_t vector_index);
/// <summary>
///
/// </summary>
const cell_vector get_vector(std::size_t vector_index) const;
const cell_vector vector(std::size_t vector_index) const;
/// <summary>
///
/// </summary>
cell get_cell(const cell_reference &ref);
cell cell(const cell_reference &ref);
/// <summary>
///
/// </summary>
const cell get_cell(const cell_reference &ref) const;
const class cell cell(const cell_reference &ref) const;
/// <summary>
///
/// </summary>
range_reference get_reference() const;
range_reference reference() const;
/// <summary>
///

View File

@ -77,32 +77,32 @@ public:
/// <summary>
///
/// </summary>
std::size_t get_width() const;
std::size_t width() const;
/// <summary>
///
/// </summary>
std::size_t get_height() const;
std::size_t height() const;
/// <summary>
///
/// </summary>
cell_reference get_top_left() const;
cell_reference top_left() const;
/// <summary>
///
/// </summary>
cell_reference get_bottom_right() const;
cell_reference bottom_right() const;
/// <summary>
///
/// </summary>
cell_reference &get_top_left();
cell_reference &top_left();
/// <summary>
///
/// </summary>
cell_reference &get_bottom_right();
cell_reference &bottom_right();
/// <summary>
///

View File

@ -38,38 +38,46 @@ public:
/// <summary>
///
/// </summary>
bool has_active_cell() const { return has_active_cell_; }
bool has_active_cell() const { return active_cell_.is_set(); }
/// <summary>
///
/// </summary>
cell_reference get_active_cell() const { return active_cell_; }
cell_reference active_cell() const { return active_cell_.get(); }
/// <summary>
///
/// </summary>
range_reference get_sqref() const { return sqref_; }
void active_cell(const cell_reference &ref) { active_cell_ = ref; }
/// <summary>
///
/// </summary>
pane_corner get_pane() const { return pane_; }
range_reference sqref() const { return sqref_; }
/// <summary>
///
/// </summary>
void set_pane(pane_corner corner) { pane_ = corner; }
pane_corner pane() const { return pane_; }
/// <summary>
///
/// </summary>
void pane(pane_corner corner) { pane_ = corner; }
bool operator==(const selection &rhs) const
{
return active_cell_ == rhs.active_cell_
&& sqref_ == rhs.sqref_
&& pane_ == rhs.pane_;
}
private:
/// <summary>
///
/// </summary>
bool has_active_cell_ = false;
/// <summary>
///
/// </summary>
cell_reference active_cell_;
optional<cell_reference> active_cell_;
/// <summary>
///

View File

@ -43,12 +43,12 @@ public:
/// <summary>
///
/// </summary>
void set_password(const std::string &password);
void password(const std::string &password);
/// <summary>
///
/// </summary>
std::string get_hashed_password() const;
std::string hashed_password() const;
private:
/// <summary>

View File

@ -24,6 +24,7 @@
#pragma once
#include <xlnt/xlnt_config.hpp>
#include <xlnt/utils/optional.hpp>
#include <xlnt/worksheet/pane.hpp>
#include <xlnt/worksheet/selection.hpp>
@ -39,33 +40,117 @@ public:
/// <summary>
///
/// </summary>
pane &get_pane() { return pane_; }
void id(std::size_t new_id) { id_ = new_id; }
/// <summary>
///
/// </summary>
const pane &get_pane() const { return pane_; }
std::size_t id() const { return id_; }
/// <summary>
///
/// </summary>
std::vector<selection> &get_selections() { return selections_; }
bool has_pane() const { return pane_.is_set(); }
/// <summary>
///
/// </summary>
const std::vector<selection> &get_selections() const { return selections_; }
pane &pane() { return pane_.get(); }
/// <summary>
///
/// </summary>
const struct pane &pane() const { return pane_.get(); }
/// <summary>
///
/// </summary>
void clear_pane() { pane_.clear(); }
/// <summary>
///
/// </summary>
void pane(const struct pane &new_pane) { pane_ = new_pane; }
/// <summary>
///
/// </summary>
bool has_selections() const { return !selections_.empty(); }
/// <summary>
///
/// </summary>
void add_selection(const selection &new_selection) { selections_.push_back(new_selection); }
/// <summary>
///
/// </summary>
void clear_selections() { selections_.clear(); }
/// <summary>
///
/// </summary>
std::vector<selection> selections() const { return selections_; }
/// <summary>
///
/// </summary>
class selection &selection(std::size_t index) { return selections_.at(index); }
/// <summary>
///
/// </summary>
void show_grid_lines(bool show) { show_grid_lines_ = show; }
/// <summary>
///
/// </summary>
bool show_grid_lines() const { return show_grid_lines_; }
/// <summary>
///
/// </summary>
void default_grid_color(bool is_default) { default_grid_color_ = is_default; }
/// <summary>
///
/// </summary>
bool default_grid_color() const { return default_grid_color_; }
bool operator==(const sheet_view &rhs) const
{
return id_ == rhs.id_
&& show_grid_lines_ == rhs.show_grid_lines_
&& default_grid_color_ == rhs.default_grid_color_
&& pane_ == rhs.pane_
&& selections_ == rhs.selections_;
}
private:
/// <summary>
///
/// </summary>
pane pane_;
std::size_t id_ = 0;
/// <summary>
///
/// </summary>
std::vector<selection> selections_;
bool show_grid_lines_ = true;
/// <summary>
///
/// </summary>
bool default_grid_color_ = true;
/// <summary>
///
/// </summary>
optional<xlnt::pane> pane_;
/// <summary>
///
/// </summary>
std::vector<xlnt::selection> selections_;
};
} // namespace xlnt

View File

@ -109,12 +109,12 @@ public:
/// <summary>
///
/// </summary>
workbook &get_workbook();
workbook &workbook();
/// <summary>
///
/// </summary>
const workbook &get_workbook() const;
const class workbook &workbook() const;
/// <summary>
///
@ -126,29 +126,29 @@ public:
/// <summary>
///
/// </summary>
std::size_t get_id() const;
std::size_t id() const;
/// <summary>
///
/// </summary>
void set_id(std::size_t id);
void id(std::size_t id);
/// <summary>
///
/// </summary>
std::string get_title() const;
std::string title() const;
/// <summary>
///
/// </summary>
void set_title(const std::string &title);
void title(const std::string &title);
// freeze panes
/// <summary>
///
/// </summary>
cell_reference get_frozen_panes() const;
cell_reference frozen_panes() const;
/// <summary>
///
@ -158,7 +158,7 @@ public:
/// <summary>
///
/// </summary>
void freeze_panes(const std::string &top_left_coordinate);
void freeze_panes(const cell_reference &top_left_coordinate);
/// <summary>
///
@ -175,22 +175,22 @@ public:
/// <summary>
///
/// </summary>
cell get_cell(column_t column, row_t row);
cell cell(column_t column, row_t row);
/// <summary>
///
/// </summary>
const cell get_cell(column_t column, row_t row) const;
const class cell cell(column_t column, row_t row) const;
/// <summary>
///
/// </summary>
cell get_cell(const cell_reference &reference);
class cell cell(const cell_reference &reference);
/// <summary>
///
/// </summary>
const cell get_cell(const cell_reference &reference) const;
const class cell cell(const cell_reference &reference) const;
/// <summary>
///
@ -200,59 +200,59 @@ public:
/// <summary>
///
/// </summary>
range get_range(const std::string &reference_string);
range range(const std::string &reference_string);
/// <summary>
///
/// </summary>
range get_range(const range_reference &reference);
class range range(const range_reference &reference);
/// <summary>
///
/// </summary>
const range get_range(const std::string &reference_string) const;
const class range range(const std::string &reference_string) const;
/// <summary>
///
/// </summary>
const range get_range(const range_reference &reference) const;
const class range range(const range_reference &reference) const;
/// <summary>
///
/// </summary>
range rows() const;
class range rows() const;
/// <summary>
///
/// </summary>
range rows(const std::string &range_string) const;
class range rows(const std::string &range_string) const;
/// <summary>
///
/// </summary>
range rows(int row_offset, int column_offset) const;
class range rows(int row_offset, int column_offset) const;
/// <summary>
///
/// </summary>
range rows(const std::string &range_string, int row_offset, int column_offset) const;
class range rows(const std::string &range_string, int row_offset, int column_offset) const;
/// <summary>
///
/// </summary>
range columns() const;
class range columns() const;
// properties
/// <summary>
///
/// </summary>
column_properties &get_column_properties(column_t column);
column_properties &column_properties(column_t column);
/// <summary>
///
/// </summary>
const column_properties &get_column_properties(column_t column) const;
const class column_properties &column_properties(column_t column) const;
/// <summary>
///
@ -262,17 +262,17 @@ public:
/// <summary>
///
/// </summary>
void add_column_properties(column_t column, const column_properties &props);
void add_column_properties(column_t column, const class column_properties &props);
/// <summary>
///
/// </summary>
row_properties &get_row_properties(row_t row);
row_properties &row_properties(row_t row);
/// <summary>
///
/// </summary>
const row_properties &get_row_properties(row_t row) const;
const class row_properties &row_properties(row_t row) const;
/// <summary>
///
@ -282,19 +282,19 @@ public:
/// <summary>
///
/// </summary>
void add_row_properties(row_t row, const row_properties &props);
void add_row_properties(row_t row, const class row_properties &props);
// positioning
/// <summary>
///
/// </summary>
cell_reference get_point_pos(int left, int top) const;
cell_reference point_pos(int left, int top) const;
/// <summary>
///
/// </summary>
cell_reference get_point_pos(const std::pair<int, int> &point) const;
cell_reference point_pos(const std::pair<int, int> &point) const;
/// <summary>
///
@ -321,7 +321,7 @@ public:
/// <summary>
///
/// </summary>
range get_named_range(const std::string &name);
class range named_range(const std::string &name);
/// <summary>
///
@ -333,27 +333,27 @@ public:
/// <summary>
///
/// </summary>
row_t get_lowest_row() const;
row_t lowest_row() const;
/// <summary>
///
/// </summary>
row_t get_highest_row() const;
row_t highest_row() const;
/// <summary>
///
/// </summary>
row_t get_next_row() const;
row_t next_row() const;
/// <summary>
///
/// </summary>
column_t get_lowest_column() const;
column_t lowest_column() const;
/// <summary>
///
/// </summary>
column_t get_highest_column() const;
column_t highest_column() const;
/// <summary>
///
@ -400,7 +400,7 @@ public:
/// <summary>
///
/// </summary>
std::vector<range_reference> get_merged_ranges() const;
std::vector<range_reference> merged_ranges() const;
// append
@ -464,42 +464,42 @@ public:
/// <summary>
///
/// </summary>
cell operator[](const cell_reference &reference);
class cell operator[](const cell_reference &reference);
/// <summary>
///
/// </summary>
const cell operator[](const cell_reference &reference) const;
const class cell operator[](const cell_reference &reference) const;
/// <summary>
///
/// </summary>
range operator[](const range_reference &reference);
class range operator[](const range_reference &reference);
/// <summary>
///
/// </summary>
const range operator[](const range_reference &reference) const;
const class range operator[](const range_reference &reference) const;
/// <summary>
///
/// </summary>
range operator[](const std::string &range_string);
class range operator[](const std::string &range_string);
/// <summary>
///
/// </summary>
const range operator[](const std::string &range_string) const;
const class range operator[](const std::string &range_string) const;
/// <summary>
///
/// </summary>
range operator()(const cell_reference &top_left, const cell_reference &bottom_right);
class range operator()(const cell_reference &top_left, const cell_reference &bottom_right);
/// <summary>
///
/// </summary>
const range operator()(const cell_reference &top_left, const cell_reference &bottom_right) const;
const class range operator()(const cell_reference &top_left, const cell_reference &bottom_right) const;
/// <summary>
///
@ -516,12 +516,12 @@ public:
/// <summary>
///
/// </summary>
page_setup get_page_setup() const;
page_setup page_setup() const;
/// <summary>
///
/// </summary>
void set_page_setup(const page_setup &setup);
void page_setup(const struct page_setup &setup);
/// <summary>
///
@ -531,12 +531,12 @@ public:
/// <summary>
///
/// </summary>
page_margins get_page_margins() const;
page_margins page_margins() const;
/// <summary>
///
/// </summary>
void set_page_margins(const page_margins &margins);
void page_margins(const class page_margins &margins);
/// <summary>
///
@ -548,7 +548,7 @@ public:
/// <summary>
///
/// </summary>
range_reference get_auto_filter() const;
range_reference auto_filter() const;
/// <summary>
///
@ -568,7 +568,7 @@ public:
/// <summary>
///
/// </summary>
void unset_auto_filter();
void clear_auto_filter();
/// <summary>
///
@ -590,7 +590,7 @@ public:
/// <summary>
///
/// </summary>
std::size_t get_comment_count() const;
std::size_t comment_count() const;
/// <summary>
///
@ -600,32 +600,32 @@ public:
/// <summary>
///
/// </summary>
header_footer &get_header_footer();
header_footer &header_footer();
/// <summary>
///
/// </summary>
const header_footer &get_header_footer() const;
const class header_footer &header_footer() const;
/// <summary>
///
/// </summary>
void set_parent(workbook &wb);
void parent(class workbook &wb);
/// <summary>
///
/// </summary>
std::vector<std::string> get_formula_attributes() const;
std::vector<std::string> formula_attributes() const;
/// <summary>
///
/// </summary>
sheet_state get_sheet_state() const;
sheet_state sheet_state() const;
/// <summary>
///
/// </summary>
void set_sheet_state(sheet_state state);
void sheet_state(enum sheet_state state);
/// <summary>
///
@ -660,42 +660,42 @@ public:
/// <summary>
///
/// </summary>
range iter_cells(bool skip_null);
class range iter_cells(bool skip_null);
/// <summary>
///
/// </summary>
void set_print_title_rows(row_t first_row, row_t last_row);
void print_title_rows(row_t first_row, row_t last_row);
/// <summary>
///
/// </summary>
void set_print_title_rows(row_t last_row);
void print_title_rows(row_t last_row);
/// <summary>
///
/// </summary>
void set_print_title_cols(column_t first_column, column_t last_column);
void print_title_cols(column_t first_column, column_t last_column);
/// <summary>
///
/// </summary>
void set_print_title_cols(column_t last_column);
void print_title_cols(column_t last_column);
/// <summary>
///
/// </summary>
std::string get_print_titles() const;
std::string print_titles() const;
/// <summary>
///
/// </summary>
void set_print_area(const std::string &print_area);
void print_area(const std::string &print_area);
/// <summary>
///
/// </summary>
range_reference get_print_area() const;
range_reference print_area() const;
/// <summary>
///
@ -705,22 +705,12 @@ public:
/// <summary>
///
/// </summary>
sheet_view get_view() const;
sheet_view view(std::size_t index = 0) const;
/// <summary>
///
/// </summary>
bool x14ac_enabled() const;
/// <summary>
///
/// </summary>
void enable_x14ac();
/// <summary>
///
/// </summary>
void disable_x14ac();
void add_view(const sheet_view &new_view);
private:
friend class cell;

View File

@ -3,10 +3,10 @@
int main()
{
xlnt::workbook wb;
xlnt::worksheet ws = wb.get_active_sheet();
ws.get_cell("A1").set_value(5);
ws.get_cell("B2").set_value("string data");
ws.get_cell("C3").set_formula("=RAND()");
xlnt::worksheet ws = wb.active_sheet();
ws.cell("A1").value(5);
ws.cell("B2").value("string data");
ws.cell("C3").formula("=RAND()");
ws.merge_cells("C3:C4");
ws.freeze_panes("B2");
wb.save("data/sample.xlsx");

View File

@ -193,73 +193,73 @@ cell::cell(detail::cell_impl *d) : d_(d)
bool cell::garbage_collectible() const
{
return !(get_data_type() != type::null || is_merged() || has_formula() || has_format());
return !(data_type() != type::null || is_merged() || has_formula() || has_format());
}
template <>
XLNT_API void cell::set_value(std::nullptr_t)
XLNT_API void cell::value(std::nullptr_t)
{
d_->type_ = type::null;
}
template <>
XLNT_API void cell::set_value(bool b)
XLNT_API void cell::value(bool b)
{
d_->value_numeric_ = b ? 1 : 0;
d_->type_ = type::boolean;
}
template <>
XLNT_API void cell::set_value(std::int8_t i)
XLNT_API void cell::value(std::int8_t i)
{
d_->value_numeric_ = static_cast<long double>(i);
d_->type_ = type::numeric;
}
template <>
XLNT_API void cell::set_value(std::int16_t i)
XLNT_API void cell::value(std::int16_t i)
{
d_->value_numeric_ = static_cast<long double>(i);
d_->type_ = type::numeric;
}
template <>
XLNT_API void cell::set_value(std::int32_t i)
XLNT_API void cell::value(std::int32_t i)
{
d_->value_numeric_ = static_cast<long double>(i);
d_->type_ = type::numeric;
}
template <>
XLNT_API void cell::set_value(std::int64_t i)
XLNT_API void cell::value(std::int64_t i)
{
d_->value_numeric_ = static_cast<long double>(i);
d_->type_ = type::numeric;
}
template <>
XLNT_API void cell::set_value(std::uint8_t i)
XLNT_API void cell::value(std::uint8_t i)
{
d_->value_numeric_ = static_cast<long double>(i);
d_->type_ = type::numeric;
}
template <>
XLNT_API void cell::set_value(std::uint16_t i)
XLNT_API void cell::value(std::uint16_t i)
{
d_->value_numeric_ = static_cast<long double>(i);
d_->type_ = type::numeric;
}
template <>
XLNT_API void cell::set_value(std::uint32_t i)
XLNT_API void cell::value(std::uint32_t i)
{
d_->value_numeric_ = static_cast<long double>(i);
d_->type_ = type::numeric;
}
template <>
XLNT_API void cell::set_value(std::uint64_t i)
XLNT_API void cell::value(std::uint64_t i)
{
d_->value_numeric_ = static_cast<long double>(i);
d_->type_ = type::numeric;
@ -267,7 +267,7 @@ XLNT_API void cell::set_value(std::uint64_t i)
#ifdef _MSC_VER
template <>
XLNT_API void cell::set_value(unsigned long i)
XLNT_API void cell::value(unsigned long i)
{
d_->value_numeric_ = static_cast<long double>(i);
d_->type_ = type::numeric;
@ -276,14 +276,14 @@ XLNT_API void cell::set_value(unsigned long i)
#ifdef __linux
template <>
XLNT_API void cell::set_value(long long i)
XLNT_API void cell::value(long long i)
{
d_->value_numeric_ = static_cast<long double>(i);
d_->type_ = type::numeric;
}
template <>
XLNT_API void cell::set_value(unsigned long long i)
XLNT_API void cell::value(unsigned long long i)
{
d_->value_numeric_ = static_cast<long double>(i);
d_->type_ = type::numeric;
@ -291,39 +291,39 @@ XLNT_API void cell::set_value(unsigned long long i)
#endif
template <>
XLNT_API void cell::set_value(float f)
XLNT_API void cell::value(float f)
{
d_->value_numeric_ = static_cast<long double>(f);
d_->type_ = type::numeric;
}
template <>
XLNT_API void cell::set_value(double d)
XLNT_API void cell::value(double d)
{
d_->value_numeric_ = static_cast<long double>(d);
d_->type_ = type::numeric;
}
template <>
XLNT_API void cell::set_value(long double d)
XLNT_API void cell::value(long double d)
{
d_->value_numeric_ = static_cast<long double>(d);
d_->type_ = type::numeric;
}
template <>
XLNT_API void cell::set_value(std::string s)
XLNT_API void cell::value(std::string s)
{
s = check_string(s);
if (s.size() > 1 && s.front() == '=')
{
d_->type_ = type::formula;
set_formula(s);
formula(s);
}
else if (cell::error_codes().find(s) != cell::error_codes().end())
{
set_error(s);
error(s);
}
else
{
@ -332,39 +332,34 @@ XLNT_API void cell::set_value(std::string s)
if (s.size() > 0)
{
get_workbook().add_shared_string(d_->value_text_);
workbook().add_shared_string(d_->value_text_);
}
}
if (get_workbook().get_guess_types())
{
guess_type_and_set_value(s);
}
}
template <>
XLNT_API void cell::set_value(formatted_text text)
XLNT_API void cell::value(formatted_text text)
{
if (text.runs().size() == 1 && !text.runs().front().has_formatting())
{
set_value(text.plain_text());
value(text.plain_text());
}
else
{
d_->type_ = type::string;
d_->value_text_ = text;
get_workbook().add_shared_string(text);
workbook().add_shared_string(text);
}
}
template <>
XLNT_API void cell::set_value(char const *c)
XLNT_API void cell::value(char const *c)
{
set_value(std::string(c));
value(std::string(c));
}
template <>
XLNT_API void cell::set_value(cell c)
XLNT_API void cell::value(cell c)
{
d_->type_ = c.d_->type_;
d_->value_numeric_ = c.d_->value_numeric_;
@ -375,48 +370,48 @@ XLNT_API void cell::set_value(cell c)
}
template <>
XLNT_API void cell::set_value(date d)
XLNT_API void cell::value(date d)
{
d_->type_ = type::numeric;
d_->value_numeric_ = d.to_number(get_base_date());
set_number_format(number_format::date_yyyymmdd2());
d_->value_numeric_ = d.to_number(base_date());
number_format(number_format::date_yyyymmdd2());
}
template <>
XLNT_API void cell::set_value(datetime d)
XLNT_API void cell::value(datetime d)
{
d_->type_ = type::numeric;
d_->value_numeric_ = d.to_number(get_base_date());
set_number_format(number_format::date_datetime());
d_->value_numeric_ = d.to_number(base_date());
number_format(number_format::date_datetime());
}
template <>
XLNT_API void cell::set_value(time t)
XLNT_API void cell::value(time t)
{
d_->type_ = type::numeric;
d_->value_numeric_ = t.to_number();
set_number_format(number_format::date_time6());
number_format(number_format::date_time6());
}
template <>
XLNT_API void cell::set_value(timedelta t)
XLNT_API void cell::value(timedelta t)
{
d_->type_ = type::numeric;
d_->value_numeric_ = t.to_number();
set_number_format(number_format("[hh]:mm:ss"));
number_format(xlnt::number_format("[hh]:mm:ss"));
}
row_t cell::get_row() const
row_t cell::row() const
{
return d_->row_;
}
column_t cell::get_column() const
column_t cell::column() const
{
return d_->column_;
}
void cell::set_merged(bool merged)
void cell::merged(bool merged)
{
d_->is_merged_ = merged;
}
@ -428,10 +423,10 @@ bool cell::is_merged() const
bool cell::is_date() const
{
return get_data_type() == type::numeric && has_format() && get_number_format().is_date_format();
return data_type() == type::numeric && has_format() && number_format().is_date_format();
}
cell_reference cell::get_reference() const
cell_reference cell::reference() const
{
return {d_->column_, d_->row_};
}
@ -464,15 +459,15 @@ cell &cell::operator=(const cell &rhs)
std::string cell::to_repr() const
{
return "<Cell " + worksheet(d_->parent_).get_title() + "." + get_reference().to_string() + ">";
return "<Cell " + worksheet().title() + "." + reference().to_string() + ">";
}
std::string cell::get_hyperlink() const
std::string cell::hyperlink() const
{
return d_->hyperlink_.get();
}
void cell::set_hyperlink(const std::string &hyperlink)
void cell::hyperlink(const std::string &hyperlink)
{
if (hyperlink.length() == 0 || std::find(hyperlink.begin(), hyperlink.end(), ':') == hyperlink.end())
{
@ -481,13 +476,13 @@ void cell::set_hyperlink(const std::string &hyperlink)
d_->hyperlink_ = hyperlink;
if (get_data_type() == type::null)
if (data_type() == type::null)
{
set_value(hyperlink);
value(hyperlink);
}
}
void cell::set_formula(const std::string &formula)
void cell::formula(const std::string &formula)
{
if (formula.empty())
{
@ -506,10 +501,10 @@ void cell::set_formula(const std::string &formula)
bool cell::has_formula() const
{
return d_->formula_;
return d_->formula_.is_set();
}
std::string cell::get_formula() const
std::string cell::formula() const
{
return d_->formula_.get();
}
@ -519,7 +514,7 @@ void cell::clear_formula()
d_->formula_.clear();
}
void cell::set_error(const std::string &error)
void cell::error(const std::string &error)
{
if (error.length() == 0 || error[0] != '#')
{
@ -532,31 +527,31 @@ void cell::set_error(const std::string &error)
cell cell::offset(int column, int row)
{
return get_worksheet().get_cell(get_reference().make_offset(column, row));
return worksheet().cell(reference().make_offset(column, row));
}
worksheet cell::get_worksheet()
worksheet cell::worksheet()
{
return worksheet(d_->parent_);
return xlnt::worksheet(d_->parent_);
}
const worksheet cell::get_worksheet() const
const worksheet cell::worksheet() const
{
return worksheet(d_->parent_);
return xlnt::worksheet(d_->parent_);
}
workbook &cell::get_workbook()
workbook &cell::workbook()
{
return get_worksheet().get_workbook();
return worksheet().workbook();
}
const workbook &cell::get_workbook() const
const workbook &cell::workbook() const
{
return get_worksheet().get_workbook();
return worksheet().workbook();
}
// TODO: this shares a lot of code with worksheet::get_point_pos, try to reduce repetion
std::pair<int, int> cell::get_anchor() const
// TODO: this shares a lot of code with worksheet::point_pos, try to reduce repetion
std::pair<int, int> cell::anchor() const
{
static const auto DefaultColumnWidth = 51.85L;
static const auto DefaultRowHeight = 15.0L;
@ -570,9 +565,9 @@ std::pair<int, int> cell::get_anchor() const
for (column_t column_index = 1; column_index <= left_columns; column_index++)
{
if (get_worksheet().has_column_properties(column_index))
if (worksheet().has_column_properties(column_index))
{
auto cdw = get_worksheet().get_column_properties(column_index).width;
auto cdw = worksheet().column_properties(column_index).width;
if (cdw > 0)
{
@ -590,9 +585,9 @@ std::pair<int, int> cell::get_anchor() const
for (row_t row_index = 1; row_index <= top_rows; row_index++)
{
if (get_worksheet().has_row_properties(row_index))
if (worksheet().has_row_properties(row_index))
{
auto rdh = get_worksheet().get_row_properties(row_index).height;
auto rdh = worksheet().row_properties(row_index).height;
if (rdh > 0)
{
@ -607,12 +602,12 @@ std::pair<int, int> cell::get_anchor() const
return {left_anchor, top_anchor};
}
cell::type cell::get_data_type() const
cell::type cell::data_type() const
{
return d_->type_;
}
void cell::set_data_type(type t)
void cell::data_type(type t)
{
d_->type_ = t;
}
@ -656,159 +651,159 @@ void cell::clear_value()
}
template <>
XLNT_API bool cell::get_value() const
XLNT_API bool cell::value() const
{
return d_->value_numeric_ != 0.L;
}
template <>
XLNT_API std::int8_t cell::get_value() const
XLNT_API std::int8_t cell::value() const
{
return static_cast<std::int8_t>(d_->value_numeric_);
}
template <>
XLNT_API std::int16_t cell::get_value() const
XLNT_API std::int16_t cell::value() const
{
return static_cast<std::int16_t>(d_->value_numeric_);
}
template <>
XLNT_API std::int32_t cell::get_value() const
XLNT_API std::int32_t cell::value() const
{
return static_cast<std::int32_t>(d_->value_numeric_);
}
template <>
XLNT_API std::int64_t cell::get_value() const
XLNT_API std::int64_t cell::value() const
{
return static_cast<std::int64_t>(d_->value_numeric_);
}
template <>
XLNT_API std::uint8_t cell::get_value() const
XLNT_API std::uint8_t cell::value() const
{
return static_cast<std::uint8_t>(d_->value_numeric_);
}
template <>
XLNT_API std::uint16_t cell::get_value() const
XLNT_API std::uint16_t cell::value() const
{
return static_cast<std::uint16_t>(d_->value_numeric_);
}
template <>
XLNT_API std::uint32_t cell::get_value() const
XLNT_API std::uint32_t cell::value() const
{
return static_cast<std::uint32_t>(d_->value_numeric_);
}
template <>
XLNT_API std::uint64_t cell::get_value() const
XLNT_API std::uint64_t cell::value() const
{
return static_cast<std::uint64_t>(d_->value_numeric_);
}
#ifdef __linux
template <>
XLNT_API long long cell::get_value() const
XLNT_API long long cell::value() const
{
return static_cast<long long>(d_->value_numeric_);
}
template <>
XLNT_API unsigned long long cell::get_value() const
XLNT_API unsigned long long cell::value() const
{
return static_cast<unsigned long long>(d_->value_numeric_);
}
#endif
template <>
XLNT_API float cell::get_value() const
XLNT_API float cell::value() const
{
return static_cast<float>(d_->value_numeric_);
}
template <>
XLNT_API double cell::get_value() const
XLNT_API double cell::value() const
{
return static_cast<double>(d_->value_numeric_);
}
template <>
XLNT_API long double cell::get_value() const
XLNT_API long double cell::value() const
{
return d_->value_numeric_;
}
template <>
XLNT_API time cell::get_value() const
XLNT_API time cell::value() const
{
return time::from_number(d_->value_numeric_);
}
template <>
XLNT_API datetime cell::get_value() const
XLNT_API datetime cell::value() const
{
return datetime::from_number(d_->value_numeric_, get_base_date());
return datetime::from_number(d_->value_numeric_, base_date());
}
template <>
XLNT_API date cell::get_value() const
XLNT_API date cell::value() const
{
return date::from_number(static_cast<int>(d_->value_numeric_), get_base_date());
return date::from_number(static_cast<int>(d_->value_numeric_), base_date());
}
template <>
XLNT_API timedelta cell::get_value() const
XLNT_API timedelta cell::value() const
{
return timedelta::from_number(d_->value_numeric_);
}
void cell::set_alignment(const xlnt::alignment &alignment_)
void cell::alignment(const class alignment &alignment_)
{
auto new_format = has_format() ? modifiable_format() : get_workbook().create_format();
auto new_format = has_format() ? modifiable_format() : workbook().create_format();
format(new_format.alignment(alignment_, true));
}
void cell::set_border(const xlnt::border &border_)
void cell::border(const class border &border_)
{
auto new_format = has_format() ? modifiable_format() : get_workbook().create_format();
auto new_format = has_format() ? modifiable_format() : workbook().create_format();
format(new_format.border(border_, true));
}
void cell::set_fill(const xlnt::fill &fill_)
void cell::fill(const class fill &fill_)
{
auto new_format = has_format() ? modifiable_format() : get_workbook().create_format();
auto new_format = has_format() ? modifiable_format() : workbook().create_format();
format(new_format.fill(fill_, true));
}
void cell::set_font(const font &font_)
void cell::font(const class font &font_)
{
auto new_format = has_format() ? modifiable_format() : get_workbook().create_format();
auto new_format = has_format() ? modifiable_format() : workbook().create_format();
format(new_format.font(font_, true));
}
void cell::set_number_format(const number_format &number_format_)
void cell::number_format(const class number_format &number_format_)
{
auto new_format = has_format() ? modifiable_format() : get_workbook().create_format();
auto new_format = has_format() ? modifiable_format() : workbook().create_format();
format(new_format.number_format(number_format_, true));
}
void cell::set_protection(const xlnt::protection &protection_)
void cell::protection(const class protection &protection_)
{
auto new_format = has_format() ? modifiable_format() : get_workbook().create_format();
auto new_format = has_format() ? modifiable_format() : workbook().create_format();
format(new_format.protection(protection_, true));
}
template <>
XLNT_API std::string cell::get_value() const
XLNT_API std::string cell::value() const
{
return d_->value_text_.plain_text();
}
template <>
XLNT_API formatted_text cell::get_value() const
XLNT_API formatted_text cell::value() const
{
return d_->value_text_;
}
@ -822,18 +817,18 @@ std::string cell::to_string() const
{
auto nf = computed_number_format();
switch (get_data_type())
switch (data_type())
{
case cell::type::null:
return "";
case cell::type::numeric:
return nf.format(get_value<long double>(), get_base_date());
return nf.format(value<long double>(), base_date());
case cell::type::string:
case cell::type::formula:
case cell::type::error:
return nf.format(get_value<std::string>());
return nf.format(value<std::string>());
case cell::type::boolean:
return get_value<long double>() == 0.L ? "FALSE" : "TRUE";
return value<long double>() == 0.L ? "FALSE" : "TRUE";
#ifdef WIN32
default:
throw xlnt::exception("unhandled");
@ -857,9 +852,9 @@ void cell::format(const class format new_format)
d_->format_ = new_format.d_;
}
calendar cell::get_base_date() const
calendar cell::base_date() const
{
return get_workbook().get_base_date();
return workbook().base_date();
}
XLNT_API std::ostream &operator<<(std::ostream &stream, const xlnt::cell &cell)
@ -867,29 +862,36 @@ XLNT_API std::ostream &operator<<(std::ostream &stream, const xlnt::cell &cell)
return stream << cell.to_string();
}
void cell::guess_type_and_set_value(const std::string &value)
void cell::value(const std::string &value_string, bool infer_type)
{
auto percentage = cast_percentage(value);
value(value_string);
if (!infer_type)
{
return;
}
auto percentage = cast_percentage(value_string);
if (percentage.first)
{
d_->value_numeric_ = percentage.second;
d_->type_ = cell::type::numeric;
set_number_format(xlnt::number_format::percentage());
number_format(xlnt::number_format::percentage());
}
else
{
auto time = cast_time(value);
auto time = cast_time(value_string);
if (time.first)
{
d_->type_ = cell::type::numeric;
set_number_format(number_format::date_time6());
number_format(number_format::date_time6());
d_->value_numeric_ = time.second.to_number();
}
else
{
auto numeric = cast_numeric(value);
auto numeric = cast_numeric(value_string);
if (numeric.first)
{
@ -916,13 +918,13 @@ void cell::clear_style()
void cell::style(const class style &new_style)
{
auto new_format = has_format() ? format() : get_workbook().create_format();
auto new_format = has_format() ? format() : workbook().create_format();
format(new_format.style(new_style));
}
void cell::style(const std::string &style_name)
{
style(get_workbook().style(style_name));
style(workbook().style(style_name));
}
const style cell::style() const
@ -960,32 +962,32 @@ const format cell::format() const
return xlnt::format(*d_->format_);
}
alignment cell::get_alignment() const
alignment cell::alignment() const
{
return format().alignment();
}
border cell::get_border() const
border cell::border() const
{
return format().border();
}
fill cell::get_fill() const
fill cell::fill() const
{
return format().fill();
}
font cell::get_font() const
font cell::font() const
{
return format().font();
}
number_format cell::get_number_format() const
number_format cell::number_format() const
{
return format().number_format();
}
protection cell::get_protection() const
protection cell::protection() const
{
return format().protection();
}
@ -1027,12 +1029,12 @@ void cell::comment(const class comment &new_comment)
d_->comment_.set(new_comment);
// offset comment 5 pixels down and 5 pixels right of the top right corner of the cell
auto cell_position = get_anchor();
auto cell_position = anchor();
// todo: make this cell_position.first += get_width() instead
if (get_worksheet().has_column_properties(get_column()))
// todo: make this cell_position.first += width() instead
if (worksheet().has_column_properties(column()))
{
cell_position.first += static_cast<int>(get_worksheet().get_column_properties(get_column()).width);
cell_position.first += static_cast<int>(worksheet().column_properties(column()).width);
}
else
{
@ -1052,7 +1054,7 @@ void cell::comment(const class comment &new_comment)
d_->comment_.get().position(cell_position.first, cell_position.second);
d_->comment_.get().size(200, 100);
get_worksheet().register_comments_in_manifest();
worksheet().register_comments_in_manifest();
}
} // namespace xlnt

View File

@ -33,7 +33,7 @@ namespace xlnt {
std::size_t cell_reference_hash::operator()(const cell_reference &k) const
{
return k.get_row() * constants::max_column().index + k.get_column_index().index;
return k.row() * constants::max_column().index + k.column_index();
}
cell_reference &cell_reference::make_absolute(bool absolute_column, bool absolute_row)
@ -52,8 +52,8 @@ cell_reference::cell_reference(const std::string &string)
{
auto split = split_reference(string, absolute_column_, absolute_row_);
set_column(split.first);
set_row(split.second);
column(split.first);
row(split.second);
}
cell_reference::cell_reference(const char *reference_string)
@ -205,32 +205,32 @@ void cell_reference::row_absolute(bool absolute_row)
absolute_row_ = absolute_row;
}
column_t cell_reference::get_column() const
column_t cell_reference::column() const
{
return column_;
}
void cell_reference::set_column(const std::string &column_string)
void cell_reference::column(const std::string &column_string)
{
column_ = column_t(column_string);
}
column_t cell_reference::get_column_index() const
column_t::index_t cell_reference::column_index() const
{
return column_;
return column_.index;
}
void cell_reference::set_column_index(column_t column)
void cell_reference::column_index(column_t column)
{
column_ = column;
}
row_t cell_reference::get_row() const
row_t cell_reference::row() const
{
return row_;
}
void cell_reference::set_row(row_t row)
void cell_reference::row(row_t row)
{
row_ = row;
}

View File

@ -42,7 +42,7 @@ void formatted_text::plain_text(const std::string &s)
std::string formatted_text::plain_text() const
{
return std::accumulate(runs_.begin(), runs_.end(), std::string(),
[](const std::string &a, const text_run &run) { return a + run.get_string(); });
[](const std::string &a, const text_run &run) { return a + run.string(); });
}
std::vector<text_run> formatted_text::runs() const
@ -61,42 +61,42 @@ bool formatted_text::operator==(const formatted_text &rhs) const
for (std::size_t i = 0; i < runs_.size(); i++)
{
if (runs_[i].get_string() != rhs.runs_[i].get_string()) return false;
if (runs_[i].string() != rhs.runs_[i].string()) return false;
if (runs_[i].has_formatting() != rhs.runs_[i].has_formatting()) return false;
if (runs_[i].has_formatting())
{
if (runs_[i].has_color() != rhs.runs_[i].has_color()
|| (runs_[i].has_color()
&& runs_[i].get_color() != rhs.runs_[i].get_color()))
&& runs_[i].color() != rhs.runs_[i].color()))
{
return false;
}
if (runs_[i].has_family() != rhs.runs_[i].has_family()
|| (runs_[i].has_family()
&& runs_[i].get_family() != rhs.runs_[i].get_family()))
&& runs_[i].family() != rhs.runs_[i].family()))
{
return false;
}
if (runs_[i].has_font() != rhs.runs_[i].has_font()
|| (runs_[i].has_font()
&& runs_[i].get_font() != rhs.runs_[i].get_font()))
&& runs_[i].font() != rhs.runs_[i].font()))
{
return false;
}
if (runs_[i].has_scheme() != rhs.runs_[i].has_scheme()
|| (runs_[i].has_scheme()
&& runs_[i].get_scheme() != rhs.runs_[i].get_scheme()))
&& runs_[i].scheme() != rhs.runs_[i].scheme()))
{
return false;
}
if (runs_[i].has_size() != rhs.runs_[i].has_size()
|| (runs_[i].has_size()
&& runs_[i].get_size() != rhs.runs_[i].get_size()))
&& runs_[i].size() != rhs.runs_[i].size()))
{
return false;
}

View File

@ -25,74 +25,70 @@ int random(int min, int max)
class test_cell : public CxxTest::TestSuite
{
private:
xlnt::workbook wb, wb_guess_types;
public:
test_cell()
{
wb_guess_types.set_guess_types(true);
}
void test_infer_numeric()
{
auto ws = wb_guess_types.create_sheet();
auto cell = ws.get_cell("A1");
xlnt::workbook wb;
auto ws = wb.active_sheet();
auto cell = ws.cell("A1");
cell.set_value("4.2");
TS_ASSERT(cell.get_value<long double>() == 4.2L);
cell.value("4.2", true);
TS_ASSERT(cell.value<long double>() == 4.2L);
cell.set_value("-42.000");
TS_ASSERT(cell.get_value<int>() == -42);
cell.value("-42.000", true);
TS_ASSERT(cell.value<int>() == -42);
cell.set_value("0");
TS_ASSERT(cell.get_value<int>() == 0);
cell.value("0", true);
TS_ASSERT(cell.value<int>() == 0);
cell.set_value("0.9999");
TS_ASSERT(cell.get_value<long double>() == 0.9999L);
cell.value("0.9999", true);
TS_ASSERT(cell.value<long double>() == 0.9999L);
cell.set_value("99E-02");
TS_ASSERT(cell.get_value<long double>() == 0.99L);
cell.value("99E-02", true);
TS_ASSERT(cell.value<long double>() == 0.99L);
cell.set_value("4");
TS_ASSERT(cell.get_value<int>() == 4);
cell.value("4", true);
TS_ASSERT(cell.value<int>() == 4);
cell.set_value("-1E3");
TS_ASSERT(cell.get_value<int>() == -1000);
cell.value("-1E3", true);
TS_ASSERT(cell.value<int>() == -1000);
cell.set_value("2e+2");
TS_ASSERT(cell.get_value<int>() == 200);
cell.value("2e+2", true);
TS_ASSERT(cell.value<int>() == 200);
cell.set_value("3.1%");
TS_ASSERT(cell.get_value<long double>() == 0.031L);
cell.value("3.1%", true);
TS_ASSERT(cell.value<long double>() == 0.031L);
cell.set_value("03:40:16");
TS_ASSERT(cell.get_value<xlnt::time>() == xlnt::time(3, 40, 16));
cell.value("03:40:16", true);
TS_ASSERT(cell.value<xlnt::time>() == xlnt::time(3, 40, 16));
cell.set_value("03:");
TS_ASSERT_EQUALS(cell.get_value<std::string>(), "03:");
cell.value("03:", true);
TS_ASSERT_EQUALS(cell.value<std::string>(), "03:");
cell.set_value("03:40");
TS_ASSERT(cell.get_value<xlnt::time>() == xlnt::time(3, 40));
cell.value("03:40", true);
TS_ASSERT(cell.value<xlnt::time>() == xlnt::time(3, 40));
cell.set_value("30:33.865633336");
TS_ASSERT(cell.get_value<xlnt::time>() == xlnt::time(0, 30, 33, 865633));
cell.value("30:33.865633336", true);
TS_ASSERT(cell.value<xlnt::time>() == xlnt::time(0, 30, 33, 865633));
}
void test_ctor()
{
auto ws = wb.create_sheet();
auto cell = ws.get_cell(xlnt::cell_reference("A", 1));
xlnt::workbook wb;
auto ws = wb.active_sheet();
auto cell = ws.cell(xlnt::cell_reference("A", 1));
TS_ASSERT(cell.get_data_type() == xlnt::cell::type::null);
TS_ASSERT(cell.get_column() == "A");
TS_ASSERT(cell.get_row() == 1);
TS_ASSERT(cell.get_reference() == "A1");
TS_ASSERT(cell.data_type() == xlnt::cell::type::null);
TS_ASSERT(cell.column() == "A");
TS_ASSERT(cell.row() == 1);
TS_ASSERT(cell.reference() == "A1");
TS_ASSERT(!cell.has_value());
}
void test_null()
{
xlnt::workbook wb;
const auto datatypes =
{
xlnt::cell::type::null,
@ -105,60 +101,64 @@ public:
for(const auto &datatype : datatypes)
{
auto ws = wb.create_sheet();
auto cell = ws.get_cell(xlnt::cell_reference(1, 1));
auto ws = wb.active_sheet();
auto cell = ws.cell(xlnt::cell_reference(1, 1));
cell.set_data_type(datatype);
TS_ASSERT(cell.get_data_type() == datatype);
cell.data_type(datatype);
TS_ASSERT(cell.data_type() == datatype);
cell.clear_value();
TS_ASSERT(cell.get_data_type() == xlnt::cell::type::null);
TS_ASSERT(cell.data_type() == xlnt::cell::type::null);
}
}
void test_string()
{
auto ws = wb.create_sheet();
auto cell = ws.get_cell(xlnt::cell_reference(1, 1));
xlnt::workbook wb;
auto ws = wb.active_sheet();
auto cell = ws.cell(xlnt::cell_reference(1, 1));
cell.set_value("hello");
TS_ASSERT(cell.get_data_type() == xlnt::cell::type::string);
cell.value("hello");
TS_ASSERT(cell.data_type() == xlnt::cell::type::string);
cell.set_value(".");
TS_ASSERT(cell.get_data_type() == xlnt::cell::type::string);
cell.value(".");
TS_ASSERT(cell.data_type() == xlnt::cell::type::string);
cell.set_value("0800");
TS_ASSERT(cell.get_data_type() == xlnt::cell::type::string);
cell.value("0800");
TS_ASSERT(cell.data_type() == xlnt::cell::type::string);
}
void test_formula1()
{
auto ws = wb_guess_types.create_sheet();
auto cell = ws.get_cell(xlnt::cell_reference(1, 1));
xlnt::workbook wb;
auto ws = wb.active_sheet();
auto cell = ws.cell(xlnt::cell_reference(1, 1));
cell.set_value("=42");
TS_ASSERT(cell.get_data_type() == xlnt::cell::type::formula);
cell.value("=42", true);
TS_ASSERT(cell.data_type() == xlnt::cell::type::formula);
}
void test_formula2()
{
auto ws = wb_guess_types.create_sheet();
auto cell = ws.get_cell(xlnt::cell_reference(1, 1));
xlnt::workbook wb;
auto ws = wb.active_sheet();
auto cell = ws.cell(xlnt::cell_reference(1, 1));
cell.set_value("=if(A1<4;-1;1)");
TS_ASSERT(cell.get_data_type() == xlnt::cell::type::formula);
cell.value("=if(A1<4;-1;1)", true);
TS_ASSERT(cell.data_type() == xlnt::cell::type::formula);
}
void test_formula3()
{
auto ws = wb.create_sheet();
auto cell = ws.get_cell(xlnt::cell_reference(1, 1));
xlnt::workbook wb;
auto ws = wb.active_sheet();
auto cell = ws.cell(xlnt::cell_reference(1, 1));
TS_ASSERT(!cell.has_formula());
TS_ASSERT_THROWS(cell.set_formula(""), xlnt::invalid_parameter);
TS_ASSERT_THROWS(cell.get_formula(), xlnt::invalid_attribute);
cell.set_formula("=42");
TS_ASSERT_THROWS(cell.formula(""), xlnt::invalid_parameter);
TS_ASSERT(!cell.has_formula());
cell.formula("=42");
TS_ASSERT(cell.has_formula());
TS_ASSERT_EQUALS(cell.get_formula(), "42");
TS_ASSERT_EQUALS(cell.formula(), "42");
cell.clear_formula();
TS_ASSERT(!cell.has_formula());
}
@ -166,81 +166,88 @@ public:
void test_not_formula()
{
auto ws = wb.create_sheet();
auto cell = ws.get_cell(xlnt::cell_reference(1, 1));
xlnt::workbook wb;
auto ws = wb.active_sheet();
auto cell = ws.cell(xlnt::cell_reference(1, 1));
cell.set_value("=");
TS_ASSERT(cell.get_data_type() == xlnt::cell::type::string);
TS_ASSERT(cell.get_value<std::string>() == "=");
cell.value("=");
TS_ASSERT(cell.data_type() == xlnt::cell::type::string);
TS_ASSERT(cell.value<std::string>() == "=");
TS_ASSERT(!cell.has_formula());
}
void test_boolean()
{
auto ws = wb.create_sheet();
auto cell = ws.get_cell(xlnt::cell_reference(1, 1));
xlnt::workbook wb;
auto ws = wb.active_sheet();
auto cell = ws.cell(xlnt::cell_reference(1, 1));
for(auto value : {true, false})
{
cell.set_value(value);
TS_ASSERT(cell.get_data_type() == xlnt::cell::type::boolean);
cell.value(value);
TS_ASSERT(cell.data_type() == xlnt::cell::type::boolean);
}
}
void test_error_codes()
{
auto ws = wb_guess_types.create_sheet();
auto cell = ws.get_cell(xlnt::cell_reference(1, 1));
xlnt::workbook wb;
auto ws = wb.active_sheet();
auto cell = ws.cell(xlnt::cell_reference(1, 1));
for(auto error_code : xlnt::cell::error_codes())
{
cell.set_value(error_code.first);
TS_ASSERT(cell.get_data_type() == xlnt::cell::type::error);
cell.value(error_code.first, true);
TS_ASSERT(cell.data_type() == xlnt::cell::type::error);
}
}
void test_insert_datetime()
{
auto ws = wb.create_sheet();
auto cell = ws.get_cell(xlnt::cell_reference(1, 1));
xlnt::workbook wb;
auto ws = wb.active_sheet();
auto cell = ws.cell(xlnt::cell_reference(1, 1));
cell.set_value(xlnt::datetime(2010, 7, 13, 6, 37, 41));
TS_ASSERT(cell.get_data_type() == xlnt::cell::type::numeric);
TS_ASSERT(cell.get_value<long double>() == 40372.27616898148L);
cell.value(xlnt::datetime(2010, 7, 13, 6, 37, 41));
TS_ASSERT(cell.data_type() == xlnt::cell::type::numeric);
TS_ASSERT(cell.value<long double>() == 40372.27616898148L);
TS_ASSERT(cell.is_date());
TS_ASSERT(cell.get_number_format().get_format_string() == "yyyy-mm-dd h:mm:ss");
TS_ASSERT(cell.number_format().format_string() == "yyyy-mm-dd h:mm:ss");
}
void test_insert_date()
{
auto ws = wb.create_sheet();
auto cell = ws.get_cell(xlnt::cell_reference(1, 1));
xlnt::workbook wb;
auto ws = wb.active_sheet();
auto cell = ws.cell(xlnt::cell_reference(1, 1));
cell.set_value(xlnt::date(2010, 7, 13));
TS_ASSERT(cell.get_data_type() == xlnt::cell::type::numeric);
TS_ASSERT(cell.get_value<long double>() == 40372.L);
cell.value(xlnt::date(2010, 7, 13));
TS_ASSERT(cell.data_type() == xlnt::cell::type::numeric);
TS_ASSERT(cell.value<long double>() == 40372.L);
TS_ASSERT(cell.is_date());
TS_ASSERT(cell.get_number_format().get_format_string() == "yyyy-mm-dd");
TS_ASSERT(cell.number_format().format_string() == "yyyy-mm-dd");
}
void test_insert_time()
{
auto ws = wb.create_sheet();
auto cell = ws.get_cell(xlnt::cell_reference(1, 1));
xlnt::workbook wb;
auto ws = wb.active_sheet();
auto cell = ws.cell(xlnt::cell_reference(1, 1));
cell.set_value(xlnt::time(1, 3));
TS_ASSERT(cell.get_data_type() == xlnt::cell::type::numeric);
TS_ASSERT(cell.get_value<long double>() == 0.04375L);
cell.value(xlnt::time(1, 3));
TS_ASSERT(cell.data_type() == xlnt::cell::type::numeric);
TS_ASSERT(cell.value<long double>() == 0.04375L);
TS_ASSERT(cell.is_date());
TS_ASSERT(cell.get_number_format().get_format_string() == "h:mm:ss");
TS_ASSERT(cell.number_format().format_string() == "h:mm:ss");
}
void test_cell_formatted_as_date1()
{
auto ws = wb.create_sheet();
auto cell = ws.get_cell(xlnt::cell_reference(1, 1));
xlnt::workbook wb;
auto ws = wb.active_sheet();
auto cell = ws.cell(xlnt::cell_reference(1, 1));
cell.set_value(xlnt::datetime::today());
cell.value(xlnt::datetime::today());
cell.clear_value();
TS_ASSERT(!cell.is_date()); // disagree with openpyxl
TS_ASSERT(!cell.has_value());
@ -248,30 +255,33 @@ public:
void test_cell_formatted_as_date2()
{
auto ws = wb.create_sheet();
auto cell = ws.get_cell(xlnt::cell_reference(1, 1));
xlnt::workbook wb;
auto ws = wb.active_sheet();
auto cell = ws.cell(xlnt::cell_reference(1, 1));
cell.set_value(xlnt::datetime::today());
cell.set_value("testme");
cell.value(xlnt::datetime::today());
cell.value("testme");
TS_ASSERT(!cell.is_date());
TS_ASSERT(cell.get_value<std::string>() == "testme");
TS_ASSERT(cell.value<std::string>() == "testme");
}
void test_cell_formatted_as_date3()
{
auto ws = wb.create_sheet();
auto cell = ws.get_cell(xlnt::cell_reference(1, 1));
xlnt::workbook wb;
auto ws = wb.active_sheet();
auto cell = ws.cell(xlnt::cell_reference(1, 1));
cell.set_value(xlnt::datetime::today());
cell.set_value(true);
cell.value(xlnt::datetime::today());
cell.value(true);
TS_ASSERT(!cell.is_date());
TS_ASSERT(cell.get_value<bool>() == true);
TS_ASSERT(cell.value<bool>() == true);
}
void test_illegal_characters()
{
auto ws = wb.create_sheet();
auto cell = ws.get_cell(xlnt::cell_reference(1, 1));
xlnt::workbook wb;
auto ws = wb.active_sheet();
auto cell = ws.cell(xlnt::cell_reference(1, 1));
// The bytes 0x00 through 0x1F inclusive must be manually escaped in values.
auto illegal_chrs = {0, 1, 2, 3, 4, 5, 6, 7, 8, 11, 12, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31};
@ -279,130 +289,138 @@ public:
for(auto i : illegal_chrs)
{
std::string str(1, i);
TS_ASSERT_THROWS(cell.set_value(str), xlnt::illegal_character);
TS_ASSERT_THROWS(cell.value(str), xlnt::illegal_character);
}
cell.set_value(std::string(1, 33));
cell.set_value(std::string(1, 9)); // Tab
cell.set_value(std::string(1, 10)); // Newline
cell.set_value(std::string(1, 13)); // Carriage return
cell.set_value(" Leading and trailing spaces are legal ");
cell.value(std::string(1, 33));
cell.value(std::string(1, 9)); // Tab
cell.value(std::string(1, 10)); // Newline
cell.value(std::string(1, 13)); // Carriage return
cell.value(" Leading and trailing spaces are legal ");
}
// void test_time_regex() {}
void test_timedelta()
{
auto ws = wb.create_sheet();
auto cell = ws.get_cell(xlnt::cell_reference(1, 1));
xlnt::workbook wb;
auto ws = wb.active_sheet();
auto cell = ws.cell(xlnt::cell_reference(1, 1));
cell.set_value(xlnt::timedelta(1, 3, 0, 0, 0));
cell.value(xlnt::timedelta(1, 3, 0, 0, 0));
TS_ASSERT(cell.get_value<long double>() == 1.125);
TS_ASSERT(cell.get_data_type() == xlnt::cell::type::numeric);
TS_ASSERT(cell.value<long double>() == 1.125);
TS_ASSERT(cell.data_type() == xlnt::cell::type::numeric);
TS_ASSERT(!cell.is_date());
TS_ASSERT(cell.get_number_format().get_format_string() == "[hh]:mm:ss");
TS_ASSERT(cell.number_format().format_string() == "[hh]:mm:ss");
}
void test_repr()
{
auto ws = wb[1];
auto cell = ws.get_cell(xlnt::cell_reference(1, 1));
xlnt::workbook wb;
auto ws = wb.active_sheet();
auto cell = ws.cell(xlnt::cell_reference(1, 1));
TS_ASSERT(cell.to_repr() == "<Cell Sheet2.A1>");
TS_ASSERT(cell.to_repr() == "<Cell Sheet1.A1>");
}
void test_cell_offset()
{
auto ws = wb.create_sheet();
auto cell = ws.get_cell(xlnt::cell_reference(1, 1));
TS_ASSERT(cell.offset(1, 2).get_reference() == "B3");
xlnt::workbook wb;
auto ws = wb.active_sheet();
auto cell = ws.cell(xlnt::cell_reference(1, 1));
TS_ASSERT(cell.offset(1, 2).reference() == "B3");
}
void test_font()
{
auto ws = wb.create_sheet();
auto cell = ws.get_cell("A1");
xlnt::workbook wb;
auto ws = wb.active_sheet();
auto cell = ws.cell("A1");
auto font = xlnt::font().bold(true);
cell.set_font(font);
cell.font(font);
TS_ASSERT(cell.has_format());
TS_ASSERT(cell.format().font_applied());
TS_ASSERT_EQUALS(cell.get_font(), font);
TS_ASSERT_EQUALS(cell.font(), font);
}
void test_fill()
{
auto ws = wb.create_sheet();
auto cell = ws.get_cell("A1");
xlnt::workbook wb;
auto ws = wb.active_sheet();
auto cell = ws.cell("A1");
xlnt::fill fill(xlnt::pattern_fill()
.type(xlnt::pattern_fill_type::solid)
.foreground(xlnt::color::red()));
cell.set_fill(fill);
cell.fill(fill);
TS_ASSERT(cell.has_format());
TS_ASSERT(cell.format().fill_applied());
TS_ASSERT_EQUALS(cell.get_fill(), fill);
TS_ASSERT_EQUALS(cell.fill(), fill);
}
void test_border()
{
auto ws = wb.create_sheet();
auto cell = ws.get_cell("A1");
xlnt::workbook wb;
auto ws = wb.active_sheet();
auto cell = ws.cell("A1");
xlnt::border border;
cell.set_border(border);
cell.border(border);
TS_ASSERT(cell.has_format());
TS_ASSERT(cell.format().border_applied());
TS_ASSERT_EQUALS(cell.get_border(), border);
TS_ASSERT_EQUALS(cell.border(), border);
}
void test_number_format()
{
auto ws = wb.create_sheet();
auto cell = ws.get_cell("A1");
xlnt::workbook wb;
auto ws = wb.active_sheet();
auto cell = ws.cell("A1");
xlnt::number_format format("dd--hh--mm");
cell.set_number_format(format);
cell.number_format(format);
TS_ASSERT(cell.has_format());
TS_ASSERT(cell.format().number_format_applied());
TS_ASSERT_EQUALS(cell.get_number_format().get_format_string(), "dd--hh--mm");
TS_ASSERT_EQUALS(cell.number_format().format_string(), "dd--hh--mm");
}
void test_alignment()
{
auto ws = wb.create_sheet();
auto cell = ws.get_cell("A1");
xlnt::workbook wb;
auto ws = wb.active_sheet();
auto cell = ws.cell("A1");
xlnt::alignment align;
align.wrap(true);
cell.set_alignment(align);
cell.alignment(align);
TS_ASSERT(cell.has_format());
TS_ASSERT(cell.format().alignment_applied());
TS_ASSERT_EQUALS(cell.get_alignment(), align);
TS_ASSERT_EQUALS(cell.alignment(), align);
}
void test_protection()
{
auto ws = wb.create_sheet();
auto cell = ws.get_cell("A1");
xlnt::workbook wb;
auto ws = wb.active_sheet();
auto cell = ws.cell("A1");
TS_ASSERT(!cell.has_format());
auto protection = xlnt::protection().locked(false).hidden(true);
cell.set_protection(protection);
cell.protection(protection);
TS_ASSERT(cell.has_format());
TS_ASSERT(cell.format().protection_applied());
TS_ASSERT_EQUALS(cell.get_protection(), protection);
TS_ASSERT_EQUALS(cell.protection(), protection);
TS_ASSERT(cell.has_format());
cell.clear_format();
@ -411,8 +429,9 @@ public:
void test_style()
{
auto ws = wb.create_sheet();
auto cell = ws.get_cell("A1");
xlnt::workbook wb;
auto ws = wb.active_sheet();
auto cell = ws.cell("A1");
TS_ASSERT(!cell.has_style());
@ -448,10 +467,11 @@ public:
void test_print()
{
auto ws = wb.create_sheet();
xlnt::workbook wb;
auto ws = wb.active_sheet();
{
auto cell = ws.get_cell("A1");
auto cell = ws.cell("A1");
std::stringstream ss;
ss << cell;
@ -463,9 +483,9 @@ public:
}
{
auto cell = ws.get_cell("A2");
auto cell = ws.cell("A2");
cell.set_value(false);
cell.value(false);
std::stringstream ss;
ss << cell;
@ -477,9 +497,9 @@ public:
}
{
auto cell = ws.get_cell("A3");
auto cell = ws.cell("A3");
cell.set_value(true);
cell.value(true);
std::stringstream ss;
ss << cell;
@ -491,9 +511,9 @@ public:
}
{
auto cell = ws.get_cell("A4");
auto cell = ws.cell("A4");
cell.set_value(1.234);
cell.value(1.234);
std::stringstream ss;
ss << cell;
@ -505,9 +525,9 @@ public:
}
{
auto cell = ws.get_cell("A5");
auto cell = ws.cell("A5");
cell.set_error("#REF");
cell.error("#REF");
std::stringstream ss;
ss << cell;
@ -519,9 +539,9 @@ public:
}
{
auto cell = ws.get_cell("A6");
auto cell = ws.cell("A6");
cell.set_value("test");
cell.value("test");
std::stringstream ss;
ss << cell;
@ -535,57 +555,58 @@ public:
void test_values()
{
auto ws = wb.create_sheet();
auto cell = ws.get_cell("A1");
xlnt::workbook wb;
auto ws = wb.active_sheet();
auto cell = ws.cell("A1");
cell.set_value(static_cast<std::int8_t>(4));
TS_ASSERT_EQUALS(cell.get_value<int8_t>(), 4);
cell.value(static_cast<std::int8_t>(4));
TS_ASSERT_EQUALS(cell.value<int8_t>(), 4);
cell.set_value(static_cast<std::uint8_t>(3));
TS_ASSERT_EQUALS(cell.get_value<std::uint8_t>(), 3);
cell.value(static_cast<std::uint8_t>(3));
TS_ASSERT_EQUALS(cell.value<std::uint8_t>(), 3);
cell.set_value(static_cast<std::int16_t>(4));
TS_ASSERT_EQUALS(cell.get_value<int16_t>(), 4);
cell.value(static_cast<std::int16_t>(4));
TS_ASSERT_EQUALS(cell.value<int16_t>(), 4);
cell.set_value(static_cast<std::uint16_t>(3));
TS_ASSERT_EQUALS(cell.get_value<std::uint16_t>(), 3);
cell.value(static_cast<std::uint16_t>(3));
TS_ASSERT_EQUALS(cell.value<std::uint16_t>(), 3);
cell.set_value(static_cast<std::int32_t>(4));
TS_ASSERT_EQUALS(cell.get_value<int32_t>(), 4);
cell.value(static_cast<std::int32_t>(4));
TS_ASSERT_EQUALS(cell.value<int32_t>(), 4);
cell.set_value(static_cast<std::uint32_t>(3));
TS_ASSERT_EQUALS(cell.get_value<std::uint32_t>(), 3);
cell.value(static_cast<std::uint32_t>(3));
TS_ASSERT_EQUALS(cell.value<std::uint32_t>(), 3);
cell.set_value(static_cast<std::int64_t>(4));
TS_ASSERT_EQUALS(cell.get_value<int64_t>(), 4);
cell.value(static_cast<std::int64_t>(4));
TS_ASSERT_EQUALS(cell.value<int64_t>(), 4);
cell.set_value(static_cast<std::uint64_t>(3));
TS_ASSERT_EQUALS(cell.get_value<std::uint64_t>(), 3);
cell.value(static_cast<std::uint64_t>(3));
TS_ASSERT_EQUALS(cell.value<std::uint64_t>(), 3);
#ifdef __linux
cell.set_value(static_cast<long long>(3));
TS_ASSERT_EQUALS(cell.get_value<long long>(), 3);
cell.value(static_cast<long long>(3));
TS_ASSERT_EQUALS(cell.value<long long>(), 3);
cell.set_value(static_cast<unsigned long long>(3));
TS_ASSERT_EQUALS(cell.get_value<unsigned long long>(), 3);
cell.value(static_cast<unsigned long long>(3));
TS_ASSERT_EQUALS(cell.value<unsigned long long>(), 3);
#endif
cell.set_value(static_cast<std::uint64_t>(3));
TS_ASSERT_EQUALS(cell.get_value<std::uint64_t>(), 3);
cell.value(static_cast<std::uint64_t>(3));
TS_ASSERT_EQUALS(cell.value<std::uint64_t>(), 3);
cell.set_value(static_cast<float>(3.14));
TS_ASSERT_DELTA(cell.get_value<float>(), 3.14, 0.001);
cell.value(static_cast<float>(3.14));
TS_ASSERT_DELTA(cell.value<float>(), 3.14, 0.001);
cell.set_value(static_cast<double>(4.1415));
TS_ASSERT_EQUALS(cell.get_value<double>(), 4.1415);
cell.value(static_cast<double>(4.1415));
TS_ASSERT_EQUALS(cell.value<double>(), 4.1415);
cell.set_value(static_cast<long double>(3.141592));
TS_ASSERT_EQUALS(cell.get_value<long double>(), 3.141592);
cell.value(static_cast<long double>(3.141592));
TS_ASSERT_EQUALS(cell.value<long double>(), 3.141592);
auto cell2 = ws.get_cell("A2");
cell2.set_value(std::string(100'000, 'a'));
cell.set_value(cell2);
TS_ASSERT_EQUALS(cell.get_value<std::string>(), std::string(32'767, 'a'));
auto cell2 = ws.cell("A2");
cell2.value(std::string(100'000, 'a'));
cell.value(cell2);
TS_ASSERT_EQUALS(cell.value<std::string>(), std::string(32'767, 'a'));
}
void test_reference()
@ -610,8 +631,8 @@ public:
void test_anchor()
{
xlnt::workbook wb;
auto cell = wb.get_active_sheet().get_cell("A1");
auto anchor = cell.get_anchor();
auto cell = wb.active_sheet().cell("A1");
auto anchor = cell.anchor();
TS_ASSERT_EQUALS(anchor.first, 0);
TS_ASSERT_EQUALS(anchor.second, 0);
}
@ -619,21 +640,21 @@ public:
void test_hyperlink()
{
xlnt::workbook wb;
auto cell = wb.get_active_sheet().get_cell("A1");
auto cell = wb.active_sheet().cell("A1");
TS_ASSERT(!cell.has_hyperlink());
TS_ASSERT_THROWS(cell.get_hyperlink(), xlnt::invalid_attribute);
TS_ASSERT_THROWS(cell.set_hyperlink("notaurl"), xlnt::invalid_parameter);
TS_ASSERT_THROWS(cell.set_hyperlink(""), xlnt::invalid_parameter);
cell.set_hyperlink("http://example.com");
TS_ASSERT_THROWS(cell.hyperlink(), xlnt::invalid_attribute);
TS_ASSERT_THROWS(cell.hyperlink("notaurl"), xlnt::invalid_parameter);
TS_ASSERT_THROWS(cell.hyperlink(""), xlnt::invalid_parameter);
cell.hyperlink("http://example.com");
TS_ASSERT(cell.has_hyperlink());
TS_ASSERT_EQUALS(cell.get_hyperlink(), "http://example.com");
TS_ASSERT_EQUALS(cell.hyperlink(), "http://example.com");
}
void test_comment()
{
xlnt::workbook wb;
auto ws = wb.get_active_sheet();
auto cell = ws.get_cell("A1");
auto ws = wb.active_sheet();
auto cell = ws.cell("A1");
TS_ASSERT(!cell.has_comment());
TS_ASSERT_THROWS(cell.comment(), xlnt::exception);
cell.comment(xlnt::comment("comment", "author"));

View File

@ -22,41 +22,41 @@ public:
TS_ASSERT_EQUALS(text1, text2);
xlnt::text_run run_formatted;
run_formatted.set_color(xlnt::color::green());
run_formatted.set_font("Cambria");
run_formatted.set_scheme("ascheme");
run_formatted.set_size(40);
run_formatted.set_family(17);
run_formatted.color(xlnt::color::green());
run_formatted.font("Cambria");
run_formatted.scheme("ascheme");
run_formatted.size(40);
run_formatted.family(17);
xlnt::formatted_text text_formatted;
text_formatted.add_run(run_formatted);
xlnt::text_run run_color_differs = run_formatted;
run_color_differs.set_color(xlnt::color::red());
run_color_differs.color(xlnt::color::red());
xlnt::formatted_text text_color_differs;
text_color_differs.add_run(run_color_differs);
TS_ASSERT_DIFFERS(text_formatted, text_color_differs);
xlnt::text_run run_font_differs = run_formatted;
run_font_differs.set_font("Calibri");
run_font_differs.font("Calibri");
xlnt::formatted_text text_font_differs;
text_font_differs.add_run(run_font_differs);
TS_ASSERT_DIFFERS(text_formatted, text_font_differs);
xlnt::text_run run_scheme_differs = run_formatted;
run_scheme_differs.set_scheme("bscheme");
run_scheme_differs.scheme("bscheme");
xlnt::formatted_text text_scheme_differs;
text_scheme_differs.add_run(run_scheme_differs);
TS_ASSERT_DIFFERS(text_formatted, text_scheme_differs);
xlnt::text_run run_size_differs = run_formatted;
run_size_differs.set_size(41);
run_size_differs.size(41);
xlnt::formatted_text text_size_differs;
text_size_differs.add_run(run_size_differs);
TS_ASSERT_DIFFERS(text_formatted, text_size_differs);
xlnt::text_run run_family_differs = run_formatted;
run_family_differs.set_family(18);
run_family_differs.family(18);
xlnt::formatted_text text_family_differs;
text_family_differs.add_run(run_family_differs);
TS_ASSERT_DIFFERS(text_formatted, text_family_differs);

View File

@ -34,109 +34,144 @@ text_run::text_run(const std::string &string) : string_(string)
{
}
std::string text_run::get_string() const
std::string text_run::string() const
{
return string_;
}
void text_run::set_string(const std::string &string)
void text_run::string(const std::string &string)
{
string_ = string;
}
bool text_run::has_formatting() const
{
return has_size() || has_color() || has_font() || has_family() || has_scheme();
return font_.is_set();
}
bool text_run::has_size() const
{
return size_.is_set();
return font_.is_set() && font_.get().has_size();
}
std::size_t text_run::get_size() const
std::size_t text_run::size() const
{
return *size_;
return font_.get().size();
}
void text_run::set_size(std::size_t size)
void text_run::size(std::size_t size)
{
size_ = size;
if (!font_.is_set())
{
font_ = xlnt::font();
}
font_.get().size(size);
}
bool text_run::has_color() const
{
return color_.is_set();
return font_.is_set() && font_.get().has_color();
}
color text_run::get_color() const
color text_run::color() const
{
return *color_;
return font_.get().color();
}
void text_run::set_color(const color &new_color)
void text_run::color(const class color &new_color)
{
color_ = new_color;
if (!font_.is_set())
{
font_ = xlnt::font();
}
font_.get().color(new_color);
}
bool text_run::has_font() const
{
return font_.is_set();
return font_.is_set() && font_.get().has_name();
}
std::string text_run::get_font() const
std::string text_run::font() const
{
return *font_;
return font_.get().name();
}
void text_run::set_font(const std::string &font)
void text_run::font(const std::string &font)
{
font_ = font;
if (!font_.is_set())
{
font_ = xlnt::font();
}
font_.get().name(font);
}
bool text_run::has_family() const
{
return family_.is_set();
return font_.is_set() && font_.get().has_family();
}
std::size_t text_run::get_family() const
std::size_t text_run::family() const
{
return *family_;
return font_.get().family();
}
void text_run::set_family(std::size_t family)
void text_run::family(std::size_t family)
{
family_ = family;
if (!font_.is_set())
{
font_ = xlnt::font();
}
font_.get().family(family);
}
bool text_run::has_scheme() const
{
return scheme_.is_set();
return font_.is_set() && font_.get().has_scheme();
}
std::string text_run::get_scheme() const
std::string text_run::scheme() const
{
return *scheme_;
return font_.get().scheme();
}
void text_run::set_scheme(const std::string &scheme)
void text_run::scheme(const std::string &scheme)
{
scheme_ = scheme;
if (!font_.is_set())
{
font_ = xlnt::font();
}
font_.get().scheme(scheme);
}
bool text_run::bold_set() const
bool text_run::bold() const
{
return bold_.is_set();
return font_.is_set() && font_.get().bold();
}
bool text_run::is_bold() const
void text_run::bold(bool bold)
{
return *bold_;
if (!font_.is_set())
{
font_ = xlnt::font();
}
font_.get().bold(bold);
}
void text_run::set_bold(bool bold)
void text_run::underline(font::underline_style style)
{
bold_ = bold;
if (!font_.is_set())
{
font_ = xlnt::font();
}
font_.get().underline(style);
}
} // namespace xlnt

View File

@ -65,7 +65,7 @@ const path constants::part_styles() { return package_xl().append("styles.xml");
const path constants::part_theme() { return package_theme().append("theme1.xml"); }
const path constants::part_shared_strings() { return package_xl().append("sharedStrings.xml"); }
const std::unordered_map<std::string, std::string> &constants::get_namespaces()
const std::unordered_map<std::string, std::string> &constants::namespaces()
{
static const std::unordered_map<std::string, std::string> *namespaces =
new std::unordered_map<std::string, std::string>
@ -77,6 +77,7 @@ const std::unordered_map<std::string, std::string> &constants::get_namespaces()
{ "workbook", "http://schemas.openxmlformats.org/spreadsheetml/2006/main" },
{ "core-properties", "http://schemas.openxmlformats.org/package/2006/metadata/core-properties" },
{ "extended-properties", "http://schemas.openxmlformats.org/officeDocument/2006/extended-properties" },
{ "custom-properties", "http://schemas.openxmlformats.org/officeDocument/2006/customProperties" },
{ "encryption", "http://schemas.microsoft.com/office/2006/encryption" },
{ "encryption-password", "http://schemas.microsoft.com/office/2006/keyEncryptor/password" },
@ -103,11 +104,11 @@ const std::unordered_map<std::string, std::string> &constants::get_namespaces()
return *namespaces;
}
const std::string &constants::get_namespace(const std::string &id)
const std::string &constants::namespace_(const std::string &id)
{
auto match = get_namespaces().find(id);
auto match = namespaces().find(id);
if (match == get_namespaces().end())
if (match == namespaces().end())
{
throw xlnt::exception("bad namespace");
}

View File

@ -125,12 +125,12 @@ struct XLNT_API constants
/// <summary>
/// Returns an unordered_map mapping namespace names to namespaces.
/// </summary>
static const std::unordered_map<std::string, std::string> &get_namespaces();
static const std::unordered_map<std::string, std::string> &namespaces();
/// <summary>
/// Returns the namespace URI from a namespace name.
/// </summary>
static const std::string &get_namespace(const std::string &id);
static const std::string &namespace_(const std::string &id);
};
} // namespace xlnt

View File

@ -25,80 +25,80 @@ std::string to_string(font::underline_style style)
/// <summary>
/// Returns the string representation of the relationship type.
/// </summary>
std::string to_string(relationship::type t)
std::string to_string(relationship_type t)
{
switch (t)
{
case relationship::type::office_document:
case relationship_type::office_document:
return "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument";
case relationship::type::thumbnail:
case relationship_type::thumbnail:
return "http://schemas.openxmlformats.org/package/2006/relationships/metadata/thumbnail";
case relationship::type::calculation_chain:
case relationship_type::calculation_chain:
return "http://purl.oclc.org/ooxml/officeDocument/relationships/calcChain";
case relationship::type::extended_properties:
case relationship_type::extended_properties:
return "http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties";
case relationship::type::core_properties:
case relationship_type::core_properties:
return "http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties";
case relationship::type::worksheet:
case relationship_type::worksheet:
return "http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet";
case relationship::type::shared_string_table:
case relationship_type::shared_string_table:
return "http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings";
case relationship::type::stylesheet:
case relationship_type::stylesheet:
return "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles";
case relationship::type::theme:
case relationship_type::theme:
return "http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme";
case relationship::type::hyperlink:
case relationship_type::hyperlink:
return "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink";
case relationship::type::chartsheet:
case relationship_type::chartsheet:
return "http://schemas.openxmlformats.org/officeDocument/2006/relationships/chartsheet";
case relationship::type::comments:
case relationship_type::comments:
return "http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments";
case relationship::type::vml_drawing:
case relationship_type::vml_drawing:
return "http://schemas.openxmlformats.org/officeDocument/2006/relationships/vmlDrawing";
case relationship::type::unknown:
case relationship_type::unknown:
return "unknown";
case relationship::type::custom_properties:
case relationship_type::custom_properties:
return "custom-properties";
case relationship::type::printer_settings:
case relationship_type::printer_settings:
return "printer-settings";
case relationship::type::connections:
case relationship_type::connections:
return "connections";
case relationship::type::custom_property:
case relationship_type::custom_property:
return "custom-property";
case relationship::type::custom_xml_mappings:
case relationship_type::custom_xml_mappings:
return "custom-xml-mappings";
case relationship::type::dialogsheet:
case relationship_type::dialogsheet:
return "dialogsheet";
case relationship::type::drawings:
case relationship_type::drawings:
return "drawings";
case relationship::type::external_workbook_references:
case relationship_type::external_workbook_references:
return "external-workbook-references";
case relationship::type::metadata:
case relationship_type::metadata:
return "metadata";
case relationship::type::pivot_table:
case relationship_type::pivot_table:
return "pivot-table";
case relationship::type::pivot_table_cache_definition:
case relationship_type::pivot_table_cache_definition:
return "pivot-table-cache-definition";
case relationship::type::pivot_table_cache_records:
case relationship_type::pivot_table_cache_records:
return "pivot-table-cache-records";
case relationship::type::query_table:
case relationship_type::query_table:
return "query-table";
case relationship::type::shared_workbook_revision_headers:
case relationship_type::shared_workbook_revision_headers:
return "shared-workbook-revision-headers";
case relationship::type::shared_workbook:
case relationship_type::shared_workbook:
return "shared-workbook";
case relationship::type::revision_log:
case relationship_type::revision_log:
return "revision-log";
case relationship::type::shared_workbook_user_data:
case relationship_type::shared_workbook_user_data:
return "shared-workbook-user-data";
case relationship::type::single_cell_table_definitions:
case relationship_type::single_cell_table_definitions:
return "single-cell-table-definitions";
case relationship::type::table_definition:
case relationship_type::table_definition:
return "table-definition";
case relationship::type::volatile_dependencies:
case relationship_type::volatile_dependencies:
return "volatile-dependencies";
case relationship::type::image:
return "image";
case relationship_type::image:
return "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image";
#ifdef WIN32
default:
throw xlnt::exception("unhandled");

View File

@ -9,6 +9,7 @@
#include <xlnt/styles/horizontal_alignment.hpp>
#include <xlnt/styles/vertical_alignment.hpp>
#include <xlnt/utils/exceptions.hpp>
#include <xlnt/worksheet/pane.hpp>
namespace xlnt {
namespace detail {
@ -30,7 +31,7 @@ std::string to_string(font::underline_style underline_style);
/// <summary>
/// Returns the string representation of the relationship type.
/// </summary>
std::string to_string(relationship::type t);
std::string to_string(relationship_type t);
std::string to_string(pattern_fill_type fill_type);
@ -382,6 +383,52 @@ struct value_traits<xlnt::target_mode>
}
}; // struct value_traits<xlnt::target_mode>
template <>
struct value_traits<xlnt::pane_state>
{
static xlnt::pane_state parse(std::string string, const parser &)
{
if (string == "frozen") return xlnt::pane_state::frozen;
else if (string == "frozenSplit") return xlnt::pane_state::frozen_split;
else if (string == "split") return xlnt::pane_state::split;
return xlnt::pane_state::split;
}
static std::string serialize (xlnt::pane_state state, const serializer &)
{
switch (state)
{
case xlnt::pane_state::frozen: return "frozen";
case xlnt::pane_state::frozen_split: return "frozenSplit";
case xlnt::pane_state::split: return "split";
}
}
}; // struct value_traits<xlnt::pane_state>
template <>
struct value_traits<xlnt::pane_corner>
{
static xlnt::pane_corner parse(std::string string, const parser &)
{
if (string == "bottomLeft") return xlnt::pane_corner::bottom_left;
else if (string == "bottomRight") return xlnt::pane_corner::bottom_right;
else if (string == "topLeft") return xlnt::pane_corner::top_left;
else if (string == "topRight") return xlnt::pane_corner::top_right;
return xlnt::pane_corner::top_left;
}
static std::string serialize (xlnt::pane_corner corner, const serializer &)
{
switch (corner)
{
case xlnt::pane_corner::bottom_left: return "bottomLeft";
case xlnt::pane_corner::bottom_right: return "bottomRight";
case xlnt::pane_corner::top_left: return "topLeft";
case xlnt::pane_corner::top_right: return "topRight";
}
}
}; // struct value_traits<xlnt::pane_corner>
}

View File

@ -191,7 +191,7 @@ number_format_parser::number_format_parser(const std::string &format_string)
reset(format_string);
}
const std::vector<format_code> &number_format_parser::get_result() const
const std::vector<format_code> &number_format_parser::result() const
{
return codes_;
}
@ -1153,7 +1153,7 @@ number_formatter::number_formatter(const std::string &format_string, xlnt::calen
calendar_(calendar)
{
parser_.parse();
format_ = parser_.get_result();
format_ = parser_.result();
}
std::string number_formatter::format_number(long double number)

View File

@ -331,7 +331,7 @@ class number_format_parser
{
public:
number_format_parser(const std::string &format_string);
const std::vector<format_code> &get_result() const;
const std::vector<format_code> &result() const;
void reset(const std::string &format_string);
void parse();

View File

@ -57,14 +57,14 @@ struct stylesheet
impl.references = default_format ? 1 : 0;
return format(&impl);
return xlnt::format(&impl);
}
format get_format(std::size_t index)
format format(std::size_t index)
{
auto iter = format_impls.begin();
std::advance(iter, static_cast<std::list<format_impl>::difference_type>(index));
return format(&*iter);
return xlnt::format(&*iter);
}
class style create_style(const std::string &name)
@ -100,9 +100,9 @@ struct stylesheet
for (const auto &nf : number_formats)
{
if (nf.get_id() >= id)
if (nf.id() >= id)
{
id = nf.get_id() + 1;
id = nf.id() + 1;
}
}

View File

@ -44,32 +44,7 @@ struct worksheet_impl;
struct workbook_impl
{
workbook_impl()
: active_sheet_index_(0),
guess_types_(false),
data_only_(false),
has_theme_(false),
write_core_properties_(false),
created_(xlnt::datetime::now()),
modified_(xlnt::datetime::now()),
base_date_(calendar::windows_1900),
write_app_properties_(false),
application_("libxlnt"),
doc_security_(0),
scale_crop_(false),
links_up_to_date_(false),
shared_doc_(false),
hyperlinks_changed_(false),
app_version_("0.9"),
x15_(false),
has_properties_(false),
has_absolute_path_(false),
has_view_(false),
has_code_name_(false),
has_file_version_(false),
has_calculation_properties_(false),
has_arch_id_(false),
short_bools_(true)
workbook_impl() : active_sheet_index_(0)
{
}
@ -77,46 +52,12 @@ struct workbook_impl
: active_sheet_index_(other.active_sheet_index_),
worksheets_(other.worksheets_),
shared_strings_(other.shared_strings_),
guess_types_(other.guess_types_),
data_only_(other.data_only_),
stylesheet_(other.stylesheet_),
manifest_(other.manifest_),
has_theme_(other.has_theme_),
theme_(other.theme_),
write_core_properties_(other.write_core_properties_),
creator_(other.creator_),
last_modified_by_(other.last_modified_by_),
created_(other.created_),
modified_(other.modified_),
title_(other.title_),
subject_(other.subject_),
description_(other.description_),
keywords_(other.keywords_),
category_(other.category_),
company_(other.company_),
base_date_(other.base_date_),
write_app_properties_(other.write_app_properties_),
application_(other.application_),
doc_security_(other.doc_security_),
scale_crop_(other.scale_crop_),
links_up_to_date_(other.links_up_to_date_),
shared_doc_(other.shared_doc_),
hyperlinks_changed_(other.hyperlinks_changed_),
app_version_(other.app_version_),
sheet_title_rel_id_map_(other.sheet_title_rel_id_map_),
x15_(other.x15_),
has_properties_(other.has_properties_),
has_absolute_path_(other.has_absolute_path_),
absolute_path_(other.absolute_path_),
has_view_(other.has_view_),
view_(other.view_),
has_code_name_(other.has_code_name_),
code_name_(other.code_name_),
has_file_version_(other.has_file_version_),
file_version_(other.file_version_),
has_calculation_properties_(other.has_calculation_properties_),
has_arch_id_(other.has_arch_id_),
short_bools_(other.short_bools_)
file_version_(other.file_version_)
{
}
@ -127,120 +68,49 @@ struct workbook_impl
std::copy(other.worksheets_.begin(), other.worksheets_.end(), back_inserter(worksheets_));
shared_strings_.clear();
std::copy(other.shared_strings_.begin(), other.shared_strings_.end(), std::back_inserter(shared_strings_));
guess_types_ = other.guess_types_;
data_only_ = other.data_only_;
has_theme_ = other.has_theme_;
theme_ = other.theme_;
manifest_ = other.manifest_;
write_core_properties_ = other.write_core_properties_;
creator_ = other.creator_;
last_modified_by_ = other.last_modified_by_;
created_ = other.created_;
modified_ = other.modified_;
title_ = other.title_;
subject_ = other.subject_;
description_ = other.description_;
keywords_ = other.keywords_;
category_ = other.category_;
company_ = other.company_;
base_date_ = other.base_date_;
write_app_properties_ = other.write_app_properties_;
application_ = other.application_;
doc_security_ = other.doc_security_;
scale_crop_ = other.scale_crop_;
links_up_to_date_ = other.links_up_to_date_;
shared_doc_ = other.shared_doc_;
hyperlinks_changed_ = other.hyperlinks_changed_;
app_version_ = other.app_version_;
sheet_title_rel_id_map_ = other.sheet_title_rel_id_map_;
x15_ = other.x15_;
has_properties_ = other.has_properties_;
has_absolute_path_ = other.has_absolute_path_;
absolute_path_ = other.absolute_path_;
has_view_ = other.has_view_;
view_ = other.view_;
has_code_name_ = other.has_code_name_;
code_name_ = other.code_name_;
has_file_version_ = other.has_file_version_;
file_version_ = other.file_version_;
has_calculation_properties_ = other.has_calculation_properties_;
has_arch_id_ = other.has_arch_id_;
short_bools_ = other.short_bools_;
return *this;
}
std::size_t active_sheet_index_;
optional<std::size_t> active_sheet_index_;
std::list<worksheet_impl> worksheets_;
std::vector<formatted_text> shared_strings_;
bool guess_types_;
bool data_only_;
optional<stylesheet> stylesheet_;
stylesheet stylesheet_;
calendar base_date_;
optional<std::string> title_;
manifest manifest_;
bool has_theme_;
theme theme_;
std::vector<std::uint8_t> thumbnail_;
optional<theme> theme_;
std::unordered_map<std::string, std::vector<std::uint8_t>> images_;
// core properties
bool write_core_properties_;
std::string creator_;
std::string last_modified_by_;
datetime created_;
datetime modified_;
std::string title_;
std::string subject_;
std::string description_;
std::string keywords_;
std::string category_;
std::string company_;
calendar base_date_;
// application properties
bool write_app_properties_;
std::string application_;
int doc_security_;
bool scale_crop_;
bool links_up_to_date_;
bool shared_doc_;
bool hyperlinks_changed_;
std::string app_version_;
std::unordered_map<std::string, std::string> core_properties_;
std::unordered_map<std::string, std::string> extended_properties_;
std::unordered_map<std::string, std::string> custom_properties_;
std::unordered_map<std::string, std::string> sheet_title_rel_id_map_;
bool x15_;
bool has_properties_;
bool has_absolute_path_;
path absolute_path_;
bool has_view_;
workbook_view view_;
bool has_code_name_;
std::string code_name_;
optional<workbook_view> view_;
optional<std::string> code_name_;
bool has_file_version_;
struct file_version_t
{
std::string app_name;
std::size_t last_edited;
std::size_t lowest_edited;
std::size_t rup_build;
} file_version_;
};
bool has_calculation_properties_;
bool has_arch_id_;
bool short_bools_;
optional<file_version_t> file_version_;
};
} // namespace detail

View File

@ -84,8 +84,7 @@ struct worksheet_impl
print_title_cols_ = other.print_title_cols_;
print_title_rows_ = other.print_title_rows_;
print_area_ = other.print_area_;
view_ = other.view_;
x14ac_ = other.x14ac_;
views_ = other.views_;
has_dimension_ = other.has_dimension_;
has_format_properties_ = other.has_format_properties_;
}
@ -109,9 +108,7 @@ struct worksheet_impl
std::string print_title_cols_;
std::string print_title_rows_;
range_reference print_area_;
bool has_view_ = false;
sheet_view view_;
bool x14ac_ = false;
std::vector<sheet_view> views_;
bool has_dimension_ = false;
bool has_format_properties_ = false;
};

File diff suppressed because it is too large Load Diff

View File

@ -37,6 +37,7 @@ namespace xlnt {
class color;
class formatted_text;
class manifest;
class path;
class relationship;
class workbook;
@ -59,52 +60,36 @@ public:
void read(std::istream &source, const std::string &password);
private:
/// <summary>
/// Ignore all remaining elements at the same depth in the current XML parser.
/// </summary>
void skip_remaining_elements();
/// <summary>
/// Convenience method to dereference the pointer to the current parser to avoid
/// having to use "parser_->" constantly.
/// </summary>
xml::parser &parser();
/// <summary>
/// Read all the files needed from the XLSX archive and initialize all of
/// the data in the workbook to match.
/// </summary>
void populate_workbook();
// Package Parts
/// <summary>
/// Parse content types ([Content_Types].xml) and package relationships (_rels/.rels).
///
/// </summary>
void read_manifest();
void read_content_types();
// Metadata Readers
/// <summary>
/// Parse the core properties about the current package (usually docProps/core.xml).
/// Read core, extended, and custom properties.
/// </summary>
void read_core_properties();
void read_metadata_properties();
/// <summary>
/// Parse extra application-speicific package properties (usually docProps/app.xml).
void read_extended_properties();
/// <summary>
/// Parse custom file properties. These aren't associated with a particular application
/// but extensions to OOXML can use this part to hold extra data about the package.
/// Parse the core properties about the current package.
/// </summary>
void read_custom_file_properties();
void read_properties(const path &part, const xml::qname &root);
// SpreadsheetML-Specific Package Parts
// SpreadsheetML-Specific Package Part Readers
/// <summary>
/// Parse the main XML document about the workbook and then all child relationships
/// of the workbook (e.g. worksheets).
/// </summary>
void read_workbook();
void read_office_document(const std::string &content_type);
// Workbook Relationship Target Parts
@ -222,36 +207,134 @@ private:
/// </summary>
void read_unknown_relationships();
/// <summary>
///
/// </summary>
void read_image(const path &part);
// Common Section Readers
/// <summary>
/// Read part from the archive and return a vector of relationships
/// based on the content of that part.
/// </summary>
std::vector<relationship> read_relationships(const path &part);
std::string read_text();
formatted_text read_formatted_text(const std::string &xmlns);
void read_part(const std::vector<relationship> &rel_chain);
void skip_attributes();
void skip_attributes(const std::vector<xml::qname> &names);
void skip_attributes(const std::vector<std::string> &names);
void skip_remaining_content(const xml::qname &name);
xml::qname expect_start_element(xml::content content);
void expect_start_element(const xml::qname &name, xml::content content);
void expect_end_element(const xml::qname &name);
bool in_element(const xml::qname &name);
/// <summary>
/// Read a CT_Color from the document currently being parsed.
/// </summary>
color read_color();
void check_document_type(const std::string &document_content_type);
/// <summary>
/// Read a rich text CT_RElt from the document currently being parsed.
/// </summary>
formatted_text read_formatted_text(const xml::qname &parent);
/// <summary>
/// Returns true if the givent document type represents an XLSX file.
/// </summary>
bool document_type_is_xlsx(const std::string &document_content_type);
// SAX Parsing Helpers
/// <summary>
/// In mixed content XML elements, whitespace before and after is not ignored.
/// Additionally, if PCDATA spans the boundary of the XML read buffer, it will
/// be parsed as two separate strings instead of on longer string. This method
/// will read character data until non-character data is peek()ed from the parser
/// and returns the combined strings. This should be used when parsing mixed
/// content to ignore whitespace and whenever character data is expected between
/// tags.
/// </summary>
std::string read_text();
/// <summary>
/// Read the part from the archive and parse it as XML. After this is called,
/// xlsx_consumer::parser() will return a reference to the parser that reads
/// this part.
/// </summary>
void read_part(const std::vector<relationship> &rel_chain);
/// <summary>
/// libstudxml will throw an exception if all attributes on an element are not
/// read with xml::parser::attribute(const std::string &). This should therefore
/// be called if every remaining attribute should be ignored on an element.
/// </summary>
void skip_attributes();
/// <summary>
/// Skip attribute name if it exists on the currently parsed element in the XML
/// parser.
/// </summary>
void skip_attribute(const std::string &name);
/// <summary>
/// Skip attribute name if it exists on the currently parsed element in the XML
/// parser.
/// </summary>
void skip_attribute(const xml::qname &name);
/// <summary>
/// Call skip_attribute on every name in names.
/// </summary>
void skip_attributes(const std::vector<xml::qname> &names);
/// <summary>
/// Call skip_attribute on every name in names.
/// </summary>
void skip_attributes(const std::vector<std::string> &names);
/// <summary>
/// Read all content in name until the closing tag is reached.
/// The closing tag will not be handled after this is called.
/// </summary>
void skip_remaining_content(const xml::qname &name);
/// <summary>
/// Handles the next event in the XML parser and throws an exception
/// if it is not the start of an element. Additionally sets the content
/// type of the element to content.
/// </summary>
xml::qname expect_start_element(xml::content content);
/// <summary>
/// Handles the next event in the XML parser and throws an exception
/// if the next element is not named name. Sets the content type of
/// the element to content.
/// </summary>
void expect_start_element(const xml::qname &name, xml::content content);
/// <summary>
/// Throws an exception if the next event in the XML parser is not
/// the end of element called name.
/// </summary>
void expect_end_element(const xml::qname &name);
/// <summary>
/// Returns true if the top of the parsing stack is called name and
/// the end of that element hasn't been reached in the XML document.
/// </summary>
bool in_element(const xml::qname &name);
/// <summary>
/// Handles all start and end namespace events from the current parser
/// and returns a vector of strings containing the URL for each namespace.
/// </summary>
std::vector<std::string> read_namespaces();
// Properties
/// <summary>
/// Convenience method to dereference the pointer to the current parser to avoid
/// having to use "parser_->" constantly.
/// </summary>
xml::parser &parser();
/// <summary>
/// Convenience method to access the target workbook's manifest.
/// </summary>
manifest &manifest();
/// <summary>
/// The ZIP file containing the files that make up the OOXML package.
/// </summary>

View File

@ -172,7 +172,7 @@ struct crypto_helper
return std::vector<std::uint8_t>(hash.begin(), hash.end());
}
static std::vector<std::uint8_t> get_file(POLE::Storage &storage, const std::string &name)
static std::vector<std::uint8_t> file(POLE::Storage &storage, const std::string &name)
{
POLE::Stream stream(&storage, name.c_str());
if (stream.fail()) return {};
@ -389,8 +389,8 @@ struct crypto_helper
static std::vector<std::uint8_t> write_agile_encryption_info(const std::string &password)
{
static const auto &xmlns = xlnt::constants::get_namespace("encryption");
static const auto &xmlns_p = xlnt::constants::get_namespace("encryption-password");
static const auto &xmlns = xlnt::constants::namespace_("encryption");
static const auto &xmlns_p = xlnt::constants::namespace_("encryption-password");
std::vector<std::uint8_t> encryption_info;
xlnt::detail::vector_ostreambuf encryption_info_buffer(encryption_info);
@ -445,9 +445,9 @@ struct crypto_helper
static std::vector<std::uint8_t> decrypt_xlsx_agile(const std::vector<std::uint8_t> &encryption_info,
const std::string &password, const std::vector<std::uint8_t> &encrypted_package)
{
static const auto &xmlns = xlnt::constants::get_namespace("encryption");
static const auto &xmlns_p = xlnt::constants::get_namespace("encryption-password");
//static const auto &xmlns_c = xlnt::constants::get_namespace("encryption-certificate");
static const auto &xmlns = xlnt::constants::namespace_("encryption");
static const auto &xmlns_p = xlnt::constants::namespace_("encryption-password");
//static const auto &xmlns_c = xlnt::constants::namespace_("encryption-certificate");
agile_encryption_info result;
@ -652,8 +652,8 @@ struct crypto_helper
throw xlnt::exception("not an ole compound file");
}
auto encrypted_package = get_file(storage, "EncryptedPackage");
auto encryption_info = get_file(storage, "EncryptionInfo");
auto encrypted_package = file(storage, "EncryptedPackage");
auto encryption_info = file(storage, "EncryptionInfo");
std::size_t index = 0;

File diff suppressed because it is too large Load Diff

View File

@ -74,7 +74,7 @@ private:
void write_core_properties(const relationship &rel);
void write_extended_properties(const relationship &rel);
void write_custom_properties(const relationship &rel);
void write_thumbnail(const relationship &rel);
void write_image(const path &image_path);
// SpreadsheetML-Specific Package Parts

View File

@ -470,32 +470,32 @@ zip_file_ostream::~zip_file_ostream()
{
}
ZipFileWriter::ZipFileWriter(std::ostream &stream) : target_stream_(stream)
ZipFileWriter::ZipFileWriter(std::ostream &stream) : tarstream_(stream)
{
if (!target_stream_) throw std::runtime_error("ZIP: Invalid file handle");
if (!tarstream_) throw std::runtime_error("ZIP: Invalid file handle");
}
ZipFileWriter::~ZipFileWriter()
{
// Write all file headers
std::ios::streampos final_position = target_stream_.tellp();
std::ios::streampos final_position = tarstream_.tellp();
for (unsigned int i = 0; i < file_headers_.size(); i++)
{
file_headers_[i].Write(target_stream_, true);
file_headers_[i].Write(tarstream_, true);
}
std::ios::streampos central_end = target_stream_.tellp();
std::ios::streampos central_end = tarstream_.tellp();
// Write end of central
write_int(target_stream_, static_cast<std::uint32_t>(0x06054b50)); // end of central
write_int(target_stream_, static_cast<std::uint16_t>(0)); // this disk number
write_int(target_stream_, static_cast<std::uint16_t>(0)); // this disk number
write_int(target_stream_, static_cast<std::uint16_t>(file_headers_.size())); // one entry in center in this disk
write_int(target_stream_, static_cast<std::uint16_t>(file_headers_.size())); // one entry in center
write_int(target_stream_, static_cast<std::uint32_t>(central_end - final_position)); // size of header
write_int(target_stream_, static_cast<std::uint32_t>(final_position)); // offset to header
write_int(target_stream_, static_cast<std::uint16_t>(0)); // zip comment
write_int(tarstream_, static_cast<std::uint32_t>(0x06054b50)); // end of central
write_int(tarstream_, static_cast<std::uint16_t>(0)); // this disk number
write_int(tarstream_, static_cast<std::uint16_t>(0)); // this disk number
write_int(tarstream_, static_cast<std::uint16_t>(file_headers_.size())); // one entry in center in this disk
write_int(tarstream_, static_cast<std::uint16_t>(file_headers_.size())); // one entry in center
write_int(tarstream_, static_cast<std::uint32_t>(central_end - final_position)); // size of header
write_int(tarstream_, static_cast<std::uint32_t>(final_position)); // offset to header
write_int(tarstream_, static_cast<std::uint16_t>(0)); // zip comment
}
std::ostream &ZipFileWriter::open(const std::string &filename)
@ -503,7 +503,7 @@ std::ostream &ZipFileWriter::open(const std::string &filename)
zip_file_header header;
header.filename = filename;
file_headers_.push_back(header);
auto streambuf = std::make_unique<ZipStreambufCompress>(&file_headers_.back(), target_stream_);
auto streambuf = std::make_unique<ZipStreambufCompress>(&file_headers_.back(), tarstream_);
auto stream = new zip_file_ostream(std::move(streambuf));
write_stream_.reset(stream);
return *write_stream_;

View File

@ -92,7 +92,7 @@ public:
void close();
private:
std::vector<zip_file_header> file_headers_;
std::ostream &target_stream_;
std::ostream &tarstream_;
std::unique_ptr<std::ostream> write_stream_;
};

View File

@ -37,7 +37,7 @@ void manifest::clear()
relationships_.clear();
}
path manifest::canonicalize(const std::vector<relationship> &rels) const
path manifest::canonicalize(const std::vector<xlnt::relationship> &rels) const
{
xlnt::path relative;
@ -45,11 +45,11 @@ path manifest::canonicalize(const std::vector<relationship> &rels) const
{
if (component == rels.back())
{
relative = relative.append(component.get_target().get_path());
relative = relative.append(component.target().path());
}
else
{
relative = relative.append(component.get_target().get_path().parent());
relative = relative.append(component.target().path().parent());
}
}
@ -78,39 +78,39 @@ path manifest::canonicalize(const std::vector<relationship> &rels) const
return result;
}
bool manifest::has_relationship(const path &part, relationship::type type) const
bool manifest::has_relationship(const path &part, relationship_type type) const
{
if (relationships_.find(part) == relationships_.end()) return false;
for (const auto &rel : relationships_.at(part))
{
if (rel.second.get_type() == type) return true;
if (rel.second.type() == type) return true;
}
return false;
}
relationship manifest::get_relationship(const path &part, relationship::type type) const
relationship manifest::relationship(const path &part, relationship_type type) const
{
if (relationships_.find(part) == relationships_.end()) throw key_not_found();
for (const auto &rel : relationships_.at(part))
{
if (rel.second.get_type() == type) return rel.second;
if (rel.second.type() == type) return rel.second;
}
throw key_not_found();
}
std::vector<relationship> manifest::get_relationships(const path &part, relationship::type type) const
std::vector<xlnt::relationship> manifest::relationships(const path &part, relationship_type type) const
{
std::vector<relationship> matches;
std::vector<xlnt::relationship> matches;
if (has_relationship(part, type))
{
for (const auto &rel : relationships_.at(part))
{
if (rel.second.get_type() == type)
if (rel.second.type() == type)
{
matches.push_back(rel.second);
}
@ -120,18 +120,18 @@ std::vector<relationship> manifest::get_relationships(const path &part, relation
return matches;
}
std::string manifest::get_content_type(const path &part) const
std::string manifest::content_type(const path &part) const
{
auto absolute = part.resolve(path("/"));
if (has_override_type(absolute))
{
return get_override_type(absolute);
return override_type(absolute);
}
if (has_default_type(part.extension()))
{
return get_default_type(part.extension());
return default_type(part.extension());
}
throw key_not_found();
@ -147,7 +147,7 @@ void manifest::unregister_override_type(const path &part)
override_content_types_.erase(part);
}
std::vector<path> manifest::get_parts_with_overriden_types() const
std::vector<path> manifest::parts_with_overriden_types() const
{
std::vector<path> overriden;
@ -159,14 +159,14 @@ std::vector<path> manifest::get_parts_with_overriden_types() const
return overriden;
}
std::vector<relationship> manifest::get_relationships(const path &part) const
std::vector<relationship> manifest::relationships(const path &part) const
{
if (relationships_.find(part) == relationships_.end())
{
return {};
}
std::vector<relationship> relationships;
std::vector<xlnt::relationship> relationships;
for (const auto &rel : relationships_.at(part))
{
@ -176,7 +176,7 @@ std::vector<relationship> manifest::get_relationships(const path &part) const
return relationships;
}
relationship manifest::get_relationship(const path &part, const std::string &rel_id) const
relationship manifest::relationship(const path &part, const std::string &rel_id) const
{
if (relationships_.find(part) == relationships_.end())
{
@ -185,7 +185,7 @@ relationship manifest::get_relationship(const path &part, const std::string &rel
for (const auto &rel : relationships_.at(part))
{
if (rel.second.get_id() == rel_id)
if (rel.second.id() == rel_id)
{
return rel.second;
}
@ -194,7 +194,7 @@ relationship manifest::get_relationship(const path &part, const std::string &rel
throw key_not_found();
}
std::vector<path> manifest::get_parts() const
std::vector<path> manifest::parts() const
{
std::unordered_set<path> parts;
@ -204,9 +204,9 @@ std::vector<path> manifest::get_parts() const
for (const auto &rel : part_rels.second)
{
if (rel.second.get_target_mode() == target_mode::internal)
if (rel.second.target_mode() == target_mode::internal)
{
parts.insert(rel.second.get_target().get_path());
parts.insert(rel.second.target().path());
}
}
}
@ -214,20 +214,20 @@ std::vector<path> manifest::get_parts() const
return std::vector<path>(parts.begin(), parts.end());
}
std::string manifest::register_relationship(const uri &source, relationship::type type, const uri &target, target_mode mode)
std::string manifest::register_relationship(const uri &source, relationship_type type, const uri &target, target_mode mode)
{
return register_relationship(source, type, target, mode, next_relationship_id(source.get_path()));
return register_relationship(source, type, target, mode, next_relationship_id(source.path()));
}
std::string manifest::register_relationship(const uri &source, relationship::type type, const uri &target, target_mode mode, const std::string &rel_id)
std::string manifest::register_relationship(const uri &source, relationship_type type, const uri &target, target_mode mode, const std::string &rel_id)
{
relationships_[source.get_path()][rel_id] = relationship(rel_id, type, source, target, mode);
relationships_[source.path()][rel_id] = xlnt::relationship(rel_id, type, source, target, mode);
return rel_id;
}
void manifest::unregister_relationship(const uri &source, const std::string &rel_id)
{
relationships_.at(source.get_path()).erase(rel_id);
relationships_.at(source.path()).erase(rel_id);
}
bool manifest::has_default_type(const std::string &extension) const
@ -235,7 +235,7 @@ bool manifest::has_default_type(const std::string &extension) const
return default_content_types_.find(extension) != default_content_types_.end();
}
std::vector<std::string> manifest::get_extensions_with_default_types() const
std::vector<std::string> manifest::extensions_with_default_types() const
{
std::vector<std::string> extensions;
@ -247,7 +247,7 @@ std::vector<std::string> manifest::get_extensions_with_default_types() const
return extensions;
}
std::string manifest::get_default_type(const std::string &extension) const
std::string manifest::default_type(const std::string &extension) const
{
if (default_content_types_.find(extension) == default_content_types_.end())
{
@ -287,7 +287,7 @@ bool manifest::has_override_type(const xlnt::path &part) const
return override_content_types_.find(part) != override_content_types_.end();
}
std::string manifest::get_override_type(const xlnt::path &part) const
std::string manifest::override_type(const xlnt::path &part) const
{
if (!has_override_type(part))
{

View File

@ -30,7 +30,7 @@ relationship::relationship()
{
}
relationship::relationship(const std::string &id, type t, const uri &source, const uri &target, target_mode mode)
relationship::relationship(const std::string &id, relationship_type t, const uri &source, const uri &target, enum target_mode mode)
: id_(id),
type_(t),
source_(source),
@ -39,27 +39,27 @@ relationship::relationship(const std::string &id, type t, const uri &source, con
{
}
std::string relationship::get_id() const
std::string relationship::id() const
{
return id_;
}
target_mode relationship::get_target_mode() const
target_mode relationship::target_mode() const
{
return mode_;
}
uri relationship::get_source() const
uri relationship::source() const
{
return source_;
}
uri relationship::get_target() const
uri relationship::target() const
{
return target_;
}
relationship::type relationship::get_type() const
relationship_type relationship::type() const
{
return type_;
}

View File

@ -15,7 +15,7 @@ std::string uri::to_string() const
return path_.string();
}
path uri::get_path() const
path uri::path() const
{
return path_;
}

View File

@ -89,64 +89,73 @@ const color color::darkyellow()
}
color::color()
: type_(type::auto_),
: type_(color_type::indexed),
rgb_(rgb_color(0, 0, 0, 0)),
indexed_(0),
theme_(0),
tint_(0)
tint_(0),
auto__(false)
{
}
color::color(const rgb_color &rgb)
: type_(type::rgb),
: type_(color_type::rgb),
rgb_(rgb),
indexed_(0),
theme_(0),
tint_(0)
tint_(0),
auto__(false)
{
}
color::color(const indexed_color &indexed)
: type_(type::indexed),
: type_(color_type::indexed),
rgb_(rgb_color(0, 0, 0, 0)),
indexed_(indexed),
theme_(0),
tint_(0)
tint_(0),
auto__(false)
{
}
color::color(const theme_color &theme)
: type_(type::theme),
: type_(color_type::theme),
rgb_(rgb_color(0, 0, 0, 0)),
indexed_(0),
theme_(theme),
tint_(0)
tint_(0),
auto__(false)
{
}
color::type color::get_type() const
color_type color::type() const
{
return type_;
}
bool color::is_auto() const
{
return type_ == type::auto_;
return auto__;
}
const indexed_color &color::get_indexed() const
void color::auto_(bool value)
{
assert_type(type::indexed);
auto__ = value;
}
const indexed_color &color::indexed() const
{
assert_type(color_type::indexed);
return indexed_;
}
const theme_color &color::get_theme() const
const theme_color &color::theme() const
{
assert_type(type::theme);
assert_type(color_type::theme);
return theme_;
}
std::string rgb_color::get_hex_string() const
std::string rgb_color::hex_string() const
{
static const char* digits = "0123456789abcdef";
std::string hex_string(8, '0');
@ -186,28 +195,28 @@ rgb_color::rgb_color(std::uint8_t r, std::uint8_t g, std::uint8_t b, std::uint8_
{
}
std::size_t indexed_color::get_index() const
std::size_t indexed_color::index() const
{
return index_;
}
std::size_t theme_color::get_index() const
std::size_t theme_color::index() const
{
return index_;
}
const rgb_color &color::get_rgb() const
const rgb_color &color::rgb() const
{
assert_type(type::rgb);
assert_type(color_type::rgb);
return rgb_;
}
void color::set_tint(double tint)
void color::tint(double tint)
{
tint_ = tint;
}
void color::assert_type(type t) const
void color::assert_type(color_type t) const
{
if (t != type_)
{
@ -217,20 +226,21 @@ void color::assert_type(type t) const
XLNT_API bool color::operator==(const xlnt::color &other) const
{
if (type_ != other.type_ || std::fabs(tint_ - other.tint_) != 0.)
if (type_ != other.type_
|| std::fabs(tint_ - other.tint_) != 0.0
|| auto__ != other.auto__)
{
return false;
}
switch(type_)
{
case type::auto_:
case type::indexed:
return indexed_.get_index() == other.indexed_.get_index();
case type::theme:
return theme_.get_index() == other.theme_.get_index();
case type::rgb:
return rgb_.get_hex_string() == other.rgb_.get_hex_string();
case color_type::indexed:
return indexed_.index() == other.indexed_.index();
case color_type::theme:
return theme_.index() == other.theme_.index();
case color_type::rgb:
return rgb_.hex_string() == other.rgb_.hex_string();
}
return false;

View File

@ -99,6 +99,11 @@ font::underline_style font::underline() const
return underline_;
}
bool font::has_size() const
{
return size_.is_set();
}
font &font::size(std::size_t size)
{
size_ = size;
@ -107,7 +112,12 @@ font &font::size(std::size_t size)
std::size_t font::size() const
{
return size_;
return size_.get();
}
bool font::has_name() const
{
return name_.is_set();
}
font &font::name(const std::string &name)
@ -115,9 +125,15 @@ font &font::name(const std::string &name)
name_ = name;
return *this;
}
std::string font::name() const
{
return name_;
return name_.get();
}
bool font::has_color() const
{
return color_.is_set();
}
font &font::color(const xlnt::color &c)
@ -126,31 +142,41 @@ font &font::color(const xlnt::color &c)
return *this;
}
bool font::has_family() const
{
return family_.is_set();
}
font &font::family(std::size_t family)
{
family_ = family;
return *this;
}
bool font::has_scheme() const
{
return scheme_.is_set();
}
font &font::scheme(const std::string &scheme)
{
scheme_ = scheme;
return *this;
}
optional<color> font::color() const
color font::color() const
{
return color_;
return color_.get();
}
optional<std::size_t> font::family() const
std::size_t font::family() const
{
return family_;
return family_.get();
}
optional<std::string> font::scheme() const
std::string font::scheme() const
{
return scheme_;
return scheme_.get();
}
XLNT_API bool operator==(const font &left, const font &right)
@ -160,27 +186,27 @@ XLNT_API bool operator==(const font &left, const font &right)
return false;
}
if (left.color().is_set() != right.color().is_set())
if (left.has_color() != right.has_color())
{
return false;
}
if (left.color().is_set())
if (left.has_color())
{
if (left.color().get() != right.color().get())
if (left.color() != right.color())
{
return false;
}
}
if (left.family().is_set() != right.family().is_set())
if (left.has_family() != right.has_family())
{
return false;
}
if (left.family().is_set())
if (left.has_family())
{
if (left.family().get() != right.family().get())
if (left.family() != right.family())
{
return false;
}
@ -196,14 +222,14 @@ XLNT_API bool operator==(const font &left, const font &right)
return false;
}
if (left.scheme().is_set() != right.scheme().is_set())
if (left.has_scheme() != right.has_scheme())
{
return false;
}
if (left.scheme().is_set())
if (left.has_scheme())
{
if (left.scheme().get() != right.scheme().get())
if (left.scheme() != right.scheme())
{
return false;
}

View File

@ -150,7 +150,7 @@ format format::number_format(const xlnt::number_format &new_number_format, bool
if (!copy.has_id())
{
copy.set_id(d_->parent->next_custom_number_format_id());
copy.id(d_->parent->next_custom_number_format_id());
d_->parent->number_formats.push_back(copy);
}

View File

@ -249,12 +249,12 @@ number_format::number_format(std::size_t id) : number_format(from_builtin_id(id)
number_format::number_format(const std::string &format_string) : id_set_(false), id_(0)
{
set_format_string(format_string);
this->format_string(format_string);
}
number_format::number_format(const std::string &format_string, std::size_t id) : id_set_(false), id_(0)
{
set_format_string(format_string, id);
this->format_string(format_string, id);
}
number_format number_format::from_builtin_id(std::size_t builtin_id)
@ -268,12 +268,12 @@ number_format number_format::from_builtin_id(std::size_t builtin_id)
return number_format(format_string, builtin_id);
}
std::string number_format::get_format_string() const
std::string number_format::format_string() const
{
return format_string_;
}
void number_format::set_format_string(const std::string &format_string)
void number_format::format_string(const std::string &format_string)
{
format_string_ = format_string;
id_ = 0;
@ -290,7 +290,7 @@ void number_format::set_format_string(const std::string &format_string)
}
}
void number_format::set_format_string(const std::string &format_string, std::size_t id)
void number_format::format_string(const std::string &format_string, std::size_t id)
{
format_string_ = format_string;
id_ = id;
@ -299,16 +299,16 @@ void number_format::set_format_string(const std::string &format_string, std::siz
bool number_format::has_id() const
{
return id_set_;
return id_;
}
void number_format::set_id(std::size_t id)
void number_format::id(std::size_t id)
{
id_ = id;
id_set_ = true;
}
std::size_t number_format::get_id() const
std::size_t number_format::id() const
{
if(!id_set_)
{
@ -322,7 +322,7 @@ bool number_format::is_date_format() const
{
detail::number_format_parser p(format_string_);
p.parse();
auto parsed = p.get_result();
auto parsed = p.result();
bool any_datetime = false;
bool any_timedelta = false;

View File

@ -156,16 +156,16 @@ style style::font(const xlnt::font &new_font, bool applied)
xlnt::number_format &style::number_format()
{
auto target_id = d_->number_format_id.get();
auto tarid = d_->number_format_id.get();
return *std::find_if(d_->parent->number_formats.begin(), d_->parent->number_formats.end(),
[=](const class number_format &nf) { return nf.get_id() == target_id; });
[=](const class number_format &nf) { return nf.id() == tarid; });
}
const xlnt::number_format &style::number_format() const
{
auto target_id = d_->number_format_id.get();
auto tarid = d_->number_format_id.get();
return *std::find_if(d_->parent->number_formats.begin(), d_->parent->number_formats.end(),
[=](const class number_format &nf) { return nf.get_id() == target_id; });
[=](const class number_format &nf) { return nf.id() == tarid; });
}
style style::number_format(const xlnt::number_format &new_number_format, bool applied)
@ -174,18 +174,18 @@ style style::number_format(const xlnt::number_format &new_number_format, bool ap
if (!copy.has_id())
{
copy.set_id(d_->parent->next_custom_number_format_id());
copy.id(d_->parent->next_custom_number_format_id());
d_->parent->number_formats.push_back(copy);
}
else if (std::find_if(d_->parent->number_formats.begin(),
d_->parent->number_formats.end(),
[&copy](const class number_format &nf) { return nf.get_id() == copy.get_id(); })
[&copy](const class number_format &nf) { return nf.id() == copy.id(); })
== d_->parent->number_formats.end())
{
d_->parent->number_formats.push_back(copy);
}
d_->number_format_id = copy.get_id();
d_->number_format_id = copy.id();
d_->number_format_applied = applied;
return style(d_);

View File

@ -26,28 +26,22 @@ public:
for (auto pair : known_colors)
{
TS_ASSERT_EQUALS(pair.first.get_rgb().get_hex_string(), pair.second);
TS_ASSERT_EQUALS(pair.first.rgb().hex_string(), pair.second);
}
}
void test_non_rgb_colors()
{
xlnt::color auto_;
TS_ASSERT(auto_.is_auto());
TS_ASSERT_THROWS(auto_.get_theme(), xlnt::invalid_attribute);
TS_ASSERT_THROWS(auto_.get_indexed(), xlnt::invalid_attribute);
TS_ASSERT_THROWS(auto_.get_rgb(), xlnt::invalid_attribute);
xlnt::color indexed = xlnt::indexed_color(1);
TS_ASSERT(!indexed.is_auto());
TS_ASSERT_EQUALS(indexed.get_indexed().get_index(), 1);
TS_ASSERT_THROWS(indexed.get_theme(), xlnt::invalid_attribute);
TS_ASSERT_THROWS(indexed.get_rgb(), xlnt::invalid_attribute);
TS_ASSERT_EQUALS(indexed.indexed().index(), 1);
TS_ASSERT_THROWS(indexed.theme(), xlnt::invalid_attribute);
TS_ASSERT_THROWS(indexed.rgb(), xlnt::invalid_attribute);
xlnt::color theme = xlnt::theme_color(3);
TS_ASSERT(!theme.is_auto());
TS_ASSERT_EQUALS(theme.get_theme().get_index(), 3);
TS_ASSERT_THROWS(theme.get_indexed(), xlnt::invalid_attribute);
TS_ASSERT_THROWS(theme.get_rgb(), xlnt::invalid_attribute);
TS_ASSERT_EQUALS(theme.theme().index(), 3);
TS_ASSERT_THROWS(theme.indexed(), xlnt::invalid_attribute);
TS_ASSERT_THROWS(theme.rgb(), xlnt::invalid_attribute);
}
};

View File

@ -32,11 +32,11 @@ public:
fill = fill.pattern_fill().foreground(xlnt::color::black());
TS_ASSERT(fill.pattern_fill().foreground());
TS_ASSERT_EQUALS((*fill.pattern_fill().foreground()).get_rgb().get_hex_string(), xlnt::color::black().get_rgb().get_hex_string());
TS_ASSERT_EQUALS((*fill.pattern_fill().foreground()).rgb().hex_string(), xlnt::color::black().rgb().hex_string());
fill = fill.pattern_fill().background(xlnt::color::green());
TS_ASSERT(fill.pattern_fill().background());
TS_ASSERT_EQUALS((*fill.pattern_fill().background()).get_rgb().get_hex_string(), xlnt::color::green().get_rgb().get_hex_string());
TS_ASSERT_EQUALS((*fill.pattern_fill().background()).rgb().hex_string(), xlnt::color::green().rgb().hex_string());
const auto &const_fill = fill;
TS_ASSERT(const_fill.pattern_fill().foreground());
@ -57,18 +57,18 @@ public:
void test_two_fills()
{
xlnt::workbook wb;
auto ws1 = wb.get_active_sheet();
auto ws1 = wb.active_sheet();
auto cell1 = ws1.get_cell("A10");
auto cell2 = ws1.get_cell("A11");
auto cell1 = ws1.cell("A10");
auto cell2 = ws1.cell("A11");
cell1.set_fill(xlnt::fill::solid(xlnt::color::yellow()));
cell1.set_value("Fill Yellow");
cell1.fill(xlnt::fill::solid(xlnt::color::yellow()));
cell1.value("Fill Yellow");
cell2.set_fill(xlnt::fill::solid(xlnt::color::green()));
cell2.set_value(xlnt::date(2010, 7, 13));
cell2.fill(xlnt::fill::solid(xlnt::color::green()));
cell2.value(xlnt::date(2010, 7, 13));
TS_ASSERT_EQUALS(cell1.get_fill(), xlnt::fill::solid(xlnt::color::yellow()));
TS_ASSERT_EQUALS(cell2.get_fill(), xlnt::fill::solid(xlnt::color::green()));
TS_ASSERT_EQUALS(cell1.fill(), xlnt::fill::solid(xlnt::color::yellow()));
TS_ASSERT_EQUALS(cell2.fill(), xlnt::fill::solid(xlnt::color::green()));
}
};

View File

@ -11,33 +11,33 @@ public:
void test_basic()
{
xlnt::number_format no_id("#\\x\\y\\z");
TS_ASSERT_THROWS(no_id.get_id(), std::runtime_error);
TS_ASSERT_THROWS(no_id.id(), std::runtime_error);
xlnt::number_format id("General", 200);
TS_ASSERT_EQUALS(id.get_id(), 200);
TS_ASSERT_EQUALS(id.get_format_string(), "General");
TS_ASSERT_EQUALS(id.id(), 200);
TS_ASSERT_EQUALS(id.format_string(), "General");
xlnt::number_format general(0);
TS_ASSERT_EQUALS(general, xlnt::number_format::general());
TS_ASSERT_EQUALS(general.get_id(), 0);
TS_ASSERT_EQUALS(general.get_format_string(), "General");
TS_ASSERT_EQUALS(general.id(), 0);
TS_ASSERT_EQUALS(general.format_string(), "General");
}
void test_simple_format()
{
xlnt::number_format nf;
nf.set_format_string("\"positive\"General;\"negative\"General");
nf.format_string("\"positive\"General;\"negative\"General");
auto formatted = nf.format(3.14, xlnt::calendar::windows_1900);
TS_ASSERT_EQUALS(formatted, "positive3.14");
formatted = nf.format(-3.14, xlnt::calendar::windows_1900);
TS_ASSERT_EQUALS(formatted, "negative3.14");
nf.set_format_string("\"any\"General");
nf.format_string("\"any\"General");
formatted = nf.format(-3.14, xlnt::calendar::windows_1900);
TS_ASSERT_EQUALS(formatted, "-any3.14");
nf.set_format_string("\"positive\"General;\"negative\"General;\"zero\"General");
nf.format_string("\"positive\"General;\"negative\"General;\"zero\"General");
formatted = nf.format(3.14, xlnt::calendar::windows_1900);
TS_ASSERT_EQUALS(formatted, "positive3.14");
formatted = nf.format(-3.14, xlnt::calendar::windows_1900);
@ -63,7 +63,7 @@ public:
auto date_number = date.to_number(xlnt::calendar::windows_1900);
xlnt::number_format nf;
nf.set_format_string("m");
nf.format_string("m");
auto formatted = nf.format(date_number, xlnt::calendar::windows_1900);
TS_ASSERT_EQUALS(formatted, "6");
@ -75,7 +75,7 @@ public:
auto date_number = date.to_number(xlnt::calendar::windows_1900);
xlnt::number_format nf;
nf.set_format_string("mmm");
nf.format_string("mmm");
auto formatted = nf.format(date_number, xlnt::calendar::windows_1900);
TS_ASSERT_EQUALS(formatted, "Jun");
@ -87,7 +87,7 @@ public:
auto date_number = date.to_number(xlnt::calendar::windows_1900);
xlnt::number_format nf;
nf.set_format_string("mmmm");
nf.format_string("mmmm");
auto formatted = nf.format(date_number, xlnt::calendar::windows_1900);
TS_ASSERT_EQUALS(formatted, "June");
@ -99,7 +99,7 @@ public:
auto date_number = date.to_number(xlnt::calendar::windows_1900);
xlnt::number_format nf;
nf.set_format_string("d");
nf.format_string("d");
auto formatted = nf.format(date_number, xlnt::calendar::windows_1900);
TS_ASSERT_EQUALS(formatted, "8");
@ -111,7 +111,7 @@ public:
auto date_number = date.to_number(xlnt::calendar::windows_1900);
xlnt::number_format nf;
nf.set_format_string("dd");
nf.format_string("dd");
auto formatted = nf.format(date_number, xlnt::calendar::windows_1900);
TS_ASSERT_EQUALS(formatted, "08");
@ -123,7 +123,7 @@ public:
auto date_number = date.to_number(xlnt::calendar::windows_1900);
xlnt::number_format nf;
nf.set_format_string("yyyy");
nf.format_string("yyyy");
auto formatted = nf.format(date_number, xlnt::calendar::windows_1900);
TS_ASSERT_EQUALS(formatted, "2016");
@ -135,7 +135,7 @@ public:
auto date_number = date.to_number(xlnt::calendar::windows_1900);
xlnt::number_format nf;
nf.set_format_string("dddd");
nf.format_string("dddd");
auto formatted = nf.format(date_number, xlnt::calendar::windows_1900);
TS_ASSERT_EQUALS(formatted, "Sunday");
@ -147,7 +147,7 @@ public:
auto date_number = date.to_number(xlnt::calendar::windows_1900);
xlnt::number_format nf;
nf.set_format_string("ddd");
nf.format_string("ddd");
auto formatted = nf.format(date_number, xlnt::calendar::windows_1900);
TS_ASSERT_EQUALS(formatted, "Sun");
@ -159,7 +159,7 @@ public:
auto date_number = date.to_number(xlnt::calendar::windows_1900);
xlnt::number_format nf;
nf.set_format_string("mmmmm");
nf.format_string("mmmmm");
auto formatted = nf.format(date_number, xlnt::calendar::windows_1900);
TS_ASSERT_EQUALS(formatted, "J");
@ -248,7 +248,7 @@ public:
auto time_number = time.to_number();
xlnt::number_format nf;
nf.set_format_string("hh AM/PM");
nf.format_string("hh AM/PM");
auto formatted = nf.format(time_number, xlnt::calendar::windows_1900);
TS_ASSERT_EQUALS(formatted, "08 PM");
@ -277,7 +277,7 @@ public:
auto time_number = time.to_number();
xlnt::number_format nf;
nf.set_format_string("hh");
nf.format_string("hh");
auto formatted = nf.format(time_number, xlnt::calendar::windows_1900);
TS_ASSERT_EQUALS(formatted, "20");
@ -289,7 +289,7 @@ public:
auto time_number = time.to_number();
xlnt::number_format nf;
nf.set_format_string("h:m");
nf.format_string("h:m");
auto formatted = nf.format(time_number, xlnt::calendar::windows_1900);
TS_ASSERT_EQUALS(formatted, "20:5");
@ -301,7 +301,7 @@ public:
auto time_number = time.to_number();
xlnt::number_format nf;
nf.set_format_string("h:mm");
nf.format_string("h:mm");
auto formatted = nf.format(time_number, xlnt::calendar::windows_1900);
TS_ASSERT_EQUALS(formatted, "20:05");
@ -313,7 +313,7 @@ public:
auto time_number = time.to_number();
xlnt::number_format nf;
nf.set_format_string("h:m:s");
nf.format_string("h:m:s");
auto formatted = nf.format(time_number, xlnt::calendar::windows_1900);
TS_ASSERT_EQUALS(formatted, "20:15:1");
@ -325,7 +325,7 @@ public:
auto time_number = time.to_number();
xlnt::number_format nf;
nf.set_format_string("h:m:ss");
nf.format_string("h:m:ss");
auto formatted = nf.format(time_number, xlnt::calendar::windows_1900);
TS_ASSERT_EQUALS(formatted, "20:15:01");
@ -337,7 +337,7 @@ public:
auto time_number = time.to_number();
xlnt::number_format nf;
nf.set_format_string("h:m:ss ");
nf.format_string("h:m:ss ");
auto formatted = nf.format(time_number, xlnt::calendar::windows_1900);
TS_ASSERT_EQUALS(formatted, "20:15:01 ");
@ -346,7 +346,7 @@ public:
void test_text_section_string()
{
xlnt::number_format nf;
nf.set_format_string("General;General;General;[Green]\"a\"@\"b\"");
nf.format_string("General;General;General;[Green]\"a\"@\"b\"");
auto formatted = nf.format("text");
@ -356,7 +356,7 @@ public:
void test_text_section_no_string()
{
xlnt::number_format nf;
nf.set_format_string("General;General;General;[Green]m\"ab\"");
nf.format_string("General;General;General;[Green]m\"ab\"");
auto formatted = nf.format("text");
@ -366,7 +366,7 @@ public:
void test_text_section_no_text()
{
xlnt::number_format nf;
nf.set_format_string("General;General;General;[Green]m");
nf.format_string("General;General;General;[Green]m");
auto formatted = nf.format("text");
@ -377,7 +377,7 @@ public:
{
xlnt::number_format nf;
nf.set_format_string("[>5]General\"first\";[>3]\"second\"General;\"third\"General");
nf.format_string("[>5]General\"first\";[>3]\"second\"General;\"third\"General");
auto formatted = nf.format(6, xlnt::calendar::windows_1900);
TS_ASSERT_EQUALS(formatted, "6first");
formatted = nf.format(4, xlnt::calendar::windows_1900);
@ -389,7 +389,7 @@ public:
formatted = nf.format(2, xlnt::calendar::windows_1900);
TS_ASSERT_EQUALS(formatted, "third2");
nf.set_format_string("[>=5]\"first\"General;[>=3]\"second\"General;\"third\"General");
nf.format_string("[>=5]\"first\"General;[>=3]\"second\"General;\"third\"General");
formatted = nf.format(5, xlnt::calendar::windows_1900);
TS_ASSERT_EQUALS(formatted, "first5");
formatted = nf.format(6, xlnt::calendar::windows_1900);
@ -401,15 +401,15 @@ public:
formatted = nf.format(2, xlnt::calendar::windows_1900);
TS_ASSERT_EQUALS(formatted, "third2");
nf.set_format_string("[>=5]\"first\"General");
nf.format_string("[>=5]\"first\"General");
formatted = nf.format(4, xlnt::calendar::windows_1900);
TS_ASSERT_EQUALS(formatted, "###########");
nf.set_format_string("[>=5]\"first\"General;[>=4]\"second\"General");
nf.format_string("[>=5]\"first\"General;[>=4]\"second\"General");
formatted = nf.format(3, xlnt::calendar::windows_1900);
TS_ASSERT_EQUALS(formatted, "###########");
nf.set_format_string("[<1]\"first\"General;[<5]\"second\"General;\"third\"General");
nf.format_string("[<1]\"first\"General;[<5]\"second\"General;\"third\"General");
formatted = nf.format(0, xlnt::calendar::windows_1900);
TS_ASSERT_EQUALS(formatted, "first0");
formatted = nf.format(1, xlnt::calendar::windows_1900);
@ -419,7 +419,7 @@ public:
formatted = nf.format(6, xlnt::calendar::windows_1900);
TS_ASSERT_EQUALS(formatted, "third6");
nf.set_format_string("[<=1]\"first\"General;[<=5]\"second\"General;\"third\"General");
nf.format_string("[<=1]\"first\"General;[<=5]\"second\"General;\"third\"General");
formatted = nf.format(-1000, xlnt::calendar::windows_1900);
TS_ASSERT_EQUALS(formatted, "-first1000");
formatted = nf.format(0, xlnt::calendar::windows_1900);
@ -435,7 +435,7 @@ public:
formatted = nf.format(1000, xlnt::calendar::windows_1900);
TS_ASSERT_EQUALS(formatted, "third1000");
nf.set_format_string("[=1]\"first\"General;[=2]\"second\"General;\"third\"General");
nf.format_string("[=1]\"first\"General;[=2]\"second\"General;\"third\"General");
formatted = nf.format(1, xlnt::calendar::windows_1900);
TS_ASSERT_EQUALS(formatted, "first1");
formatted = nf.format(2, xlnt::calendar::windows_1900);
@ -445,7 +445,7 @@ public:
formatted = nf.format(0, xlnt::calendar::windows_1900);
TS_ASSERT_EQUALS(formatted, "third0");
nf.set_format_string("[<>1]\"first\"General;[<>2]\"second\"General");
nf.format_string("[<>1]\"first\"General;[<>2]\"second\"General");
formatted = nf.format(2, xlnt::calendar::windows_1900);
TS_ASSERT_EQUALS(formatted, "first2");
formatted = nf.format(1, xlnt::calendar::windows_1900);
@ -455,7 +455,7 @@ public:
void test_space()
{
xlnt::number_format nf;
nf.set_format_string("_(General_)");
nf.format_string("_(General_)");
auto formatted = nf.format(6, xlnt::calendar::windows_1900);
TS_ASSERT_EQUALS(formatted, " 6 ");
}
@ -463,15 +463,15 @@ public:
void test_fill()
{
xlnt::number_format nf;
nf.set_format_string("*-General");
nf.format_string("*-General");
auto formatted = nf.format(6, xlnt::calendar::windows_1900);
TS_ASSERT_EQUALS(formatted, "----------6");
nf.set_format_string("General*-");
nf.format_string("General*-");
formatted = nf.format(6, xlnt::calendar::windows_1900);
TS_ASSERT_EQUALS(formatted, "6----------");
nf.set_format_string("\\a*-\\b");
nf.format_string("\\a*-\\b");
formatted = nf.format(6, xlnt::calendar::windows_1900);
TS_ASSERT_EQUALS(formatted, "a---------b");
}
@ -479,11 +479,11 @@ public:
void test_placeholders_zero()
{
xlnt::number_format nf;
nf.set_format_string("00");
nf.format_string("00");
auto formatted = nf.format(6, xlnt::calendar::windows_1900);
TS_ASSERT_EQUALS(formatted, "06");
nf.set_format_string("00");
nf.format_string("00");
formatted = nf.format(63, xlnt::calendar::windows_1900);
TS_ASSERT_EQUALS(formatted, "63");
}
@ -491,23 +491,23 @@ public:
void test_placeholders_space()
{
xlnt::number_format nf;
nf.set_format_string("?0");
nf.format_string("?0");
auto formatted = nf.format(6, xlnt::calendar::windows_1900);
TS_ASSERT_EQUALS(formatted, " 6");
nf.set_format_string("?0");
nf.format_string("?0");
formatted = nf.format(63, xlnt::calendar::windows_1900);
TS_ASSERT_EQUALS(formatted, "63");
nf.set_format_string("?0");
nf.format_string("?0");
formatted = nf.format(637, xlnt::calendar::windows_1900);
TS_ASSERT_EQUALS(formatted, "637");
nf.set_format_string("0.?");
nf.format_string("0.?");
formatted = nf.format(6, xlnt::calendar::windows_1900);
TS_ASSERT_EQUALS(formatted, "6. ");
nf.set_format_string("0.0?");
nf.format_string("0.0?");
formatted = nf.format(6.3, xlnt::calendar::windows_1900);
TS_ASSERT_EQUALS(formatted, "6.3 ");
formatted = nf.format(6.34, xlnt::calendar::windows_1900);
@ -517,7 +517,7 @@ public:
void test_scientific()
{
xlnt::number_format nf;
nf.set_format_string("0.0E-0");
nf.format_string("0.0E-0");
auto formatted = nf.format(6.1, xlnt::calendar::windows_1900);
TS_ASSERT_EQUALS(formatted, "6.1E0");
}
@ -526,11 +526,11 @@ public:
{
xlnt::number_format nf;
nf.set_format_string("[$€-407]#,##0.00");
nf.format_string("[$€-407]#,##0.00");
auto formatted = nf.format(-45000.1, xlnt::calendar::windows_1900);
TS_ASSERT_EQUALS(formatted, "-€45,000.10");
nf.set_format_string("[$$-1009]#,##0.00");
nf.format_string("[$$-1009]#,##0.00");
formatted = nf.format(-45000.1, xlnt::calendar::windows_1900);
TS_ASSERT_EQUALS(formatted, "-$45,000.10");
}
@ -539,16 +539,16 @@ public:
{
xlnt::number_format nf;
nf.set_format_string("[$-]#,##0.00");
nf.format_string("[$-]#,##0.00");
TS_ASSERT_THROWS(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error);
nf.set_format_string("[$-G]#,##0.00");
nf.format_string("[$-G]#,##0.00");
TS_ASSERT_THROWS(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error);
nf.set_format_string("[$-4002]#,##0.00");
nf.format_string("[$-4002]#,##0.00");
TS_ASSERT_THROWS(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error);
nf.set_format_string("[-4001]#,##0.00");
nf.format_string("[-4001]#,##0.00");
TS_ASSERT_THROWS(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error);
}
@ -556,13 +556,13 @@ public:
{
xlnt::number_format nf;
nf.set_format_string("[Red][Green]#,##0.00");
nf.format_string("[Red][Green]#,##0.00");
TS_ASSERT_THROWS(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error);
nf.set_format_string("[$-403][$-4001]#,##0.00");
nf.format_string("[$-403][$-4001]#,##0.00");
TS_ASSERT_THROWS(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error);
nf.set_format_string("[>3][>4]#,##0.00");
nf.format_string("[>3][>4]#,##0.00");
TS_ASSERT_THROWS(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error);
}
@ -570,7 +570,7 @@ public:
{
xlnt::number_format nf;
nf.set_format_string("\"\\\"\"General");
nf.format_string("\"\\\"\"General");
auto formatted = nf.format(6, xlnt::calendar::windows_1900);
TS_ASSERT_EQUALS(formatted, "\"6");
}
@ -579,7 +579,7 @@ public:
{
xlnt::number_format nf;
nf.set_format_string("#,");
nf.format_string("#,");
auto formatted = nf.format(61234, xlnt::calendar::windows_1900);
TS_ASSERT_EQUALS(formatted, "61");
}
@ -588,43 +588,43 @@ public:
{
xlnt::number_format nf;
nf.set_format_string("[Black]#");
nf.format_string("[Black]#");
auto formatted = nf.format(6, xlnt::calendar::windows_1900);
TS_ASSERT_EQUALS(formatted, "6");
nf.set_format_string("[Black]#");
nf.format_string("[Black]#");
formatted = nf.format(6, xlnt::calendar::windows_1900);
TS_ASSERT_EQUALS(formatted, "6");
nf.set_format_string("[Blue]#");
nf.format_string("[Blue]#");
formatted = nf.format(6, xlnt::calendar::windows_1900);
TS_ASSERT_EQUALS(formatted, "6");
nf.set_format_string("[Green]#");
nf.format_string("[Green]#");
formatted = nf.format(6, xlnt::calendar::windows_1900);
TS_ASSERT_EQUALS(formatted, "6");
nf.set_format_string("[Red]#");
nf.format_string("[Red]#");
formatted = nf.format(6, xlnt::calendar::windows_1900);
TS_ASSERT_EQUALS(formatted, "6");
nf.set_format_string("[Cyan]#");
nf.format_string("[Cyan]#");
formatted = nf.format(6, xlnt::calendar::windows_1900);
TS_ASSERT_EQUALS(formatted, "6");
nf.set_format_string("[Magenta]#");
nf.format_string("[Magenta]#");
formatted = nf.format(6, xlnt::calendar::windows_1900);
TS_ASSERT_EQUALS(formatted, "6");
nf.set_format_string("[Yellow]#");
nf.format_string("[Yellow]#");
formatted = nf.format(6, xlnt::calendar::windows_1900);
TS_ASSERT_EQUALS(formatted, "6");
nf.set_format_string("[White]#");
nf.format_string("[White]#");
formatted = nf.format(6, xlnt::calendar::windows_1900);
TS_ASSERT_EQUALS(formatted, "6");
nf.set_format_string("[Color15]#");
nf.format_string("[Color15]#");
formatted = nf.format(6, xlnt::calendar::windows_1900);
TS_ASSERT_EQUALS(formatted, "6");
}
@ -633,31 +633,31 @@ public:
{
xlnt::number_format nf;
nf.set_format_string("[=1]\"first\"General;[=2]\"second\"General;[=3]\"third\"General");
nf.format_string("[=1]\"first\"General;[=2]\"second\"General;[=3]\"third\"General");
TS_ASSERT_THROWS(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error);
nf.set_format_string("\"first\"General;\"second\"General;\"third\"General;\"fourth\"General;\"fifth\"General");
nf.format_string("\"first\"General;\"second\"General;\"third\"General;\"fourth\"General;\"fifth\"General");
TS_ASSERT_THROWS(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error);
nf.set_format_string("[");
nf.format_string("[");
TS_ASSERT_THROWS(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error);
nf.set_format_string("[]");
nf.format_string("[]");
TS_ASSERT_THROWS(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error);
nf.set_format_string("[Redd]");
nf.format_string("[Redd]");
TS_ASSERT_THROWS(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error);
nf.set_format_string("[$1]#");
nf.format_string("[$1]#");
TS_ASSERT_THROWS(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error);
nf.set_format_string("Gee");
nf.format_string("Gee");
TS_ASSERT_THROWS(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error);
nf.set_format_string("!");
nf.format_string("!");
TS_ASSERT_THROWS(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error);
nf.set_format_string("A/");
nf.format_string("A/");
TS_ASSERT_THROWS(nf.format(1.2, xlnt::calendar::windows_1900), std::runtime_error);
}

View File

@ -27,6 +27,20 @@
#include <xlnt/utils/date.hpp>
#include <xlnt/utils/time.hpp>
namespace {
std::string fill(const std::string &string, std::size_t length = 2)
{
if (string.size() >= length)
{
return string;
}
return std::string(length - string.size(), '0') + string;
}
} // namespace
namespace xlnt {
datetime datetime::from_number(long double raw_time, calendar base_date)
@ -92,4 +106,33 @@ int datetime::weekday() const
return date(year, month, day).weekday();
}
datetime datetime::from_iso_string(const std::string &string)
{
xlnt::datetime result(1900, 1, 1);
auto separator_index = string.find('-');
result.year = std::stoi(string.substr(0, separator_index));
result.month = std::stoi(string.substr(separator_index + 1, string.find('-', separator_index + 1)));
separator_index = string.find('-', separator_index + 1);
result.day = std::stoi(string.substr(separator_index + 1, string.find('T', separator_index + 1)));
separator_index = string.find('T', separator_index + 1);
result.hour = std::stoi(string.substr(separator_index + 1, string.find(':', separator_index + 1)));
separator_index = string.find(':', separator_index + 1);
result.minute = std::stoi(string.substr(separator_index + 1, string.find(':', separator_index + 1)));
separator_index = string.find(':', separator_index + 1);
result.second = std::stoi(string.substr(separator_index + 1, string.find('Z', separator_index + 1)));
return result;
}
std::string datetime::to_iso_string() const
{
return std::to_string(year) + "-"
+ fill(std::to_string(month)) + "-"
+ fill(std::to_string(day)) + "T"
+ fill(std::to_string(hour)) + ":"
+ fill(std::to_string(minute)) + ":"
+ fill(std::to_string(second)) + "Z";
}
} // namespace xlnt

View File

@ -29,14 +29,14 @@ namespace xlnt {
exception::exception(const std::string &message)
: std::runtime_error("xlnt::error : " + message)
{
set_message(message);
this->message(message);
}
exception::~exception()
{
}
void exception::set_message(const std::string &message)
void exception::message(const std::string &message)
{
message_ = message;
}

View File

@ -293,6 +293,29 @@ char path::guess_separator() const
return internal_.find('\\') != std::string::npos ? '\\' : '/';
}
path path::relative_to(const path &base_path) const
{
if (is_relative()) return *this;
auto base_split = base_path.split();
auto this_split = split();
auto index = std::size_t(0);
while (index < base_split.size() && index < this_split.size() && base_split[index] == this_split[index])
{
index++;
}
auto result = path();
for (auto i = index; i < this_split.size(); i++)
{
result = result.append(this_split[i]);
}
return result;
}
bool operator==(const path &left, const path &right)
{
return left.internal_ == right.internal_;

View File

@ -37,7 +37,7 @@ const_worksheet_iterator::const_worksheet_iterator(const const_worksheet_iterato
const worksheet const_worksheet_iterator::operator*()
{
return wb_.get_sheet_by_index(index_);
return wb_.sheet_by_index(index_);
}
const_worksheet_iterator &const_worksheet_iterator::operator++()

View File

@ -58,12 +58,12 @@ std::vector<std::string> split_string(const std::string &string, char delim)
namespace xlnt {
std::string named_range::get_name() const
std::string named_range::name() const
{
return name_;
}
const std::vector<named_range::target> &named_range::get_targets() const
const std::vector<named_range::target> &named_range::targets() const
{
return targets_;
}

View File

@ -56,14 +56,14 @@ public:
wb.load("data/18_basic_comments.xlsx");
auto sheet1 = wb[0];
TS_ASSERT_EQUALS(sheet1.get_cell("A1").get_value<std::string>(), "Sheet1!A1");
TS_ASSERT_EQUALS(sheet1.get_cell("A1").comment().plain_text(), "Sheet1 comment");
TS_ASSERT_EQUALS(sheet1.get_cell("A1").comment().author(), "Microsoft Office User");
TS_ASSERT_EQUALS(sheet1.cell("A1").value<std::string>(), "Sheet1!A1");
TS_ASSERT_EQUALS(sheet1.cell("A1").comment().plain_text(), "Sheet1 comment");
TS_ASSERT_EQUALS(sheet1.cell("A1").comment().author(), "Microsoft Office User");
auto sheet2 = wb[1];
TS_ASSERT_EQUALS(sheet2.get_cell("A1").get_value<std::string>(), "Sheet2!A1");
TS_ASSERT_EQUALS(sheet2.get_cell("A1").comment().plain_text(), "Sheet2 comment");
TS_ASSERT_EQUALS(sheet2.get_cell("A1").comment().author(), "Microsoft Office User");
TS_ASSERT_EQUALS(sheet2.cell("A1").value<std::string>(), "Sheet2!A1");
TS_ASSERT_EQUALS(sheet2.cell("A1").comment().plain_text(), "Sheet2 comment");
TS_ASSERT_EQUALS(sheet2.cell("A1").comment().author(), "Microsoft Office User");
}
void test_read_unicode_filename()
@ -71,12 +71,12 @@ public:
#ifdef _MSC_VER
xlnt::workbook wb;
wb.load(L"data\\19_unicode_Λ.xlsx");
TS_ASSERT_EQUALS(wb.get_active_sheet().get_cell("A1").get_value<std::string>(), "unicode!");
TS_ASSERT_EQUALS(wb.active_sheet().cell("A1").value<std::string>(), "unicode!");
#endif
#ifndef __MINGW32__
xlnt::workbook wb2;
wb2.load(u8"data/19_unicode_Λ.xlsx");
TS_ASSERT_EQUALS(wb2.get_active_sheet().get_cell("A1").get_value<std::string>(), "unicode!");
TS_ASSERT_EQUALS(wb2.active_sheet().cell("A1").value<std::string>(), "unicode!");
#endif
}
@ -84,8 +84,8 @@ public:
{
xlnt::workbook wb;
wb.load("data/20_with_hyperlink.xlsx");
TS_ASSERT(wb.get_active_sheet().get_cell("A1").has_hyperlink());
TS_ASSERT_EQUALS(wb.get_active_sheet().get_cell("A1").get_hyperlink(),
TS_ASSERT(wb.active_sheet().cell("A1").has_hyperlink());
TS_ASSERT_EQUALS(wb.active_sheet().cell("A1").hyperlink(),
"https://fr.wikipedia.org/wiki/Ille-et-Vilaine");
}
};

View File

@ -50,75 +50,75 @@ public:
void test_produce_simple_excel()
{
xlnt::workbook wb = xlnt::workbook::empty_excel();
auto ws = wb.get_active_sheet();
auto ws = wb.active_sheet();
auto bold_font = xlnt::font().bold(true);
ws.get_cell("A1").set_value("Type");
ws.get_cell("A1").set_font(bold_font);
ws.cell("A1").value("Type");
ws.cell("A1").font(bold_font);
ws.get_cell("B1").set_value("Value");
ws.get_cell("B1").set_font(bold_font);
ws.cell("B1").value("Value");
ws.cell("B1").font(bold_font);
ws.get_cell("A2").set_value("null");
ws.get_cell("B2").set_value(nullptr);
ws.cell("A2").value("null");
ws.cell("B2").value(nullptr);
ws.get_cell("A3").set_value("bool (true)");
ws.get_cell("B3").set_value(true);
ws.cell("A3").value("bool (true)");
ws.cell("B3").value(true);
ws.get_cell("A4").set_value("bool (false)");
ws.get_cell("B4").set_value(false);
ws.cell("A4").value("bool (false)");
ws.cell("B4").value(false);
ws.get_cell("A5").set_value("number (std::int8_t)");
ws.get_cell("B5").set_value(std::numeric_limits<std::int8_t>::max());
ws.cell("A5").value("number (std::int8_t)");
ws.cell("B5").value(std::numeric_limits<std::int8_t>::max());
ws.get_cell("A6").set_value("number (std::uint8_t)");
ws.get_cell("B6").set_value(std::numeric_limits<std::uint8_t>::max());
ws.cell("A6").value("number (std::uint8_t)");
ws.cell("B6").value(std::numeric_limits<std::uint8_t>::max());
ws.get_cell("A7").set_value("number (std::uint16_t)");
ws.get_cell("B7").set_value(std::numeric_limits<std::int16_t>::max());
ws.cell("A7").value("number (std::uint16_t)");
ws.cell("B7").value(std::numeric_limits<std::int16_t>::max());
ws.get_cell("A8").set_value("number (std::uint16_t)");
ws.get_cell("B8").set_value(std::numeric_limits<std::uint16_t>::max());
ws.cell("A8").value("number (std::uint16_t)");
ws.cell("B8").value(std::numeric_limits<std::uint16_t>::max());
ws.get_cell("A9").set_value("number (std::uint32_t)");
ws.get_cell("B9").set_value(std::numeric_limits<std::int32_t>::max());
ws.cell("A9").value("number (std::uint32_t)");
ws.cell("B9").value(std::numeric_limits<std::int32_t>::max());
ws.get_cell("A10").set_value("number (std::uint32_t)");
ws.get_cell("B10").set_value(std::numeric_limits<std::uint32_t>::max());
ws.cell("A10").value("number (std::uint32_t)");
ws.cell("B10").value(std::numeric_limits<std::uint32_t>::max());
ws.get_cell("A11").set_value("number (std::uint64_t)");
ws.get_cell("B11").set_value(std::numeric_limits<std::int64_t>::max());
ws.cell("A11").value("number (std::uint64_t)");
ws.cell("B11").value(std::numeric_limits<std::int64_t>::max());
ws.get_cell("A12").set_value("number (std::uint64_t)");
ws.get_cell("B12").set_value(std::numeric_limits<std::uint64_t>::max());
ws.cell("A12").value("number (std::uint64_t)");
ws.cell("B12").value(std::numeric_limits<std::uint64_t>::max());
ws.get_cell("A13").set_value("number (float)");
ws.get_cell("B13").set_value(std::numeric_limits<float>::max());
ws.cell("A13").value("number (float)");
ws.cell("B13").value(std::numeric_limits<float>::max());
ws.get_cell("A14").set_value("number (double)");
ws.get_cell("B14").set_value(std::numeric_limits<double>::max());
ws.cell("A14").value("number (double)");
ws.cell("B14").value(std::numeric_limits<double>::max());
ws.get_cell("A15").set_value("number (long double)");
ws.get_cell("B15").set_value(std::numeric_limits<long double>::max());
ws.cell("A15").value("number (long double)");
ws.cell("B15").value(std::numeric_limits<long double>::max());
ws.get_cell("A16").set_value("text (char *)");
ws.get_cell("B16").set_value("string");
ws.cell("A16").value("text (char *)");
ws.cell("B16").value("string");
ws.get_cell("A17").set_value("text (std::string)");
ws.get_cell("B17").set_value(std::string("string"));
ws.cell("A17").value("text (std::string)");
ws.cell("B17").value(std::string("string"));
ws.get_cell("A18").set_value("date");
ws.get_cell("B18").set_value(xlnt::date(2016, 2, 3));
ws.cell("A18").value("date");
ws.cell("B18").value(xlnt::date(2016, 2, 3));
ws.get_cell("A19").set_value("time");
ws.get_cell("B19").set_value(xlnt::time(1, 2, 3, 4));
ws.cell("A19").value("time");
ws.cell("B19").value(xlnt::time(1, 2, 3, 4));
ws.get_cell("A20").set_value("datetime");
ws.get_cell("B20").set_value(xlnt::datetime(2016, 2, 3, 1, 2, 3, 4));
ws.cell("A20").value("datetime");
ws.cell("B20").value(xlnt::datetime(2016, 2, 3, 1, 2, 3, 4));
ws.get_cell("A21").set_value("timedelta");
ws.get_cell("B21").set_value(xlnt::timedelta(1, 2, 3, 4, 5));
ws.cell("A21").value("timedelta");
ws.cell("B21").value(xlnt::timedelta(1, 2, 3, 4, 5));
ws.freeze_panes("B2");
@ -131,14 +131,14 @@ public:
{
xlnt::workbook workbook;
TS_ASSERT_EQUALS(workbook.get_sheet_titles().size(), 1);
TS_ASSERT_EQUALS(workbook.sheet_titles().size(), 1);
auto sheet = workbook.create_sheet();
sheet.set_title("XXX1");
TS_ASSERT_EQUALS(workbook.get_sheet_titles().size(), 2);
sheet.title("XXX1");
TS_ASSERT_EQUALS(workbook.sheet_titles().size(), 2);
workbook.remove_sheet(workbook.get_sheet_by_title("XXX1"));
TS_ASSERT_EQUALS(workbook.get_sheet_titles().size(), 1);
workbook.remove_sheet(workbook.sheet_by_title("XXX1"));
TS_ASSERT_EQUALS(workbook.sheet_titles().size(), 1);
std::vector<std::uint8_t> temp_buffer;
TS_ASSERT_THROWS_NOTHING(workbook.save(temp_buffer));
@ -151,37 +151,37 @@ public:
xlnt::formatted_text comment_text;
xlnt::text_run formatted_run;;
formatted_run.set_bold(true);
formatted_run.set_size(10);
formatted_run.set_color(xlnt::indexed_color(81));
formatted_run.set_font("Calibri");
formatted_run.bold(true);
formatted_run.size(10);
formatted_run.color(xlnt::indexed_color(81));
formatted_run.font("Calibri");
auto sheet1 = wb.get_active_sheet();
auto sheet1 = wb.active_sheet();
sheet1.get_cell("A1").set_value("Sheet1!A1");
formatted_run.set_string("Sheet1 comment");
sheet1.cell("A1").value("Sheet1!A1");
formatted_run.string("Sheet1 comment");
comment_text.add_run(formatted_run);
sheet1.get_cell("A1").comment(xlnt::comment(comment_text, "Microsoft Office User"));
sheet1.get_cell("A1").comment("Sheet1 comment");
sheet1.cell("A1").comment(xlnt::comment(comment_text, "Microsoft Office User"));
sheet1.cell("A1").comment("Sheet1 comment");
sheet1.get_cell("A2").set_value("Sheet1!A2");
formatted_run.set_string("Sheet1 comment2");
sheet1.cell("A2").value("Sheet1!A2");
formatted_run.string("Sheet1 comment2");
comment_text.clear();
comment_text.add_run(formatted_run);
sheet1.get_cell("A2").comment(xlnt::comment(comment_text, "Microsoft Office User"));
sheet1.cell("A2").comment(xlnt::comment(comment_text, "Microsoft Office User"));
auto sheet2 = wb.create_sheet();
sheet2.get_cell("A1").set_value("Sheet2!A1");
formatted_run.set_string("Sheet2 comment");
sheet2.cell("A1").value("Sheet2!A1");
formatted_run.string("Sheet2 comment");
comment_text.clear();
comment_text.add_run(formatted_run);
sheet2.get_cell("A1").comment(xlnt::comment(comment_text, "Microsoft Office User"));
sheet2.cell("A1").comment(xlnt::comment(comment_text, "Microsoft Office User"));
sheet2.get_cell("A2").set_value("Sheet2!A2");
formatted_run.set_string("Sheet2 comment2");
sheet2.cell("A2").value("Sheet2!A2");
formatted_run.string("Sheet2 comment2");
comment_text.clear();
comment_text.add_run(formatted_run);
sheet2.get_cell("A2").comment(xlnt::comment(comment_text, "Microsoft Office User"));
sheet2.cell("A2").comment(xlnt::comment(comment_text, "Microsoft Office User"));
// TS_ASSERT(workbook_matches_file(wb, xlnt::path("data/18_basic_comments.xlsx")));
}

View File

@ -52,6 +52,7 @@ public:
std::vector<std::uint8_t> buffer;
original_workbook.save(buffer);
original_workbook.save("a.xlsx");
return xml_helper::xlsx_archives_match(original_data, buffer);
}
@ -76,7 +77,6 @@ public:
void test_round_trip_empty_numbers_wrw()
{
TS_SKIP("");
xlnt::workbook wb = xlnt::workbook::empty_numbers();
TS_ASSERT(round_trip_matches_wrw(wb));
}
@ -101,8 +101,7 @@ public:
void test_round_trip_empty_numbers_rw()
{
TS_SKIP("");
auto path = path_helper::get_data_directory("10_default-numbers.xlsx");
auto path = path_helper::get_data_directory("11_default-numbers.xlsx");
TS_ASSERT(round_trip_matches_rw(path));
}

View File

@ -12,10 +12,10 @@
class test_workbook : public CxxTest::TestSuite
{
public:
void test_get_active_sheet()
void test_active_sheet()
{
xlnt::workbook wb;
TS_ASSERT_EQUALS(wb.get_active_sheet(), wb[0]);
TS_ASSERT_EQUALS(wb.active_sheet(), wb[0]);
}
void test_create_sheet()
@ -30,42 +30,42 @@ public:
{
xlnt::workbook wb;
auto new_sheet = wb.create_sheet();
new_sheet.get_cell("A6").set_value(1.498);
new_sheet.cell("A6").value(1.498);
wb.copy_sheet(new_sheet);
TS_ASSERT(wb[1].compare(wb[2], false));
wb.create_sheet().get_cell("A6").set_value(1.497);
wb.create_sheet().cell("A6").value(1.497);
TS_ASSERT(!wb[1].compare(wb[3], false));
}
void test_add_sheet_from_other_workbook()
{
xlnt::workbook wb1, wb2;
auto new_sheet = wb1.get_active_sheet();
auto new_sheet = wb1.active_sheet();
TS_ASSERT_THROWS(wb2.copy_sheet(new_sheet), xlnt::invalid_parameter);
TS_ASSERT_THROWS(wb2.get_index(new_sheet), std::runtime_error);
TS_ASSERT_THROWS(wb2.index(new_sheet), std::runtime_error);
}
void test_add_sheet_at_index()
{
xlnt::workbook wb;
auto ws = wb.get_active_sheet();
ws.get_cell("B3").set_value(2);
ws.set_title("Active");
auto ws = wb.active_sheet();
ws.cell("B3").value(2);
ws.title("Active");
wb.copy_sheet(ws, 0);
TS_ASSERT_EQUALS(wb.get_sheet_titles().at(0), "Sheet1");
TS_ASSERT_EQUALS(wb.get_sheet_by_index(0).get_cell("B3").get_value<int>(), 2);
TS_ASSERT_EQUALS(wb.get_sheet_titles().at(1), "Active");
TS_ASSERT_EQUALS(wb.get_sheet_by_index(1).get_cell("B3").get_value<int>(), 2);
TS_ASSERT_EQUALS(wb.sheet_titles().at(0), "Sheet1");
TS_ASSERT_EQUALS(wb.sheet_by_index(0).cell("B3").value<int>(), 2);
TS_ASSERT_EQUALS(wb.sheet_titles().at(1), "Active");
TS_ASSERT_EQUALS(wb.sheet_by_index(1).cell("B3").value<int>(), 2);
}
void test_remove_sheet()
{
xlnt::workbook wb, wb2;
auto new_sheet = wb.create_sheet(0);
new_sheet.set_title("removed");
new_sheet.title("removed");
wb.remove_sheet(new_sheet);
TS_ASSERT(!wb.contains("removed"));
TS_ASSERT_THROWS(wb.remove_sheet(wb2.get_active_sheet()), std::runtime_error);
TS_ASSERT_THROWS(wb.remove_sheet(wb2.active_sheet()), std::runtime_error);
}
void test_get_sheet_by_title()
@ -73,12 +73,12 @@ public:
xlnt::workbook wb;
auto new_sheet = wb.create_sheet();
std::string title = "my sheet";
new_sheet.set_title(title);
auto found_sheet = wb.get_sheet_by_title(title);
new_sheet.title(title);
auto found_sheet = wb.sheet_by_title(title);
TS_ASSERT_EQUALS(new_sheet, found_sheet);
TS_ASSERT_THROWS(wb.get_sheet_by_title("error"), xlnt::key_not_found);
TS_ASSERT_THROWS(wb.sheet_by_title("error"), xlnt::key_not_found);
const auto &wb_const = wb;
TS_ASSERT_THROWS(wb_const.get_sheet_by_title("error"), xlnt::key_not_found);
TS_ASSERT_THROWS(wb_const.sheet_by_title("error"), xlnt::key_not_found);
}
void test_get_sheet_by_title_const()
@ -86,9 +86,9 @@ public:
xlnt::workbook wb;
auto new_sheet = wb.create_sheet();
std::string title = "my sheet";
new_sheet.set_title(title);
new_sheet.title(title);
const xlnt::workbook& wbconst = wb;
auto found_sheet = wbconst.get_sheet_by_title(title);
auto found_sheet = wbconst.sheet_by_title(title);
TS_ASSERT_EQUALS(new_sheet, found_sheet);
}
@ -114,31 +114,31 @@ public:
for(auto ws : wb)
{
TS_ASSERT_EQUALS(ws.get_title(), "Sheet1");
TS_ASSERT_EQUALS(ws.title(), "Sheet1");
}
}
void test_get_index()
{
xlnt::workbook wb;
wb.create_sheet().set_title("1");
wb.create_sheet().set_title("2");
wb.create_sheet().title("1");
wb.create_sheet().title("2");
auto sheet_index = wb.get_index(wb.get_sheet_by_title("1"));
auto sheet_index = wb.index(wb.sheet_by_title("1"));
TS_ASSERT_EQUALS(sheet_index, 1);
sheet_index = wb.get_index(wb.get_sheet_by_title("2"));
sheet_index = wb.index(wb.sheet_by_title("2"));
TS_ASSERT_EQUALS(sheet_index, 2);
}
void test_get_sheet_names()
{
xlnt::workbook wb;
wb.create_sheet().set_title("test_get_sheet_titles");
wb.create_sheet().title("test_get_sheet_titles");
const std::vector<std::string> expected_titles = { "Sheet1", "test_get_sheet_titles" };
TS_ASSERT_EQUALS(wb.get_sheet_titles(), expected_titles);
TS_ASSERT_EQUALS(wb.sheet_titles(), expected_titles);
}
void test_add_named_range()
@ -156,10 +156,10 @@ public:
xlnt::workbook wb;
auto new_sheet = wb.create_sheet();
wb.create_named_range("test_nr", new_sheet, "A1");
auto found_range = wb.get_named_range("test_nr");
auto expected_range = new_sheet.get_range("A1");
auto found_range = wb.named_range("test_nr");
auto expected_range = new_sheet.range("A1");
TS_ASSERT_EQUALS(expected_range, found_range);
TS_ASSERT_THROWS(wb.get_named_range("test_nr2"), std::runtime_error);
TS_ASSERT_THROWS(wb.named_range("test_nr2"), std::runtime_error);
}
void test_remove_named_range()
@ -177,23 +177,23 @@ public:
{
xlnt::workbook wb;
wb.create_sheet().set_title("Sheet2");
wb.create_sheet().set_title("Sheet3");
wb.create_sheet().title("Sheet2");
wb.create_sheet().title("Sheet3");
auto iter = wb.begin();
TS_ASSERT_EQUALS((*(iter++)).get_title(), "Sheet1");
TS_ASSERT_EQUALS((*(iter++)).get_title(), "Sheet2");
TS_ASSERT_EQUALS((*(iter++)).get_title(), "Sheet3");
TS_ASSERT_EQUALS((*(iter++)).title(), "Sheet1");
TS_ASSERT_EQUALS((*(iter++)).title(), "Sheet2");
TS_ASSERT_EQUALS((*(iter++)).title(), "Sheet3");
TS_ASSERT_EQUALS(iter, wb.end());
const auto wb_const = wb;
auto const_iter = wb_const.begin();
TS_ASSERT_EQUALS((*(const_iter++)).get_title(), "Sheet1");
TS_ASSERT_EQUALS((*(const_iter++)).get_title(), "Sheet2");
TS_ASSERT_EQUALS((*(const_iter++)).get_title(), "Sheet3");
TS_ASSERT_EQUALS((*(const_iter++)).title(), "Sheet1");
TS_ASSERT_EQUALS((*(const_iter++)).title(), "Sheet2");
TS_ASSERT_EQUALS((*(const_iter++)).title(), "Sheet3");
TS_ASSERT_EQUALS(const_iter, wb_const.end());
}
@ -201,26 +201,26 @@ public:
{
xlnt::workbook wb;
wb.create_sheet().set_title("Sheet2");
wb.create_sheet().set_title("Sheet3");
wb.create_sheet().title("Sheet2");
wb.create_sheet().title("Sheet3");
auto iter = wb.begin();
TS_ASSERT_EQUALS((*iter).get_title(), "Sheet1");
TS_ASSERT_EQUALS((*iter).title(), "Sheet1");
iter++;
TS_ASSERT_EQUALS((*iter).get_title(), "Sheet2");
TS_ASSERT_EQUALS((*iter).title(), "Sheet2");
auto copy = wb.begin();
copy = iter;
TS_ASSERT_EQUALS((*iter).get_title(), "Sheet2");
TS_ASSERT_EQUALS((*iter).title(), "Sheet2");
TS_ASSERT_EQUALS(iter, copy);
iter++;
TS_ASSERT_EQUALS((*iter).get_title(), "Sheet3");
TS_ASSERT_EQUALS((*iter).title(), "Sheet3");
TS_ASSERT_DIFFERS(iter, copy);
copy++;
TS_ASSERT_EQUALS((*iter).get_title(), "Sheet3");
TS_ASSERT_EQUALS((*iter).title(), "Sheet3");
TS_ASSERT_EQUALS(iter, copy);
}
@ -228,41 +228,41 @@ public:
{
xlnt::manifest m;
TS_ASSERT(!m.has_default_type("xml"));
TS_ASSERT_THROWS(m.get_default_type("xml"), xlnt::key_not_found);
TS_ASSERT(!m.has_relationship(xlnt::path("/"), xlnt::relationship::type::office_document));
TS_ASSERT(m.get_relationships(xlnt::path("xl/workbook.xml")).empty());
TS_ASSERT_THROWS(m.default_type("xml"), xlnt::key_not_found);
TS_ASSERT(!m.has_relationship(xlnt::path("/"), xlnt::relationship_type::office_document));
TS_ASSERT(m.relationships(xlnt::path("xl/workbook.xml")).empty());
}
void test_memory()
{
xlnt::workbook wb, wb2;
wb.get_active_sheet().set_title("swap");
wb.active_sheet().title("swap");
std::swap(wb, wb2);
TS_ASSERT_EQUALS(wb.get_active_sheet().get_title(), "Sheet1");
TS_ASSERT_EQUALS(wb2.get_active_sheet().get_title(), "swap");
TS_ASSERT_EQUALS(wb.active_sheet().title(), "Sheet1");
TS_ASSERT_EQUALS(wb2.active_sheet().title(), "swap");
wb = wb2;
TS_ASSERT_EQUALS(wb.get_active_sheet().get_title(), "swap");
TS_ASSERT_EQUALS(wb.active_sheet().title(), "swap");
}
void test_clear()
{
xlnt::workbook wb;
xlnt::style s = wb.create_style("s");
wb.get_active_sheet().get_cell("B2").set_value("B2");
wb.get_active_sheet().get_cell("B2").style(s);
TS_ASSERT(wb.get_active_sheet().get_cell("B2").has_style());
wb.active_sheet().cell("B2").value("B2");
wb.active_sheet().cell("B2").style(s);
TS_ASSERT(wb.active_sheet().cell("B2").has_style());
wb.clear_styles();
TS_ASSERT(!wb.get_active_sheet().get_cell("B2").has_style());
TS_ASSERT(!wb.active_sheet().cell("B2").has_style());
xlnt::format format = wb.create_format();
xlnt::font font;
font.size(41);
format.font(font, true);
wb.get_active_sheet().get_cell("B2").format(format);
TS_ASSERT(wb.get_active_sheet().get_cell("B2").has_format());
wb.active_sheet().cell("B2").format(format);
TS_ASSERT(wb.active_sheet().cell("B2").has_format());
wb.clear_formats();
TS_ASSERT(!wb.get_active_sheet().get_cell("B2").has_format());
TS_ASSERT(!wb.active_sheet().cell("B2").has_format());
wb.clear();
TS_ASSERT(wb.get_sheet_titles().empty());
TS_ASSERT(wb.sheet_titles().empty());
}
void test_comparison()
@ -275,7 +275,7 @@ public:
const auto &wb_const = wb;
//TODO these aren't tests...
wb_const.get_manifest();
wb_const.manifest();
TS_ASSERT(wb.has_theme());

File diff suppressed because it is too large Load Diff

View File

@ -55,20 +55,20 @@ cell_iterator &cell_iterator::operator--()
{
if (order_ == major_order::row)
{
current_cell_.set_column_index(current_cell_.get_column_index() - 1);
current_cell_.column_index(current_cell_.column_index() - 1);
while (!ws_.has_cell(current_cell_) && current_cell_.get_column() > range_.get_top_left().get_column())
while (!ws_.has_cell(current_cell_) && current_cell_.column() > range_.top_left().column())
{
current_cell_.set_column_index(current_cell_.get_column_index() - 1);
current_cell_.column_index(current_cell_.column_index() - 1);
}
}
else
{
current_cell_.set_row(current_cell_.get_row() - 1);
current_cell_.row(current_cell_.row() - 1);
while (!ws_.has_cell(current_cell_) && current_cell_.get_row() > range_.get_top_left().get_row())
while (!ws_.has_cell(current_cell_) && current_cell_.row() > range_.top_left().row())
{
current_cell_.set_row(current_cell_.get_row() - 1);
current_cell_.row(current_cell_.row() - 1);
}
}
@ -86,26 +86,26 @@ cell_iterator &cell_iterator::operator++()
{
if (order_ == major_order::row)
{
if (current_cell_.get_column() <= range_.get_bottom_right().get_column())
if (current_cell_.column() <= range_.bottom_right().column())
{
current_cell_.set_column_index(current_cell_.get_column_index() + 1);
current_cell_.column_index(current_cell_.column_index() + 1);
}
while (!ws_.has_cell(current_cell_) && current_cell_.get_column() <= range_.get_bottom_right().get_column())
while (!ws_.has_cell(current_cell_) && current_cell_.column() <= range_.bottom_right().column())
{
current_cell_.set_column_index(current_cell_.get_column_index() + 1);
current_cell_.column_index(current_cell_.column_index() + 1);
}
}
else
{
if (current_cell_.get_row() <= range_.get_bottom_right().get_row())
if (current_cell_.row() <= range_.bottom_right().row())
{
current_cell_.set_row(current_cell_.get_row() + 1);
current_cell_.row(current_cell_.row() + 1);
}
while (!ws_.has_cell(current_cell_) && current_cell_.get_row() <= range_.get_bottom_right().get_row())
while (!ws_.has_cell(current_cell_) && current_cell_.row() <= range_.bottom_right().row())
{
current_cell_.set_row(current_cell_.get_row() + 1);
current_cell_.row(current_cell_.row() + 1);
}
}

View File

@ -29,55 +29,45 @@ namespace xlnt {
cell_vector::iterator cell_vector::begin()
{
return iterator(ws_, ref_.get_top_left(), ref_, order_);
return iterator(ws_, ref_.top_left(), ref_, order_);
}
cell_vector::iterator cell_vector::end()
{
if (order_ == major_order::row)
{
auto past_end = ref_.get_bottom_right();
past_end.set_column_index(past_end.get_column_index() + 1);
auto past_end = ref_.bottom_right();
past_end.column_index(past_end.column_index() + 1);
return iterator(ws_, past_end, ref_, order_);
}
auto past_end = ref_.get_bottom_right();
past_end.set_row(past_end.get_row() + 1);
auto past_end = ref_.bottom_right();
past_end.row(past_end.row() + 1);
return iterator(ws_, past_end, ref_, order_);
}
cell_vector::const_iterator cell_vector::cbegin() const
{
return const_iterator(ws_, ref_.get_top_left(), order_);
return const_iterator(ws_, ref_.top_left(), order_);
}
cell_vector::const_iterator cell_vector::cend() const
{
if (order_ == major_order::row)
{
auto past_end = ref_.get_bottom_right();
past_end.set_column_index(past_end.get_column_index() + 1);
auto past_end = ref_.bottom_right();
past_end.column_index(past_end.column_index() + 1);
return const_iterator(ws_, past_end, order_);
}
auto past_end = ref_.get_bottom_right();
past_end.set_row(past_end.get_row() + 1);
auto past_end = ref_.bottom_right();
past_end.row(past_end.row() + 1);
return const_iterator(ws_, past_end, order_);
}
cell cell_vector::operator[](std::size_t cell_index)
{
return get_cell(cell_index);
}
std::size_t cell_vector::num_cells() const
{
if (order_ == major_order::row)
{
return ref_.get_width() + 1;
}
return ref_.get_height() + 1;
return cell(cell_index);
}
cell_vector::cell_vector(worksheet ws, const range_reference &reference, major_order order)
@ -89,35 +79,37 @@ cell cell_vector::front()
{
if (order_ == major_order::row)
{
return ws_.get_cell(ref_.get_top_left());
return ws_.cell(ref_.top_left());
}
return ws_.get_cell(ref_.get_top_left());
return ws_.cell(ref_.top_left());
}
cell cell_vector::back()
{
if (order_ == major_order::row)
{
return ws_.get_cell(ref_.get_bottom_right());
return ws_.cell(ref_.bottom_right());
}
return ws_.get_cell(ref_.get_bottom_right());
return ws_.cell(ref_.bottom_right());
}
cell cell_vector::get_cell(std::size_t index)
cell cell_vector::cell(std::size_t index)
{
if (order_ == major_order::row)
{
return ws_.get_cell(ref_.get_top_left().make_offset(static_cast<int>(index), 0));
return ws_.cell(ref_.top_left().make_offset(static_cast<int>(index), 0));
}
return ws_.get_cell(ref_.get_top_left().make_offset(0, static_cast<int>(index)));
return ws_.cell(ref_.top_left().make_offset(0, static_cast<int>(index)));
}
std::size_t cell_vector::length() const
{
return num_cells();
return order_ == major_order::row
? ref_.width() + 1
: ref_.height() + 1;
}
cell_vector::const_iterator cell_vector::begin() const

View File

@ -51,11 +51,11 @@ const_cell_iterator &const_cell_iterator::operator--()
{
if (order_ == major_order::row)
{
current_cell_.set_column_index(current_cell_.get_column_index() - 1);
current_cell_.column_index(current_cell_.column_index() - 1);
}
else
{
current_cell_.set_row(current_cell_.get_row() - 1);
current_cell_.row(current_cell_.row() - 1);
}
return *this;
@ -72,11 +72,11 @@ const_cell_iterator &const_cell_iterator::operator++()
{
if (order_ == major_order::row)
{
current_cell_.set_column_index(current_cell_.get_column_index() + 1);
current_cell_.column_index(current_cell_.column_index() + 1);
}
else
{
current_cell_.set_row(current_cell_.get_row() + 1);
current_cell_.row(current_cell_.row() + 1);
}
return *this;
@ -91,7 +91,7 @@ const_cell_iterator const_cell_iterator::operator++(int)
const cell const_cell_iterator::operator*() const
{
return ws_.get_cell(current_cell_);
return ws_.cell(current_cell_);
}
} // namespace xlnt

View File

@ -29,7 +29,7 @@
namespace xlnt {
const_range_iterator::const_range_iterator(const worksheet &ws, const range_reference &start_cell, major_order order)
: ws_(ws.d_), current_cell_(start_cell.get_top_left()), range_(start_cell), order_(order)
: ws_(ws.d_), current_cell_(start_cell.top_left()), range_(start_cell), order_(order)
{
}
@ -52,11 +52,11 @@ const_range_iterator &const_range_iterator::operator--()
{
if (order_ == major_order::row)
{
current_cell_.set_row(current_cell_.get_row() - 1);
current_cell_.row(current_cell_.row() - 1);
}
else
{
current_cell_.set_column_index(current_cell_.get_column_index() - 1);
current_cell_.column_index(current_cell_.column_index() - 1);
}
return *this;
@ -74,11 +74,11 @@ const_range_iterator &const_range_iterator::operator++()
{
if (order_ == major_order::row)
{
current_cell_.set_row(current_cell_.get_row() + 1);
current_cell_.row(current_cell_.row() + 1);
}
else
{
current_cell_.set_column_index(current_cell_.get_column_index() + 1);
current_cell_.column_index(current_cell_.column_index() + 1);
}
return *this;
@ -96,13 +96,13 @@ const cell_vector const_range_iterator::operator*() const
{
if (order_ == major_order::row)
{
range_reference reference(range_.get_top_left().get_column_index(), current_cell_.get_row(),
range_.get_bottom_right().get_column_index(), current_cell_.get_row());
range_reference reference(range_.top_left().column_index(), current_cell_.row(),
range_.bottom_right().column_index(), current_cell_.row());
return cell_vector(ws_, reference, order_);
}
range_reference reference(current_cell_.get_column_index(), range_.get_top_left().get_row(),
current_cell_.get_column_index(), range_.get_bottom_right().get_row());
range_reference reference(current_cell_.column_index(), range_.top_left().row(),
current_cell_.column_index(), range_.bottom_right().row());
return cell_vector(ws_, reference, order_);
}

View File

@ -25,25 +25,25 @@
namespace xlnt {
void footer::set_text(const std::string &text)
void footer::text(const std::string &text)
{
default_ = false;
text_ = text;
}
void footer::set_font_name(const std::string &font_name)
void footer::font_name(const std::string &font_name)
{
default_ = false;
font_name_ = font_name;
}
void footer::set_font_size(std::size_t font_size)
void footer::font_size(std::size_t font_size)
{
default_ = false;
font_size_ = font_size;
}
void footer::set_font_color(const std::string &font_color)
void footer::font_color(const std::string &font_color)
{
default_ = false;
font_color_ = font_color;

View File

@ -25,25 +25,25 @@
namespace xlnt {
void header::set_text(const std::string &text)
void header::text(const std::string &text)
{
default_ = false;
text_ = text;
}
void header::set_font_name(const std::string &font_name)
void header::font_name(const std::string &font_name)
{
default_ = false;
font_name_ = font_name;
}
void header::set_font_size(std::size_t font_size)
void header::font_size(std::size_t font_size)
{
default_ = false;
font_size_ = font_size;
}
void header::set_font_color(const std::string &font_color)
void header::font_color(const std::string &font_color)
{
default_ = false;
font_color_ = font_color;

View File

@ -25,27 +25,27 @@
namespace xlnt {
header &header_footer::get_left_header()
header &header_footer::left_header()
{
return left_header_;
}
header &header_footer::get_center_header()
header &header_footer::center_header()
{
return center_header_;
}
header &header_footer::get_right_header()
header &header_footer::right_header()
{
return right_header_;
}
footer &header_footer::get_left_footer()
footer &header_footer::left_footer()
{
return left_footer_;
}
footer &header_footer::get_center_footer()
footer &header_footer::center_footer()
{
return center_footer_;
}
footer &header_footer::get_right_footer()
footer &header_footer::right_footer()
{
return right_footer_;
}

View File

@ -29,62 +29,62 @@ page_margins::page_margins()
{
}
double page_margins::get_top() const
double page_margins::top() const
{
return top_;
}
void page_margins::set_top(double top)
void page_margins::top(double top)
{
top_ = top;
}
double page_margins::get_left() const
double page_margins::left() const
{
return left_;
}
void page_margins::set_left(double left)
void page_margins::left(double left)
{
left_ = left;
}
double page_margins::get_bottom() const
double page_margins::bottom() const
{
return bottom_;
}
void page_margins::set_bottom(double bottom)
void page_margins::bottom(double bottom)
{
bottom_ = bottom;
}
double page_margins::get_right() const
double page_margins::right() const
{
return right_;
}
void page_margins::set_right(double right)
void page_margins::right(double right)
{
right_ = right;
}
double page_margins::get_header() const
double page_margins::header() const
{
return header_;
}
void page_margins::set_header(double header)
void page_margins::header(double header)
{
header_ = header;
}
double page_margins::get_footer() const
double page_margins::footer() const
{
return footer_;
}
void page_margins::set_footer(double footer)
void page_margins::footer(double footer)
{
footer_ = footer;
}

View File

@ -39,42 +39,42 @@ page_setup::page_setup()
{
}
page_break page_setup::get_break() const
page_break page_setup::page_break() const
{
return break_;
}
void page_setup::set_break(page_break b)
void page_setup::page_break(enum page_break b)
{
break_ = b;
}
sheet_state page_setup::get_sheet_state() const
sheet_state page_setup::sheet_state() const
{
return sheet_state_;
}
void page_setup::set_sheet_state(sheet_state sheet_state)
void page_setup::sheet_state(enum sheet_state sheet_state)
{
sheet_state_ = sheet_state;
}
paper_size page_setup::get_paper_size() const
paper_size page_setup::paper_size() const
{
return paper_size_;
}
void page_setup::set_paper_size(paper_size paper_size)
void page_setup::paper_size(enum paper_size paper_size)
{
paper_size_ = paper_size;
}
orientation page_setup::get_orientation() const
orientation page_setup::orientation() const
{
return orientation_;
}
void page_setup::set_orientation(orientation orientation)
void page_setup::orientation(enum orientation orientation)
{
orientation_ = orientation;
}
@ -84,7 +84,7 @@ bool page_setup::fit_to_page() const
return fit_to_page_;
}
void page_setup::set_fit_to_page(bool fit_to_page)
void page_setup::fit_to_page(bool fit_to_page)
{
fit_to_page_ = fit_to_page;
}
@ -94,7 +94,7 @@ bool page_setup::fit_to_height() const
return fit_to_height_;
}
void page_setup::set_fit_to_height(bool fit_to_height)
void page_setup::fit_to_height(bool fit_to_height)
{
fit_to_height_ = fit_to_height;
}
@ -104,37 +104,37 @@ bool page_setup::fit_to_width() const
return fit_to_width_;
}
void page_setup::set_fit_to_width(bool fit_to_width)
void page_setup::fit_to_width(bool fit_to_width)
{
fit_to_width_ = fit_to_width;
}
void page_setup::set_horizontal_centered(bool horizontal_centered)
void page_setup::horizontal_centered(bool horizontal_centered)
{
horizontal_centered_ = horizontal_centered;
}
bool page_setup::get_horizontal_centered() const
bool page_setup::horizontal_centered() const
{
return horizontal_centered_;
}
void page_setup::set_vertical_centered(bool vertical_centered)
void page_setup::vertical_centered(bool vertical_centered)
{
vertical_centered_ = vertical_centered;
}
bool page_setup::get_vertical_centered() const
bool page_setup::vertical_centered() const
{
return vertical_centered_;
}
void page_setup::set_scale(double scale)
void page_setup::scale(double scale)
{
scale_ = scale;
}
double page_setup::get_scale() const
double page_setup::scale() const
{
return scale_;
}

View File

@ -40,10 +40,10 @@ range::~range()
cell_vector range::operator[](std::size_t index)
{
return get_vector(index);
return vector(index);
}
range_reference range::get_reference() const
range_reference range::reference() const
{
return ref_;
}
@ -52,10 +52,10 @@ std::size_t range::length() const
{
if (order_ == major_order::row)
{
return ref_.get_bottom_right().get_row() - ref_.get_top_left().get_row() + 1;
return ref_.bottom_right().row() - ref_.top_left().row() + 1;
}
return (ref_.get_bottom_right().get_column() - ref_.get_top_left().get_column()).index + 1;
return (ref_.bottom_right().column() - ref_.top_left().column()).index + 1;
}
bool range::operator==(const range &comparand) const
@ -63,51 +63,51 @@ bool range::operator==(const range &comparand) const
return ref_ == comparand.ref_ && ws_ == comparand.ws_ && order_ == comparand.order_;
}
cell_vector range::get_vector(std::size_t vector_index)
cell_vector range::vector(std::size_t vector_index)
{
if (order_ == major_order::row)
{
range_reference reference(
ref_.get_top_left().get_column_index(),
static_cast<row_t>(static_cast<std::size_t>(ref_.get_top_left().get_row()) + vector_index),
ref_.get_bottom_right().get_column_index(),
static_cast<row_t>(static_cast<std::size_t>(ref_.get_top_left().get_row()) + vector_index));
ref_.top_left().column_index(),
static_cast<row_t>(static_cast<std::size_t>(ref_.top_left().row()) + vector_index),
ref_.bottom_right().column_index(),
static_cast<row_t>(static_cast<std::size_t>(ref_.top_left().row()) + vector_index));
return cell_vector(ws_, reference, order_);
}
range_reference reference(
static_cast<column_t::index_t>(static_cast<std::size_t>(ref_.get_top_left().get_column().index) + vector_index),
ref_.get_top_left().get_row(),
static_cast<column_t::index_t>(static_cast<std::size_t>(ref_.get_top_left().get_column().index) + vector_index),
ref_.get_bottom_right().get_row());
static_cast<column_t::index_t>(static_cast<std::size_t>(ref_.top_left().column().index) + vector_index),
ref_.top_left().row(),
static_cast<column_t::index_t>(static_cast<std::size_t>(ref_.top_left().column().index) + vector_index),
ref_.bottom_right().row());
return cell_vector(ws_, reference, order_);
}
bool range::contains(const cell_reference &ref)
{
return ref_.get_top_left().get_column_index() <= ref.get_column_index() &&
ref_.get_bottom_right().get_column_index() >= ref.get_column_index() &&
ref_.get_top_left().get_row() <= ref.get_row() && ref_.get_bottom_right().get_row() >= ref.get_row();
return ref_.top_left().column_index() <= ref.column_index() &&
ref_.bottom_right().column_index() >= ref.column_index() &&
ref_.top_left().row() <= ref.row() && ref_.bottom_right().row() >= ref.row();
}
cell range::get_cell(const cell_reference &ref)
cell range::cell(const cell_reference &ref)
{
return (*this)[ref.get_row() - 1][ref.get_column().index - 1];
return (*this)[ref.row() - 1][ref.column().index - 1];
}
range::iterator range::begin()
{
if (order_ == major_order::row)
{
cell_reference top_right(ref_.get_bottom_right().get_column_index(), ref_.get_top_left().get_row());
range_reference row_range(ref_.get_top_left(), top_right);
cell_reference top_right(ref_.bottom_right().column_index(), ref_.top_left().row());
range_reference row_range(ref_.top_left(), top_right);
return iterator(ws_, row_range, ref_, order_);
}
cell_reference bottom_left(ref_.get_top_left().get_column_index(), ref_.get_bottom_right().get_row());
range_reference row_range(ref_.get_top_left(), bottom_left);
cell_reference bottom_left(ref_.top_left().column_index(), ref_.bottom_right().row());
range_reference row_range(ref_.top_left(), bottom_left);
return iterator(ws_, row_range, ref_, order_);
}
@ -115,15 +115,15 @@ range::iterator range::end()
{
if (order_ == major_order::row)
{
auto past_end_row_index = ref_.get_bottom_right().get_row() + 1;
cell_reference bottom_left(ref_.get_top_left().get_column_index(), past_end_row_index);
cell_reference bottom_right(ref_.get_bottom_right().get_column_index(), past_end_row_index);
auto past_end_row_index = ref_.bottom_right().row() + 1;
cell_reference bottom_left(ref_.top_left().column_index(), past_end_row_index);
cell_reference bottom_right(ref_.bottom_right().column_index(), past_end_row_index);
return iterator(ws_, range_reference(bottom_left, bottom_right), ref_, order_);
}
auto past_end_column_index = ref_.get_bottom_right().get_column_index() + 1;
cell_reference top_right(past_end_column_index, ref_.get_top_left().get_row());
cell_reference bottom_right(past_end_column_index, ref_.get_bottom_right().get_row());
auto past_end_column_index = ref_.bottom_right().column_index() + 1;
cell_reference top_right(past_end_column_index, ref_.top_left().row());
cell_reference bottom_right(past_end_column_index, ref_.bottom_right().row());
return iterator(ws_, range_reference(top_right, bottom_right), ref_, order_);
}
@ -131,13 +131,13 @@ range::const_iterator range::cbegin() const
{
if (order_ == major_order::row)
{
cell_reference top_right(ref_.get_bottom_right().get_column_index(), ref_.get_top_left().get_row());
range_reference row_range(ref_.get_top_left(), top_right);
cell_reference top_right(ref_.bottom_right().column_index(), ref_.top_left().row());
range_reference row_range(ref_.top_left(), top_right);
return const_iterator(ws_, row_range, order_);
}
cell_reference bottom_left(ref_.get_top_left().get_column_index(), ref_.get_bottom_right().get_row());
range_reference row_range(ref_.get_top_left(), bottom_left);
cell_reference bottom_left(ref_.top_left().column_index(), ref_.bottom_right().row());
range_reference row_range(ref_.top_left(), bottom_left);
return const_iterator(ws_, row_range, order_);
}
@ -145,15 +145,15 @@ range::const_iterator range::cend() const
{
if (order_ == major_order::row)
{
auto past_end_row_index = ref_.get_bottom_right().get_row() + 1;
cell_reference bottom_left(ref_.get_top_left().get_column_index(), past_end_row_index);
cell_reference bottom_right(ref_.get_bottom_right().get_column_index(), past_end_row_index);
auto past_end_row_index = ref_.bottom_right().row() + 1;
cell_reference bottom_left(ref_.top_left().column_index(), past_end_row_index);
cell_reference bottom_right(ref_.bottom_right().column_index(), past_end_row_index);
return const_iterator(ws_, range_reference(bottom_left, bottom_right), order_);
}
auto past_end_column_index = ref_.get_bottom_right().get_column_index() + 1;
cell_reference top_right(past_end_column_index, ref_.get_top_left().get_row());
cell_reference bottom_right(past_end_column_index, ref_.get_bottom_right().get_row());
auto past_end_column_index = ref_.bottom_right().column_index() + 1;
cell_reference top_right(past_end_column_index, ref_.top_left().row());
cell_reference bottom_right(past_end_column_index, ref_.bottom_right().row());
return const_iterator(ws_, range_reference(top_right, bottom_right), order_);
}

View File

@ -32,18 +32,18 @@ cell_vector range_iterator::operator*() const
{
if (order_ == major_order::row)
{
range_reference reference(range_.get_top_left().get_column_index(), current_cell_.get_row(),
range_.get_bottom_right().get_column_index(), current_cell_.get_row());
range_reference reference(range_.top_left().column_index(), current_cell_.row(),
range_.bottom_right().column_index(), current_cell_.row());
return cell_vector(ws_, reference, order_);
}
range_reference reference(current_cell_.get_column_index(), range_.get_top_left().get_row(),
current_cell_.get_column_index(), range_.get_bottom_right().get_row());
range_reference reference(current_cell_.column_index(), range_.top_left().row(),
current_cell_.column_index(), range_.bottom_right().row());
return cell_vector(ws_, reference, order_);
}
range_iterator::range_iterator(worksheet &ws, const range_reference &start_cell, const range_reference &limits, major_order order)
: ws_(ws), current_cell_(start_cell.get_top_left()), range_(limits), order_(order)
: ws_(ws), current_cell_(start_cell.top_left()), range_(limits), order_(order)
{
}
@ -66,11 +66,11 @@ range_iterator &range_iterator::operator--()
{
if (order_ == major_order::row)
{
current_cell_.set_row(current_cell_.get_row() - 1);
current_cell_.row(current_cell_.row() - 1);
}
else
{
current_cell_.set_column_index(current_cell_.get_column_index() - 1);
current_cell_.column_index(current_cell_.column_index() - 1);
}
return *this;
@ -91,22 +91,22 @@ range_iterator &range_iterator::operator++()
bool any_non_null = false;
do
{
current_cell_.set_row(current_cell_.get_row() + 1);
current_cell_.row(current_cell_.row() + 1);
any_non_null = false;
for (auto column = current_cell_.get_column(); column <= range_.get_bottom_right().get_column(); column++)
for (auto column = current_cell_.column(); column <= range_.bottom_right().column(); column++)
{
if (ws_.has_cell(cell_reference(column, current_cell_.get_row())))
if (ws_.has_cell(cell_reference(column, current_cell_.row())))
{
any_non_null = true;
break;
}
}
}
while (!any_non_null && current_cell_.get_row() <= range_.get_bottom_right().get_row());
while (!any_non_null && current_cell_.row() <= range_.bottom_right().row());
}
else
{
current_cell_.set_column_index(current_cell_.get_column_index() + 1);
current_cell_.column_index(current_cell_.column_index() + 1);
}
return *this;

View File

@ -75,19 +75,19 @@ range_reference range_reference::make_offset(int column_offset, int row_offset)
bottom_right_.make_offset(column_offset, row_offset));
}
std::size_t range_reference::get_height() const
std::size_t range_reference::height() const
{
return bottom_right_.get_row() - top_left_.get_row();
return bottom_right_.row() - top_left_.row();
}
std::size_t range_reference::get_width() const
std::size_t range_reference::width() const
{
return (bottom_right_.get_column() - top_left_.get_column()).index;
return (bottom_right_.column() - top_left_.column()).index;
}
bool range_reference::is_single_cell() const
{
return get_width() == 0 && get_height() == 0;
return width() == 0 && height() == 0;
}
std::string range_reference::to_string() const
@ -105,19 +105,19 @@ bool range_reference::operator!=(const range_reference &comparand) const
return comparand.top_left_ != top_left_ || comparand.bottom_right_ != bottom_right_;
}
cell_reference range_reference::get_top_left() const
cell_reference range_reference::top_left() const
{
return top_left_;
}
cell_reference range_reference::get_bottom_right() const
cell_reference range_reference::bottom_right() const
{
return bottom_right_;
}
cell_reference &range_reference::get_top_left()
cell_reference &range_reference::top_left()
{
return top_left_;
}
cell_reference &range_reference::get_bottom_right()
cell_reference &range_reference::bottom_right()
{
return bottom_right_;
}

View File

@ -41,12 +41,12 @@ std::string int_to_hex(T i)
namespace xlnt {
void sheet_protection::set_password(const std::string &password)
void sheet_protection::password(const std::string &password)
{
hashed_password_ = hash_password(password);
}
std::string sheet_protection::get_hashed_password() const
std::string sheet_protection::hashed_password() const
{
return hashed_password_;
}

View File

@ -12,32 +12,32 @@ public:
{
xlnt::page_setup ps;
TS_ASSERT_EQUALS(ps.get_paper_size(), xlnt::paper_size::letter);
ps.set_paper_size(xlnt::paper_size::executive);
TS_ASSERT_EQUALS(ps.get_paper_size(), xlnt::paper_size::executive);
TS_ASSERT_EQUALS(ps.paper_size(), xlnt::paper_size::letter);
ps.paper_size(xlnt::paper_size::executive);
TS_ASSERT_EQUALS(ps.paper_size(), xlnt::paper_size::executive);
TS_ASSERT_EQUALS(ps.get_orientation(), xlnt::orientation::portrait);
ps.set_orientation(xlnt::orientation::landscape);
TS_ASSERT_EQUALS(ps.get_orientation(), xlnt::orientation::landscape);
TS_ASSERT_EQUALS(ps.orientation(), xlnt::orientation::portrait);
ps.orientation(xlnt::orientation::landscape);
TS_ASSERT_EQUALS(ps.orientation(), xlnt::orientation::landscape);
TS_ASSERT(!ps.fit_to_page());
ps.set_fit_to_page(true);
ps.fit_to_page(true);
TS_ASSERT(ps.fit_to_page());
TS_ASSERT(!ps.fit_to_height());
ps.set_fit_to_height(true);
ps.fit_to_height(true);
TS_ASSERT(ps.fit_to_height());
TS_ASSERT(!ps.fit_to_width());
ps.set_fit_to_width(true);
ps.fit_to_width(true);
TS_ASSERT(ps.fit_to_width());
TS_ASSERT(!ps.get_horizontal_centered());
ps.set_horizontal_centered(true);
TS_ASSERT(ps.get_horizontal_centered());
TS_ASSERT(!ps.horizontal_centered());
ps.horizontal_centered(true);
TS_ASSERT(ps.horizontal_centered());
TS_ASSERT(!ps.get_vertical_centered());
ps.set_vertical_centered(true);
TS_ASSERT(ps.get_vertical_centered());
TS_ASSERT(!ps.vertical_centered());
ps.vertical_centered(true);
TS_ASSERT(ps.vertical_centered());
}
};

File diff suppressed because it is too large Load Diff

View File

@ -64,12 +64,15 @@ worksheet::worksheet(const worksheet &rhs) : d_(rhs.d_)
bool worksheet::has_frozen_panes() const
{
return get_frozen_panes() != cell_reference("A1");
return !d_->views_.empty()
&& d_->views_.front().has_pane()
&& (d_->views_.front().pane().state == pane_state::frozen
|| d_->views_.front().pane().state == pane_state::frozen_split);
}
std::string worksheet::unique_sheet_name(const std::string &value) const
{
auto names = get_workbook().get_sheet_titles();
auto names = workbook().sheet_titles();
auto match = std::find(names.begin(), names.end(), value);
std::size_t append = 0;
@ -109,20 +112,20 @@ void worksheet::create_named_range(const std::string &name, const range_referenc
std::vector<named_range::target> targets;
targets.push_back({ *this, reference });
d_->named_ranges_[name] = named_range(name, targets);
d_->named_ranges_[name] = xlnt::named_range(name, targets);
}
range worksheet::operator()(const xlnt::cell_reference &top_left, const xlnt::cell_reference &bottom_right)
{
return get_range(range_reference(top_left, bottom_right));
return range(range_reference(top_left, bottom_right));
}
cell worksheet::operator[](const cell_reference &ref)
{
return get_cell(ref);
return cell(ref);
}
std::vector<range_reference> worksheet::get_merged_ranges() const
std::vector<range_reference> worksheet::merged_ranges() const
{
return d_->merged_cells_;
}
@ -137,12 +140,12 @@ bool worksheet::has_page_setup() const
return d_->has_page_setup_;
}
page_margins worksheet::get_page_margins() const
page_margins worksheet::page_margins() const
{
return d_->page_margins_;
}
void worksheet::set_page_margins(const page_margins &margins)
void worksheet::page_margins(const class page_margins &margins)
{
d_->page_margins_ = margins;
d_->has_page_margins_ = true;
@ -160,31 +163,31 @@ void worksheet::auto_filter(const range_reference &reference)
void worksheet::auto_filter(const xlnt::range &range)
{
auto_filter(range.get_reference());
auto_filter(range.reference());
}
range_reference worksheet::get_auto_filter() const
range_reference worksheet::auto_filter() const
{
return d_->auto_filter_;
}
bool worksheet::has_auto_filter() const
{
return d_->auto_filter_.get_width() > 0;
return d_->auto_filter_.width() > 0;
}
void worksheet::unset_auto_filter()
void worksheet::clear_auto_filter()
{
d_->auto_filter_ = range_reference(1, 1, 1, 1);
}
void worksheet::set_page_setup(const page_setup &setup)
void worksheet::page_setup(const struct page_setup &setup)
{
d_->has_page_setup_ = true;
d_->page_setup_ = setup;
}
page_setup worksheet::get_page_setup() const
page_setup worksheet::page_setup() const
{
if (!d_->has_page_setup_)
{
@ -199,12 +202,12 @@ std::string worksheet::to_string() const
return "<Worksheet \"" + d_->title_ + "\">";
}
workbook &worksheet::get_workbook()
workbook &worksheet::workbook()
{
return *d_->parent_;
}
const workbook &worksheet::get_workbook() const
const workbook &worksheet::workbook() const
{
return *d_->parent_;
}
@ -219,7 +222,7 @@ void worksheet::garbage_collect()
while (cell_iter != cell_map_iter->second.end())
{
cell current_cell(&cell_iter->second);
class cell current_cell(&cell_iter->second);
if (current_cell.garbage_collectible())
{
@ -240,22 +243,22 @@ void worksheet::garbage_collect()
}
}
void worksheet::set_id(std::size_t id)
void worksheet::id(std::size_t id)
{
d_->id_ = id;
}
std::size_t worksheet::get_id() const
std::size_t worksheet::id() const
{
return d_->id_;
}
std::string worksheet::get_title() const
std::string worksheet::title() const
{
return d_->title_;
}
void worksheet::set_title(const std::string &title)
void worksheet::title(const std::string &title)
{
if (title.length() > 31)
{
@ -267,119 +270,145 @@ void worksheet::set_title(const std::string &title)
throw invalid_sheet_title(title);
}
auto same_title = std::find_if(get_workbook().begin(), get_workbook().end(),
[&](worksheet ws) { return ws.get_title() == title; });
auto same_title = std::find_if(workbook().begin(), workbook().end(),
[&](worksheet ws) { return ws.title() == title; });
if (same_title != get_workbook().end() && *same_title != *this)
if (same_title != workbook().end() && *same_title != *this)
{
throw invalid_sheet_title(title);
}
get_workbook().d_->sheet_title_rel_id_map_[title] =
get_workbook().d_->sheet_title_rel_id_map_[d_->title_];
get_workbook().d_->sheet_title_rel_id_map_.erase(d_->title_);
workbook().d_->sheet_title_rel_id_map_[title] =
workbook().d_->sheet_title_rel_id_map_[d_->title_];
workbook().d_->sheet_title_rel_id_map_.erase(d_->title_);
d_->title_ = title;
}
cell_reference worksheet::get_frozen_panes() const
cell_reference worksheet::frozen_panes() const
{
return d_->view_.get_pane().top_left_cell;
if (!has_frozen_panes())
{
throw xlnt::invalid_attribute();
}
return d_->views_.front().pane().top_left_cell.get();
}
void worksheet::freeze_panes(xlnt::cell top_left_cell)
{
freeze_panes(top_left_cell.get_reference().to_string());
freeze_panes(top_left_cell.reference());
}
void worksheet::freeze_panes(const std::string &top_left_coordinate)
void worksheet::freeze_panes(const cell_reference &ref)
{
auto ref = cell_reference(top_left_coordinate);
d_->view_.get_pane().top_left_cell = ref;
d_->view_.get_pane().state = pane_state::frozen;
d_->view_.get_selections().clear();
d_->view_.get_selections().push_back(selection());
if (ref.get_column_index() == 1
&& ref.get_row() == 1)
if (!has_view())
{
d_->view_.get_selections().back().set_pane(pane_corner::top_left);
d_->view_.get_pane().active_pane = pane_corner::top_left;
d_->view_.get_pane().state = pane_state::normal;
d_->views_.push_back(sheet_view());
}
else if (ref.get_column_index() == 1)
auto &primary_view = d_->views_.front();
if (!primary_view.has_pane())
{
d_->view_.get_selections().back().set_pane(pane_corner::bottom_left);
d_->view_.get_pane().active_pane = pane_corner::bottom_left;
d_->view_.get_pane().y_split = ref.get_row() - 1;
primary_view.pane(pane());
}
else if (ref.get_row() == 1)
primary_view.pane().top_left_cell = ref;
primary_view.pane().state = pane_state::frozen;
primary_view.clear_selections();
primary_view.add_selection(selection());
if (ref == "A1")
{
d_->view_.get_selections().back().set_pane(pane_corner::top_right);
d_->view_.get_pane().active_pane = pane_corner::top_right;
d_->view_.get_pane().x_split = ref.get_column_index().index - 1;
unfreeze_panes();
}
else if (ref.column() == "A")
{
primary_view.add_selection(selection());
primary_view.selection(0).pane(pane_corner::bottom_left);
primary_view.selection(0).active_cell(ref.make_offset(0, -1)); // cell above
primary_view.selection(1).active_cell(ref);
primary_view.pane().active_pane = pane_corner::bottom_left;
primary_view.pane().y_split = ref.row() - 1;
}
else if (ref.row() == 1)
{
primary_view.add_selection(selection());
primary_view.selection(0).pane(pane_corner::top_right);
primary_view.selection(0).active_cell(ref.make_offset(-1, 0)); // cell to the left
primary_view.selection(1).active_cell(ref);
primary_view.pane().active_pane = pane_corner::top_right;
primary_view.pane().x_split = ref.column_index() - 1;
}
else
{
d_->view_.get_selections().push_back(selection());
d_->view_.get_selections().push_back(selection());
d_->view_.get_selections()[0].set_pane(pane_corner::top_right);
d_->view_.get_selections()[1].set_pane(pane_corner::bottom_left);
d_->view_.get_selections()[2].set_pane(pane_corner::bottom_right);
d_->view_.get_pane().active_pane = pane_corner::bottom_right;
d_->view_.get_pane().x_split = ref.get_column_index().index - 1;
d_->view_.get_pane().y_split = ref.get_row() - 1;
primary_view.add_selection(selection());
primary_view.add_selection(selection());
primary_view.selection(0).pane(pane_corner::top_right);
primary_view.selection(0).active_cell(ref.make_offset(0, -1)); // cell above
primary_view.selection(1).pane(pane_corner::bottom_left);
primary_view.selection(1).active_cell(ref.make_offset(-1, 0)); // cell to the left
primary_view.selection(2).pane(pane_corner::bottom_right);
primary_view.selection(2).active_cell(ref);
primary_view.pane().active_pane = pane_corner::bottom_right;
primary_view.pane().x_split = ref.column_index() - 1;
primary_view.pane().y_split = ref.row() - 1;
}
}
void worksheet::unfreeze_panes()
{
d_->view_.get_pane().top_left_cell = cell_reference("A1");
d_->view_.get_pane().state = pane_state::normal;
if (!has_view()) return;
auto &primary_view = d_->views_.front();
primary_view.clear_selections();
primary_view.clear_pane();
}
cell worksheet::get_cell(column_t column, row_t row)
cell worksheet::cell(column_t column, row_t row)
{
return get_cell(cell_reference(column, row));
return cell(cell_reference(column, row));
}
const cell worksheet::get_cell(column_t column, row_t row) const
const cell worksheet::cell(column_t column, row_t row) const
{
return get_cell(cell_reference(column, row));
return cell(cell_reference(column, row));
}
cell worksheet::get_cell(const cell_reference &reference)
cell worksheet::cell(const cell_reference &reference)
{
if (d_->cell_map_.find(reference.get_row()) == d_->cell_map_.end())
if (d_->cell_map_.find(reference.row()) == d_->cell_map_.end())
{
d_->cell_map_[reference.get_row()] = std::unordered_map<column_t, detail::cell_impl>();
d_->cell_map_[reference.row()] = std::unordered_map<column_t, detail::cell_impl>();
}
auto &row = d_->cell_map_[reference.get_row()];
auto &row = d_->cell_map_[reference.row()];
if (row.find(reference.get_column_index()) == row.end())
if (row.find(reference.column_index()) == row.end())
{
auto &impl = row[reference.get_column_index()] = detail::cell_impl();
auto &impl = row[reference.column_index()] = detail::cell_impl();
impl.parent_ = d_;
impl.column_ = reference.get_column_index();
impl.row_ = reference.get_row();
impl.column_ = reference.column_index();
impl.row_ = reference.row();
}
return cell(&row[reference.get_column_index()]);
return xlnt::cell(&row[reference.column_index()]);
}
const cell worksheet::get_cell(const cell_reference &reference) const
const cell worksheet::cell(const cell_reference &reference) const
{
return cell(&d_->cell_map_.at(reference.get_row()).at(reference.get_column_index()));
return xlnt::cell(&d_->cell_map_.at(reference.row()).at(reference.column_index()));
}
bool worksheet::has_cell(const cell_reference &reference) const
{
const auto row = d_->cell_map_.find(reference.get_row());
const auto row = d_->cell_map_.find(reference.row());
if(row == d_->cell_map_.cend())
return false;
const auto col = row->second.find(reference.get_column_index());
const auto col = row->second.find(reference.column_index());
if(col == row->second.cend())
return false;
@ -391,9 +420,9 @@ 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::named_range(const std::string &name)
{
if (!get_workbook().has_named_range(name))
if (!workbook().has_named_range(name))
{
throw key_not_found();
}
@ -403,10 +432,10 @@ range worksheet::get_named_range(const std::string &name)
throw key_not_found();
}
return get_range(d_->named_ranges_[name].get_targets()[0].second);
return range(d_->named_ranges_[name].targets()[0].second);
}
column_t worksheet::get_lowest_column() const
column_t worksheet::lowest_column() const
{
if (d_->cell_map_.empty())
{
@ -426,7 +455,7 @@ column_t worksheet::get_lowest_column() const
return lowest;
}
row_t worksheet::get_lowest_row() const
row_t worksheet::lowest_row() const
{
if (d_->cell_map_.empty())
{
@ -443,7 +472,7 @@ row_t worksheet::get_lowest_row() const
return lowest;
}
row_t worksheet::get_highest_row() const
row_t worksheet::highest_row() const
{
row_t highest = constants::min_row();
@ -455,7 +484,7 @@ row_t worksheet::get_highest_row() const
return highest;
}
column_t worksheet::get_highest_column() const
column_t worksheet::highest_column() const
{
column_t highest = constants::min_column();
@ -482,33 +511,27 @@ bool worksheet::has_format_properties() const
range_reference worksheet::calculate_dimension() const
{
auto lowest_column = get_lowest_column();
auto lowest_row = get_lowest_row();
auto highest_column = get_highest_column();
auto highest_row = get_highest_row();
return range_reference(lowest_column, lowest_row, highest_column, highest_row);
return range_reference(lowest_column(), lowest_row(), highest_column(), highest_row());
}
range worksheet::get_range(const std::string &reference_string)
range worksheet::range(const std::string &reference_string)
{
return get_range(range_reference(reference_string));
return range(range_reference(reference_string));
}
range worksheet::get_range(const range_reference &reference)
range worksheet::range(const range_reference &reference)
{
return range(*this, reference);
return xlnt::range(*this, reference);
}
const range worksheet::get_range(const std::string &reference_string) const
const range worksheet::range(const std::string &reference_string) const
{
return get_range(range_reference(reference_string));
return range(range_reference(reference_string));
}
const range worksheet::get_range(const range_reference &reference) const
const range worksheet::range(const range_reference &reference) const
{
return range(*this, reference);
return xlnt::range(*this, reference);
}
void worksheet::merge_cells(const std::string &reference_string)
@ -526,17 +549,17 @@ void worksheet::merge_cells(const range_reference &reference)
d_->merged_cells_.push_back(reference);
bool first = true;
for (auto row : get_range(reference))
for (auto row : range(reference))
{
for (auto cell : row)
{
cell.set_merged(true);
cell.merged(true);
if (!first)
{
if (cell.get_data_type() == cell::type::string)
if (cell.data_type() == cell::type::string)
{
cell.set_value("");
cell.value("");
}
else
{
@ -565,11 +588,11 @@ void worksheet::unmerge_cells(const range_reference &reference)
d_->merged_cells_.erase(match);
for (auto row : get_range(reference))
for (auto row : range(reference))
{
for (auto cell : row)
{
cell.set_merged(false);
cell.merged(false);
}
}
}
@ -581,23 +604,23 @@ void worksheet::unmerge_cells(column_t start_column, row_t start_row, column_t e
void worksheet::append()
{
get_cell(cell_reference(1, get_next_row()));
cell(cell_reference(1, next_row()));
}
void worksheet::append(const std::vector<std::string> &cells)
{
xlnt::cell_reference next(1, get_next_row());
xlnt::cell_reference next(1, next_row());
for (auto cell : cells)
{
get_cell(next).set_value(cell);
next.set_column_index(next.get_column_index() + 1);
this->cell(next).value(cell);
next.column_index(next.column_index() + 1);
}
}
row_t worksheet::get_next_row() const
row_t worksheet::next_row() const
{
auto row = get_highest_row() + 1;
auto row = highest_row() + 1;
if (row == 2 && d_->cell_map_.size() == 0)
{
@ -609,71 +632,71 @@ row_t worksheet::get_next_row() const
void worksheet::append(const std::vector<int> &cells)
{
xlnt::cell_reference next(1, get_next_row());
xlnt::cell_reference next(1, next_row());
for (auto cell : cells)
{
get_cell(next).set_value(cell);
next.set_column_index(next.get_column_index() + 1);
this->cell(next).value(cell);
next.column_index(next.column_index() + 1);
}
}
void worksheet::append(const std::unordered_map<std::string, std::string> &cells)
{
auto row = get_next_row();
auto row = next_row();
for (auto cell : cells)
{
get_cell(cell_reference(cell.first, row)).set_value(cell.second);
this->cell(cell_reference(cell.first, row)).value(cell.second);
}
}
void worksheet::append(const std::unordered_map<int, std::string> &cells)
{
auto row = get_next_row();
auto row = next_row();
for (auto cell : cells)
{
get_cell(cell_reference(static_cast<column_t::index_t>(cell.first), row)).set_value(cell.second);
this->cell(cell_reference(static_cast<column_t::index_t>(cell.first), row)).value(cell.second);
}
}
void worksheet::append(const std::vector<int>::const_iterator begin, const std::vector<int>::const_iterator end)
{
xlnt::cell_reference next(1, get_next_row());
xlnt::cell_reference next(1, next_row());
for (auto i = begin; i != end; i++)
{
get_cell(next).set_value(*i);
next.set_column_index(next.get_column_index() + 1);
cell(next).value(*i);
next.column_index(next.column_index() + 1);
}
}
xlnt::range worksheet::rows() const
{
return get_range(calculate_dimension());
return range(calculate_dimension());
}
xlnt::range worksheet::rows(const std::string &range_string) const
{
return get_range(range_reference(range_string));
return range(range_reference(range_string));
}
xlnt::range worksheet::rows(const std::string &range_string, int row_offset, int column_offset) const
{
range_reference reference(range_string);
return get_range(reference.make_offset(column_offset, row_offset));
return range(reference.make_offset(column_offset, row_offset));
}
xlnt::range worksheet::rows(int row_offset, int column_offset) const
{
range_reference reference(calculate_dimension());
return get_range(reference.make_offset(column_offset, row_offset));
return range(reference.make_offset(column_offset, row_offset));
}
xlnt::range worksheet::columns() const
{
return range(*this, calculate_dimension(), major_order::column);
return xlnt::range(*this, calculate_dimension(), major_order::column);
}
bool worksheet::operator==(const worksheet &other) const
@ -707,13 +730,13 @@ bool worksheet::compare(const worksheet &other, bool reference) const
xlnt::cell this_cell(&cell.second);
xlnt::cell other_cell(&other.d_->cell_map_[row.first][cell.first]);
if (this_cell.get_data_type() != other_cell.get_data_type())
if (this_cell.data_type() != other_cell.data_type())
{
return false;
}
if (this_cell.get_data_type() == xlnt::cell::type::numeric
&& std::fabs(this_cell.get_value<long double>() - other_cell.get_value<long double>()) > 0.L)
if (this_cell.data_type() == xlnt::cell::type::numeric
&& std::fabs(this_cell.value<long double>() - other_cell.value<long double>()) > 0.L)
{
return false;
}
@ -724,7 +747,7 @@ bool worksheet::compare(const worksheet &other, bool reference) const
if(d_->auto_filter_ == other.d_->auto_filter_
&& d_->comment_count_ == other.d_->comment_count_
&& d_->view_.get_pane().top_left_cell == other.d_->view_.get_pane().top_left_cell
&& d_->views_ == other.d_->views_
&& d_->merged_cells_ == other.d_->merged_cells_
&& d_->relationships_ == other.d_->relationships_)
{
@ -756,21 +779,21 @@ void worksheet::operator=(const worksheet &other)
const cell worksheet::operator[](const cell_reference &ref) const
{
return get_cell(ref);
return cell(ref);
}
range worksheet::operator[](const range_reference &ref)
{
return get_range(ref);
return range(ref);
}
range worksheet::operator[](const std::string &name)
{
if (has_named_range(name))
{
return get_named_range(name);
return named_range(name);
}
return get_range(range_reference(name));
return range(range_reference(name));
}
bool worksheet::has_named_range(const std::string &name)
@ -803,17 +826,17 @@ void worksheet::decrement_comments()
d_->comment_count_--;
}
std::size_t worksheet::get_comment_count() const
std::size_t worksheet::comment_count() const
{
return d_->comment_count_;
}
header_footer &worksheet::get_header_footer()
header_footer &worksheet::header_footer()
{
return d_->header_footer_;
}
const header_footer &worksheet::get_header_footer() const
const header_footer &worksheet::header_footer() const
{
return d_->header_footer_;
}
@ -830,17 +853,17 @@ footer::footer() : default_(true), font_size_(12)
{
}
void worksheet::set_parent(xlnt::workbook &wb)
void worksheet::parent(xlnt::workbook &wb)
{
d_->parent_ = &wb;
}
std::vector<std::string> worksheet::get_formula_attributes() const
std::vector<std::string> worksheet::formula_attributes() const
{
return {};
}
cell_reference worksheet::get_point_pos(int left, int top) const
cell_reference worksheet::point_pos(int left, int top) const
{
static const auto DefaultColumnWidth = 51.85L;
static const auto DefaultRowHeight = 15.0L;
@ -865,7 +888,7 @@ cell_reference worksheet::get_point_pos(int left, int top) const
if (has_column_properties(current_column))
{
auto cdw = get_column_properties(current_column).width;
auto cdw = column_properties(current_column).width;
if (cdw >= 0)
{
@ -883,7 +906,7 @@ cell_reference worksheet::get_point_pos(int left, int top) const
if (has_row_properties(current_row))
{
auto cdh = get_row_properties(current_row).height;
auto cdh = row_properties(current_row).height;
if (cdh >= 0)
{
@ -898,19 +921,19 @@ cell_reference worksheet::get_point_pos(int left, int top) const
return { current_column - 1, current_row - 1 };
}
cell_reference worksheet::get_point_pos(const std::pair<int, int> &point) const
cell_reference worksheet::point_pos(const std::pair<int, int> &point) const
{
return get_point_pos(point.first, point.second);
return point_pos(point.first, point.second);
}
void worksheet::set_sheet_state(sheet_state state)
void worksheet::sheet_state(enum sheet_state state)
{
get_page_setup().set_sheet_state(state);
page_setup().sheet_state(state);
}
sheet_state worksheet::get_sheet_state() const
sheet_state worksheet::sheet_state() const
{
return get_page_setup().get_sheet_state();
return page_setup().sheet_state();
}
void worksheet::add_column_properties(column_t column, const xlnt::column_properties &props)
@ -923,22 +946,22 @@ bool worksheet::has_column_properties(column_t column) const
return d_->column_properties_.find(column) != d_->column_properties_.end();
}
column_properties &worksheet::get_column_properties(column_t column)
column_properties &worksheet::column_properties(column_t column)
{
return d_->column_properties_[column];
}
const column_properties &worksheet::get_column_properties(column_t column) const
const column_properties &worksheet::column_properties(column_t column) const
{
return d_->column_properties_.at(column);
}
row_properties &worksheet::get_row_properties(row_t row)
row_properties &worksheet::row_properties(row_t row)
{
return d_->row_properties_[row];
}
const row_properties &worksheet::get_row_properties(row_t row) const
const row_properties &worksheet::row_properties(row_t row) const
{
return d_->row_properties_.at(row);
}
@ -946,8 +969,8 @@ const row_properties &worksheet::get_row_properties(row_t row) const
worksheet::iterator worksheet::begin()
{
auto dimensions = calculate_dimension();
cell_reference top_right(dimensions.get_bottom_right().get_column_index(), dimensions.get_top_left().get_row());
range_reference row_range(dimensions.get_top_left(), top_right);
cell_reference top_right(dimensions.bottom_right().column_index(), dimensions.top_left().row());
range_reference row_range(dimensions.top_left(), top_right);
return iterator(*this, row_range, dimensions, major_order::row);
}
@ -955,9 +978,9 @@ worksheet::iterator worksheet::begin()
worksheet::iterator worksheet::end()
{
auto dimensions = calculate_dimension();
auto past_end_row_index = dimensions.get_bottom_right().get_row() + 1;
cell_reference bottom_left(dimensions.get_top_left().get_column_index(), past_end_row_index);
cell_reference bottom_right(dimensions.get_bottom_right().get_column_index(), past_end_row_index);
auto past_end_row_index = dimensions.bottom_right().row() + 1;
cell_reference bottom_left(dimensions.top_left().column_index(), past_end_row_index);
cell_reference bottom_right(dimensions.bottom_right().column_index(), past_end_row_index);
return iterator(*this, range_reference(bottom_left, bottom_right), dimensions, major_order::row);
}
@ -965,8 +988,8 @@ worksheet::iterator worksheet::end()
worksheet::const_iterator worksheet::cbegin() const
{
auto dimensions = calculate_dimension();
cell_reference top_right(dimensions.get_bottom_right().get_column_index(), dimensions.get_top_left().get_row());
range_reference row_range(dimensions.get_top_left(), top_right);
cell_reference top_right(dimensions.bottom_right().column_index(), dimensions.top_left().row());
range_reference row_range(dimensions.top_left(), top_right);
return const_iterator(*this, row_range, major_order::row);
}
@ -974,9 +997,9 @@ worksheet::const_iterator worksheet::cbegin() const
worksheet::const_iterator worksheet::cend() const
{
auto dimensions = calculate_dimension();
auto past_end_row_index = dimensions.get_bottom_right().get_row() + 1;
cell_reference bottom_left(dimensions.get_top_left().get_column_index(), past_end_row_index);
cell_reference bottom_right(dimensions.get_bottom_right().get_column_index(), past_end_row_index);
auto past_end_row_index = dimensions.bottom_right().row() + 1;
cell_reference bottom_left(dimensions.top_left().column_index(), past_end_row_index);
cell_reference bottom_right(dimensions.bottom_right().column_index(), past_end_row_index);
return const_iterator(*this, range_reference(bottom_left, bottom_right), major_order::row);
}
@ -993,30 +1016,30 @@ worksheet::const_iterator worksheet::end() const
range worksheet::iter_cells(bool skip_null)
{
return range(*this, calculate_dimension(), major_order::row, skip_null);
return xlnt::range(*this, calculate_dimension(), major_order::row, skip_null);
}
void worksheet::set_print_title_rows(row_t last_row)
void worksheet::print_title_rows(row_t last_row)
{
set_print_title_rows(1, last_row);
print_title_rows(1, last_row);
}
void worksheet::set_print_title_rows(row_t first_row, row_t last_row)
void worksheet::print_title_rows(row_t first_row, row_t last_row)
{
d_->print_title_rows_ = std::to_string(first_row) + ":" + std::to_string(last_row);
}
void worksheet::set_print_title_cols(column_t last_column)
void worksheet::print_title_cols(column_t last_column)
{
set_print_title_cols(1, last_column);
print_title_cols(1, last_column);
}
void worksheet::set_print_title_cols(column_t first_column, column_t last_column)
void worksheet::print_title_cols(column_t first_column, column_t last_column)
{
d_->print_title_cols_ = first_column.column_string() + ":" + last_column.column_string();
}
std::string worksheet::get_print_titles() const
std::string worksheet::print_titles() const
{
if (!d_->print_title_rows_.empty() && !d_->print_title_cols_.empty())
{
@ -1032,44 +1055,34 @@ std::string worksheet::get_print_titles() const
}
}
void worksheet::set_print_area(const std::string &print_area)
void worksheet::print_area(const std::string &print_area)
{
d_->print_area_ = range_reference::make_absolute(range_reference(print_area));
}
range_reference worksheet::get_print_area() const
range_reference worksheet::print_area() const
{
return d_->print_area_;
}
bool worksheet::has_view() const
{
return d_->has_view_;
return !d_->views_.empty();
}
sheet_view worksheet::get_view() const
sheet_view worksheet::view(std::size_t index) const
{
return d_->view_;
return d_->views_.at(index);
}
bool worksheet::x14ac_enabled() const
void worksheet::add_view(const sheet_view &new_view)
{
return d_->x14ac_;
}
void worksheet::enable_x14ac()
{
d_->x14ac_ = true;
}
void worksheet::disable_x14ac()
{
d_->x14ac_ = false;
d_->views_.push_back(new_view);
}
void worksheet::register_comments_in_manifest()
{
get_workbook().register_comments_in_manifest(*this);
workbook().register_comments_in_manifest(*this);
}
} // namespace xlnt

View File

@ -368,14 +368,14 @@ public:
bool match = true;
xlnt::workbook right_workbook;
right_workbook.load(right);
xlnt::workbook left_workbook;
left_workbook.load(left);
auto &left_manifest = left_workbook.get_manifest();
auto &right_manifest = right_workbook.get_manifest();
xlnt::workbook right_workbook;
right_workbook.load(right);
auto &left_manifest = left_workbook.manifest();
auto &right_manifest = right_workbook.manifest();
for (auto left_member : left_info)
{
@ -404,8 +404,8 @@ public:
if (left_member != "[Content_Types].xml")
{
left_content_type = left_manifest.get_content_type(xlnt::path(left_member));
right_content_type = right_manifest.get_content_type(xlnt::path(left_member));
left_content_type = left_manifest.content_type(xlnt::path(left_member));
right_content_type = right_manifest.content_type(xlnt::path(left_member));
}
else
{