restore worksheet::cell(column_t, row_t) method (#137) and move some single use classes/structs/enums into parent header

This commit is contained in:
Thomas Fussell 2017-03-22 21:44:59 -04:00
parent 0541b74c1f
commit c7f61e38c1
30 changed files with 793 additions and 187 deletions

View File

@ -92,12 +92,12 @@ public:
path canonicalize(const std::vector<xlnt::relationship> &rels) const; path canonicalize(const std::vector<xlnt::relationship> &rels) const;
/// <summary> /// <summary>
/// /// Registers a new relationship by specifying all of the relationship properties explicitly.
/// </summary> /// </summary>
std::string register_relationship(const uri &source, relationship_type type, const uri &target, target_mode mode); std::string register_relationship(const uri &source, relationship_type type, const uri &target, target_mode mode);
/// <summary> /// <summary>
/// /// Registers a new relationship already constructed elsewhere.
/// </summary> /// </summary>
std::string register_relationship(const class relationship &rel); std::string register_relationship(const class relationship &rel);
@ -174,22 +174,22 @@ public:
private: private:
/// <summary> /// <summary>
/// /// Returns the lowest rId for the given part that hasn't already been registered.
/// </summary> /// </summary>
std::string next_relationship_id(const path &part) const; std::string next_relationship_id(const path &part) const;
/// <summary> /// <summary>
/// /// The map of extensions to default content types.
/// </summary> /// </summary>
std::unordered_map<std::string, std::string> default_content_types_; std::unordered_map<std::string, std::string> default_content_types_;
/// <summary> /// <summary>
/// /// The map of package parts to overriding content types.
/// </summary> /// </summary>
std::unordered_map<path, std::string> override_content_types_; std::unordered_map<path, std::string> override_content_types_;
/// <summary> /// <summary>
/// /// The map of package parts to their registered relationships.
/// </summary> /// </summary>
std::unordered_map<path, std::unordered_map<std::string, xlnt::relationship>> relationships_; std::unordered_map<path, std::unordered_map<std::string, xlnt::relationship>> relationships_;
}; };

View File

@ -102,15 +102,15 @@ class XLNT_API relationship
{ {
public: public:
/// <summary> /// <summary>
/// /// Constructs a new empty relationship.
/// </summary> /// </summary>
relationship(); relationship();
/// <summary> /// <summary>
/// /// Constructs a new relationship by specifying all of its properties.
/// </summary> /// </summary>
relationship( relationship(const std::string &id, relationship_type t, const uri &source,
const std::string &id, relationship_type t, const uri &source, const uri &target, xlnt::target_mode mode); const uri &target, xlnt::target_mode mode);
/// <summary> /// <summary>
/// Returns a string of the form rId# that identifies the relationship. /// Returns a string of the form rId# that identifies the relationship.
@ -149,27 +149,27 @@ public:
private: private:
/// <summary> /// <summary>
/// /// The id of this relationship in the format "rId#"
/// </summary> /// </summary>
std::string id_; std::string id_;
/// <summary> /// <summary>
/// /// The type of this relationship.
/// </summary> /// </summary>
relationship_type type_; relationship_type type_;
/// <summary> /// <summary>
/// /// The URI of the source of this relationship.
/// </summary> /// </summary>
uri source_; uri source_;
/// <summary> /// <summary>
/// /// The URI of the target of this relationshp.
/// </summary> /// </summary>
uri target_; uri target_;
/// <summary> /// <summary>
/// /// Whether the target of this relationship is internal or external.
/// </summary> /// </summary>
xlnt::target_mode mode_; xlnt::target_mode mode_;
}; };

View File

