clang-format all files, update .clang-format, fix minor compilation errors

This commit is contained in:
Thomas Fussell 2015-11-01 09:43:01 -05:00
parent 3a50c2bb9d
commit 7f840bb904
98 changed files with 3722 additions and 3215 deletions

View File

@ -1,51 +1,45 @@
---
Language: Cpp
AccessModifierOffset: -4
ConstructorInitializerIndentWidth: 4
AlignEscapedNewlinesLeft: false
AlignTrailingComments: false
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortIfStatementsOnASingleLine: false
BasedOnStyle: LLVM
AllowShortBlocksOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: true
AllowShortLoopsOnASingleLine: false
AllowShortFunctionsOnASingleLine: true
AlwaysBreakTemplateDeclarations: false
AlwaysBreakBeforeMultilineStrings: false
BreakBeforeBinaryOperators: false
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BinPackParameters: true
ColumnLimit: 0
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: true
BraceWrapping:
AfterClass: true
AfterControlStatement: true
AfterEnum: true
AfterFunction: true
AfterNamespace: false
AfterObjCDeclaration: true
AfterStruct: true
AfterUnion: true
BeforeCatch: true
BeforeElse: true
BreakBeforeBraces: Custom
ColumnLimit: 120
ConstructorInitializerAllOnOneLineOrOnePerLine: true
DerivePointerBinding: false
ExperimentalAutoDetectBinPacking: false
Cpp11BracedListStyle: false
DerivePointerAlignment: false
DisableFormat: false
IndentCaseLabels: false
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakString: 1000
PenaltyBreakFirstLessLess: 120
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerBindsToType: false
SpacesBeforeTrailingComments: 1
Cpp11BracedListStyle: true
Standard: Cpp11
IndentWidth: 4
TabWidth: 8
UseTab: Never
BreakBeforeBraces: Allman
IndentFunctionDeclarationAfterType: false
SpacesInParentheses: false
SpacesInAngles: false
KeepEmptyLinesAtTheStartOfBlocks: false
Language: Cpp
NamespaceIndentation: None
MaxEmptyLinesToKeep: 1
PointerAlignment: Right
SpaceAfterCStyleCast: false
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInCStyleCastParentheses: false
SpacesInContainerLiterals: true
SpaceBeforeAssignmentOperators: true
ContinuationIndentWidth: 4
CommentPragmas: '^ IWYU pragma:'
SpaceBeforeParens: Never
...
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp11
UseTab: Never
...

View File

@ -68,8 +68,8 @@ public:
/// <summary>
/// Split a coordinate string like "A1" into an equivalent pair like {"A", 1}.
/// </summary>
static std::pair<std::string, row_t> split_reference(const std::string &reference_string,
bool &absolute_column, bool &absolute_row);
static std::pair<std::string, row_t> split_reference(const std::string &reference_string, bool &absolute_column,
bool &absolute_row);
// constructors
/// <summary>
@ -82,18 +82,42 @@ public:
cell_reference(column_t column, row_t row, bool absolute = false);
// absoluateness
bool is_absolute() const { return absolute_; }
void set_absolute(bool absolute) { absolute_ = absolute; }
bool is_absolute() const
{
return absolute_;
}
void set_absolute(bool absolute)
{
absolute_ = absolute;
}
// getters/setters
std::string get_column() const { return column_string_from_index(column_); }
void set_column(const std::string &column_string) { column_ = column_index_from_string(column_string); }
std::string get_column() const
{
return column_string_from_index(column_);
}
void set_column(const std::string &column_string)
{
column_ = column_index_from_string(column_string);
}
column_t get_column_index() const { return column_; }
void set_column_index(column_t column) { column_ = column; }
column_t get_column_index() const
{
return column_;
}
void set_column_index(column_t column)
{
column_ = column;
}
row_t get_row() const { return row_ ; }
void set_row(row_t row) { row_ = row; }
row_t get_row() const
{
return row_;
}
void set_row(row_t row)
{
row_ = row;
}
/// <summary>
/// Return a cell_reference offset from this cell_reference by
@ -122,11 +146,26 @@ public:
range_reference operator, (const cell_reference &other) const;
bool operator==(const cell_reference &comparand) const;
bool operator==(const std::string &reference_string) const { return *this == cell_reference(reference_string); }
bool operator==(const char *reference_string) const { return *this == std::string(reference_string); }
bool operator!=(const cell_reference &comparand) const { return !(*this == comparand); }
bool operator!=(const std::string &reference_string) const { return *this != cell_reference(reference_string); }
bool operator!=(const char *reference_string) const { return *this != std::string(reference_string); }
bool operator==(const std::string &reference_string) const
{
return *this == cell_reference(reference_string);
}
bool operator==(const char *reference_string) const
{
return *this == std::string(reference_string);
}
bool operator!=(const cell_reference &comparand) const
{
return !(*this == comparand);
}
bool operator!=(const std::string &reference_string) const
{
return *this != cell_reference(reference_string);
}
bool operator!=(const char *reference_string) const
{
return *this != std::string(reference_string);
}
bool operator<(const cell_reference &other);
bool operator>(const cell_reference &other);

View File

@ -54,8 +54,7 @@ struct date
/// </summary>
static date from_number(int days_since_base_year, calendar base_date);
date(int year_, int month_, int day_)
: year(year_), month(month_), day(day_)
date(int year_, int month_, int day_) : year(year_), month(month_), day(day_)
{
}
@ -119,7 +118,10 @@ struct datetime
/// Return the current date and time according to the system time.
/// This is equivalent to datetime::now().
/// </summary>
static datetime today() { return now(); }
static datetime today()
{
return now();
}
/// <summary>
/// Return a datetime from number by converting the integer part into
@ -129,7 +131,13 @@ struct datetime
static datetime from_number(long double number, calendar base_date);
datetime(int year_, int month_, int day_, int hour_ = 0, int minute_ = 0, int second_ = 0, int microsecond_ = 0)
: year(year_), month(month_), day(day_), hour(hour_), minute(minute_), second(second_), microsecond(microsecond_)
: year(year_),
month(month_),
day(day_),
hour(hour_),
minute(minute_),
second(second_),
microsecond(microsecond_)
{
}
@ -155,11 +163,7 @@ struct timedelta
static timedelta from_number(long double number);
timedelta(int days_, int hours_, int minutes_ = 0, int seconds_ = 0, int microseconds_ = 0)
: days(days_),
hours(hours_),
minutes(minutes_),
seconds(seconds_),
microseconds(microseconds_)
: days(days_), hours(hours_), minutes(minutes_), seconds(seconds_), microseconds(microseconds_)
{
}

View File

@ -43,7 +43,8 @@ enum class target_mode
};
/// <summary>
/// Represents an association between a source Package or part, and a target object which can be a part or external resource.
/// Represents an association between a source Package or part, and a target object which can be a part or external
/// resource.
/// </summary>
class relationship
{
@ -114,54 +115,83 @@ public:
{
switch (t)
{
case type::extended_properties: return "http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties";
case type::core_properties: return "http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties";
case type::office_document: return "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument";
case type::worksheet: return "http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet";
case type::shared_strings: return "http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings";
case type::styles: return "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles";
case type::theme: return "http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme";
case type::hyperlink: return "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink";
case type::chartsheet: return "http://schemas.openxmlformats.org/officeDocument/2006/relationships/chartsheet";
case type::custom_xml: return "http://schemas.openxmlformats.org/officeDocument/2006/relationships/customXml";
default: return "??";
case type::extended_properties:
return "http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties";
case type::core_properties:
return "http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties";
case type::office_document:
return "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument";
case type::worksheet:
return "http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet";
case type::shared_strings:
return "http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings";
case type::styles:
return "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles";
case type::theme:
return "http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme";
case type::hyperlink:
return "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink";
case type::chartsheet:
return "http://schemas.openxmlformats.org/officeDocument/2006/relationships/chartsheet";
case type::custom_xml:
return "http://schemas.openxmlformats.org/officeDocument/2006/relationships/customXml";
default:
return "??";
}
}
relationship();
relationship(const std::string &t, const std::string &r_id = "", const std::string &target_uri = "") : relationship(type_from_string(t), r_id, target_uri) {}
relationship(const std::string &t, const std::string &r_id = "", const std::string &target_uri = "")
: relationship(type_from_string(t), r_id, target_uri)
{
}
relationship(type t, const std::string &r_id = "", const std::string &target_uri = "");
/// <summary>
/// gets a string that identifies the relationship.
/// </summary>
std::string get_id() const { return id_; }
std::string get_id() const
{
return id_;
}
/// <summary>
/// gets the URI of the package or part that owns the relationship.
/// </summary>
std::string get_source_uri() const { return source_uri_; }
std::string get_source_uri() const
{
return source_uri_;
}
/// <summary>
/// gets a value that indicates whether the target of the relationship is or External to the Package.
/// </summary>
target_mode get_target_mode() const { return target_mode_; }
target_mode get_target_mode() const
{
return target_mode_;
}
/// <summary>
/// gets the URI of the target resource of the relationship.
/// </summary>
std::string get_target_uri() const { return target_uri_; }
std::string get_target_uri() const
{
return target_uri_;
}
type get_type() const { return type_; }
std::string get_type_string() const { return type_to_string(type_); }
type get_type() const
{
return type_;
}
std::string get_type_string() const
{
return type_to_string(type_);
}
friend bool operator==(const relationship &left, const relationship &right)
{
return left.type_ == right.type_
&& left.id_ == right.id_
&& left.source_uri_ == right.source_uri_
&& left.target_uri_ == right.target_uri_
&& left.target_mode_ == right.target_mode_;
return left.type_ == right.type_ && left.id_ == right.id_ && left.source_uri_ == right.source_uri_ &&
left.target_uri_ == right.target_uri_ && left.target_mode_ == right.target_mode_;
}
private:

View File

@ -102,7 +102,10 @@ public:
void writestr(const std::string &arcname, const std::string &bytes);
void writestr(const zip_info &arcname, const std::string &bytes);
std::string get_filename() const { return filename_; }
std::string get_filename() const
{
return filename_;
}
std::string comment;

View File

@ -44,5 +44,4 @@ enum class limit_style
/// See limit_style for more information.
/// </summary>
const limit_style LimitStyle = limit_style::openpyxl;
}

View File

@ -1,7 +1,7 @@
namespace xlnt {
class tokenizer {
class tokenizer
{
};
} // namespace xlnt

View File

@ -62,19 +62,18 @@ public:
/// </summary>
bool load_workbook(const std::string &filename, bool guess_types = false, bool data_only = false);
/// <summary>
/// Create a ZIP file in memory, load archive from stream, then populate workbook
/// with data from archive.
/// </summary>
bool load_stream_workbook(std::istream &stream, bool guess_types = false, bool data_only = false);
/// <summary>
/// Create a ZIP file in memory, load archive from bytes, then populate workbook
/// with data from archive.
/// </summary>
bool load_virtual_workbook(const std::vector<std::uint8_t> &bytes, bool guess_types = false, bool data_only = false);
bool load_virtual_workbook(const std::vector<std::uint8_t> &bytes, bool guess_types = false,
bool data_only = false);
/// <summary>
/// Create a ZIP file in memory, save workbook to this archive, then save archive

View File

@ -12,7 +12,8 @@ class relationship_serializer
{
public:
static std::vector<relationship> read_relationships(zip_file &archive, const std::string &target);
static bool write_relationships(const std::vector<relationship> &relationships, const std::string &target, zip_file &archive);
static bool write_relationships(const std::vector<relationship> &relationships, const std::string &target,
zip_file &archive);
};
} // namespace xlnt

View File