@ -31,194 +31,207 @@
namespace xlnt { namespace xlnt {
/// <summary> /// <summary>
/// /// Encapsulates a uniform resource identifier (URI) as described
/// by RFC 3986.
/// </summary> /// </summary>
class XLNT_API uri class XLNT_API uri
{ {
public: public:
/// <summary> /// <summary>
/// /// Constructs an empty URI.
/// </summary> /// </summary>
uri(); uri();
/// <summary> /// <summary>
/// /// Constructs a URI by combining base with relative.
/// </summary> /// </summary>
uri(const uri &base, const uri &relative); uri(const uri &base, const uri &relative);
/// <summary> /// <summary>
/// /// Constructs a URI by combining base with relative path.
/// </summary> /// </summary>
uri(const uri &base, const path &relative); uri(const uri &base, const path &relative);
/// <summary> /// <summary>
/// /// Constructs a URI by parsing the given uri_string.
/// </summary> /// </summary>
uri(const std::string &uri_string); uri(const std::string &uri_string);
/// <summary> /// <summary>
/// /// Returns true if this URI is relative.
/// </summary> /// </summary>
bool is_relative() const; bool is_relative() const;
/// <summary> /// <summary>
/// /// Returns true if this URI is not relative (i.e. absolute).
/// </summary> /// </summary>
bool is_absolute() const; bool is_absolute() const;
/// <summary> /// <summary>
/// /// Returns the scheme of this URI.
/// E.g. the scheme of http://user:pass@example.com is "http"
/// </summary> /// </summary>
std::string scheme() const; std::string scheme() const;
/// <summary> /// <summary>
/// /// Returns the authority of this URI.
/// E.g. the authority of http://user:pass@example.com:80/document is "user:pass@example.com:80"
/// </summary> /// </summary>
std::string authority() const; std::string authority() const;
/// <summary> /// <summary>
/// /// Returns true if an authentication section is specified for this URI.
/// </summary> /// </summary>
bool has_authentication() const; bool has_authentication() const;
/// <summary> /// <summary>
/// /// Returns the authentication of this URI.
/// E.g. the authentication of http://user:pass@example.com is "user:pass"
/// </summary> /// </summary>
std::string authentication() const; std::string authentication() const;
/// <summary> /// <summary>
/// /// Returns the username of this URI.
/// E.g. the username of http://user:pass@example.com is "user"
/// </summary> /// </summary>
std::string username() const; std::string username() const;
/// <summary> /// <summary>
/// /// Returns the password of this URI.
/// E.g. the password of http://user:pass@example.com is "pass"
/// </summary> /// </summary>
std::string password() const; std::string password() const;
/// <summary> /// <summary>
/// /// Returns the host of this URI.
/// E.g. the host of http://example.com:80/document is "example.com"
/// </summary> /// </summary>
std::string host() const; std::string host() const;
/// <summary> /// <summary>
/// /// Returns true if a non-default port is specified for this URI.
/// </summary> /// </summary>
bool has_port() const; bool has_port() const;
/// <summary> /// <summary>
/// /// Returns the port of this URI.
/// E.g. the port of https://example.com:443/document is "443"
/// </summary> /// </summary>
std::size_t port() const; std::size_t port() const;
/// <summary> /// <summary>
/// /// Returns the path of this URI.
/// E.g. the path of http://example.com/document is "/document"
/// </summary> /// </summary>
class path path() const; class path path() const;
/// <summary> /// <summary>
/// /// Returns true if this URI has a non-null query string section.
/// </summary> /// </summary>
bool has_query() const; bool has_query() const;
/// <summary> /// <summary>
/// /// Returns the query string of this URI.
/// E.g. the query of http://example.com/document?v=1&x=3#abc is "v=1&x=3"
/// </summary> /// </summary>
std::string query() const; std::string query() const;
/// <summary> /// <summary>
/// /// Returns true if this URI has a non-empty fragment section.
/// </summary> /// </summary>
bool has_fragment() const; bool has_fragment() const;
/// <summary> /// <summary>
/// /// Returns the fragment section of this URI.
/// E.g. the fragment of http://example.com/document#abc is "abc"
/// </summary> /// </summary>
std::string fragment() const; std::string fragment() const;
/// <summary> /// <summary>
/// /// Returns a string representation of this URI.
/// </summary> /// </summary>
std::string to_string() const; std::string to_string() const;
/// <summary> /// <summary>
/// /// If this URI is relative, an absolute URI will be returned by appending
/// the path to the given absolute base URI.
/// </summary> /// </summary>
uri make_absolute(const uri &base); uri make_absolute(const uri &base);
/// <summary> /// <summary>
/// /// If this URI is absolute, a relative URI will be returned by removing the
/// common base path from the given absolute base URI.
/// </summary> /// </summary>
uri make_reference(const uri &base); uri make_reference(const uri &base);
/// <summary> /// <summary>
/// /// Returns true if this URI is equivalent to other.
/// </summary> /// </summary>
friend XLNT_API bool operator==(const uri &left, const uri &right); bool operator==(const uri &other) const;
private: private:
/// <summary> /// <summary>
/// /// True if this URI is absolute.
/// </summary> /// </summary>
bool absolute_ = false; bool absolute_ = false;
/// <summary> /// <summary>
/// /// The scheme, like "http"
/// </summary> /// </summary>
std::string scheme_; std::string scheme_;
/// <summary> /// <summary>
/// /// True if this URI has an authentication section.
/// </summary> /// </summary>
bool has_authentication_ = false; bool has_authentication_ = false;
/// <summary> /// <summary>
/// /// The username
/// </summary> /// </summary>
std::string username_; std::string username_;
/// <summary> /// <summary>
/// /// The password
/// </summary> /// </summary>
std::string password_; std::string password_;
/// <summary> /// <summary>
/// /// The host
/// </summary> /// </summary>
std::string host_; std::string host_;
/// <summary> /// <summary>
/// /// True if this URI has a non-default port specified
/// </summary> /// </summary>
bool has_port_ = false; bool has_port_ = false;
/// <summary> /// <summary>
/// /// The numeric port
/// </summary> /// </summary>
std::size_t port_ = 0; std::size_t port_ = 0;
/// <summary> /// <summary>
/// /// True if this URI has a query section
/// </summary> /// </summary>
bool has_query_ = false; bool has_query_ = false;
/// <summary> /// <summary>
/// /// The query section
/// </summary> /// </summary>
std::string query_; std::string query_;
/// <summary> /// <summary>
/// /// True if this URI has a fragment section
/// </summary> /// </summary>
bool has_fragment_ = false; bool has_fragment_ = false;
/// <summary> /// <summary>
/// /// The fragment section
/// </summary> /// </summary>
std::string fragment_; std::string fragment_;
/// <summary> /// <summary>
/// /// The path section
/// </summary> /// </summary>
class path path_; class path path_;
}; };

View File

@ -25,12 +25,37 @@
#pragma once #pragma once
#include <xlnt/xlnt_config.hpp> #include <xlnt/xlnt_config.hpp>
#include <xlnt/styles/horizontal_alignment.hpp>
#include <xlnt/styles/vertical_alignment.hpp>
#include <xlnt/utils/optional.hpp> #include <xlnt/utils/optional.hpp>
namespace xlnt { namespace xlnt {
/// <summary>
/// Text can be aligned horizontally in these enumerated ways.
/// </summary>
enum class XLNT_API horizontal_alignment
{
general,
left,
center,
right,
fill,
justify,
center_continuous,
distributed
};
/// <summary>
/// Text can be aligned vertically in these enumerated ways.
/// </summary>
enum class XLNT_API vertical_alignment
{
top,
center,
bottom,
justify,
distributed
};
/// <summary> /// <summary>
/// Alignment options for use in cell formats. /// Alignment options for use in cell formats.
/// </summary> /// </summary>
@ -98,17 +123,14 @@ public:
alignment &vertical(vertical_alignment vertical); alignment &vertical(vertical_alignment vertical);
/// <summary> /// <summary>
/// Returns true if left is exactly equal to right. /// Returns true if this alignment is equivalent to other.
/// </summary> /// </summary>
XLNT_API friend bool operator==(const alignment &left, const alignment &right); bool operator==(const alignment &other) const;
/// <summary> /// <summary>
/// Returns true if left is not exactly equal to right. /// Returns true if this alignment is not equivalent to other.
/// </summary> /// </summary>
XLNT_API friend bool operator!=(const alignment &left, const alignment &right) bool operator!=(const alignment &other) const;
{
return !(left == right);
}
private: private:
bool shrink_to_fit_ = false; bool shrink_to_fit_ = false;

View File

@ -30,15 +30,13 @@
#include <vector> #include <vector>
#include <xlnt/xlnt_config.hpp> #include <xlnt/xlnt_config.hpp>
#include <xlnt/styles/border_style.hpp>
#include <xlnt/styles/color.hpp> #include <xlnt/styles/color.hpp>
#include <xlnt/styles/diagonal_direction.hpp>
#include <xlnt/utils/optional.hpp> #include <xlnt/utils/optional.hpp>
namespace xlnt { namespace xlnt {
/// <summary> /// <summary>
/// /// Enumerates the sides of a cell to which a border style can be applied.
/// </summary> /// </summary>
enum class XLNT_API border_side enum class XLNT_API border_side
{ {
@ -51,6 +49,40 @@ enum class XLNT_API border_side
horizontal horizontal
}; };
/// <summary>
///
/// </summary>
enum class XLNT_API border_style
{
none,
dashdot,
dashdotdot,
dashed,
dotted,
double_,
hair,
medium,
mediumdashdot,
mediumdashdotdot,
mediumdashed,
slantdashdot,
thick,
thin
};
/// <summary>
/// Cells can have borders that go from the top-left to bottom-right
/// or from the top-right to bottom-left, or both, or neither.
/// Used by style->border.
/// </summary>
enum class XLNT_API diagonal_direction
{
neither,
up,
down,
both
};
} // namespace xlnt } // namespace xlnt
namespace xlnt { namespace xlnt {
@ -62,139 +94,132 @@ class XLNT_API border
{ {
public: public:
/// <summary> /// <summary>
/// /// Each side of a cell can have a border_property applied to it to change
/// how it is displayed.
/// </summary> /// </summary>
class XLNT_API border_property class XLNT_API border_property
{ {
public: public:
/// <summary> /// <summary>
/// /// Returns the color of the side.
/// </summary> /// </summary>
optional<class color> color() const; optional<class color> color() const;
/// <summary> /// <summary>
/// /// Sets the color of the side and returns a reference to the side properties.
/// </summary> /// </summary>
border_property &color(const xlnt::color &c); border_property &color(const xlnt::color &c);
/// <summary> /// <summary>
/// /// Returns the style of the side.
/// </summary> /// </summary>
optional<border_style> style() const; optional<border_style> style() const;
/// <summary> /// <summary>
/// /// Sets the style of the side and returns a reference to the side properties.
/// </summary> /// </summary>
border_property &style(border_style style); border_property &style(border_style style);
/// <summary> /// <summary>
/// Returns true if left is exactly equal to right. /// Returns true if left is exactly equal to right.
/// </summary> /// </summary>
friend bool operator==(const border_property &left, const border_property &right); bool operator==(const border_property &right) const;
/// <summary> /// <summary>
/// Returns true if left is not exactly equal to right. /// Returns true if left is not exactly equal to right.
/// </summary> /// </summary>
friend bool operator!=(const border_property &left, const border_property &right) bool operator!=(const border_property &right) const;
{
return !(left == right);
}
private: private:
/// <summary> /// <summary>
/// /// The color of the side
/// </summary> /// </summary>
optional<class color> color_; optional<class color> color_;
/// <summary> /// <summary>
/// /// The style of the side
/// </summary> /// </summary>
optional<border_style> style_; optional<border_style> style_;
}; };
/// <summary> /// <summary>
/// /// A vector to the all of the border sides for iteration.
/// </summary> /// </summary>
static const std::vector<border_side> &all_sides(); static const std::vector<border_side> &all_sides();
/// <summary> /// <summary>
/// /// Constructs a default border.
/// </summary> /// </summary>
border(); border();
/// <summary> /// <summary>
/// /// Returns the border properties of the given side.
/// </summary> /// </summary>
optional<border_property> side(border_side s) const; optional<border_property> side(border_side s) const;
/// <summary> /// <summary>
/// /// Sets the border properties of the side s to prop.
/// </summary> /// </summary>
border &side(border_side s, const border_property &prop); border &side(border_side s, const border_property &prop);
/// <summary> /// <summary>
/// /// Returns the diagonal direction of this border.
/// </summary> /// </summary>
optional<diagonal_direction> diagonal() const; optional<diagonal_direction> diagonal() const;
/// <summary> /// <summary>
/// /// Sets the diagonal direction of this border to dir.
/// </summary> /// </summary>
border &diagonal(diagonal_direction dir); border &diagonal(diagonal_direction dir);
/// <summary> /// <summary>
/// Returns true if left is exactly equal to right. /// Returns true if left is exactly equal to right.
/// </summary> /// </summary>
XLNT_API friend bool operator==(const border &left, const border &right); bool operator==(const border &right) const;
/// <summary> /// <summary>
/// Returns true if left is not exactly equal to right. /// Returns true if left is not exactly equal to right.
/// </summary> /// </summary>
XLNT_API friend bool operator!=(const border &left, const border &right) bool operator!=(const border &right) const;
{
return !(left == right);
}
private: private:
/// <summary> /// <summary>
/// /// Start side (i.e. left) border properties
/// </summary> /// </summary>
optional<border_property> start_; optional<border_property> start_;
/// <summary> /// <summary>
/// /// End side (i.e. right) border properties
/// </summary> /// </summary>
optional<border_property> end_; optional<border_property> end_;
/// <summary> /// <summary>
/// /// Top side border properties
/// </summary> /// </summary>
optional<border_property> top_; optional<border_property> top_;
/// <summary> /// <summary>
/// /// Bottom side border properties
/// </summary> /// </summary>
optional<border_property> bottom_; optional<border_property> bottom_;
/// <summary> /// <summary>
/// /// Vertical border properties
/// </summary> /// </summary>
optional<border_property> vertical_; optional<border_property> vertical_;
/// <summary> /// <summary>
/// /// Horizontal border properties
/// </summary> /// </summary>
optional<border_property> horizontal_; optional<border_property> horizontal_;
/// <summary> /// <summary>
/// /// Diagonal border properties
/// </summary> /// </summary>
optional<border_property> diagonal_; optional<border_property> diagonal_;
// bool outline_ = true;
/// <summary> /// <summary>
/// /// Direction of diagonal border properties to be applied
/// </summary> /// </summary>
optional<diagonal_direction> diagonal_direction_; optional<diagonal_direction> diagonal_direction_;
}; };

View File

@ -28,18 +28,20 @@
namespace xlnt { namespace xlnt {
/// <summary> /// <summary>
/// /// Workbook file properties relating to calculations.
/// </summary> /// </summary>
class XLNT_API calculation_properties class XLNT_API calculation_properties
{ {
public: public:
/// <summary> /// <summary>
/// Uniquely identifies these calculation properties. /// The version of calculation engine used to calculate cell formula values.
/// If this is older than the version of the Excel calculation engine opening
/// the workbook, cell values will be recalculated.
/// </summary> /// </summary>
std::size_t calc_id; std::size_t calc_id;
/// <summary> /// <summary>
/// If this is true, concurrent calculation is enabled. /// If this is true, concurrent calculation will be enabled for the workbook.
/// </summary> /// </summary>
bool concurrent_calc; bool concurrent_calc;
}; };

View File

@ -31,40 +31,68 @@
namespace xlnt { namespace xlnt {
/// <summary> /// <summary>
/// Security information about the OOXML document. /// Properties governing how the data in a workbook should be protected.
/// These values can be ignored by consumers.
/// </summary> /// </summary>
class XLNT_API document_security class XLNT_API document_security
{ {
public: public:
/// <summary> /// <summary>
/// /// Holds data describing the verifier that locks revisions or a workbook.
/// </summary>
struct lock_verifier
{
/// <summary>
///
/// </summary>
std::string hash_algorithm;
/// <summary>
///
/// </summary>
std::string salt;
/// <summary>
///
/// </summary>
std::string hash;
/// <summary>
///
/// </summary>
std::size_t spin_count;
};
/// <summary>
/// Constructs a new document security object with default values.
/// </summary> /// </summary>
document_security(); document_security();
/// <summary> /// <summary>
/// /// If true, the workbook is locked for revisions.
/// </summary> /// </summary>
bool lock_revision; bool lock_revision = false;
/// <summary> /// <summary>
/// /// If true, worksheets can't be moved, renamed, (un)hidden, inserted, or deleted.
/// </summary> /// </summary>
bool lock_structure; bool lock_structure = false;
/// <summary> /// <summary>
/// /// If true, workbook windows will be opened at the same position with the same size
/// every time they are loaded.
/// </summary> /// </summary>
bool lock_windows; bool lock_windows = false;
/// <summary> /// <summary>
/// /// The settings to allow the revision lock to be removed.
/// </summary> /// </summary>
std::string revision_password; lock_verifier revision_lock;
/// <summary> /// <summary>
/// /// The settings to allow the structure and windows lock to be removed.
/// </summary> /// </summary>
std::string workbook_password; lock_verifier workbook_lock;
}; };
} // namespace xlnt } // namespace xlnt

View File

@ -42,48 +42,48 @@ class XLNT_API named_range
{ {
public: public:
/// <summary> /// <summary>
/// /// Type alias for the combination of sheet and range this named_range points to.
/// </summary> /// </summary>
using target = std::pair<worksheet, range_reference>; using target = std::pair<worksheet, range_reference>;
/// <summary> /// <summary>
/// /// Constructs a named range that has no name and has no targets.
/// </summary> /// </summary>
named_range(); named_range();
/// <summary> /// <summary>
/// /// Constructs a named range by copying its name and targets from other.
/// </summary> /// </summary>
named_range(const named_range &other); named_range(const named_range &other);
/// <summary> /// <summary>
/// /// Constructs a named range with the given name and targets.
/// </summary> /// </summary>
named_range(const std::string &name, const std::vector<target> &targets); named_range(const std::string &name, const std::vector<target> &targets);
/// <summary> /// <summary>
/// /// Returns the name of this range.
/// </summary> /// </summary>
std::string name() const; std::string name() const;
/// <summary> /// <summary>
/// /// Returns the set of targets of this named range as a vector.
/// </summary> /// </summary>
const std::vector<target> &targets() const; const std::vector<target> &targets() const;
/// <summary> /// <summary>
/// /// Assigns the name and targets of this named_range to that of other.
/// </summary> /// </summary>
named_range &operator=(const named_range &other); named_range &operator=(const named_range &other);
private: private:
/// <summary> /// <summary>
/// /// The name of this named range.
/// </summary> /// </summary>
std::string name_; std::string name_;
/// <summary> /// <summary>
/// /// The targets of this named range.
/// </summary> /// </summary>
std::vector<target> targets_; std::vector<target> targets_;
}; };

View File

@ -37,67 +37,67 @@ class XLNT_API workbook_view
{ {
public: public:
/// <summary> /// <summary>
/// /// If true, dates will be grouped when presenting the user with filtering options.
/// </summary> /// </summary>
bool auto_filter_date_grouping = false; bool auto_filter_date_grouping = true;
/// <summary> /// <summary>
/// /// If true, the view will be minimized.
/// </summary> /// </summary>
bool minimized = false; bool minimized = false;
/// <summary> /// <summary>
/// /// If true, the horizontal scroll bar will be displayed.
/// </summary> /// </summary>
bool show_horizontal_scroll = false; bool show_horizontal_scroll = true;
/// <summary> /// <summary>
/// /// If true, the sheet tabs will be displayed.
/// </summary> /// </summary>
bool show_sheet_tabs = false; bool show_sheet_tabs = true;
/// <summary> /// <summary>
/// /// If true, the vertical scroll bar will be displayed.
/// </summary> /// </summary>
bool show_vertical_scroll = false; bool show_vertical_scroll = true;
/// <summary> /// <summary>
/// /// If true, the workbook window will be visible.
/// </summary> /// </summary>
bool visible = true; bool visible = true;
/// <summary> /// <summary>
/// /// The optional index to the active sheet in this view.
/// </summary> /// </summary>
optional<std::size_t> active_tab; optional<std::size_t> active_tab;
/// <summary> /// <summary>
/// /// The optional index to the first sheet in this view.
/// </summary> /// </summary>
optional<std::size_t> first_sheet; optional<std::size_t> first_sheet;
/// <summary> /// <summary>
/// /// The optional ratio between the tabs bar and the horizontal scroll bar.
/// </summary> /// </summary>
optional<std::size_t> tab_ratio; optional<std::size_t> tab_ratio;
/// <summary> /// <summary>
/// /// The width of the workbook window in twips.
/// </summary> /// </summary>
optional<std::size_t> window_width; optional<std::size_t> window_width;
/// <summary> /// <summary>
/// /// The height of the workbook window in twips.
/// </summary> /// </summary>
optional<std::size_t> window_height; optional<std::size_t> window_height;
/// <summary> /// <summary>
/// /// The distance of the workbook window from the left side of the screen in twips.
/// </summary> /// </summary>
optional<std::size_t> x_window; optional<std::size_t> x_window;
/// <summary> /// <summary>
/// /// The distance of the workbook window from the top of the screen in twips.
/// </summary> /// </summary>
optional<std::size_t> y_window; optional<std::size_t> y_window;
}; };

View File

@ -33,6 +33,10 @@ namespace xlnt {
class workbook; class workbook;
class worksheet; class worksheet;
// Note: There are const and non-const implementations of this iterator
// because one needs to point at a const workbook and the other needs
// to point at a non-const workbook stored as a member variable, respectively.
/// <summary> /// <summary>
/// Alias the parent class of this iterator to increase clarity. /// Alias the parent class of this iterator to increase clarity.
/// </summary> /// </summary>
@ -40,62 +44,132 @@ using ws_iter_type = std::iterator<std::bidirectional_iterator_tag,
worksheet, std::ptrdiff_t, worksheet *, worksheet>; worksheet, std::ptrdiff_t, worksheet *, worksheet>;
/// <summary> /// <summary>
/// /// An iterator which is used to iterate over the worksheets in a workbook.
/// </summary> /// </summary>
class XLNT_API worksheet_iterator : public ws_iter_type class XLNT_API worksheet_iterator : public ws_iter_type
{ {
public: public:
/// <summary> /// <summary>
/// /// Constructs a worksheet iterator from a workbook and sheet index.
/// </summary> /// </summary>
worksheet_iterator(workbook &wb, std::size_t index); worksheet_iterator(workbook &wb, std::size_t index);
/// <summary> /// <summary>
/// /// Copy constructs a worksheet iterator from another iterator.
/// </summary> /// </summary>
worksheet_iterator(const worksheet_iterator &); worksheet_iterator(const worksheet_iterator &);
/// <summary> /// <summary>
/// /// Assigns the iterator so that it points to the same worksheet in the same workbook.
/// </summary> /// </summary>
worksheet_iterator &operator=(const worksheet_iterator &); worksheet_iterator &operator=(const worksheet_iterator &);
/// <summary> /// <summary>
/// /// Dereferences the iterator to return the worksheet it is pointing to.
/// If the iterator points to one-past-the-end of the workbook, an invalid_parameter
/// exception will be thrown.
/// </summary> /// </summary>
worksheet operator*(); worksheet operator*();
/// <summary> /// <summary>
/// /// Returns true if this iterator points to the same worksheet as comparand.
/// </summary> /// </summary>
bool operator==(const worksheet_iterator &comparand) const; bool operator==(const worksheet_iterator &comparand) const;
/// <summary> /// <summary>
/// /// Returns true if this iterator doesn't point to the same worksheet as comparand.
/// </summary> /// </summary>
bool operator!=(const worksheet_iterator &comparand) const bool operator!=(const worksheet_iterator &comparand) const;
{
return !(*this == comparand);
}
/// <summary> /// <summary>
/// /// Post-increment the iterator's internal workseet index. Returns a copy of the
/// iterator as it was before being incremented.
/// </summary> /// </summary>
worksheet_iterator operator++(int); worksheet_iterator operator++(int);
/// <summary> /// <summary>
/// /// Pre-increment the iterator's internal workseet index. Returns a refernce
/// to the same iterator.
/// </summary> /// </summary>
worksheet_iterator &operator++(); worksheet_iterator &operator++();
private: private:
/// <summary> /// <summary>
/// /// The target workbook of this iterator.
/// </summary> /// </summary>
workbook &wb_; workbook &wb_;
/// <summary> /// <summary>
/// /// The index of the worksheet in wb_ this iterator is currently pointing to.
/// </summary>
std::size_t index_;
};
/// <summary>
/// Alias the parent class of this iterator to increase clarity.
/// </summary>
using c_ws_iter_type = std::iterator<std::bidirectional_iterator_tag,
const worksheet, std::ptrdiff_t, const worksheet *, const worksheet>;
/// <summary>
/// An iterator which is used to iterate over the worksheets in a const workbook.
/// </summary>
class XLNT_API const_worksheet_iterator : public c_ws_iter_type
{
public:
/// <summary>
/// Constructs a worksheet iterator from a workbook and sheet index.
/// </summary>
const_worksheet_iterator(const workbook &wb, std::size_t index);
/// <summary>
/// Copy constructs a worksheet iterator from another iterator.
/// </summary>
const_worksheet_iterator(const const_worksheet_iterator &);
/// <summary>
/// Assigns the iterator so that it points to the same worksheet in the same workbook.
/// </summary>
const_worksheet_iterator &operator=(const const_worksheet_iterator &);
/// <summary>
/// Dereferences the iterator to return the worksheet it is pointing to.
/// If the iterator points to one-past-the-end of the workbook, an invalid_parameter
/// exception will be thrown.
/// </summary>
const worksheet operator*();
/// <summary>
/// Returns true if this iterator points to the same worksheet as comparand.
/// </summary>
bool operator==(const const_worksheet_iterator &comparand) const;
/// <summary>
/// Returns true if this iterator doesn't point to the same worksheet as comparand.
/// </summary>
bool operator!=(const const_worksheet_iterator &comparand) const;
/// <summary>
/// Post-increment the iterator's internal workseet index. Returns a copy of the
/// iterator as it was before being incremented.
/// </summary>
const_worksheet_iterator operator++(int);
/// <summary>
/// Pre-increment the iterator's internal workseet index. Returns a refernce
/// to the same iterator.
/// </summary>
const_worksheet_iterator &operator++();
private:
/// <summary>
/// The target workbook of this iterator.
/// </summary>
const workbook &wb_;
/// <summary>
/// The index of the worksheet in wb_ this iterator is currently pointing to.
/// </summary> /// </summary>
std::size_t index_; std::size_t index_;
}; };

View File

@ -129,4 +129,93 @@ private:
major_order order_; major_order order_;
}; };
/// <summary>
/// Alias the parent class of this iterator to increase clarity.
/// </summary>
using cc_iter_type = std::iterator<std::bidirectional_iterator_tag,
const cell, std::ptrdiff_t, const cell *, const cell>;
/// <summary>
///
/// </summary>
class XLNT_API const_cell_iterator : public cc_iter_type
{
public:
/// <summary>
///
/// </summary>
const_cell_iterator(worksheet ws, const cell_reference &start_cell);
/// <summary>
///
/// </summary>
const_cell_iterator(worksheet ws, const cell_reference &start_cell, major_order order);
/// <summary>
///
/// </summary>
const_cell_iterator(const const_cell_iterator &other);
/// <summary>
///
/// </summary>
const_cell_iterator &operator=(const const_cell_iterator &) = default;
/// <summary>
///
/// </summary>
const cell operator*() const;
/// <summary>
///
/// </summary>
bool operator==(const const_cell_iterator &other) const;
/// <summary>
///
/// </summary>
bool operator!=(const const_cell_iterator &other) const;
/// <summary>
///
/// </summary>
const_cell_iterator &operator--();
/// <summary>
///
/// </summary>
const_cell_iterator operator--(int);
/// <summary>
///
/// </summary>
const_cell_iterator &operator++();
/// <summary>
///
/// </summary>
const_cell_iterator operator++(int);
private:
/// <summary>
///
/// </summary>
worksheet ws_;
/// <summary>
///
/// </summary>
cell_reference current_cell_;
/// <summary>
///
/// </summary>
range_reference range_;
/// <summary>
///
/// </summary>
major_order order_;
};
} // namespace xlnt } // namespace xlnt

View File

@ -28,7 +28,6 @@
#include <xlnt/xlnt_config.hpp> #include <xlnt/xlnt_config.hpp>
#include <xlnt/cell/cell_reference.hpp> #include <xlnt/cell/cell_reference.hpp>
#include <xlnt/worksheet/cell_iterator.hpp> #include <xlnt/worksheet/cell_iterator.hpp>
#include <xlnt/worksheet/const_cell_iterator.hpp>
#include <xlnt/worksheet/major_order.hpp> #include <xlnt/worksheet/major_order.hpp>
#include <xlnt/worksheet/range_reference.hpp> #include <xlnt/worksheet/range_reference.hpp>
#include <xlnt/worksheet/worksheet.hpp> #include <xlnt/worksheet/worksheet.hpp>

View File

@ -25,13 +25,57 @@
#pragma once #pragma once
#include <xlnt/xlnt_config.hpp> #include <xlnt/xlnt_config.hpp>
#include <xlnt/worksheet/orientation.hpp>
#include <xlnt/worksheet/page_break.hpp>
#include <xlnt/worksheet/paper_size.hpp>
#include <xlnt/worksheet/sheet_state.hpp>
namespace xlnt { namespace xlnt {
/// <summary>
/// The orientation of the worksheet when it is printed.
/// </summary>
enum class XLNT_API orientation
{
portrait,
landscape
};
/// <summary>
/// The types of page breaks.
/// </summary>
enum class XLNT_API page_break
{
none = 0,
row = 1,
column = 2
};
/// <summary>
/// The possible paper sizes for printing.
/// </summary>
enum class XLNT_API paper_size
{
letter = 1,
letter_small = 2,
tabloid = 3,
ledger = 4,
legal = 5,
statement = 6,
executive = 7,
a3 = 8,
a4 = 9,
a4_small = 10,
a5 = 11
};
/// <summary>
/// Defines how a worksheet appears in the workbook.
/// A workbook must have at least one sheet which is visible at all times.
/// </summary>
enum class XLNT_API sheet_state
{
visible,
hidden,
very_hidden
};
/// <summary> /// <summary>
/// Describes how a worksheet will be converted into a page during printing. /// Describes how a worksheet will be converted into a page during printing.
/// </summary> /// </summary>

View File

@ -31,7 +31,6 @@
#include <xlnt/xlnt_config.hpp> #include <xlnt/xlnt_config.hpp>
#include <xlnt/worksheet/cell_vector.hpp> #include <xlnt/worksheet/cell_vector.hpp>
#include <xlnt/worksheet/const_range_iterator.hpp>
#include <xlnt/worksheet/major_order.hpp> #include <xlnt/worksheet/major_order.hpp>
#include <xlnt/worksheet/range_iterator.hpp> #include <xlnt/worksheet/range_iterator.hpp>
#include <xlnt/worksheet/range_reference.hpp> #include <xlnt/worksheet/range_reference.hpp>

View File

@ -121,4 +121,89 @@ private:
major_order order_; major_order order_;
}; };
/// <summary>
/// Alias the parent class of this iterator to increase clarity.
/// </summary>
using cr_iter_type = std::iterator<std::bidirectional_iterator_tag,
const cell_vector, std::ptrdiff_t, const cell_vector *, const cell_vector>;
/// <summary>
/// A const version of range_iterator which does not allow modification
/// to the dereferenced cell_vector.
/// </summary>
class XLNT_API const_range_iterator : public cr_iter_type
{
public:
/// <summary>
///
/// </summary>
const_range_iterator(const worksheet &ws, const range_reference &start_cell, major_order order = major_order::row);
/// <summary>
///
/// </summary>
const_range_iterator(const const_range_iterator &other);
/// <summary>
///
/// </summary>
const cell_vector operator*() const;
/// <summary>
///
/// </summary>
const_range_iterator &operator=(const const_range_iterator &) = default;
/// <summary>
///
/// </summary>
bool operator==(const const_range_iterator &other) const;
/// <summary>
///
/// </summary>
bool operator!=(const const_range_iterator &other) const;
/// <summary>
///
/// </summary>
const_range_iterator &operator--();
/// <summary>
///
/// </summary>
const_range_iterator operator--(int);
/// <summary>
///
/// </summary>
const_range_iterator &operator++();
/// <summary>
///
/// </summary>
const_range_iterator operator++(int);
private:
/// <summary>
///
/// </summary>
detail::worksheet_impl *ws_;
/// <summary>
///
/// </summary>
cell_reference current_cell_;
/// <summary>
///
/// </summary>
range_reference range_;
/// <summary>
///
/// </summary>
major_order order_;
};
} // namespace xlnt } // namespace xlnt

View File

@ -188,6 +188,18 @@ public:
/// </summary> /// </summary>
const class cell cell(const cell_reference &reference) const; const class cell cell(const cell_reference &reference) const;
/// <summary>
/// Returns the cell at the given column and row. If the cell doesn't exist, it
/// will be initialized to null before being returned.
/// </summary>
class cell cell(column_t column, row_t row);
/// <summary>
/// Returns the cell at the given column and row. If the cell doesn't exist, an
/// invalid_parameter exception will be thrown.
/// </summary>
const class cell cell(column_t column, row_t row) const;
/// <summary> /// <summary>
/// Returns the range defined by reference string. If reference string is the name of /// Returns the range defined by reference string. If reference string is the name of
/// a previously-defined named range in the sheet, it will be returned. /// a previously-defined named range in the sheet, it will be returned.

View File

@ -37,21 +37,18 @@
// packaging // packaging
#include <xlnt/packaging/manifest.hpp> #include <xlnt/packaging/manifest.hpp>
#include <xlnt/packaging/relationship.hpp> #include <xlnt/packaging/relationship.hpp>
#include <xlnt/packaging/uri.hpp>
// styles // styles
#include <xlnt/styles/alignment.hpp> #include <xlnt/styles/alignment.hpp>
#include <xlnt/styles/border.hpp> #include <xlnt/styles/border.hpp>
#include <xlnt/styles/border_style.hpp>
#include <xlnt/styles/color.hpp> #include <xlnt/styles/color.hpp>
#include <xlnt/styles/diagonal_direction.hpp>
#include <xlnt/styles/fill.hpp> #include <xlnt/styles/fill.hpp>
#include <xlnt/styles/font.hpp> #include <xlnt/styles/font.hpp>
#include <xlnt/styles/format.hpp> #include <xlnt/styles/format.hpp>
#include <xlnt/styles/horizontal_alignment.hpp>
#include <xlnt/styles/number_format.hpp> #include <xlnt/styles/number_format.hpp>
#include <xlnt/styles/protection.hpp> #include <xlnt/styles/protection.hpp>
#include <xlnt/styles/style.hpp> #include <xlnt/styles/style.hpp>
#include <xlnt/styles/vertical_alignment.hpp>
// utils // utils
#include <xlnt/utils/calendar.hpp> #include <xlnt/utils/calendar.hpp>
@ -64,7 +61,6 @@
#include <xlnt/utils/variant.hpp> #include <xlnt/utils/variant.hpp>
// workbook // workbook
#include <xlnt/workbook/const_worksheet_iterator.hpp>
#include <xlnt/workbook/document_security.hpp> #include <xlnt/workbook/document_security.hpp>
#include <xlnt/workbook/external_book.hpp> #include <xlnt/workbook/external_book.hpp>
#include <xlnt/workbook/metadata_property.hpp> #include <xlnt/workbook/metadata_property.hpp>
@ -77,24 +73,17 @@
#include <xlnt/worksheet/cell_iterator.hpp> #include <xlnt/worksheet/cell_iterator.hpp>
#include <xlnt/worksheet/cell_vector.hpp> #include <xlnt/worksheet/cell_vector.hpp>
#include <xlnt/worksheet/column_properties.hpp> #include <xlnt/worksheet/column_properties.hpp>
#include <xlnt/worksheet/const_cell_iterator.hpp>
#include <xlnt/worksheet/const_range_iterator.hpp>
#include <xlnt/worksheet/header_footer.hpp> #include <xlnt/worksheet/header_footer.hpp>
#include <xlnt/worksheet/header_footer.hpp> #include <xlnt/worksheet/header_footer.hpp>
#include <xlnt/worksheet/major_order.hpp> #include <xlnt/worksheet/major_order.hpp>
#include <xlnt/worksheet/orientation.hpp>
#include <xlnt/worksheet/page_break.hpp>
#include <xlnt/worksheet/page_margins.hpp> #include <xlnt/worksheet/page_margins.hpp>
#include <xlnt/worksheet/page_setup.hpp> #include <xlnt/worksheet/page_setup.hpp>
#include <xlnt/worksheet/pane.hpp> #include <xlnt/worksheet/pane.hpp>
#include <xlnt/worksheet/paper_size.hpp>
#include <xlnt/worksheet/range.hpp> #include <xlnt/worksheet/range.hpp>
#include <xlnt/worksheet/range_iterator.hpp> #include <xlnt/worksheet/range_iterator.hpp>
#include <xlnt/worksheet/range_reference.hpp> #include <xlnt/worksheet/range_reference.hpp>
#include <xlnt/worksheet/row_properties.hpp> #include <xlnt/worksheet/row_properties.hpp>
#include <xlnt/worksheet/selection.hpp> #include <xlnt/worksheet/selection.hpp>
#include <xlnt/worksheet/sheet_protection.hpp> #include <xlnt/worksheet/sheet_protection.hpp>
#include <xlnt/worksheet/sheet_state.hpp>
#include <xlnt/worksheet/sheet_view.hpp> #include <xlnt/worksheet/sheet_view.hpp>
#include <xlnt/worksheet/worksheet.hpp> #include <xlnt/worksheet/worksheet.hpp>
#include <xlnt/worksheet/worksheet_properties.hpp>

View File

@ -3,11 +3,10 @@
#include <detail/default_case.hpp> #include <detail/default_case.hpp>
#include <detail/include_libstudxml.hpp> #include <detail/include_libstudxml.hpp>
#include <xlnt/packaging/relationship.hpp> #include <xlnt/packaging/relationship.hpp>
#include <xlnt/styles/alignment.hpp>
#include <xlnt/styles/border.hpp> #include <xlnt/styles/border.hpp>
#include <xlnt/styles/font.hpp> #include <xlnt/styles/font.hpp>
#include <xlnt/styles/fill.hpp> #include <xlnt/styles/fill.hpp>
#include <xlnt/styles/horizontal_alignment.hpp>
#include <xlnt/styles/vertical_alignment.hpp>
#include <xlnt/utils/exceptions.hpp> #include <xlnt/utils/exceptions.hpp>
#include <xlnt/utils/variant.hpp> #include <xlnt/utils/variant.hpp>
#include <xlnt/worksheet/pane.hpp> #include <xlnt/worksheet/pane.hpp>

View File

@ -27,7 +27,6 @@
#include <xlnt/cell/cell.hpp> #include <xlnt/cell/cell.hpp>
#include <xlnt/packaging/manifest.hpp> #include <xlnt/packaging/manifest.hpp>
#include <xlnt/utils/path.hpp> #include <xlnt/utils/path.hpp>
#include <xlnt/workbook/const_worksheet_iterator.hpp>
#include <xlnt/workbook/workbook.hpp> #include <xlnt/workbook/workbook.hpp>
#include <xlnt/worksheet/worksheet.hpp> #include <xlnt/worksheet/worksheet.hpp>
#include <detail/constants.hpp> #include <detail/constants.hpp>

View File

@ -29,7 +29,6 @@
#include <xlnt/cell/cell.hpp> #include <xlnt/cell/cell.hpp>
#include <xlnt/packaging/manifest.hpp> #include <xlnt/packaging/manifest.hpp>
#include <xlnt/utils/path.hpp> #include <xlnt/utils/path.hpp>
#include <xlnt/workbook/const_worksheet_iterator.hpp>
#include <xlnt/workbook/workbook.hpp> #include <xlnt/workbook/workbook.hpp>
#include <xlnt/workbook/workbook_view.hpp> #include <xlnt/workbook/workbook_view.hpp>
#include <xlnt/worksheet/header_footer.hpp> #include <xlnt/worksheet/header_footer.hpp>

View File

@ -21,9 +21,9 @@ path uri::path() const
return path_; return path_;
} }
bool operator==(const uri &left, const uri &right) bool uri::operator==(const uri &other) const
{ {
return left.to_string() == right.to_string(); return to_string() == other.to_string();
} }
} // namespace xlnt } // namespace xlnt

View File

@ -92,8 +92,10 @@ optional<int> alignment::rotation() const
return text_rotation_; return text_rotation_;
} }
XLNT_API bool operator==(const alignment &left, const alignment &right) bool alignment::operator==(const alignment &right) const
{ {
auto &left = *this;
if (left.horizontal().is_set() != right.horizontal().is_set()) if (left.horizontal().is_set() != right.horizontal().is_set())
{ {
return false; return false;
@ -159,4 +161,9 @@ XLNT_API bool operator==(const alignment &left, const alignment &right)
return true; return true;
} }
bool alignment::operator!=(const alignment &other) const
{
return !(*this == other);
}
} // namespace xlnt } // namespace xlnt

View File

@ -50,8 +50,10 @@ border::border_property &border::border_property::style(border_style s)
return *this; return *this;
} }
bool operator==(const border::border_property &left, const border::border_property &right) bool border::border_property::operator==(const border::border_property &right) const
{ {
auto &left = *this;
if (left.style().is_set() != right.style().is_set()) if (left.style().is_set() != right.style().is_set())
{ {
return false; return false;
@ -81,6 +83,11 @@ bool operator==(const border::border_property &left, const border::border_proper
return true; return true;
} }
bool border::border_property::operator!=(const border::border_property &right) const
{
return !(*this == right);
}
border::border() border::border()
{ {
} }
@ -158,8 +165,10 @@ optional<diagonal_direction> border::diagonal() const
return diagonal_direction_; return diagonal_direction_;
} }
XLNT_API bool operator==(const border &left, const border &right) bool border::operator==(const border &right) const
{ {
auto &left = *this;
for (auto side : border::all_sides()) for (auto side : border::all_sides())
{ {
if (left.side(side).is_set() != right.side(side).is_set()) if (left.side(side).is_set() != right.side(side).is_set())
@ -179,4 +188,9 @@ XLNT_API bool operator==(const border &left, const border &right)
return true; return true;
} }
bool border::operator!=(const border &right) const
{
return !(*this == right);
}
} // namespace xlnt } // namespace xlnt

View File

@ -46,7 +46,6 @@
#include <xlnt/utils/exceptions.hpp> #include <xlnt/utils/exceptions.hpp>
#include <xlnt/utils/path.hpp> #include <xlnt/utils/path.hpp>
#include <xlnt/utils/variant.hpp> #include <xlnt/utils/variant.hpp>
#include <xlnt/workbook/const_worksheet_iterator.hpp>
#include <xlnt/workbook/metadata_property.hpp> #include <xlnt/workbook/metadata_property.hpp>
#include <xlnt/workbook/named_range.hpp> #include <xlnt/workbook/named_range.hpp>
#include <xlnt/workbook/theme.hpp> #include <xlnt/workbook/theme.hpp>

View File

@ -60,10 +60,53 @@ bool worksheet_iterator::operator==(const worksheet_iterator &comparand) const
return index_ == comparand.index_ && wb_ == comparand.wb_; return index_ == comparand.index_ && wb_ == comparand.wb_;
} }
bool worksheet_iterator::operator!=(const worksheet_iterator &comparand) const
{
return !(*this == comparand);
}
worksheet_iterator &worksheet_iterator::operator=(const worksheet_iterator &other) worksheet_iterator &worksheet_iterator::operator=(const worksheet_iterator &other)
{ {
index_ = other.index_; index_ = other.index_;
return *this; return *this;
} }
const_worksheet_iterator::const_worksheet_iterator(const workbook &wb, std::size_t index)
: wb_(wb), index_(index)
{
}
const_worksheet_iterator::const_worksheet_iterator(const const_worksheet_iterator &rhs)
: wb_(rhs.wb_), index_(rhs.index_)
{
}
const worksheet const_worksheet_iterator::operator*()
{
return wb_.sheet_by_index(index_);
}
const_worksheet_iterator &const_worksheet_iterator::operator++()
{
index_++;
return *this;
}
const_worksheet_iterator const_worksheet_iterator::operator++(int)
{
const_worksheet_iterator old(wb_, index_);
++*this;
return old;
}
bool const_worksheet_iterator::operator==(const const_worksheet_iterator &comparand) const
{
return index_ == comparand.index_ && wb_ == comparand.wb_;
}
bool const_worksheet_iterator::operator!=(const const_worksheet_iterator &comparand) const
{
return !(*this == comparand);
}
} // namespace xlnt } // namespace xlnt