@ -51,7 +51,9 @@ public:
static const color yellow;
static const color darkyellow;
color() {}
color()
{
}
color(type t, std::size_t v) : type_(t), index_(v)
{

View File

@ -68,8 +68,14 @@ public:
mediumgray,
};
type get_type() const { return type_; }
void set_type(type t) { type_ = t; }
type get_type() const
{
return type_;
}
void set_type(type t)
{
type_ = t;
}
std::string get_pattern_type_string() const
{
@ -80,26 +86,46 @@ public:
switch (pattern_type_)
{
case pattern_type::none: return "none";
case pattern_type::solid: return "solid";
case pattern_type::darkdown: return "darkdown";
case pattern_type::darkgray: return "darkgray";
case pattern_type::darkgrid: return "darkgrid";
case pattern_type::darkhorizontal: return "darkhorizontal";
case pattern_type::darktrellis: return "darktrellis";
case pattern_type::darkup: return "darkup";
case pattern_type::darkvertical: return "darkvertical";
case pattern_type::gray0625: return "gray0625";
case pattern_type::gray125: return "gray125";
case pattern_type::lightdown: return "lightdown";
case pattern_type::lightgray: return "lightgray";
case pattern_type::lightgrid: return "lightgrid";
case pattern_type::lighthorizontal: return "lighthorizontal";
case pattern_type::lighttrellis: return "lighttrellis";
case pattern_type::lightup: return "lightup";
case pattern_type::lightvertical: return "lightvertical";
case pattern_type::mediumgray: return "mediumgray";
default: throw std::runtime_error("invalid type");
case pattern_type::none:
return "none";
case pattern_type::solid:
return "solid";
case pattern_type::darkdown:
return "darkdown";
case pattern_type::darkgray:
return "darkgray";
case pattern_type::darkgrid:
return "darkgrid";
case pattern_type::darkhorizontal:
return "darkhorizontal";
case pattern_type::darktrellis:
return "darktrellis";
case pattern_type::darkup:
return "darkup";
case pattern_type::darkvertical:
return "darkvertical";
case pattern_type::gray0625:
return "gray0625";
case pattern_type::gray125:
return "gray125";
case pattern_type::lightdown:
return "lightdown";
case pattern_type::lightgray:
return "lightgray";
case pattern_type::lightgrid:
return "lightgrid";
case pattern_type::lighthorizontal:
return "lighthorizontal";
case pattern_type::lighttrellis:
return "lighttrellis";
case pattern_type::lightup:
return "lightup";
case pattern_type::lightvertical:
return "lightvertical";
case pattern_type::mediumgray:
return "mediumgray";
default:
throw std::runtime_error("invalid type");
}
}
@ -112,9 +138,12 @@ public:
switch (gradient_type_)
{
case gradient_type::linear: return "linear";
case gradient_type::path: return "path";
default: throw std::runtime_error("invalid type");
case gradient_type::linear:
return "linear";
case gradient_type::path:
return "path";
default:
throw std::runtime_error("invalid type");
}
}
@ -269,10 +298,22 @@ public:
return seed;
}
double get_gradient_left() const { return gradient_path_left_; }
double get_gradient_right() const { return gradient_path_right_; }
double get_gradient_top() const { return gradient_path_top_; }
double get_gradient_bottom() const { return gradient_path_bottom_; }
double get_gradient_left() const
{
return gradient_path_left_;
}
double get_gradient_right() const
{
return gradient_path_right_;
}
double get_gradient_top() const
{
return gradient_path_top_;
}
double get_gradient_bottom() const
{
return gradient_path_bottom_;
}
private:
type type_ = type::none;

View File