View File

@ -131,4 +131,77 @@ cell cell_iterator::operator*()
return ws_[current_cell_]; return ws_[current_cell_];
} }
const_cell_iterator::const_cell_iterator(worksheet ws, const cell_reference &start_cell, major_order order)
: ws_(ws),
current_cell_(start_cell),
range_(start_cell.to_range()),
order_(order)
{
}
const_cell_iterator::const_cell_iterator(const const_cell_iterator &other)
{
*this = other;
}
bool const_cell_iterator::operator==(const const_cell_iterator &other) const
{
return ws_ == other.ws_ && current_cell_ == other.current_cell_ && order_ == other.order_;
}
bool const_cell_iterator::operator!=(const const_cell_iterator &other) const
{
return !(*this == other);
}
const_cell_iterator &const_cell_iterator::operator--()
{
if (order_ == major_order::row)
{
current_cell_.column_index(current_cell_.column_index() - 1);
}
else
{
current_cell_.row(current_cell_.row() - 1);
}
return *this;
}
const_cell_iterator const_cell_iterator::operator--(int)
{
const_cell_iterator old = *this;
--*this;
return old;
}
const_cell_iterator &const_cell_iterator::operator++()
{
if (order_ == major_order::row)
{
current_cell_.column_index(current_cell_.column_index() + 1);
}
else
{
current_cell_.row(current_cell_.row() + 1);
}
return *this;
}
const_cell_iterator const_cell_iterator::operator++(int)
{
const_cell_iterator old = *this;
++*this;
return old;
}
const cell const_cell_iterator::operator*() const
{
return ws_.cell(current_cell_);
}
} // namespace xlnt } // namespace xlnt