@ -44,35 +44,97 @@ public:
single_accounting
};
void set_bold(bool bold) { bold_ = bold; }
bool is_bold() const { return bold_; }
void set_bold(bool bold)
{
bold_ = bold;
}
bool is_bold() const
{
return bold_;
}
void set_italic(bool italic) { italic_ = italic; }
bool is_italic() const { return italic_; }
void set_italic(bool italic)
{
italic_ = italic;
}
bool is_italic() const
{
return italic_;
}
void set_strikethrough(bool strikethrough) { strikethrough_ = strikethrough; }
bool is_strikethrough() const { return strikethrough_; }
void set_strikethrough(bool strikethrough)
{
strikethrough_ = strikethrough;
}
bool is_strikethrough() const
{
return strikethrough_;
}
void set_underline(underline_style new_underline) { underline_ = new_underline; }
bool is_underline() const { return underline_ != underline_style::none; }
underline_style get_underline() const { return underline_; }
void set_underline(underline_style new_underline)
{
underline_ = new_underline;
}
bool is_underline() const
{
return underline_ != underline_style::none;
}
underline_style get_underline() const
{
return underline_;
}
void set_size(int size) { size_ = size; }
int get_size() const { return size_; }
void set_size(int size)
{
size_ = size;
}
int get_size() const
{
return size_;
}
void set_name(const std::string &name) { name_ = name; }
std::string get_name() const { return name_; }
void set_name(const std::string &name)
{
name_ = name;
}
std::string get_name() const
{
return name_;
}
void set_color(color c) { color_ = c; }
void set_family(int family) { has_family_ = true; family_ = family; }
void set_scheme(const std::string &scheme) { has_scheme_ = true; scheme_ = scheme; }
void set_color(color c)
{
color_ = c;
}
void set_family(int family)
{
has_family_ = true;
family_ = family;
}
void set_scheme(const std::string &scheme)
{
has_scheme_ = true;
scheme_ = scheme;
}
color get_color() const { return color_; }
color get_color() const
{
return color_;
}
bool has_family() const { return has_family_; }
int get_family() const { return family_; }
bool has_family() const
{
return has_family_;
}
int get_family() const
{
return family_;
}
bool has_scheme() const { return has_scheme_; }
bool has_scheme() const
{
return has_scheme_;
}
std::size_t hash() const
{
@ -87,9 +149,14 @@ public:
hash_combine(seed, static_cast<std::size_t>(color_.get_type()));
switch (color_.get_type())
{
case color::type::indexed: hash_combine(seed, color_.get_index()); break;
case color::type::theme: hash_combine(seed, color_.get_theme()); break;
default: break;
case color::type::indexed:
hash_combine(seed, color_.get_index());
break;
case color::type::theme:
hash_combine(seed, color_.get_theme());
break;
default:
break;
}
hash_combine(seed, family_);
hash_combine(seed, scheme_);

View File

@ -76,8 +76,14 @@ public:
void set_format_string(const std::string &format_code, int id = -1);
std::string get_format_string() const;
void set_id(int id) { id_ = id; }
int get_id() const { return id_; }
void set_id(int id)
{
id_ = id;
}
int get_id() const
{
return id_;
}
std::size_t hash() const;

View File

@ -52,19 +52,52 @@ public:
bool pivot_button() const;
bool quote_prefix() const;
std::size_t get_id() const { return id_; }
std::size_t get_id() const
{
return id_;
}
std::size_t get_fill_id() const { return fill_id_; }
std::size_t get_font_id() const { return font_id_; }
std::size_t get_border_id() const { return border_id_; }
std::size_t get_number_format_id() const { return number_format_id_; }
std::size_t get_fill_id() const
{
return fill_id_;
}
std::size_t get_font_id() const
{
return font_id_;
}
std::size_t get_border_id() const
{
return border_id_;
}
std::size_t get_number_format_id() const
{
return number_format_id_;
}
void apply_alignment(bool apply) { alignment_apply_ = apply; }
void apply_border(bool apply) { border_apply_ = apply; }
void apply_fill(bool apply) { fill_apply_ = apply; }
void apply_font(bool apply) { font_apply_ = apply; }
void apply_number_format(bool apply) { number_format_apply_ = apply; }
void apply_protection(bool apply) { protection_apply_ = apply; }
void apply_alignment(bool apply)
{
alignment_apply_ = apply;
}
void apply_border(bool apply)
{
border_apply_ = apply;
}
void apply_fill(bool apply)
{
fill_apply_ = apply;
}
void apply_font(bool apply)
{
font_apply_ = apply;
}
void apply_number_format(bool apply)
{
number_format_apply_ = apply;
}
void apply_protection(bool apply)
{
protection_apply_ = apply;
}
bool operator==(const style &other) const
{

View File

@ -2,8 +2,7 @@
namespace xlnt {
class external_book {
class external_book
{
};
}

View File

@ -13,8 +13,14 @@ public:
default_type(const default_type &other);
default_type &operator=(const default_type &other);
std::string get_extension() const { return extension_; }
std::string get_content_type() const { return content_type_; }
std::string get_extension() const
{
return extension_;
}
std::string get_content_type() const
{
return content_type_;
}
private:
std::string extension_;
@ -29,8 +35,14 @@ public:
override_type(const override_type &other);
override_type &operator=(const override_type &other);
std::string get_part_name() const { return part_name_; }
std::string get_content_type() const { return content_type_; }
std::string get_part_name() const
{
return part_name_;
}
std::string get_content_type() const
{
return content_type_;
}
private:
std::string part_name_;
@ -43,8 +55,14 @@ public:
void add_default_type(const std::string &extension, const std::string &content_type);
void add_override_type(const std::string &part_name, const std::string &content_type);
const std::vector<default_type> &get_default_types() const { return default_types_; }
const std::vector<override_type> &get_override_types() const { return override_types_; }
const std::vector<default_type> &get_default_types() const
{
return default_types_;
}
const std::vector<override_type> &get_override_types() const
{
return override_types_;
}
bool has_default_type(const std::string &extension) const;
bool has_override_type(const std::string &part_name) const;

View File

@ -19,8 +19,14 @@ public:
named_range(const named_range &other);
named_range(const std::string &name, const std::vector<target> &targets);
std::string get_name() const { return name_; }
const std::vector<target> &get_targets() const { return targets_; }
std::string get_name() const
{
return name_;
}
const std::vector<target> &get_targets() const
{
return targets_;
}
named_range &operator=(const named_range &other);
@ -28,5 +34,4 @@ private:
std::string name_;
std::vector<target> targets_;
};
}

View File

@ -4,7 +4,6 @@ namespace xlnt {
class theme
{
};
} // namespace xlnt

View File

@ -73,7 +73,10 @@ public:
iterator &operator=(const iterator &);
worksheet operator*();
bool operator==(const iterator &comparand) const;
bool operator!=(const iterator &comparand) const { return !(*this == comparand); }
bool operator!=(const iterator &comparand) const
{
return !(*this == comparand);
}
iterator operator++(int);
iterator &operator++();
@ -90,7 +93,10 @@ public:
const_iterator &operator=(const const_iterator &);
const worksheet operator*();
bool operator==(const const_iterator &comparand) const;
bool operator!=(const const_iterator &comparand) const { return !(*this == comparand); }
bool operator!=(const const_iterator &comparand) const
{
return !(*this == comparand);
}
const_iterator operator++(int);
const_iterator &operator++();
@ -148,8 +154,14 @@ public:
iterator begin();
iterator end();
const_iterator begin() const { return cbegin(); }
const_iterator end() const { return cend(); }
const_iterator begin() const
{
return cbegin();
}
const_iterator end() const
{
return cend();
}
const_iterator cbegin() const;
const_iterator cend() const;

View File

@ -15,16 +15,12 @@ class range_reference;
class cell_vector
{
public:
template <bool is_const = true>
class common_iterator : public std::iterator<std::bidirectional_iterator_tag, cell>
{
public:
common_iterator(worksheet ws, const cell_reference &start_cell, major_order order = major_order::row)
: ws_(ws),
current_cell_(start_cell),
range_(start_cell.to_range()),
order_(order)
: ws_(ws), current_cell_(start_cell), range_(start_cell.to_range()), order_(order)
{
}
@ -37,9 +33,7 @@ public:
bool operator==(const common_iterator &other) const
{
return ws_ == other.ws_
&& current_cell_ == other.current_cell_
&& order_ == other.order_;
return ws_ == other.ws_ && current_cell_ == other.current_cell_ && order_ == other.order_;
}
bool operator!=(const common_iterator &other) const
@ -121,13 +115,22 @@ public:
const cell get_cell(std::size_t column_index) const;
std::size_t length() const { return num_cells(); }
std::size_t length() const
{
return num_cells();
}
iterator begin();
iterator end();
const_iterator begin() const { return cbegin(); }
const_iterator end() const { return cend(); }
const_iterator begin() const
{
return cbegin();
}
const_iterator end() const
{
return cend();
}
const_iterator cbegin() const;
const_iterator cend() const;

View File

@ -28,13 +28,9 @@ namespace xlnt {
class column_properties
{
public:
void set_height(int height) { this->height = height; }
int row_index;
int height;
bool visible;
int outline_level;
bool collapsed;
int style_index;
double width;
std::size_t style;
bool custom;
};
} // namespace xlnt

View File

@ -28,21 +28,68 @@ namespace xlnt {
class page_margins
{
public:
margins() : default_(true), top_(0), left_(0), bottom_(0), right_(0), header_(0), footer_(0) {}
page_margins() : default_(true), top_(0), left_(0), bottom_(0), right_(0), header_(0), footer_(0)
{
}
bool is_default() const { return default_; }
double get_top() const { return top_; }
void set_top(double top) { default_ = false; top_ = top; }
double get_left() const { return left_; }
void set_left(double left) { default_ = false; left_ = left; }
double get_bottom() const { return bottom_; }
void set_bottom(double bottom) { default_ = false; bottom_ = bottom; }
double get_right() const { return right_; }
void set_right(double right) { default_ = false; right_ = right; }
double get_header() const { return header_; }
void set_header(double header) { default_ = false; header_ = header; }
double get_footer() const { return footer_; }
void set_footer(double footer) { default_ = false; footer_ = footer; }
bool is_default() const
{
return default_;
}
double get_top() const
{
return top_;
}
void set_top(double top)
{
default_ = false;
top_ = top;
}
double get_left() const
{
return left_;
}
void set_left(double left)
{
default_ = false;
left_ = left;
}
double get_bottom() const
{
return bottom_;
}
void set_bottom(double bottom)
{
default_ = false;
bottom_ = bottom;
}
double get_right() const
{
return right_;
}
void set_right(double right)
{
default_ = false;
right_ = right;
}
double get_header() const
{
return header_;
}
void set_header(double header)
{
default_ = false;
header_ = header;
}
double get_footer() const
{
return footer_;
}
void set_footer(double footer)
{
default_ = false;
footer_ = footer;
}
private:
bool default_;

View File

@ -63,29 +63,113 @@ struct page_setup
};
public:
page_setup() : default_(true), break_(page_break::none), sheet_state_(sheet_state::visible), paper_size_(paper_size::letter),
orientation_(orientation::portrait), fit_to_page_(false), fit_to_height_(false), fit_to_width_(false), horizontal_centered_(false), vertical_centered_(false), scale_(1) {}
bool is_default() const { return default_; }
page_break get_break() const { return break_; }
void set_break(page_break b) { default_ = false; break_ = b; }
sheet_state get_sheet_state() const { return sheet_state_; }
void set_sheet_state(sheet_state sheet_state) { sheet_state_ = sheet_state; }
paper_size get_paper_size() const { return paper_size_; }
void set_paper_size(paper_size paper_size) { default_ = false; paper_size_ = paper_size; }
orientation get_orientation() const { return orientation_; }
void set_orientation(orientation orientation) { default_ = false; orientation_ = orientation; }
bool fit_to_page() const { return fit_to_page_; }
void set_fit_to_page(bool fit_to_page) { default_ = false; fit_to_page_ = fit_to_page; }
bool fit_to_height() const { return fit_to_height_; }
void set_fit_to_height(bool fit_to_height) { default_ = false; fit_to_height_ = fit_to_height; }
bool fit_to_width() const { return fit_to_width_; }
void set_fit_to_width(bool fit_to_width) { default_ = false; fit_to_width_ = fit_to_width; }
void set_horizontal_centered(bool horizontal_centered) { default_ = false; horizontal_centered_ = horizontal_centered; }
bool get_horizontal_centered() const { return horizontal_centered_; }
void set_vertical_centered(bool vertical_centered) { default_ = false; vertical_centered_ = vertical_centered; }
bool get_vertical_centered() const { return vertical_centered_; }
void set_scale(double scale) { default_ = false; scale_ = scale; }
double get_scale() const { return scale_; }
page_setup()
: default_(true),
break_(page_break::none),
sheet_state_(sheet_state::visible),
paper_size_(paper_size::letter),
orientation_(orientation::portrait),
fit_to_page_(false),
fit_to_height_(false),
fit_to_width_(false),
horizontal_centered_(false),
vertical_centered_(false),
scale_(1)
{
}
bool is_default() const
{
return default_;
}
page_break get_break() const
{
return break_;
}
void set_break(page_break b)
{
default_ = false;
break_ = b;
}
sheet_state get_sheet_state() const
{
return sheet_state_;
}
void set_sheet_state(sheet_state sheet_state)
{
sheet_state_ = sheet_state;
}
paper_size get_paper_size() const
{
return paper_size_;
}
void set_paper_size(paper_size paper_size)
{
default_ = false;
paper_size_ = paper_size;
}
orientation get_orientation() const
{
return orientation_;
}
void set_orientation(orientation orientation)
{
default_ = false;
orientation_ = orientation;
}
bool fit_to_page() const
{
return fit_to_page_;
}
void set_fit_to_page(bool fit_to_page)
{
default_ = false;
fit_to_page_ = fit_to_page;
}
bool fit_to_height() const
{
return fit_to_height_;
}
void set_fit_to_height(bool fit_to_height)
{
default_ = false;
fit_to_height_ = fit_to_height;
}
bool fit_to_width() const
{
return fit_to_width_;
}
void set_fit_to_width(bool fit_to_width)
{
default_ = false;
fit_to_width_ = fit_to_width;
}
void set_horizontal_centered(bool horizontal_centered)
{
default_ = false;
horizontal_centered_ = horizontal_centered;
}
bool get_horizontal_centered() const
{
return horizontal_centered_;
}
void set_vertical_centered(bool vertical_centered)
{
default_ = false;
vertical_centered_ = vertical_centered;
}
bool get_vertical_centered() const
{
return vertical_centered_;
}
void set_scale(double scale)
{
default_ = false;
scale_ = scale;
}
double get_scale() const
{
return scale_;
}
private:
bool default_;

View File

@ -42,10 +42,7 @@ public:
{
public:
common_iterator(worksheet ws, const range_reference &start_cell, major_order order = major_order::row)
: ws_(ws),
current_cell_(start_cell.get_top_left()),
range_(start_cell),
order_(order)
: ws_(ws), current_cell_(start_cell.get_top_left()), range_(start_cell), order_(order)
{
}
@ -58,9 +55,7 @@ public:
bool operator==(const common_iterator &other) const
{
return ws_ == other.ws_
&& current_cell_ == other.current_cell_
&& order_ == other.order_;
return ws_ == other.ws_ && current_cell_ == other.current_cell_ && order_ == other.order_;
}
bool operator!=(const common_iterator &other) const
@ -132,7 +127,10 @@ public:
bool operator==(const range &comparand) const;
bool operator!=(const range &comparand) const { return !(*this == comparand); }
bool operator!=(const range &comparand) const
{
return !(*this == comparand);
}
cell_vector get_vector(std::size_t vector_index);
@ -151,8 +149,14 @@ public:
iterator begin();
iterator end();
const_iterator begin() const { return cbegin(); }
const_iterator end() const { return cend(); }
const_iterator begin() const
{
return cbegin();
}
const_iterator end() const
{
return cend();
}
const_iterator cbegin() const;
const_iterator cend() const;

View File

@ -44,21 +44,45 @@ public:
bool is_single_cell() const;
column_t get_width() const;
row_t get_height() const;
cell_reference get_top_left() const { return top_left_; }
cell_reference get_bottom_right() const { return bottom_right_; }
cell_reference &get_top_left() { return top_left_; }
cell_reference &get_bottom_right() { return bottom_right_; }
cell_reference get_top_left() const
{
return top_left_;
}
cell_reference get_bottom_right() const
{
return bottom_right_;
}
cell_reference &get_top_left()
{
return top_left_;
}
cell_reference &get_bottom_right()
{
return bottom_right_;
}
range_reference make_offset(int column_offset, int row_offset) const;
std::string to_string() const;
bool operator==(const range_reference &comparand) const;
bool operator==(const std::string &reference_string) const { return *this == range_reference(reference_string); }
bool operator==(const char *reference_string) const { return *this == std::string(reference_string); }
bool operator==(const std::string &reference_string) const
{
return *this == range_reference(reference_string);
}
bool operator==(const char *reference_string) const
{
return *this == std::string(reference_string);
}
bool operator!=(const range_reference &comparand) const;
bool operator!=(const std::string &reference_string) const { return *this != range_reference(reference_string); }
bool operator!=(const char *reference_string) const { return *this != std::string(reference_string); }
bool operator!=(const std::string &reference_string) const
{
return *this != range_reference(reference_string);
}
bool operator!=(const char *reference_string) const
{
return *this != std::string(reference_string);
}
private:
cell_reference top_left_;

View File

@ -28,9 +28,7 @@ namespace xlnt {
class row_properties
{
public:
void set_height(int height) { this->height = height; }
int row_index;
int height;
double height;
bool visible;
int outline_level;
bool collapsed;

View File

@ -24,10 +24,8 @@
namespace xlnt {
class selection {
};
class selection
{
};
} // namespace xlnt

View File

@ -10,7 +10,10 @@ public:
static std::string hash_password(const std::string &password);
void set_password(const std::string &password);
std::string get_hashed_password() const { return hashed_password_; }
std::string get_hashed_password() const
{
return hashed_password_;
}
private:
std::string hashed_password_;

View File

@ -37,10 +37,12 @@ namespace xlnt {
class cell;
class cell_reference;
class column_properties;
class comment;
class range;
class range_reference;
class relationship;
class row_properties;
class workbook;
struct date;
@ -49,33 +51,34 @@ namespace detail {
struct worksheet_impl;
} // namespace detail
class row_properties
{
public:
double height;
bool visible;
int outline_level;
bool collapsed;
int style_index;
};
class column_properties
{
public:
double width;
std::size_t style;
bool custom;
};
class header
{
public:
header();
void set_text(const std::string &text) { default_ = false; text_ = text; }
void set_font_name(const std::string &font_name) { default_ = false; font_name_ = font_name; }
void set_font_size(std::size_t font_size) { default_ = false; font_size_ = font_size; }
void set_font_color(const std::string &font_color) { default_ = false; font_color_ = font_color; }
bool is_default() const { return default_; }
void set_text(const std::string &text)
{
default_ = false;
text_ = text;
}
void set_font_name(const std::string &font_name)
{
default_ = false;
font_name_ = font_name;
}
void set_font_size(std::size_t font_size)
{
default_ = false;
font_size_ = font_size;
}
void set_font_color(const std::string &font_color)
{
default_ = false;
font_color_ = font_color;
}
bool is_default() const
{
return default_;
}
private:
bool default_;
@ -89,11 +92,30 @@ class footer
{
public:
footer();
void set_text(const std::string &text) { default_ = false; text_ = text; }
void set_font_name(const std::string &font_name) { default_ = false; font_name_ = font_name; }
void set_font_size(std::size_t font_size) { default_ = false; font_size_ = font_size; }
void set_font_color(const std::string &font_color) { default_ = false; font_color_ = font_color; }
bool is_default() const { return default_; }
void set_text(const std::string &text)
{
default_ = false;
text_ = text;
}
void set_font_name(const std::string &font_name)
{
default_ = false;
font_name_ = font_name;
}
void set_font_size(std::size_t font_size)
{
default_ = false;
font_size_ = font_size;
}
void set_font_color(const std::string &font_color)
{
default_ = false;
font_color_ = font_color;
}
bool is_default() const
{
return default_;
}
private:
bool default_;
@ -108,16 +130,43 @@ class header_footer
public:
header_footer();
header &get_left_header() { return left_header_; }
header &get_center_header() { return center_header_; }
header &get_right_header() { return right_header_; }
footer &get_left_footer() { return left_footer_; }
footer &get_center_footer() { return center_footer_; }
footer &get_right_footer() { return right_footer_; }
header &get_left_header()
{
return left_header_;
}
header &get_center_header()
{
return center_header_;
}
header &get_right_header()
{
return right_header_;
}
footer &get_left_footer()
{
return left_footer_;
}
footer &get_center_footer()
{
return center_footer_;
}
footer &get_right_footer()
{
return right_footer_;
}
bool is_default_header() const { return left_header_.is_default() && center_header_.is_default() && right_header_.is_default(); }
bool is_default_footer() const { return left_footer_.is_default() && center_footer_.is_default() && right_footer_.is_default(); }
bool is_default() const { return is_default_header() && is_default_footer(); }
bool is_default_header() const
{
return left_header_.is_default() && center_header_.is_default() && right_header_.is_default();
}
bool is_default_footer() const
{
return left_footer_.is_default() && center_footer_.is_default() && right_footer_.is_default();
}
bool is_default() const
{
return is_default_header() && is_default_footer();
}
private:
header left_header_, right_header_, center_header_;
@ -127,21 +176,68 @@ private:
struct margins
{
public:
margins() : default_(true), top_(0), left_(0), bottom_(0), right_(0), header_(0), footer_(0) {}
margins() : default_(true), top_(0), left_(0), bottom_(0), right_(0), header_(0), footer_(0)
{
}
bool is_default() const { return default_; }
double get_top() const { return top_; }
void set_top(double top) { default_ = false; top_ = top; }
double get_left() const { return left_; }
void set_left(double left) { default_ = false; left_ = left; }
double get_bottom() const { return bottom_; }
void set_bottom(double bottom) { default_ = false; bottom_ = bottom; }
double get_right() const { return right_; }
void set_right(double right) { default_ = false; right_ = right; }
double get_header() const { return header_; }
void set_header(double header) { default_ = false; header_ = header; }
double get_footer() const { return footer_; }
void set_footer(double footer) { default_ = false; footer_ = footer; }
bool is_default() const
{
return default_;
}
double get_top() const
{
return top_;
}
void set_top(double top)
{
default_ = false;
top_ = top;
}
double get_left() const
{
return left_;
}
void set_left(double left)
{
default_ = false;
left_ = left;
}
double get_bottom() const
{
return bottom_;
}
void set_bottom(double bottom)
{
default_ = false;
bottom_ = bottom;
}
double get_right() const
{
return right_;
}
void set_right(double right)
{
default_ = false;
right_ = right;
}
double get_header() const
{
return header_;
}
void set_header(double header)
{
default_ = false;
header_ = header;
}
double get_footer() const
{
return footer_;
}
void set_footer(double footer)
{
default_ = false;
footer_ = footer;
}
private:
bool default_;

View File

@ -25,7 +25,8 @@
namespace xlnt {
class worksheet_properties {
class worksheet_properties
{
};
} // namespace xlnt

View File

@ -33,6 +33,8 @@ const std::string author_email = "thomas.fussell@gmail.com";
const std::string url = "https://github.com/tfussell/xlnt";
const std::string download_url = "https://github.com/tfussell/xlnt/archive/master.zip";
#include "config.hpp"
#include "cell/cell.hpp"
#include "cell/cell_reference.hpp"
#include "cell/comment.hpp"
@ -40,11 +42,36 @@ const std::string download_url = "https://github.com/tfussell/xlnt/archive/maste
#include "common/encoding.hpp"
#include "common/exceptions.hpp"
#include "common/relationship.hpp"
#include "common/string_table.hpp"
#include "common/types.hpp"
#include "common/zip_file.hpp"
#include "styles/alignment.hpp"
#include "styles/border.hpp"
#include "styles/color.hpp"
#include "styles/fill.hpp"
#include "styles/font.hpp"
#include "styles/named_style.hpp"
#include "styles/number_format.hpp"
#include "styles/protection.hpp"
#include "styles/side.hpp"
#include "styles/style.hpp"
#include "workbook/document_properties.hpp"
#include "workbook/document_security.hpp"
#include "workbook/external_book.hpp"
#include "workbook/manifest.hpp"
#include "workbook/named_range.hpp"
#include "workbook/theme.hpp"
#include "workbook/workbook.hpp"
#include "worksheet/cell_vector.hpp"
#include "worksheet/column_properties.hpp"
#include "worksheet/major_order.hpp"
#include "worksheet/page_margins.hpp"
#include "worksheet/page_setup.hpp"
#include "worksheet/pane.hpp"
#include "worksheet/range.hpp"
#include "worksheet/range_reference.hpp"
#include "worksheet/row_properties.hpp"
#include "worksheet/selection.hpp"
#include "worksheet/sheet_protection.hpp"
#include "worksheet/sheet_view.hpp"
#include "worksheet/worksheet_properties.hpp"
#include "worksheet/worksheet.hpp"

View File

@ -10,11 +10,13 @@
#include <xlnt/common/relationship.hpp>
#include <xlnt/workbook/workbook.hpp>
#include <xlnt/workbook/document_properties.hpp>
#include <xlnt/worksheet/column_properties.hpp>
#include <xlnt/worksheet/row_properties.hpp>
#include <xlnt/worksheet/worksheet.hpp>
#include <xlnt/styles/color.hpp>
#include "detail/cell_impl.hpp"
#include "detail/comment_impl.hpp"
#include <detail/cell_impl.hpp>
#include <detail/comment_impl.hpp>
namespace {
@ -123,11 +125,12 @@ bool is_date_format(const std::string &format_string)
bool is_valid_color(const std::string &color)
{
static const std::vector<std::string> colors = { "Black", "Green"
"White", "Blue", "Magenta", "Yellow", "Cyan", "Red" };
static const std::vector<std::string> colors = { "Black",
"Green"
"White",
"Blue", "Magenta", "Yellow", "Cyan", "Red" };
auto compare_color = [&](const std::string &other)
{
auto compare_color = [&](const std::string &other) {
if (color.size() != other.size()) return false;
for (std::size_t i = 0; i < color.size(); i++)
@ -197,9 +200,7 @@ bool is_hex(char c)
return false;
}
const std::unordered_map<int, std::string> known_locales =
{
{0x401, "Arabic - Saudi Arabia"},
const std::unordered_map<int, std::string> known_locales = { { 0x401, "Arabic - Saudi Arabia" },
{ 0x402, "Bulgarian" },
{ 0x403, "Catalan" },
{ 0x404, "Chinese - Taiwan" },
@ -303,8 +304,7 @@ const std::unordered_map<int, std::string> known_locales =
{ 0x3401, "Arabic - Kuwait" },
{ 0x3409, "English - Phillippines" },
{ 0x3801, "Arabic - United Arab Emirates" },
{0x4001, "Arabic - Qatar"}
};
{ 0x4001, "Arabic - Qatar" } };
bool is_valid_locale(const std::string &locale_string)
{
@ -383,7 +383,8 @@ section parse_section(const std::string &section_string)
for (auto bracket_time : bracket_times)
{
if(i < section_string.size() - bracket_time.size() && section_string.substr(i + 1, bracket_time.size()) == bracket_time)
if (i < section_string.size() - bracket_time.size() &&
section_string.substr(i + 1, bracket_time.size()) == bracket_time)
{
in_brackets = false;
break;
@ -501,21 +502,8 @@ format_sections parse_format_sections(const std::string &combined)
return result;
}
const std::vector<std::string> MonthNames =
{
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"
};
const std::vector<std::string> MonthNames = { "January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December" };
std::string format_section(long double number, const section &format, xlnt::calendar base_date)
{
@ -527,44 +515,22 @@ std::string format_section(long double number, const section &format, xlnt::cale
{
const std::string date_unquoted = ",-/: ";
const std::vector<std::string> dates =
{
"m",
"mm",
"mmm",
"mmmmm",
"mmmmmm",
"d",
"dd",
"ddd",
"dddd",
"yy",
const std::vector<std::string> dates = { "m", "mm", "mmm", "mmmmm", "mmmmmm", "d", "dd", "ddd", "dddd", "yy",
"yyyy"
"h",
"[h]",
"hh",
"m",
"[m]",
"mm",
"s",
"[s]",
"ss",
"AM/PM",
"am/pm",
"A/P",
"a/p"
};
"[h]", "hh", "m", "[m]", "mm", "s", "[s]", "ss", "AM/PM", "am/pm",
"A/P", "a/p" };
auto split = split_string_any(format.value, date_unquoted);
std::string::size_type index = 0, prev = 0;
auto d = xlnt::datetime::from_number(number, base_date);
bool processed_month = false;
auto lower_string = [](const std::string &s)
{
auto lower_string = [](const std::string &s) {
std::string lower;
lower.resize(s.size());
for(std::size_t i = 0; i < s.size(); i++) lower[i] = std::tolower(s[i]);
for (std::size_t i = 0; i < s.size(); i++)
lower[i] = std::tolower(s[i]);
return lower;
};
@ -752,8 +718,7 @@ std::string format_section(const std::string &text, const section &format)
first_part = format.value;
}
auto unquote = [](std::string &s)
{
auto unquote = [](std::string &s) {
if (!s.empty())
{
if (s.front() != '"' || s.back() != '"') return false;
@ -794,23 +759,15 @@ std::string format_text(const std::string &text, const std::string &format)
auto sections = parse_format_sections(format);
return format_section(text, sections.fourth);
}
}
namespace xlnt {
const std::unordered_map<std::string, int> cell::error_codes()
{
static const std::unordered_map<std::string, int> codes =
{
{"#NULL!", 0},
{"#DIV/0!", 1},
{"#VALUE!", 2},
{"#REF!", 3},
{"#NAME?", 4},
{"#NUM!", 5},
{"#N/A!", 6}
};
static const std::unordered_map<std::string, int> codes = { { "#NULL!", 0 }, { "#DIV/0!", 1 }, { "#VALUE!", 2 },
{ "#REF!", 3 }, { "#NAME?", 4 }, { "#NUM!", 5 },
{ "#N/A!", 6 } };
return codes;
};
@ -840,7 +797,6 @@ bool cell::garbage_collectible() const
return !(get_data_type() != type::null || is_merged() || has_comment() || has_formula() || has_style());
}
template <>
void cell::set_value(bool b)
{

View File

@ -33,13 +33,10 @@ cell_reference::cell_reference(const std::string &string)
cell_reference::cell_reference(const char *reference_string) : cell_reference(std::string(reference_string))
{
}
cell_reference::cell_reference(const std::string &column, row_t row, bool absolute)
: column_(column_index_from_string(column)),
row_(row),
absolute_(absolute)
: column_(column_index_from_string(column)), row_(row), absolute_(absolute)
{
if (row == 0 || row_ >= constants::MaxRow || column_ == 0 || column_ >= constants::MaxColumn)
{
@ -48,9 +45,7 @@ cell_reference::cell_reference(const std::string &column, row_t row, bool absolu
}
cell_reference::cell_reference(column_t column_index, row_t row, bool absolute)
: column_(column_index),
row_(row),
absolute_(absolute)
: column_(column_index), row_(row), absolute_(absolute)
{
if (row_ == 0 || row_ >= constants::MaxRow || column_ == 0 || column_ >= constants::MaxColumn)
{
@ -78,7 +73,8 @@ range_reference cell_reference::to_range() const
return range_reference(column_, row_, column_, row_);
}
std::pair<std::string, row_t> cell_reference::split_reference(const std::string &reference_string, bool &absolute_column, bool &absolute_row)
std::pair<std::string, row_t> cell_reference::split_reference(const std::string &reference_string,
bool &absolute_column, bool &absolute_row)
{
absolute_column = false;
absolute_row = false;
@ -160,9 +156,7 @@ cell_reference cell_reference::make_offset(int column_offset, int row_offset) co
bool cell_reference::operator==(const cell_reference &comparand) const
{
return comparand.column_ == column_
&& comparand.row_ == row_
&& absolute_ == comparand.absolute_;
return comparand.column_ == column_ && comparand.row_ == row_ && absolute_ == comparand.absolute_;
}
column_t cell_reference::column_index_from_string(const std::string &column_string)
@ -182,7 +176,8 @@ column_t cell_reference::column_index_from_string(const std::string &column_stri
throw column_string_index_exception();
}
column_index += static_cast<column_t>((std::toupper(column_string[static_cast<std::size_t>(i)], std::locale::classic()) - 'A' + 1) * place);
column_index += static_cast<column_t>(
(std::toupper(column_string[static_cast<std::size_t>(i)], std::locale::classic()) - 'A' + 1) * place);
place *= 26;
}

View File

@ -76,33 +76,25 @@ datetime datetime::from_number(long double raw_time, calendar base_date)
{
auto date_part = date::from_number((int)raw_time, base_date);
auto time_part = time::from_number(raw_time);
return datetime(date_part.year, date_part.month, date_part.day, time_part.hour, time_part.minute, time_part.second, time_part.microsecond);
return datetime(date_part.year, date_part.month, date_part.day, time_part.hour, time_part.minute, time_part.second,
time_part.microsecond);
}
bool date::operator==(const date &comparand) const
{
return year == comparand.year
&& month == comparand.month
&& day == comparand.day;
return year == comparand.year && month == comparand.month && day == comparand.day;
}
bool time::operator==(const time &comparand) const
{
return hour == comparand.hour
&& minute == comparand.minute
&& second == comparand.second
&& microsecond == comparand.microsecond;
return hour == comparand.hour && minute == comparand.minute && second == comparand.second &&
microsecond == comparand.microsecond;
}
bool datetime::operator==(const datetime &comparand) const
{
return year == comparand.year
&& month == comparand.month
&& day == comparand.day
&& hour == comparand.hour
&& minute == comparand.minute
&& second == comparand.second
&& microsecond == comparand.microsecond;
return year == comparand.year && month == comparand.month && day == comparand.day && hour == comparand.hour &&
minute == comparand.minute && second == comparand.second && microsecond == comparand.microsecond;
}
time::time(const std::string &time_string) : hour(0), minute(0), second(0), microsecond(0)
@ -139,10 +131,9 @@ int date::to_number(calendar base_date) const
return 60;
}
int days_since_1900 = int((1461 * (year + 4800 + int((month - 14) / 12))) / 4)
+ int((367 * (month - 2 - 12 * ((month - 14) / 12))) / 12)
- int((3 * (int((year + 4900 + int((month - 14) / 12)) / 100))) / 4)
+ day - 2415019 - 32075;
int days_since_1900 = int((1461 * (year + 4800 + int((month - 14) / 12))) / 4) +
int((367 * (month - 2 - 12 * ((month - 14) / 12))) / 12) -
int((3 * (int((year + 4900 + int((month - 14) / 12)) / 100))) / 4) + day - 2415019 - 32075;
if (days_since_1900 <= 60)
{
@ -159,13 +150,13 @@ int date::to_number(calendar base_date) const
long double datetime::to_number(calendar base_date) const
{
return date(year, month, day).to_number(base_date)
+ time(hour, minute, second, microsecond).to_number();
return date(year, month, day).to_number(base_date) + time(hour, minute, second, microsecond).to_number();
}
std::string datetime::to_string(xlnt::calendar /*base_date*/) const
{
return std::to_string(year) + "/" + std::to_string(month) + "/" + std::to_string(day) + " " +std::to_string(hour) + ":" + std::to_string(minute) + ":" + std::to_string(second) + ":" + std::to_string(microsecond);
return std::to_string(year) + "/" + std::to_string(month) + "/" + std::to_string(day) + " " + std::to_string(hour) +
":" + std::to_string(minute) + ":" + std::to_string(second) + ":" + std::to_string(microsecond);
}
date date::today()

View File

@ -5,55 +5,44 @@ namespace xlnt {
sheet_title_exception::sheet_title_exception(const std::string &title)
: std::runtime_error(std::string("bad worksheet title: ") + title)
{
}
column_string_index_exception::column_string_index_exception()
: std::runtime_error("")
column_string_index_exception::column_string_index_exception() : std::runtime_error("")
{
}
data_type_exception::data_type_exception()
: std::runtime_error("")
data_type_exception::data_type_exception() : std::runtime_error("")
{
}
attribute_error::attribute_error()
: std::runtime_error("")
attribute_error::attribute_error() : std::runtime_error("")
{
}
named_range_exception::named_range_exception()
: std::runtime_error("named range not found or not owned by this worksheet")
{
}
invalid_file_exception::invalid_file_exception(const std::string &filename)
: std::runtime_error(std::string("couldn't open file: (") + filename + ")")
{
}
cell_coordinates_exception::cell_coordinates_exception(row_t row, column_t column)
: std::runtime_error(std::string("bad cell coordinates: (") + std::to_string(row) + "," + std::to_string(column) + ")")
: std::runtime_error(std::string("bad cell coordinates: (") + std::to_string(row) + "," + std::to_string(column) +
")")
{
}
cell_coordinates_exception::cell_coordinates_exception(const std::string &coord_string)
: std::runtime_error(std::string("bad cell coordinates: (") + coord_string + ")")
{
}
illegal_character_error::illegal_character_error(char c)
: std::runtime_error(std::string("illegal character: (") + std::to_string(static_cast<unsigned char>(c)) + ")")
{
}
} // namespace xlnt

View File

@ -2,7 +2,8 @@
namespace xlnt {
relationship::relationship(type t, const std::string &r_id, const std::string &target_uri) : type_(t), id_(r_id), source_uri_(""), target_uri_(target_uri), target_mode_(target_mode::internal)
relationship::relationship(type t, const std::string &r_id, const std::string &target_uri)
: type_(t), id_(r_id), source_uri_(""), target_uri_(target_uri), target_mode_(target_mode::internal)
{
if (t == type::hyperlink)
{
@ -10,7 +11,8 @@ relationship::relationship(type t, const std::string &r_id, const std::string &t
}
}
relationship::relationship() : type_(type::invalid), id_(""), source_uri_(""), target_uri_(""), target_mode_(target_mode::internal)
relationship::relationship()
: type_(type::invalid), id_(""), source_uri_(""), target_uri_(""), target_mode_(target_mode::internal)
{
}

View File

@ -89,54 +89,40 @@ uint32_t crc32buf(const char *buf, std::size_t len)
{
uint32_t oldcrc32 = 0xFFFFFFFF;
uint32_t crc_32_tab[] = { /* CRC polynomial 0xedb88320 */
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f,
0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2,
0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172,
0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c,
0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423,
0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106,
0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d,
0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e,
0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7,
0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0,
0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa,
0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81,
0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a,
0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84,
0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc,
0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e,
0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55,
0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28,
0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f,
0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38,
0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69,
0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2,
0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc,
0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693,
0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,
uint32_t crc_32_tab[] = {
/* CRC polynomial 0xedb88320 */
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832,
0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2,
0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856, 0x646ba8c0, 0xfd62f97a,
0x8a65c9ec, 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172,
0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423,
0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, 0x2f6f7c87, 0x58684c11, 0xc1611dab,
0xb6662d3d, 0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, 0x6b6b51f4,
0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074,
0xd4bb30e2, 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0,
0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, 0x5768b525,
0x206f85b3, 0xb966d409, 0xce61e49f, 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81,
0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7, 0xfed41b76,
0x89d32be0, 0x10da7a5a, 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e,
0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c, 0x36034af6,
0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7,
0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f,
0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7,
0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc,
0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, 0xbdbdf21c, 0xcabac28a, 0x53b39330,
0x24b4a3a6, 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,
0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d
};
#define UPDC32(octet,crc) (crc_32_tab[((crc)\
^ static_cast<uint8_t>(octet)) & 0xff] ^ ((crc) >> 8))
#define UPDC32(octet, crc) (crc_32_tab[((crc) ^ static_cast<uint8_t>(octet)) & 0xff] ^ ((crc) >> 8))
for (; len; --len, ++buf)
{
@ -318,10 +304,8 @@ void zip_file::remove_comment()
for (; position >= 3; position--)
{
if(buffer_[position - 3] == 'P'
&& buffer_[position - 2] == 'K'
&& buffer_[position - 1] == '\x05'
&& buffer_[position] == '\x06')
if (buffer_[position - 3] == 'P' && buffer_[position - 2] == 'K' && buffer_[position - 1] == '\x05' &&
buffer_[position] == '\x06')
{
position = position + 17;
break;
@ -554,7 +538,9 @@ void zip_file::writestr(const zip_info &info, const std::string &bytes)
auto crc = crc32buf(bytes.c_str(), bytes.size());
if(!mz_zip_writer_add_mem_ex(archive_.get(), info.filename.c_str(), bytes.data(), bytes.size(), info.comment.c_str(), static_cast<mz_uint16>(info.comment.size()), MZ_BEST_COMPRESSION, 0, crc))
if (!mz_zip_writer_add_mem_ex(archive_.get(), info.filename.c_str(), bytes.data(), bytes.size(),
info.comment.c_str(), static_cast<mz_uint16>(info.comment.size()),
MZ_BEST_COMPRESSION, 0, crc))
{
throw std::runtime_error("write error");
}
@ -563,7 +549,8 @@ void zip_file::writestr(const zip_info &info, const std::string &bytes)
std::string zip_file::read(const zip_info &info)
{
std::size_t size;
char *data = static_cast<char *>(mz_zip_reader_extract_file_to_heap(archive_.get(), info.filename.c_str(), &size, 0));
char *data =
static_cast<char *>(mz_zip_reader_extract_file_to_heap(archive_.get(), info.filename.c_str(), &size, 0));
if (data == nullptr)
{
throw std::runtime_error("file couldn't be read");
@ -687,7 +674,15 @@ void zip_file::printdir()
void zip_file::printdir(std::ostream &stream)
{
stream << " Length " << " " << " " << "Date" << " " << " " << "Time " << " " << "Name" << std::endl;
stream << " Length "
<< " "
<< " "
<< "Date"
<< " "
<< " "
<< "Time "
<< " "
<< "Name" << std::endl;
stream << "--------- ---------- ----- ----" << std::endl;
std::size_t sum_length = 0;

View File

@ -9,7 +9,8 @@ namespace xlnt {
const row_t constants::MinRow = 1;
const row_t constants::MaxRow = LimitStyle == limit_style::excel ? (1u << 20) : UINT32_MAX;
const column_t constants::MinColumn = 1;
const column_t constants::MaxColumn = LimitStyle == limit_style::excel ? (1u << 14) : LimitStyle == limit_style::openpyxl ? 18278 : UINT32_MAX;
const column_t constants::MaxColumn =
LimitStyle == limit_style::excel ? (1u << 14) : LimitStyle == limit_style::openpyxl ? 18278 : UINT32_MAX;
// constants
const std::string constants::PackageProps = "docProps";
@ -30,8 +31,7 @@ const std::string constants::ArcStyles = PackageXl + "/styles.xml";
const std::string constants::ArcTheme = PackageTheme + "/theme1.xml";
const std::string constants::ArcSharedString = PackageXl + "/sharedStrings.xml";
const std::unordered_map<std::string, std::string> constants::Namespaces =
{
const std::unordered_map<std::string, std::string> constants::Namespaces = {
{ "spreadsheetml", "http://schemas.openxmlformats.org/spreadsheetml/2006/main" },
{ "content-types", "http://schemas.openxmlformats.org/package/2006/content-types" },
{ "relationships", "http://schemas.openxmlformats.org/package/2006/relationships" },
@ -45,5 +45,4 @@ const std::unordered_map<std::string, std::string> constants::Namespaces =
{ "vt", "http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes" },
{ "xml", "http://www.w3.org/XML/1998/namespace" }
};
}

View File

@ -0,0 +1,31 @@
#pragma once
#ifdef _MSC_VER
#pragma push_macro("NOMINMAX")
#pragma push_macro("UNICODE")
#pragma push_macro("STRICT")
#ifndef NOMINMAX
#define NOMINMAX
#endif
#ifndef UNICODE
#define UNICODE
#endif
#ifndef STRICT
#define STRICT
#endif
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#include <Windows.h>
#pragma pop_macro("STRICT")
#pragma pop_macro("UNICODE")
#pragma pop_macro("NOMINMAX")
#endif // _MSC_VER

View File

@ -38,7 +38,8 @@ struct workbook_impl
relationships_.clear();
std::copy(other.relationships_.begin(), other.relationships_.end(), std::back_inserter(relationships_));
root_relationships_.clear();
std::copy(other.root_relationships_.begin(), other.root_relationships_.end(), std::back_inserter(root_relationships_));
std::copy(other.root_relationships_.begin(), other.root_relationships_.end(),
std::back_inserter(root_relationships_));
drawings_.clear();
std::copy(other.drawings_.begin(), other.drawings_.end(), back_inserter(drawings_));
shared_strings_.clear();

View File

@ -2,6 +2,9 @@
#include <unordered_map>
#include <vector>
#include <xlnt/worksheet/column_properties.hpp>
#include <xlnt/worksheet/row_properties.hpp>
#include "cell_impl.hpp"
namespace xlnt {

View File

@ -7,8 +7,12 @@ namespace detail {
struct xml_node_impl
{
xml_node_impl() {}
explicit xml_node_impl(pugi::xml_node n) : node(n) {}
xml_node_impl()
{
}
explicit xml_node_impl(pugi::xml_node n) : node(n)
{
}
pugi::xml_node node;
};

View File

@ -6,13 +6,11 @@ struct drawing_struct
{
drawing_struct()
{
}
};
drawing::drawing() : root_(nullptr)
{
}
} // namespace xlnt

View File

@ -54,7 +54,8 @@ bool load_workbook(xlnt::zip_file &archive, bool guess_types, bool data_only, xl
wb.clear();
auto workbook_relationships = xlnt::relationship_serializer::read_relationships(archive, xlnt::constants::ArcWorkbook);
auto workbook_relationships =
xlnt::relationship_serializer::read_relationships(archive, xlnt::constants::ArcWorkbook);
for (const auto &relationship : workbook_relationships)
{
@ -66,11 +67,15 @@ bool load_workbook(xlnt::zip_file &archive, bool guess_types, bool data_only, xl
auto root_node = xml.get_child("workbook");
auto workbook_pr_node = root_node.get_child("workbookPr");
wb.get_properties().excel_base_date = (workbook_pr_node.has_attribute("date1904") && workbook_pr_node.get_attribute("date1904") != "0") ? xlnt::calendar::mac_1904 : xlnt::calendar::windows_1900;
wb.get_properties().excel_base_date =
(workbook_pr_node.has_attribute("date1904") && workbook_pr_node.get_attribute("date1904") != "0")
? xlnt::calendar::mac_1904
: xlnt::calendar::windows_1900;
xlnt::shared_strings_serializer shared_strings_serializer_;
std::vector<std::string> shared_strings;
shared_strings_serializer_.read_shared_strings(xlnt::xml_serializer::deserialize(archive.read(xlnt::constants::ArcSharedString)), shared_strings);
shared_strings_serializer_.read_shared_strings(
xlnt::xml_serializer::deserialize(archive.read(xlnt::constants::ArcSharedString)), shared_strings);
for (auto shared_string : shared_strings)
{
@ -118,8 +123,7 @@ std::string excel_serializer::repair_central_directory(const std::string &origin
bool excel_serializer::load_stream_workbook(std::istream &stream, bool guess_types, bool data_only)
{
std::vector<std::uint8_t> bytes((std::istream_iterator<char>(stream)),
std::istream_iterator<char>());
std::vector<std::uint8_t> bytes((std::istream_iterator<char>(stream)), std::istream_iterator<char>());
return load_virtual_workbook(bytes, guess_types, data_only);
}
@ -165,7 +169,9 @@ void excel_serializer::write_data(bool /*as_template*/)
archive_.writestr(constants::ArcTheme, theme_serializer_.write_theme(workbook_.get_loaded_theme()).to_string());
xlnt::shared_strings_serializer shared_strings_serializer_;
archive_.writestr(constants::ArcSharedString, xml_serializer::serialize(shared_strings_serializer_.write_shared_strings(workbook_.get_shared_strings())));
archive_.writestr(
constants::ArcSharedString,
xml_serializer::serialize(shared_strings_serializer_.write_shared_strings(workbook_.get_shared_strings())));
archive_.writestr(constants::ArcWorkbook, xml_serializer::serialize(workbook_serializer_.write_workbook()));
@ -202,7 +208,6 @@ void excel_serializer::write_worksheets()
void excel_serializer::write_external_links()
{
}
bool excel_serializer::save_stream_workbook(std::ostream &stream, bool as_template)

View File

@ -9,7 +9,6 @@ namespace xlnt {
manifest_serializer::manifest_serializer(manifest &m) : manifest_(m)
{
}
void manifest_serializer::read_manifest(const xml_document &xml)

View File

@ -24,7 +24,6 @@ std::string make_rels_name(const std::string &target)
return first_part + "_rels/" + last_part + ".rels";
}
}
namespace xlnt {
@ -55,7 +54,8 @@ std::vector<relationship> relationship_serializer::read_relationships(zip_file &
return relationships;
}
bool relationship_serializer::write_relationships(const std::vector<relationship> &relationships, const std::string &target, zip_file &archive)
bool relationship_serializer::write_relationships(const std::vector<relationship> &relationships,
const std::string &target, zip_file &archive)
{
xml_document xml;
@ -83,5 +83,4 @@ bool relationship_serializer::write_relationships(const std::vector<relationship
return true;
}
}

View File

@ -674,10 +674,17 @@ xml_document style_serializer::write_stylesheet() const
switch (fill_.get_foreground_color().get_type())
{
case color::type::auto_: fg_color_node.add_attribute("auto", std::to_string(fill_.get_foreground_color().get_auto())); break;
case color::type::theme: fg_color_node.add_attribute("theme", std::to_string(fill_.get_foreground_color().get_theme())); break;
case color::type::indexed: fg_color_node.add_attribute("indexed", std::to_string(fill_.get_foreground_color().get_index())); break;
default: throw std::runtime_error("bad type");
case color::type::auto_:
fg_color_node.add_attribute("auto", std::to_string(fill_.get_foreground_color().get_auto()));
break;
case color::type::theme:
fg_color_node.add_attribute("theme", std::to_string(fill_.get_foreground_color().get_theme()));
break;
case color::type::indexed:
fg_color_node.add_attribute("indexed", std::to_string(fill_.get_foreground_color().get_index()));
break;
default:
throw std::runtime_error("bad type");
}
}
@ -687,10 +694,17 @@ xml_document style_serializer::write_stylesheet() const
switch (fill_.get_background_color().get_type())
{
case color::type::auto_: bg_color_node.add_attribute("auto", std::to_string(fill_.get_background_color().get_auto())); break;
case color::type::theme: bg_color_node.add_attribute("theme", std::to_string(fill_.get_background_color().get_theme())); break;
case color::type::indexed: bg_color_node.add_attribute("indexed", std::to_string(fill_.get_background_color().get_index())); break;
default: throw std::runtime_error("bad type");
case color::type::auto_:
bg_color_node.add_attribute("auto", std::to_string(fill_.get_background_color().get_auto()));
break;
case color::type::theme:
bg_color_node.add_attribute("theme", std::to_string(fill_.get_background_color().get_theme()));
break;
case color::type::indexed:
bg_color_node.add_attribute("indexed", std::to_string(fill_.get_background_color().get_index()));
break;
default:
throw std::runtime_error("bad type");
}
}
}
@ -758,21 +772,50 @@ xml_document style_serializer::write_stylesheet() const
switch (side_.get_style())
{
case border_style::none: style_string = "none"; break;
case border_style::dashdot: style_string = "dashdot"; break;
case border_style::dashdotdot: style_string = "dashdotdot"; break;
case border_style::dashed: style_string = "dashed"; break;
case border_style::dotted: style_string = "dotted"; break;
case border_style::double_: style_string = "double"; break;
case border_style::hair: style_string = "hair"; break;
case border_style::medium: style_string = "thin"; break;
case border_style::mediumdashdot: style_string = "mediumdashdot"; break;
case border_style::mediumdashdotdot: style_string = "mediumdashdotdot"; break;
case border_style::mediumdashed: style_string = "mediumdashed"; break;
case border_style::slantdashdot: style_string = "slantdashdot"; break;
case border_style::thick: style_string = "thick"; break;
case border_style::thin: style_string = "thin"; break;
default: throw std::runtime_error("invalid style");
case border_style::none:
style_string = "none";
break;
case border_style::dashdot:
style_string = "dashdot";
break;
case border_style::dashdotdot:
style_string = "dashdotdot";
break;
case border_style::dashed:
style_string = "dashed";
break;
case border_style::dotted:
style_string = "dotted";
break;
case border_style::double_:
style_string = "double";
break;
case border_style::hair:
style_string = "hair";
break;
case border_style::medium:
style_string = "thin";
break;
case border_style::mediumdashdot:
style_string = "mediumdashdot";
break;
case border_style::mediumdashdotdot:
style_string = "mediumdashdotdot";
break;
case border_style::mediumdashed:
style_string = "mediumdashed";
break;
case border_style::slantdashdot:
style_string = "slantdashdot";
break;
case border_style::thick:
style_string = "thick";
break;
case border_style::thin:
style_string = "thin";
break;
default:
throw std::runtime_error("invalid style");
}
side_node.add_attribute("style", style_string);

View File

@ -26,20 +26,13 @@ xml_document theme_serializer::write_theme(const theme &) const
std::string val;
};
std::vector<scheme_element> scheme_elements =
{
{"a:dk1", "a:sysClr", "windowText"},
{"a:lt1", "a:sysClr", "window"},
{"a:dk2", "a:srgbClr", "1F497D"},
{"a:lt2", "a:srgbClr", "EEECE1"},
{"a:accent1", "a:srgbClr", "4F81BD"},
{"a:accent2", "a:srgbClr", "C0504D"},
{"a:accent3", "a:srgbClr", "9BBB59"},
{"a:accent4", "a:srgbClr", "8064A2"},
{"a:accent5", "a:srgbClr", "4BACC6"},
{"a:accent6", "a:srgbClr", "F79646"},
{"a:hlink", "a:srgbClr", "0000FF"},
{"a:folHlink", "a:srgbClr", "800080"},
std::vector<scheme_element> scheme_elements = {
{ "a:dk1", "a:sysClr", "windowText" }, { "a:lt1", "a:sysClr", "window" },
{ "a:dk2", "a:srgbClr", "1F497D" }, { "a:lt2", "a:srgbClr", "EEECE1" },
{ "a:accent1", "a:srgbClr", "4F81BD" }, { "a:accent2", "a:srgbClr", "C0504D" },
{ "a:accent3", "a:srgbClr", "9BBB59" }, { "a:accent4", "a:srgbClr", "8064A2" },
{ "a:accent5", "a:srgbClr", "4BACC6" }, { "a:accent6", "a:srgbClr", "F79646" },
{ "a:hlink", "a:srgbClr", "0000FF" }, { "a:folHlink", "a:srgbClr", "800080" },
};
for (auto element : scheme_elements)
@ -65,15 +58,17 @@ xml_document theme_serializer::write_theme(const theme &) const
std::string minor;
};
std::vector<font_scheme> font_schemes =
{
std::vector<font_scheme> font_schemes = {
{ true, "a:latin", "Cambria", "Calibri" },
{ true, "a:ea", "", "" },
{ true, "a:cs", "", "" },
{false, "Jpan", "\xef\xbc\xad\xef\xbc\xb3 \xef\xbc\xb0\xe3\x82\xb4\xe3\x82\xb7\xe3\x83\x83\xe3\x82\xaf", "\xef\xbc\xad\xef\xbc\xb3 \xef\xbc\xb0\xe3\x82\xb4\xe3\x82\xb7\xe3\x83\x83\xe3\x82\xaf"},
{false, "Hang", "\xeb\xa7\x91\xec\x9d\x80 \xea\xb3\xa0\xeb\x94\x95", "\xeb\xa7\x91\xec\x9d\x80 \xea\xb3\xa0\xeb\x94\x95"},
{ false, "Jpan", "\xef\xbc\xad\xef\xbc\xb3 \xef\xbc\xb0\xe3\x82\xb4\xe3\x82\xb7\xe3\x83\x83\xe3\x82\xaf",
"\xef\xbc\xad\xef\xbc\xb3 \xef\xbc\xb0\xe3\x82\xb4\xe3\x82\xb7\xe3\x83\x83\xe3\x82\xaf" },
{ false, "Hang", "\xeb\xa7\x91\xec\x9d\x80 \xea\xb3\xa0\xeb\x94\x95",
"\xeb\xa7\x91\xec\x9d\x80 \xea\xb3\xa0\xeb\x94\x95" },
{ false, "Hans", "\xe5\xae\x8b\xe4\xbd\x93", "\xe5\xae\x8b\xe4\xbd\x93" },
{false, "Hant", "\xe6\x96\xb0\xe7\xb4\xb0\xe6\x98\x8e\xe9\xab\x94", "\xe6\x96\xb0\xe7\xb4\xb0\xe6\x98\x8e\xe9\xab\x94"},
{ false, "Hant", "\xe6\x96\xb0\xe7\xb4\xb0\xe6\x98\x8e\xe9\xab\x94",
"\xe6\x96\xb0\xe7\xb4\xb0\xe6\x98\x8e\xe9\xab\x94" },
{ false, "Arab", "Times New Roman", "Arial" },
{ false, "Hebr", "Times New Roman", "Arial" },
{ false, "Thai", "Tahoma", "Tahoma" },

View File

@ -46,7 +46,9 @@ std::string fill(const std::string &string, std::size_t length = 2)
std::string datetime_to_w3cdtf(const xlnt::datetime &dt)
{
return std::to_string(dt.year) + "-" + fill(std::to_string(dt.month)) + "-" + fill(std::to_string(dt.day)) + "T" + fill(std::to_string(dt.hour)) + ":" + fill(std::to_string(dt.minute)) + ":" + fill(std::to_string(dt.second)) + "Z";
return std::to_string(dt.year) + "-" + fill(std::to_string(dt.month)) + "-" + fill(std::to_string(dt.day)) + "T" +
fill(std::to_string(dt.hour)) + ":" + fill(std::to_string(dt.minute)) + ":" +
fill(std::to_string(dt.second)) + "Z";
}
} // namespace
@ -129,7 +131,8 @@ void workbook_serializer::read_properties_core(const xml_document &xml)
/// </summary>
std::vector<workbook_serializer::string_pair> workbook_serializer::detect_worksheets()
{
static const std::string ValidWorksheet = "application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml";
static const std::string ValidWorksheet =
"application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml";
std::vector<std::string> valid_sheets;
@ -146,7 +149,8 @@ std::vector<workbook_serializer::string_pair> workbook_serializer::detect_worksh
for (const auto &ws : read_sheets())
{
auto rel = *std::find_if(workbook_relationships.begin(), workbook_relationships.end(), [&](const relationship &r) { return r.get_id() == ws.first; });
auto rel = *std::find_if(workbook_relationships.begin(), workbook_relationships.end(),
[&](const relationship &r) { return r.get_id() == ws.first; });
auto target = rel.get_target_uri();
if (std::find(valid_sheets.begin(), valid_sheets.end(), "/" + target) != valid_sheets.end())
@ -210,7 +214,9 @@ xml_document workbook_serializer::write_properties_app() const
heading_pairs_vector_node.add_attribute("baseType", "variant");
heading_pairs_vector_node.add_attribute("size", "2");
heading_pairs_vector_node.add_child("vt:variant").add_child("vt:lpstr").set_text("Worksheets");
heading_pairs_vector_node.add_child("vt:variant").add_child("vt:i4").set_text(std::to_string(workbook_.get_sheet_names().size()));
heading_pairs_vector_node.add_child("vt:variant")
.add_child("vt:i4")
.set_text(std::to_string(workbook_.get_sheet_names().size()));
auto titles_of_parts_node = root_node.add_child("TitlesOfParts");
auto titles_of_parts_vector_node = titles_of_parts_node.add_child("vt:vector");
@ -258,7 +264,8 @@ xml_document workbook_serializer::write_workbook() const
auto workbook_pr_node = root_node.add_child("workbookPr");
workbook_pr_node.add_attribute("codeName", "ThisWorkbook");
workbook_pr_node.add_attribute("defaultThemeVersion", "124226");
workbook_pr_node.add_attribute("date1904", workbook_.get_properties().excel_base_date == calendar::mac_1904 ? "1" : "0");
workbook_pr_node.add_attribute("date1904",
workbook_.get_properties().excel_base_date == calendar::mac_1904 ? "1" : "0");
auto book_views_node = root_node.add_child("bookViews");
auto workbook_view_node = book_views_node.add_child("workbookView");
@ -285,7 +292,8 @@ xml_document workbook_serializer::write_workbook() const
sheet_index_string = sheet_index_string.substr(sheet_index_string.find_last_of('/'));
auto iter = sheet_index_string.end();
iter--;
while (isdigit(*iter)) iter--;
while (isdigit(*iter))
iter--;
auto first_digit = iter - sheet_index_string.begin();
sheet_index_string = sheet_index_string.substr(static_cast<std::string::size_type>(first_digit + 1));
std::size_t sheet_index = static_cast<std::size_t>(std::stoll(sheet_index_string) - 1);
@ -303,7 +311,8 @@ xml_document workbook_serializer::write_workbook() const
defined_name_node.add_attribute("name", "_xlnm._FilterDatabase");
defined_name_node.add_attribute("hidden", "1");
defined_name_node.add_attribute("localSheetId", "0");
std::string name = "'" + ws.get_title() + "'!" + range_reference::make_absolute(ws.get_auto_filter()).to_string();
std::string name =
"'" + ws.get_title() + "'!" + range_reference::make_absolute(ws.get_auto_filter()).to_string();
defined_name_node.set_text(name);
}
}

View File

@ -7,10 +7,12 @@
#include <xlnt/s11n/xml_document.hpp>
#include <xlnt/s11n/xml_node.hpp>
#include <xlnt/workbook/workbook.hpp>
#include <xlnt/worksheet/column_properties.hpp>
#include <xlnt/worksheet/range.hpp>
#include <xlnt/worksheet/range_reference.hpp>
#include <xlnt/worksheet/row_properties.hpp>
#include "detail/constants.hpp"
#include <detail/constants.hpp>
namespace {
@ -125,7 +127,8 @@ bool worksheet_serializer::read_worksheet(const xml_document &xml)
int style_id = has_style ? std::stoull(cell_node.get_attribute("s")) : 0;
bool has_formula = cell_node.has_child("f");
bool has_shared_formula = has_formula && cell_node.get_child("f").has_attribute("t") && cell_node.get_child("f").get_attribute("t") == "shared";
bool has_shared_formula = has_formula && cell_node.get_child("f").has_attribute("t") &&
cell_node.get_child("f").get_attribute("t") == "shared";
auto cell = sheet_.get_cell(address);
@ -519,8 +522,10 @@ xml_document worksheet_serializer::write_worksheet() const
if (!sheet_.get_page_setup().is_default())
{
auto print_options_node = root_node.add_child("printOptions");
print_options_node.add_attribute("horizontalCentered", sheet_.get_page_setup().get_horizontal_centered() ? "1" : "0");
print_options_node.add_attribute("verticalCentered", sheet_.get_page_setup().get_vertical_centered() ? "1" : "0");
print_options_node.add_attribute("horizontalCentered",
sheet_.get_page_setup().get_horizontal_centered() ? "1" : "0");
print_options_node.add_attribute("verticalCentered",
sheet_.get_page_setup().get_vertical_centered() ? "1" : "0");
}
auto page_margins_node = root_node.add_child("pageMargins");
@ -536,9 +541,11 @@ xml_document worksheet_serializer::write_worksheet() const
{
auto page_setup_node = root_node.add_child("pageSetup");
std::string orientation_string = sheet_.get_page_setup().get_orientation() == page_setup::orientation::landscape ? "landscape" : "portrait";
std::string orientation_string =
sheet_.get_page_setup().get_orientation() == page_setup::orientation::landscape ? "landscape" : "portrait";
page_setup_node.add_attribute("orientation", orientation_string);
page_setup_node.add_attribute("paperSize", std::to_string(static_cast<int>(sheet_.get_page_setup().get_paper_size())));
page_setup_node.add_attribute("paperSize",
std::to_string(static_cast<int>(sheet_.get_page_setup().get_paper_size())));
page_setup_node.add_attribute("fitToHeight", sheet_.get_page_setup().fit_to_height() ? "1" : "0");
page_setup_node.add_attribute("fitToWidth", sheet_.get_page_setup().fit_to_width() ? "1" : "0");
}
@ -547,10 +554,15 @@ xml_document worksheet_serializer::write_worksheet() const
{
auto header_footer_node = root_node.add_child("headerFooter");
auto odd_header_node = header_footer_node.add_child("oddHeader");
std::string header_text = "&L&\"Calibri,Regular\"&K000000Left Header Text&C&\"Arial,Regular\"&6&K445566Center Header Text&R&\"Arial,Bold\"&8&K112233Right Header Text";
std::string header_text =
"&L&\"Calibri,Regular\"&K000000Left Header Text&C&\"Arial,Regular\"&6&K445566Center Header "
"Text&R&\"Arial,Bold\"&8&K112233Right Header Text";
odd_header_node.set_text(header_text);
auto odd_footer_node = header_footer_node.add_child("oddFooter");
std::string footer_text = "&L&\"Times New Roman,Regular\"&10&K445566Left Footer Text_x000D_And &D and &T&C&\"Times New Roman,Bold\"&12&K778899Center Footer Text &Z&F on &A&R&\"Times New Roman,Italic\"&14&KAABBCCRight Footer Text &P of &N";
std::string footer_text =
"&L&\"Times New Roman,Regular\"&10&K445566Left Footer Text_x000D_And &D and &T&C&\"Times New "
"Roman,Bold\"&12&K778899Center Footer Text &Z&F on &A&R&\"Times New Roman,Italic\"&14&KAABBCCRight Footer "
"Text &P of &N";
odd_footer_node.set_text(footer_text);
}

View File

@ -5,7 +5,6 @@ namespace xlnt {
side::side()
{
}
} // namespace xlnt

View File

@ -8,8 +8,7 @@ namespace {
const std::unordered_map<int, std::string> &builtin_formats()
{
static const std::unordered_map<int, std::string> formats =
{
static const std::unordered_map<int, std::string> formats = {
{ 0, "General" },
{ 1, "0" },
{ 2, "0.00" },

View File

@ -4,12 +4,10 @@ namespace xlnt {
protection::protection() : protection(type::unprotected)
{
}
protection::protection(type t) : locked_(t), hidden_(type::unprotected)
{
}
} // namespace xlnt

View File

@ -12,7 +12,6 @@ void hash_combine(std::size_t& seed, const T& v)
std::hash<T> hasher;
seed ^= hasher(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
}
}
namespace xlnt {
@ -20,8 +19,8 @@ namespace xlnt {
const color color::black = color(color::type::indexed, 0);
const color color::white = color(color::type::indexed, 0);
style::style() :
id_(0),
style::style()
: id_(0),
alignment_apply_(false),
border_apply_(false),
border_id_(0),
@ -37,8 +36,8 @@ style::style() :
{
}
style::style(const style &other) :
id_(other.id_),
style::style(const style &other)
: id_(other.id_),
alignment_apply_(other.alignment_apply_),
alignment_(other.alignment_),
border_apply_(other.border_apply_),

View File

@ -3,11 +3,8 @@
namespace xlnt {
document_properties::document_properties()
: created(1900, 1, 1),
modified(1900, 1, 1),
excel_base_date(calendar::windows_1900)
: created(1900, 1, 1), modified(1900, 1, 1), excel_base_date(calendar::windows_1900)
{
}
} // namespace xlnt

View File

@ -29,15 +29,12 @@ default_type::default_type()
{
}
default_type::default_type(const std::string &extension, const std::string &content_type) :
extension_(extension),
content_type_(content_type)
default_type::default_type(const std::string &extension, const std::string &content_type)
: extension_(extension), content_type_(content_type)
{
}
default_type::default_type(const default_type &other) :
extension_(other.extension_),
content_type_(other.content_type_)
default_type::default_type(const default_type &other) : extension_(other.extension_), content_type_(other.content_type_)
{
}
@ -53,15 +50,13 @@ override_type::override_type()
{
}
override_type::override_type(const std::string &part_name, const std::string &content_type) :
part_name_(part_name),
content_type_(content_type)
override_type::override_type(const std::string &part_name, const std::string &content_type)
: part_name_(part_name), content_type_(content_type)
{
}
override_type::override_type(const override_type &other) :
part_name_(other.part_name_),
content_type_(other.content_type_)
override_type::override_type(const override_type &other)
: part_name_(other.part_name_), content_type_(other.content_type_)
{
}
@ -81,8 +76,9 @@ bool manifest::has_default_type(const std::string &extension) const
bool manifest::has_override_type(const std::string &part_name) const
{
return std::find_if(override_types_.begin(), override_types_.end(),
[&](const override_type &d) { return match_path(d.get_part_name(), part_name); }) != override_types_.end();
return std::find_if(override_types_.begin(), override_types_.end(), [&](const override_type &d) {
return match_path(d.get_part_name(), part_name);
}) != override_types_.end();
}
void manifest::add_default_type(const std::string &extension, const std::string &content_type)

View File

@ -75,8 +75,7 @@ named_range::named_range(const named_range &other)
}
named_range::named_range(const std::string &name, const std::vector<named_range::target> &targets)
: name_(name),
targets_(targets)
: name_(name), targets_(targets)
{
}

View File

@ -4,10 +4,6 @@
#include <set>
#include <sstream>
#ifdef _WIN32
#include <Windows.h>
#endif
#include <xlnt/common/exceptions.hpp>
#include <xlnt/common/relationship.hpp>
#include <xlnt/common/zip_file.hpp>
@ -28,15 +24,16 @@
#include <xlnt/worksheet/range.hpp>
#include <xlnt/worksheet/worksheet.hpp>
#include "detail/cell_impl.hpp"
#include "detail/include_pugixml.hpp"
#include "detail/workbook_impl.hpp"
#include "detail/worksheet_impl.hpp"
#include <detail/cell_impl.hpp>
#include <detail/include_windows.hpp>
#include <detail/workbook_impl.hpp>
#include <detail/worksheet_impl.hpp>
namespace xlnt {
namespace detail {
workbook_impl::workbook_impl() : active_sheet_index_(0), guess_types_(false), data_only_(false), next_custom_format_id_(164)
workbook_impl::workbook_impl()
: active_sheet_index_(0), guess_types_(false), data_only_(false), next_custom_format_id_(164)
{
}
@ -52,12 +49,10 @@ workbook::workbook() : d_(new detail::workbook_impl())
workbook::iterator::iterator(workbook &wb, std::size_t index) : wb_(wb), index_(index)
{
}
workbook::iterator::iterator(const iterator &rhs) : wb_(rhs.wb_), index_(rhs.index_)
{
}
worksheet workbook::iterator::operator*()
@ -85,12 +80,10 @@ bool workbook::iterator::operator==(const iterator &comparand) const
workbook::const_iterator::const_iterator(const workbook &wb, std::size_t index) : wb_(wb), index_(index)
{
}
workbook::const_iterator::const_iterator(const const_iterator &rhs) : wb_(rhs.wb_), index_(rhs.index_)
{
}
const worksheet workbook::const_iterator::operator*()
@ -167,7 +160,9 @@ worksheet workbook::create_sheet()
}
d_->worksheets_.push_back(detail::worksheet_impl(this, title));
create_relationship("rId" + std::to_string(d_->relationships_.size() + 1), "xl/worksheets/sheet" + std::to_string(d_->worksheets_.size()) + ".xml", relationship::type::worksheet);
create_relationship("rId" + std::to_string(d_->relationships_.size() + 1),
"xl/worksheets/sheet" + std::to_string(d_->worksheets_.size()) + ".xml",
relationship::type::worksheet);
return worksheet(&d_->worksheets_.back());
}
@ -297,7 +292,8 @@ relationship workbook::get_relationship(const std::string &id) const
void workbook::remove_sheet(worksheet ws)
{
auto match_iter = std::find_if(d_->worksheets_.begin(), d_->worksheets_.end(), [=](detail::worksheet_impl &comp) { return worksheet(&comp) == ws; });
auto match_iter = std::find_if(d_->worksheets_.begin(), d_->worksheets_.end(),
[=](detail::worksheet_impl &comp) { return worksheet(&comp) == ws; });
if (match_iter == d_->worksheets_.end())
{
@ -305,7 +301,8 @@ void workbook::remove_sheet(worksheet ws)
}
auto sheet_filename = "xl/worksheets/sheet" + std::to_string(d_->worksheets_.size()) + ".xml";
auto rel_iter = std::find_if(d_->relationships_.begin(), d_->relationships_.end(), [=](relationship &r) { return r.get_target_uri() == sheet_filename; });
auto rel_iter = std::find_if(d_->relationships_.begin(), d_->relationships_.end(),
[=](relationship &r) { return r.get_target_uri() == sheet_filename; });
if (rel_iter == d_->relationships_.end())
{
@ -337,7 +334,8 @@ std::size_t workbook::index_from_ws_filename(const std::string &ws_filename)
sheet_index_string = sheet_index_string.substr(sheet_index_string.find_last_of('/'));
auto iter = sheet_index_string.end();
iter--;
while (isdigit(*iter)) iter--;
while (isdigit(*iter))
iter--;
auto first_digit = static_cast<std::size_t>(iter - sheet_index_string.begin());
sheet_index_string = sheet_index_string.substr(first_digit + 1);
auto sheet_index = static_cast<std::size_t>(std::stoll(sheet_index_string) - 1);
@ -373,19 +371,24 @@ worksheet workbook::create_sheet(const std::string &title)
throw sheet_title_exception(title);
}
if(std::find_if(title.begin(), title.end(),
[](char c) { return c == '*' || c == ':' || c == '/' || c == '\\' || c == '?' || c == '[' || c == ']'; }) != title.end())
if (std::find_if(title.begin(), title.end(), [](char c) {
return c == '*' || c == ':' || c == '/' || c == '\\' || c == '?' || c == '[' || c == ']';
}) != title.end())
{
throw sheet_title_exception(title);
}
std::string unique_title = title;
if(std::find_if(d_->worksheets_.begin(), d_->worksheets_.end(), [&](detail::worksheet_impl &ws) { return worksheet(&ws).get_title() == unique_title; }) != d_->worksheets_.end())
if (std::find_if(d_->worksheets_.begin(), d_->worksheets_.end(), [&](detail::worksheet_impl &ws) {
return worksheet(&ws).get_title() == unique_title;
}) != d_->worksheets_.end())
{
std::size_t suffix = 1;
while(std::find_if(d_->worksheets_.begin(), d_->worksheets_.end(), [&](detail::worksheet_impl &ws) { return worksheet(&ws).get_title() == unique_title; }) != d_->worksheets_.end())
while (std::find_if(d_->worksheets_.begin(), d_->worksheets_.end(), [&](detail::worksheet_impl &ws) {
return worksheet(&ws).get_title() == unique_title;
}) != d_->worksheets_.end())
{
unique_title = title + std::to_string(suffix);
suffix++;
@ -480,24 +483,6 @@ const std::vector<relationship> &xlnt::workbook::get_relationships() const
return d_->relationships_;
}
std::vector<content_type> xlnt::workbook::get_content_types() const
{
std::vector<content_type> content_types;
content_types.push_back({ true, "xml", "", "application/xml" });
content_types.push_back({ true, "rels", "", "application/vnd.openxmlformats-package.relationships+xml" });
content_types.push_back({ false, "", "/xl/workbook.xml", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml" });
for(std::size_t i = 0; i < get_sheet_names().size(); i++)
{
content_types.push_back({false, "", "/xl/worksheets/sheet" + std::to_string(i + 1) + ".xml", "application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"});
}
content_types.push_back({false, "", "/xl/theme/theme1.xml", "application/vnd.openxmlformats-officedocument.theme+xml"});
content_types.push_back({false, "", "/xl/styles.xml", "application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml"});
content_types.push_back({false, "", "/xl/sharedStrings.xml", "application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml"});
content_types.push_back({false, "", "/docProps/core.xml", "application/vnd.openxmlformats-package.core-properties+xml"});
content_types.push_back({false, "", "/docProps/app.xml", "application/vnd.openxmlformats-officedocument.extended-properties+xml"});
return content_types;
}
document_properties &workbook::get_properties()
{
return d_->properties_;
@ -577,7 +562,6 @@ void workbook::add_number_format(const number_format &number_format_)
void workbook::set_code_name(const std::string & /*code_name*/)
{
}
bool workbook::has_loaded_theme() const
@ -861,8 +845,10 @@ const std::vector<relationship> &workbook::get_root_relationships() const
{
if (d_->root_relationships_.empty())
{
d_->root_relationships_.push_back(relationship(relationship::type::core_properties, "rId1", "docProps/core.xml"));
d_->root_relationships_.push_back(relationship(relationship::type::extended_properties, "rId2", "docProps/app.xml"));
d_->root_relationships_.push_back(
relationship(relationship::type::core_properties, "rId1", "docProps/core.xml"));
d_->root_relationships_.push_back(
relationship(relationship::type::extended_properties, "rId2", "docProps/app.xml"));
d_->root_relationships_.push_back(relationship(relationship::type::office_document, "rId3", "xl/workbook.xml"));
}

View File

@ -65,9 +65,7 @@ std::size_t cell_vector::num_cells() const
}
cell_vector::cell_vector(worksheet ws, const range_reference &reference, major_order order)
: ws_(ws),
ref_(reference),
order_(order)
: ws_(ws), ref_(reference), order_(order)
{
}
@ -102,11 +100,8 @@ cell cell_vector::get_cell(std::size_t index)
}
range::range(worksheet ws, const range_reference &reference, major_order order)
: ws_(ws),
ref_(reference),
order_(order)
: ws_(ws), ref_(reference), order_(order)
{
}
range::~range()
@ -135,16 +130,15 @@ std::size_t range::length() const
bool range::operator==(const range &comparand) const
{
return ref_ == comparand.ref_
&& ws_ == comparand.ws_
&& order_ == comparand.order_;
return ref_ == comparand.ref_ && ws_ == comparand.ws_ && order_ == comparand.order_;
}
cell_vector range::get_vector(std::size_t vector_index)
{
if (order_ == major_order::row)
{
range_reference reference(ref_.get_top_left().get_column_index(),
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));
@ -152,7 +146,8 @@ cell_vector range::get_vector(std::size_t vector_index)
return cell_vector(ws_, reference, order_);
}
range_reference reference(static_cast<column_t>(static_cast<std::size_t>(ref_.get_top_left().get_column_index()) + vector_index),
range_reference reference(
static_cast<column_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>(static_cast<std::size_t>(ref_.get_top_left().get_column_index()) + vector_index),
ref_.get_bottom_right().get_row());
@ -162,7 +157,9 @@ cell_vector range::get_vector(std::size_t vector_index)
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_.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();
}
cell range::get_cell(const cell_reference &ref)
@ -174,14 +171,12 @@ 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());
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);
return iterator(ws_, row_range, order_);
}
cell_reference bottom_left(ref_.get_top_left().get_column_index(),
ref_.get_bottom_right().get_row());
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);
return iterator(ws_, row_range, order_);
}
@ -206,14 +201,12 @@ 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());
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);
return const_iterator(ws_, row_range, order_);
}
cell_reference bottom_left(ref_.get_top_left().get_column_index(),
ref_.get_bottom_right().get_row());
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);
return const_iterator(ws_, row_range, order_);
}
@ -239,17 +232,13 @@ cell_vector range::iterator::operator*()
{
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_.get_top_left().get_column_index(), current_cell_.get_row(),
range_.get_bottom_right().get_column_index(), current_cell_.get_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_.get_column_index(), range_.get_top_left().get_row(),
current_cell_.get_column_index(), range_.get_bottom_right().get_row());
return cell_vector(ws_, reference, order_);
}

View File

@ -20,9 +20,7 @@ range_reference::range_reference(const char *range_string) : range_reference(std
{
}
range_reference::range_reference(const std::string &range_string)
: top_left_("A1"),
bottom_right_("A1")
range_reference::range_reference(const std::string &range_string) : top_left_("A1"), bottom_right_("A1")
{
auto colon_index = range_string.find(':');
@ -39,22 +37,20 @@ range_reference::range_reference(const std::string &range_string)
}
range_reference::range_reference(const cell_reference &top_left, const cell_reference &bottom_right)
: top_left_(top_left),
bottom_right_(bottom_right)
: top_left_(top_left), bottom_right_(bottom_right)
{
}
range_reference::range_reference(column_t column_index_start, row_t row_index_start, column_t column_index_end, row_t row_index_end)
: top_left_(column_index_start, row_index_start),
bottom_right_(column_index_end, row_index_end)
range_reference::range_reference(column_t column_index_start, row_t row_index_start, column_t column_index_end,
row_t row_index_end)
: top_left_(column_index_start, row_index_start), bottom_right_(column_index_end, row_index_end)
{
}
range_reference range_reference::make_offset(int column_offset, int row_offset) const
{
return range_reference(top_left_.make_offset(column_offset, row_offset), bottom_right_.make_offset(column_offset, row_offset));
return range_reference(top_left_.make_offset(column_offset, row_offset),
bottom_right_.make_offset(column_offset, row_offset));
}
row_t range_reference::get_height() const
@ -79,14 +75,11 @@ std::string range_reference::to_string() const
bool range_reference::operator==(const range_reference &comparand) const
{
return comparand.top_left_ == top_left_
&& comparand.bottom_right_ == bottom_right_;
return comparand.top_left_ == top_left_ && comparand.bottom_right_ == bottom_right_;
}
bool range_reference::operator!=(const range_reference &comparand) const
{
return comparand.top_left_ != top_left_
|| comparand.bottom_right_ != bottom_right_;
return comparand.top_left_ != top_left_ || comparand.bottom_right_ != bottom_right_;
}
}

View File

@ -37,8 +37,8 @@ std::string sheet_protection::hash_password(const std::string &plaintext_passwor
password ^= 0xCE4B;
std::string hashed = int_to_hex(password);
std::transform(hashed.begin(), hashed.end(), hashed.begin(), [](char c){ return std::toupper(c, std::locale::classic()); });
std::transform(hashed.begin(), hashed.end(), hashed.begin(),
[](char c) { return std::toupper(c, std::locale::classic()); });
return hashed;
}
}

View File

@ -16,20 +16,18 @@ namespace xlnt {
worksheet::worksheet() : d_(nullptr)
{
}
worksheet::worksheet(detail::worksheet_impl *d) : d_(d)
{
}
worksheet::worksheet(const worksheet &rhs) : d_(rhs.d_)
{
}
worksheet::worksheet(workbook &parent, const std::string &title) : d_(title == "" ? parent.create_sheet().d_ : parent.create_sheet(title).d_)
worksheet::worksheet(workbook &parent, const std::string &title)
: d_(title == "" ? parent.create_sheet().d_ : parent.create_sheet(title).d_)
{
}
@ -543,7 +541,6 @@ bool worksheet::operator!=(std::nullptr_t) const
return d_ != nullptr;
}
void worksheet::operator=(const worksheet &other)
{
d_ = other.d_;
@ -615,17 +612,14 @@ const header_footer &worksheet::get_header_footer() const
header_footer::header_footer()
{
}
header::header() : default_(true), font_size_(12)
{
}
footer::footer() : default_(true), font_size_(12)
{
}
void worksheet::set_parent(xlnt::workbook &wb)