View File

@ -20,10 +20,10 @@
// //
// @license: http://www.opensource.org/licenses/mit-license.php // @license: http://www.opensource.org/licenses/mit-license.php
// @author: see AUTHORS file // @author: see AUTHORS file
#include <xlnt/cell/cell.hpp> #include <xlnt/cell/cell.hpp>
#include <xlnt/worksheet/cell_iterator.hpp> #include <xlnt/worksheet/cell_iterator.hpp>
#include <xlnt/worksheet/cell_vector.hpp> #include <xlnt/worksheet/cell_vector.hpp>
#include <xlnt/worksheet/const_cell_iterator.hpp>
namespace xlnt { namespace xlnt {

View File

@ -24,7 +24,6 @@
#include <xlnt/cell/cell.hpp> #include <xlnt/cell/cell.hpp>
#include <xlnt/styles/style.hpp> #include <xlnt/styles/style.hpp>
#include <xlnt/workbook/workbook.hpp> #include <xlnt/workbook/workbook.hpp>
#include <xlnt/worksheet/const_range_iterator.hpp>
#include <xlnt/worksheet/range.hpp> #include <xlnt/worksheet/range.hpp>
#include <xlnt/worksheet/range_iterator.hpp> #include <xlnt/worksheet/range_iterator.hpp>
#include <xlnt/worksheet/range_reference.hpp> #include <xlnt/worksheet/range_reference.hpp>

View File

@ -127,4 +127,89 @@ range_iterator range_iterator::operator++(int)
return old; return old;
} }
const_range_iterator::const_range_iterator(const worksheet &ws,
const range_reference &start_cell, major_order order)
: ws_(ws.d_),
current_cell_(start_cell.top_left()),
range_(start_cell),
order_(order)
{
}
const_range_iterator::const_range_iterator(const const_range_iterator &other)
{
*this = other;
}
bool const_range_iterator::operator==(const const_range_iterator &other) const
{
return ws_ == other.ws_
&& current_cell_ == other.current_cell_
&& order_ == other.order_;
}
bool const_range_iterator::operator!=(const const_range_iterator &other) const
{
return !(*this == other);
}
const_range_iterator &const_range_iterator::operator--()
{
if (order_ == major_order::row)
{
current_cell_.row(current_cell_.row() - 1);
}
else
{
current_cell_.column_index(current_cell_.column_index() - 1);
}
return *this;
}
const_range_iterator const_range_iterator::operator--(int)
{
const_range_iterator old = *this;
--*this;
return old;
}
const_range_iterator &const_range_iterator::operator++()
{
if (order_ == major_order::row)
{
current_cell_.row(current_cell_.row() + 1);
}
else
{
current_cell_.column_index(current_cell_.column_index() + 1);
}
return *this;
}
const_range_iterator const_range_iterator::operator++(int)
{
const_range_iterator old = *this;
++*this;
return old;
}
const cell_vector const_range_iterator::operator*() const
{
if (order_ == major_order::row)
{
range_reference reference(range_.top_left().column_index(), current_cell_.row(),
range_.bottom_right().column_index(), current_cell_.row());
return cell_vector(ws_, reference, order_);
}
range_reference reference(current_cell_.column_index(), range_.top_left().row(),
current_cell_.column_index(), range_.bottom_right().row());
return cell_vector(ws_, reference, order_);
}
} // namespace xlnt } // namespace xlnt

View File

@ -36,8 +36,6 @@
#include <xlnt/workbook/workbook.hpp> #include <xlnt/workbook/workbook.hpp>
#include <xlnt/workbook/worksheet_iterator.hpp> #include <xlnt/workbook/worksheet_iterator.hpp>
#include <xlnt/worksheet/cell_iterator.hpp> #include <xlnt/worksheet/cell_iterator.hpp>
#include <xlnt/worksheet/const_cell_iterator.hpp>
#include <xlnt/worksheet/const_range_iterator.hpp>
#include <xlnt/worksheet/header_footer.hpp> #include <xlnt/worksheet/header_footer.hpp>
#include <xlnt/worksheet/range.hpp> #include <xlnt/worksheet/range.hpp>
#include <xlnt/worksheet/range_iterator.hpp> #include <xlnt/worksheet/range_iterator.hpp>
@ -377,6 +375,16 @@ const cell worksheet::cell(const cell_reference &reference) const
return xlnt::cell(&d_->cell_map_.at(reference.row()).at(reference.column_index())); return xlnt::cell(&d_->cell_map_.at(reference.row()).at(reference.column_index()));
} }
cell worksheet::cell(xlnt::column_t column, row_t row)
{
return cell(cell_reference(column, row));
}
const cell worksheet::cell(xlnt::column_t column, row_t row) const
{
return cell(cell_reference(column, row));
}
bool worksheet::has_cell(const cell_reference &reference) const bool worksheet::has_cell(const cell_reference &reference) const
{ {
const auto row = d_->cell_map_.find(reference.row()); const auto row = d_->cell_map_.find(reference.row());