mirror of
https://github.com/tfussell/xlnt.git
synced 2024-03-22 13:11:17 +08:00
integrate value into cell, continue synchronizing with openpyxl 2.4
This commit is contained in:
parent
77d6bbb41b
commit
301e81d698
|
@ -35,7 +35,6 @@ namespace xlnt {
|
|||
class cell_reference;
|
||||
class comment;
|
||||
class relationship;
|
||||
class value;
|
||||
class worksheet;
|
||||
|
||||
struct date;
|
||||
|
@ -59,49 +58,91 @@ struct cell_impl;
|
|||
class cell
|
||||
{
|
||||
public:
|
||||
enum class type
|
||||
{
|
||||
null,
|
||||
numeric,
|
||||
string,
|
||||
formula,
|
||||
error,
|
||||
boolean
|
||||
};
|
||||
|
||||
static const std::unordered_map<std::string, int> ErrorCodes;
|
||||
|
||||
cell();
|
||||
cell(worksheet ws, const cell_reference &reference);
|
||||
cell(worksheet ws, const cell_reference &reference, const value &initial_value);
|
||||
cell(worksheet worksheet, const cell_reference &reference);
|
||||
template<typename T>
|
||||
cell(worksheet worksheet, const cell_reference &reference, const T &initial_value);
|
||||
|
||||
// value
|
||||
bool has_value() const;
|
||||
|
||||
template<typename T>
|
||||
T get_value();
|
||||
template<typename T>
|
||||
const T get_value() const;
|
||||
|
||||
void clear_value();
|
||||
|
||||
template<typename T>
|
||||
void set_value(T value);
|
||||
|
||||
type get_data_type() const;
|
||||
void set_data_type(type t);
|
||||
|
||||
// characteristics
|
||||
bool garbage_collectible() const;
|
||||
bool is_date() const;
|
||||
|
||||
// position
|
||||
cell_reference get_reference() const;
|
||||
std::string get_column() const;
|
||||
column_t get_column_index() const;
|
||||
row_t get_row() const;
|
||||
std::pair<int, int> get_anchor() const;
|
||||
|
||||
std::string to_string() const;
|
||||
|
||||
bool is_merged() const;
|
||||
void set_merged(bool merged);
|
||||
|
||||
// hyperlink
|
||||
relationship get_hyperlink() const;
|
||||
void set_hyperlink(const std::string &value);
|
||||
bool has_hyperlink() const;
|
||||
|
||||
void set_number_format(const std::string &format_code);
|
||||
|
||||
// style
|
||||
bool has_style() const;
|
||||
style &get_style();
|
||||
const style &get_style() const;
|
||||
void set_style(const style &s);
|
||||
|
||||
std::pair<int, int> get_anchor() const;
|
||||
|
||||
bool garbage_collectible() const;
|
||||
std::string get_number_format() const;
|
||||
void set_number_format(const std::string &format_code);
|
||||
std::size_t get_xf_index() const;
|
||||
font get_font() const;
|
||||
fill &get_fill();
|
||||
const fill &get_fill() const;
|
||||
border get_border() const;
|
||||
alignment get_alignment() const;
|
||||
protection get_protection() const;
|
||||
bool pivot_button() const;
|
||||
bool quote_prefix() const;
|
||||
|
||||
cell_reference get_reference() const;
|
||||
|
||||
bool is_date() const;
|
||||
|
||||
comment get_comment() const;
|
||||
// comment
|
||||
comment get_comment();
|
||||
void set_comment(const comment &comment);
|
||||
void clear_comment();
|
||||
bool has_comment() const;
|
||||
|
||||
|
||||
// formula
|
||||
std::string get_formula() const;
|
||||
void set_formula(const std::string &formula);
|
||||
void clear_formula();
|
||||
bool has_formula() const;
|
||||
|
||||
// printing
|
||||
std::string to_string() const;
|
||||
|
||||
// merging
|
||||
bool is_merged() const;
|
||||
void set_merged(bool merged);
|
||||
|
||||
std::string get_error() const;
|
||||
void set_error(const std::string &error);
|
||||
|
||||
|
@ -109,37 +150,8 @@ public:
|
|||
|
||||
worksheet get_parent();
|
||||
const worksheet get_parent() const;
|
||||
|
||||
value &get_value();
|
||||
const value &get_value() const;
|
||||
|
||||
void set_value(bool b);
|
||||
void set_value(std::int8_t i);
|
||||
void set_value(std::int16_t i);
|
||||
void set_value(std::int32_t i);
|
||||
void set_value(std::int64_t i);
|
||||
void set_value(std::uint8_t i);
|
||||
void set_value(std::uint16_t i);
|
||||
void set_value(std::uint32_t i);
|
||||
void set_value(std::uint64_t i);
|
||||
#ifdef _WIN32
|
||||
void set_value(unsigned long i);
|
||||
#endif
|
||||
#ifdef __linux__
|
||||
void set_value(long long i);
|
||||
void set_value(unsigned long long i);
|
||||
#endif
|
||||
void set_value(float f);
|
||||
void set_value(double d);
|
||||
void set_value(long double d);
|
||||
void set_value(const char *s);
|
||||
void set_value(const std::string &s);
|
||||
void set_value(const date &d);
|
||||
void set_value(const datetime &d);
|
||||
void set_value(const time &t);
|
||||
void set_value(const timedelta &t);
|
||||
void set_value(const value &v);
|
||||
|
||||
// operators
|
||||
cell &operator=(const cell &rhs);
|
||||
|
||||
bool operator==(const cell &comparand) const;
|
||||
|
@ -149,6 +161,7 @@ public:
|
|||
friend bool operator<(cell left, cell right);
|
||||
|
||||
private:
|
||||
void set_value_guess_type(const std::string &s);
|
||||
friend class worksheet;
|
||||
cell(detail::cell_impl *d);
|
||||
detail::cell_impl *d_;
|
||||
|
|
|
@ -65,35 +65,60 @@ public:
|
|||
/// </remarks>
|
||||
static std::string column_string_from_index(column_t column_index);
|
||||
|
||||
/// <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);
|
||||
|
||||
// constructors
|
||||
/// <summary>
|
||||
/// Default constructor makes a reference to the top-left-most cell, "A1".
|
||||
/// </summary>
|
||||
cell_reference();
|
||||
cell_reference(const char *reference_string);
|
||||
cell_reference(const std::string &reference_string);
|
||||
cell_reference(const std::string &column, row_t row, bool absolute = false);
|
||||
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; }
|
||||
|
||||
std::string get_column() const { return column_string_from_index(column_index_ + 1); }
|
||||
void set_column(const std::string &column) { column_index_ = column_index_from_string(column) - 1; }
|
||||
// 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); }
|
||||
|
||||
column_t get_column_index() const { return column_index_; }
|
||||
void set_column_index(column_t column_index) { column_index_ = column_index; }
|
||||
column_t get_column_index() const { return column_; }
|
||||
void set_column_index(column_t column) { column_ = column; }
|
||||
|
||||
row_t get_row() const { return row_index_ + 1; }
|
||||
void set_row(row_t row) { row_index_ = row - 1; }
|
||||
|
||||
row_t get_row_index() const { return row_index_; }
|
||||
void set_row_index(row_t row_index) { row_index_ = row_index; }
|
||||
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
|
||||
/// the number of columns and rows specified by the parameters.
|
||||
/// A negative value for column_offset or row_offset results
|
||||
/// in a reference above or left of this cell_reference, respectively.
|
||||
/// </summary>
|
||||
cell_reference make_offset(int column_offset, int row_offset) const;
|
||||
|
||||
/// <summary>
|
||||
/// Return a string like "A1" for cell_reference(1, 1).
|
||||
/// </summary>
|
||||
std::string to_string() const;
|
||||
|
||||
/// <summary>
|
||||
/// Return a range_reference containing only this cell_reference.
|
||||
/// </summary>
|
||||
range_reference to_range() const;
|
||||
|
||||
// operators
|
||||
/// <summary>
|
||||
/// I've always wanted to overload the comma operator.
|
||||
/// cell_reference("A", 1), cell_reference("B", 1) will return
|
||||
/// range_reference(cell_reference("A", 1), cell_reference("B", 1))
|
||||
/// </summary>
|
||||
range_reference operator,(const cell_reference &other) const;
|
||||
|
||||
bool operator==(const cell_reference &comparand) const;
|
||||
|
@ -103,11 +128,27 @@ public:
|
|||
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); }
|
||||
|
||||
friend bool operator<(const cell_reference &left, const cell_reference &right);
|
||||
bool operator<(const cell_reference &other);
|
||||
bool operator>(const cell_reference &other);
|
||||
bool operator<=(const cell_reference &other);
|
||||
bool operator>=(const cell_reference &other);
|
||||
|
||||
private:
|
||||
column_t column_index_;
|
||||
row_t row_index_;
|
||||
/// <summary>
|
||||
/// Index of the column. Important: this is one-indexed to conform
|
||||
/// with Excel. Column "A", the first column, would have an index of 1.
|
||||
/// </summary>
|
||||
column_t column_;
|
||||
|
||||
/// <summary>
|
||||
/// Index of the column. Important: this is one-indexed to conform
|
||||
/// with Excel. Column "A", the first column, would have an index of 1.
|
||||
/// </summary>
|
||||
row_t row_;
|
||||
|
||||
/// <summary>
|
||||
/// True if the reference is absolute. This looks like "$A$1" in Excel.
|
||||
/// </summary>
|
||||
bool absolute_;
|
||||
};
|
||||
|
||||
|
|
|
@ -3,20 +3,40 @@
|
|||
#include <string>
|
||||
|
||||
namespace xlnt {
|
||||
|
||||
class cell;
|
||||
|
||||
namespace detail {
|
||||
struct comment_impl;
|
||||
} // namespace detail
|
||||
|
||||
/// <summary>
|
||||
/// A comment can be applied to a cell to provide extra information.
|
||||
/// </summary>
|
||||
class comment
|
||||
{
|
||||
public:
|
||||
/// <summary>
|
||||
/// The default constructor makes an invalid comment without a parent cell.
|
||||
/// </summary>
|
||||
comment();
|
||||
comment(const std::string &text, const std::string &auth);
|
||||
comment(cell parent, const std::string &text, const std::string &auth);
|
||||
~comment();
|
||||
|
||||
std::string get_text() const;
|
||||
std::string get_author() const;
|
||||
|
||||
/// <summary>
|
||||
/// True if the comments point to the same sell.
|
||||
/// Note that a cell can only have one comment and a comment
|
||||
/// can only be applied to one cell.
|
||||
/// </summary>
|
||||
bool operator==(const comment &other) const;
|
||||
|
||||
private:
|
||||
std::string text_;
|
||||
std::string author_;
|
||||
friend class cell;
|
||||
comment(detail::comment_impl *d);
|
||||
detail::comment_impl *d_;
|
||||
};
|
||||
|
||||
} // namespace xlnt
|
||||
|
|
|
@ -1,132 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
namespace xlnt {
|
||||
|
||||
struct date;
|
||||
struct datetime;
|
||||
struct time;
|
||||
struct timedelta;
|
||||
|
||||
class value
|
||||
{
|
||||
public:
|
||||
enum class type
|
||||
{
|
||||
null,
|
||||
numeric,
|
||||
string,
|
||||
boolean,
|
||||
error
|
||||
};
|
||||
|
||||
static value null();
|
||||
static value error(const std::string &error_string);
|
||||
|
||||
value();
|
||||
value(value &&v);
|
||||
value(const value &v);
|
||||
explicit value(bool b);
|
||||
explicit value(std::int8_t i);
|
||||
explicit value(std::int16_t i);
|
||||
explicit value(std::int32_t i);
|
||||
explicit value(std::int64_t i);
|
||||
explicit value(std::uint8_t i);
|
||||
explicit value(std::uint16_t i);
|
||||
explicit value(std::uint32_t i);
|
||||
explicit value(std::uint64_t i);
|
||||
#ifdef _WIN32
|
||||
explicit value(unsigned long i);
|
||||
#endif
|
||||
#ifdef __linux__
|
||||
explicit value(long long i);
|
||||
explicit value(unsigned long long i);
|
||||
#endif
|
||||
explicit value(float f);
|
||||
explicit value(double d);
|
||||
explicit value(long double d);
|
||||
explicit value(const char *s);
|
||||
explicit value(const std::string &s);
|
||||
explicit value(const date &d);
|
||||
explicit value(const datetime &d);
|
||||
explicit value(const time &t);
|
||||
explicit value(const timedelta &t);
|
||||
|
||||
template<typename T>
|
||||
T get() const;
|
||||
|
||||
template<typename T>
|
||||
T as() const;
|
||||
|
||||
type get_type() const;
|
||||
bool is(type t) const;
|
||||
|
||||
bool is_integral() const;
|
||||
|
||||
std::string to_string() const;
|
||||
|
||||
value &operator=(value other);
|
||||
|
||||
bool operator==(const value &comparand) const;
|
||||
bool operator==(bool comparand) const;
|
||||
bool operator==(std::int8_t comparand) const;
|
||||
bool operator==(std::int16_t comparand) const;
|
||||
bool operator==(std::int32_t comparand) const;
|
||||
bool operator==(std::int64_t comparand) const;
|
||||
bool operator==(std::uint8_t comparand) const;
|
||||
bool operator==(std::uint16_t comparand) const;
|
||||
bool operator==(std::uint32_t comparand) const;
|
||||
bool operator==(std::uint64_t comparand) const;
|
||||
#ifdef _WIN32
|
||||
bool operator==(unsigned long comparand) const;
|
||||
#endif
|
||||
#ifdef __linux__
|
||||
bool operator==(long long comparand) const;
|
||||
bool operator==(unsigned long long comparand) const;
|
||||
#endif
|
||||
bool operator==(float comparand) const;
|
||||
bool operator==(double comparand) const;
|
||||
bool operator==(long double comparand) const;
|
||||
bool operator==(const std::string &comparand) const;
|
||||
bool operator==(const char *comparand) const;
|
||||
bool operator==(const date &comparand) const;
|
||||
bool operator==(const time &comparand) const;
|
||||
bool operator==(const datetime &comparand) const;
|
||||
bool operator==(const timedelta &comparand) const;
|
||||
|
||||
friend bool operator==(bool comparand, const value &v);
|
||||
friend bool operator==(std::int8_t comparand, const value &v);
|
||||
friend bool operator==(std::int16_t comparand, const value &v);
|
||||
friend bool operator==(std::int32_t comparand, const value &v);
|
||||
friend bool operator==(std::int64_t comparand, const value &v);
|
||||
friend bool operator==(std::uint8_t comparand, const value &v);
|
||||
friend bool operator==(std::uint16_t comparand, const value &v);
|
||||
friend bool operator==(std::uint32_t comparand, const value &v);
|
||||
friend bool operator==(std::uint64_t comparand, const value &v);
|
||||
#ifdef _WIN32
|
||||
friend bool operator==(unsigned long comparand, const value &v);
|
||||
#endif
|
||||
#ifdef __linux__
|
||||
friend bool operator==(long long comparand, const value &v);
|
||||
friend bool operator==(unsigned long long comparand, const value &v);
|
||||
#endif
|
||||
friend bool operator==(float comparand, const value &v);
|
||||
friend bool operator==(double comparand, const value &v);
|
||||
friend bool operator==(long double comparand, const value &v);
|
||||
friend bool operator==(const std::string &comparand, const value &v);
|
||||
friend bool operator==(const char *comparand, const value &v);
|
||||
friend bool operator==(const date &comparand, const value &v);
|
||||
friend bool operator==(const time &comparand, const value &v);
|
||||
friend bool operator==(const datetime &comparand, const value &v);
|
||||
|
||||
friend void swap(value &left, value &right);
|
||||
|
||||
private:
|
||||
type type_;
|
||||
std::string string_value_;
|
||||
long double numeric_value_;
|
||||
};
|
||||
|
||||
} // namespace xlnt
|
|
@ -26,15 +26,32 @@
|
|||
|
||||
namespace xlnt {
|
||||
|
||||
/// <summary>
|
||||
/// An enumeration of possible base dates.
|
||||
/// Dates in Excel are stored as days since this base date.
|
||||
/// </summary>
|
||||
enum class calendar
|
||||
{
|
||||
windows_1900,
|
||||
mac_1904
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// A date is a specific day specified in terms of a year, month, and day.
|
||||
/// It can also be initialized as a number of days since a base date
|
||||
/// using date::from_number.
|
||||
/// </summary>
|
||||
struct date
|
||||
{
|
||||
/// <summary>
|
||||
/// Return the current date according to the system time.
|
||||
/// </summary>
|
||||
static date today();
|
||||
|
||||
/// <summary>
|
||||
/// Return a date by adding days_since_base_year to base_date.
|
||||
/// This includes leap years.
|
||||
/// </summary>
|
||||
static date from_number(int days_since_base_year, calendar base_date);
|
||||
|
||||
date(int year, int month, int day)
|
||||
|
@ -42,7 +59,14 @@ struct date
|
|||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return the number of days between this date and base_date.
|
||||
/// </summary>
|
||||
int to_number(calendar base_date) const;
|
||||
|
||||
/// <summary>
|
||||
/// Return true if this date is equal to comparand.
|
||||
/// </summary>
|
||||
bool operator==(const date &comparand) const;
|
||||
|
||||
int year;
|
||||
|
@ -50,9 +74,23 @@ struct date
|
|||
int day;
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// A time is a specific time of the day specified in terms of an hour,
|
||||
/// minute, second, and microsecond (0-999999).
|
||||
/// It can also be initialized as a fraction of a day using time::from_number.
|
||||
/// </summary>
|
||||
struct time
|
||||
{
|
||||
/// <summary>
|
||||
/// Return the current time according to the system time.
|
||||
/// </summary>
|
||||
static time now();
|
||||
|
||||
/// <summary>
|
||||
/// Return a time from a number representing a fraction of a day.
|
||||
/// The integer part of number will be ignored.
|
||||
/// 0.5 would return time(12, 0, 0, 0) or noon, halfway through the day.
|
||||
/// </summary>
|
||||
static time from_number(long double number);
|
||||
|
||||
explicit time(int hour = 0, int minute = 0, int second = 0, int microsecond = 0)
|
||||
|
@ -72,7 +110,22 @@ struct time
|
|||
|
||||
struct datetime
|
||||
{
|
||||
/// <summary>
|
||||
/// Return the current date and time according to the system time.
|
||||
/// </summary>
|
||||
static datetime now();
|
||||
|
||||
/// <summary>
|
||||
/// Return the current date and time according to the system time.
|
||||
/// This is equivalent to datetime::now().
|
||||
/// </summary>
|
||||
static datetime today() { return now(); }
|
||||
|
||||
/// <summary>
|
||||
/// Return a datetime from number by converting the integer part into
|
||||
/// a date and the fractional part into a time according to date::from_number
|
||||
/// and time::from_number.
|
||||
/// </summary>
|
||||
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)
|
||||
|
@ -92,9 +145,13 @@ struct datetime
|
|||
int microsecond;
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Represents a span of time between two datetimes. This is
|
||||
/// not fully supported yet.
|
||||
/// </summary>
|
||||
struct timedelta
|
||||
{
|
||||
timedelta(int days, int hours, int minutes, int seconds, int microseconds) : days(days), hours(hours), minutes(minutes), seconds(seconds), microseconds(microseconds)
|
||||
timedelta(int days, int hours, int minutes = 0, int seconds = 0, int microseconds = 0) : days(days), hours(hours), minutes(minutes), seconds(seconds), microseconds(microseconds)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
18
include/xlnt/common/encoding.hpp
Normal file
18
include/xlnt/common/encoding.hpp
Normal file
|
@ -0,0 +1,18 @@
|
|||
#pragma once
|
||||
|
||||
namespace xlnt {
|
||||
|
||||
/// <summary>
|
||||
/// Specifies the encoding used in a worksheet.
|
||||
/// This isn't really supported yet.
|
||||
/// </summary>
|
||||
enum class encoding
|
||||
{
|
||||
utf8,
|
||||
latin1,
|
||||
utf16,
|
||||
utf32,
|
||||
ascii
|
||||
};
|
||||
|
||||
} // namespace xlnt
|
|
@ -109,5 +109,14 @@ class missing_number_format : public std::runtime_error
|
|||
public:
|
||||
missing_number_format();
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Error when an attribute value is invalid.
|
||||
/// </summary>
|
||||
class attribute_error : public std::runtime_error
|
||||
{
|
||||
public:
|
||||
attribute_error();
|
||||
};
|
||||
|
||||
} // namespace xlnt
|
||||
|
|
|
@ -30,6 +30,9 @@ namespace xlnt {
|
|||
|
||||
class string_table_builder;
|
||||
|
||||
/// <summary>
|
||||
/// Encapsulates a table of strings used for reading and writing sharedStrings.xml.
|
||||
/// </summary>
|
||||
class string_table
|
||||
{
|
||||
public:
|
||||
|
@ -39,6 +42,9 @@ private:
|
|||
std::vector<std::string> strings_;
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Provides a simple interface for using string_table.
|
||||
/// </summary>
|
||||
class string_table_builder
|
||||
{
|
||||
public:
|
||||
|
|
|
@ -24,5 +24,8 @@
|
|||
|
||||
#include <cstdint>
|
||||
|
||||
typedef uint32_t row_t;
|
||||
typedef uint32_t column_t;
|
||||
// We might want to change these types for various optimizations in the future
|
||||
// so use typedefs.
|
||||
|
||||
using row_t = std::uint32_t;
|
||||
using column_t = std::uint32_t;
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
// Note: this comes from https://github.com/tfussell/pyzip
|
||||
|
||||
struct mz_zip_archive_tag;
|
||||
|
||||
namespace xlnt {
|
||||
|
|
|
@ -22,15 +22,27 @@
|
|||
// @author: see AUTHORS file
|
||||
#pragma once
|
||||
|
||||
// Change these values for programs using this library.
|
||||
|
||||
namespace xlnt {
|
||||
|
||||
/// <summary>
|
||||
/// Enumeration of possible limit styles.
|
||||
/// Excel places limitations on the number of rows and columns,
|
||||
/// but we may wish to change those limits in some cases. Values
|
||||
/// other than excel might prevent the file from being opened in Excel.
|
||||
/// </summary>
|
||||
enum class limit_style
|
||||
{
|
||||
openpyxl,
|
||||
excel,
|
||||
maximum
|
||||
openpyxl, /// limit style using in openpyxl
|
||||
excel, /// limits according to Excel
|
||||
maximum /// limits based on system
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// The style of limits to use for reading and writing XLSX files.
|
||||
/// See limit_style for more information.
|
||||
/// </summary>
|
||||
const limit_style LimitStyle = limit_style::openpyxl;
|
||||
|
||||
}
|
||||
|
|
|
@ -48,12 +48,23 @@ struct alignment
|
|||
justify
|
||||
};
|
||||
|
||||
horizontal_alignment horizontal = horizontal_alignment::general;
|
||||
vertical_alignment vertical = vertical_alignment::bottom;
|
||||
int text_rotation = 0;
|
||||
bool wrap_text = false;
|
||||
bool shrink_to_fit = false;
|
||||
int indent = 0;
|
||||
void set_wrap_text(bool wrap_text)
|
||||
{
|
||||
wrap_text_ = wrap_text;
|
||||
}
|
||||
|
||||
bool operator==(const alignment &other) const
|
||||
{
|
||||
return horizontal_ == other.horizontal_;
|
||||
}
|
||||
|
||||
private:
|
||||
horizontal_alignment horizontal_ = horizontal_alignment::general;
|
||||
vertical_alignment vertical_ = vertical_alignment::bottom;
|
||||
int text_rotation_ = 0;
|
||||
bool wrap_text_ = false;
|
||||
bool shrink_to_fit_ = false;
|
||||
int indent_ = 0;
|
||||
};
|
||||
|
||||
} // namespace xlnt
|
||||
|
|
|
@ -23,53 +23,83 @@
|
|||
// @author: see AUTHORS file
|
||||
#pragma once
|
||||
|
||||
#include <xlnt/styles/color.hpp>
|
||||
|
||||
namespace xlnt {
|
||||
|
||||
class borders
|
||||
template<typename T>
|
||||
struct optional
|
||||
{
|
||||
struct border
|
||||
{
|
||||
enum class style
|
||||
{
|
||||
none,
|
||||
dashdot,
|
||||
dashdotdot,
|
||||
dashed,
|
||||
dotted,
|
||||
double_,
|
||||
hair,
|
||||
medium,
|
||||
mediumdashdot,
|
||||
mediumdashdotdot,
|
||||
mediumdashed,
|
||||
slantdashdot,
|
||||
thick,
|
||||
thin
|
||||
};
|
||||
|
||||
style style_ = style::none;
|
||||
color color_ = color::black;
|
||||
};
|
||||
T value;
|
||||
bool initialized;
|
||||
};
|
||||
|
||||
enum class diagonal_direction
|
||||
{
|
||||
none,
|
||||
up,
|
||||
down,
|
||||
both
|
||||
};
|
||||
enum class border_style
|
||||
{
|
||||
none,
|
||||
dashdot,
|
||||
dashdotdot,
|
||||
dashed,
|
||||
dotted,
|
||||
double_,
|
||||
hair,
|
||||
medium,
|
||||
mediumdashdot,
|
||||
mediumdashdotdot,
|
||||
mediumdashed,
|
||||
slantdashdot,
|
||||
thick,
|
||||
thin
|
||||
};
|
||||
|
||||
enum class diagonal_direction
|
||||
{
|
||||
none,
|
||||
up,
|
||||
down,
|
||||
both
|
||||
};
|
||||
|
||||
border left;
|
||||
border right;
|
||||
border top;
|
||||
border bottom;
|
||||
border diagonal;
|
||||
// diagonal_direction diagonal_direction = diagonal_direction::none;
|
||||
border all_borders;
|
||||
border outline;
|
||||
border inside;
|
||||
border vertical;
|
||||
border horizontal;
|
||||
class side
|
||||
{
|
||||
public:
|
||||
side(border_style style = border_style::none, color = color::black);
|
||||
|
||||
bool operator==(const side &other) const
|
||||
{
|
||||
return other.style_ == style_;
|
||||
}
|
||||
|
||||
private:
|
||||
border_style style_;
|
||||
color color_;
|
||||
};
|
||||
|
||||
class border
|
||||
{
|
||||
public:
|
||||
static border default_border();
|
||||
|
||||
optional<side> start;
|
||||
optional<side> end;
|
||||
optional<side> left;
|
||||
optional<side> right;
|
||||
optional<side> top;
|
||||
optional<side> bottom;
|
||||
optional<side> diagonal;
|
||||
optional<side> vertical;
|
||||
optional<side> horizontal;
|
||||
|
||||
bool outline;
|
||||
bool diagonal_up;
|
||||
bool diagonal_down;
|
||||
|
||||
diagonal_direction diagonal_direction;
|
||||
|
||||
bool operator==(const border &other) const
|
||||
{
|
||||
return start.value == other.start.value;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace xlnt
|
||||
|
|
|
@ -59,6 +59,22 @@ public:
|
|||
int rotation = 0;
|
||||
color start_color = color::white;
|
||||
color end_color = color::black;
|
||||
|
||||
bool operator==(const fill &other) const
|
||||
{
|
||||
return type_ == other.type_;
|
||||
}
|
||||
};
|
||||
|
||||
class pattern_fill : public fill
|
||||
{
|
||||
public:
|
||||
void set_pattern_type(const std::string &type) { type_ = type; }
|
||||
void set_foreground_color(const std::string &hex) { foreground_color_ = hex; }
|
||||
|
||||
private:
|
||||
std::string type_;
|
||||
std::string foreground_color_;
|
||||
};
|
||||
|
||||
} // namespace xlnt
|
||||
|
|
|
@ -23,10 +23,15 @@
|
|||
// @author: see AUTHORS file
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <xlnt/styles/color.hpp>
|
||||
|
||||
namespace xlnt {
|
||||
|
||||
class font
|
||||
{
|
||||
public:
|
||||
enum class underline
|
||||
{
|
||||
none,
|
||||
|
@ -36,15 +41,23 @@ class font
|
|||
single_accounting
|
||||
};
|
||||
|
||||
/* std::string name = "Calibri";
|
||||
int size = 11;
|
||||
bool bold = false;
|
||||
bool italic = false;
|
||||
bool superscript = false;
|
||||
bool subscript = false;
|
||||
underline underline = underline::none;
|
||||
bool strikethrough = false;
|
||||
color color = color::black;*/
|
||||
void set_bold(bool bold) { bold_ = bold; }
|
||||
|
||||
bool operator==(const font &other) const
|
||||
{
|
||||
return name_ == other.name_;
|
||||
}
|
||||
|
||||
private:
|
||||
std::string name_ = "Calibri";
|
||||
int size_ = 11;
|
||||
bool bold_ = false;
|
||||
bool italic_ = false;
|
||||
bool superscript_ = false;
|
||||
bool subscript_ = false;
|
||||
underline underline_ = underline::none;
|
||||
bool strikethrough_ = false;
|
||||
color color_ = color::black;
|
||||
};
|
||||
|
||||
} // namespace xlnt
|
||||
|
|
|
@ -94,8 +94,8 @@ public:
|
|||
|
||||
format get_format_code() const { return format_code_; }
|
||||
void set_format_code(format format_code) { format_code_ = format_code; }
|
||||
void set_format_code_string(const std::string &format_code) { custom_format_code_ = format_code; }
|
||||
std::string get_format_code_string();
|
||||
void set_format_code_string(const std::string &format_code) { custom_format_code_ = format_code; format_code_ = format::unknown; }
|
||||
std::string get_format_code_string() const;
|
||||
|
||||
private:
|
||||
std::string custom_format_code_ = "";
|
||||
|
|
|
@ -38,9 +38,19 @@ public:
|
|||
protection();
|
||||
protection(type locked);
|
||||
|
||||
void set_locked(bool locked)
|
||||
{
|
||||
locked_ = locked ? type::protected_ : type::unprotected;
|
||||
}
|
||||
|
||||
bool operator==(const protection &other) const
|
||||
{
|
||||
return locked_ == other.locked_ && hidden_ == other.hidden_;
|
||||
}
|
||||
|
||||
private:
|
||||
// type locked_;
|
||||
// type hidden_;
|
||||
type locked_;
|
||||
type hidden_;
|
||||
};
|
||||
|
||||
} // namespace xlnt
|
||||
|
|
|
@ -44,11 +44,12 @@ public:
|
|||
font get_font() const;
|
||||
void set_font(font font);
|
||||
|
||||
fill get_fill() const;
|
||||
void set_fill(fill fill);
|
||||
fill &get_fill();
|
||||
const fill &get_fill() const;
|
||||
void set_fill(fill &fill);
|
||||
|
||||
borders get_borders() const;
|
||||
void set_borders(borders borders);
|
||||
border get_border() const;
|
||||
void set_border(border borders);
|
||||
|
||||
alignment get_alignment() const;
|
||||
void set_alignment(alignment alignment);
|
||||
|
@ -60,14 +61,22 @@ public:
|
|||
protection get_protection() const;
|
||||
void set_protection(protection protection);
|
||||
|
||||
bool pivot_button() const;
|
||||
void set_pivot_button(bool pivot);
|
||||
|
||||
bool quote_prefix() const;
|
||||
void set_quote_prefix(bool quote);
|
||||
|
||||
private:
|
||||
bool static_ = false;
|
||||
font font_;
|
||||
fill fill_;
|
||||
borders borders_;
|
||||
border border_;
|
||||
alignment alignment_;
|
||||
number_format number_format_;
|
||||
protection protection_;
|
||||
bool pivot_button_;
|
||||
bool quote_prefix_;
|
||||
};
|
||||
|
||||
} // namespace xlnt
|
||||
|
|
|
@ -39,6 +39,15 @@ class range;
|
|||
class range_reference;
|
||||
class relationship;
|
||||
class worksheet;
|
||||
class alignment;
|
||||
class border;
|
||||
class fill;
|
||||
class pattern_fill;
|
||||
class font;
|
||||
class protection;
|
||||
class color;
|
||||
|
||||
enum class encoding;
|
||||
|
||||
namespace detail {
|
||||
struct workbook_impl;
|
||||
|
@ -95,6 +104,7 @@ public:
|
|||
|
||||
//constructors
|
||||
workbook();
|
||||
workbook(encoding e);
|
||||
|
||||
workbook &operator=(workbook other);
|
||||
workbook(workbook &&other);
|
||||
|
@ -172,6 +182,14 @@ public:
|
|||
relationship get_relationship(const std::string &id) const;
|
||||
std::vector<relationship> get_relationships() const;
|
||||
|
||||
void add_alignment(alignment a);
|
||||
void add_border(border b);
|
||||
void add_fill(fill &f);
|
||||
void add_font(font f);
|
||||
void add_protection(protection p);
|
||||
void add_color(color c);
|
||||
void add_number_format(const std::string &format);
|
||||
|
||||
private:
|
||||
static std::size_t index_from_ws_filename(const std::string &ws_filename);
|
||||
|
||||
|
|
141
include/xlnt/worksheet/cell_vector.hpp
Normal file
141
include/xlnt/worksheet/cell_vector.hpp
Normal file
|
@ -0,0 +1,141 @@
|
|||
#pragma once
|
||||
|
||||
#include <iterator>
|
||||
|
||||
#include "../cell/cell_reference.hpp"
|
||||
#include "range_reference.hpp"
|
||||
#include "major_order.hpp"
|
||||
#include "worksheet.hpp"
|
||||
|
||||
namespace xlnt {
|
||||
|
||||
class cell;
|
||||
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)
|
||||
{
|
||||
}
|
||||
|
||||
common_iterator(const common_iterator<false> &other)
|
||||
{
|
||||
*this = other;
|
||||
}
|
||||
|
||||
cell operator*();
|
||||
|
||||
bool operator== (const common_iterator& other) const
|
||||
{
|
||||
return ws_ == other.ws_
|
||||
&& current_cell_ == other.current_cell_
|
||||
&& order_ == other.order_;
|
||||
}
|
||||
|
||||
bool operator!=(const common_iterator& other) const
|
||||
{
|
||||
return !(*this == other);
|
||||
}
|
||||
|
||||
common_iterator &operator--()
|
||||
{
|
||||
if(order_ == major_order::row)
|
||||
{
|
||||
current_cell_.set_column_index(current_cell_.get_column_index() - 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
current_cell_.set_row(current_cell_.get_row() - 1);
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
common_iterator operator--(int)
|
||||
{
|
||||
iterator old = *this;
|
||||
--*this;
|
||||
return old;
|
||||
}
|
||||
|
||||
common_iterator &operator++()
|
||||
{
|
||||
if(order_ == major_order::row)
|
||||
{
|
||||
current_cell_.set_column_index(current_cell_.get_column_index() + 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
current_cell_.set_row(current_cell_.get_row() + 1);
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
common_iterator operator++(int)
|
||||
{
|
||||
iterator old = *this;
|
||||
++*this;
|
||||
return old;
|
||||
}
|
||||
|
||||
friend class common_iterator<true>;
|
||||
|
||||
private:
|
||||
worksheet ws_;
|
||||
cell_reference current_cell_;
|
||||
range_reference range_;
|
||||
major_order order_;
|
||||
};
|
||||
|
||||
using iterator = common_iterator<false>;
|
||||
using const_iterator = common_iterator<true>;
|
||||
|
||||
cell_vector(worksheet ws, const range_reference &ref, major_order order = major_order::row);
|
||||
|
||||
std::size_t num_cells() const;
|
||||
|
||||
cell front();
|
||||
|
||||
const cell front() const;
|
||||
|
||||
cell back();
|
||||
|
||||
const cell back() const;
|
||||
|
||||
cell operator[](std::size_t column_index);
|
||||
|
||||
const cell operator[](std::size_t column_index) const;
|
||||
|
||||
cell get_cell(std::size_t column_index);
|
||||
|
||||
const cell get_cell(std::size_t column_index) const;
|
||||
|
||||
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 cbegin() const;
|
||||
const_iterator cend() const;
|
||||
|
||||
private:
|
||||
worksheet ws_;
|
||||
range_reference ref_;
|
||||
major_order order_;
|
||||
};
|
||||
|
||||
} // namespace xlnt
|
11
include/xlnt/worksheet/major_order.hpp
Normal file
11
include/xlnt/worksheet/major_order.hpp
Normal file
|
@ -0,0 +1,11 @@
|
|||
#pragma once
|
||||
|
||||
namespace xlnt {
|
||||
|
||||
enum class major_order
|
||||
{
|
||||
column,
|
||||
row
|
||||
};
|
||||
|
||||
} // namespace xlnt
|
|
@ -22,104 +22,106 @@
|
|||
// @author: see AUTHORS file
|
||||
#pragma once
|
||||
|
||||
#include <iterator>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "cell_vector.hpp"
|
||||
#include "major_order.hpp"
|
||||
#include "range_reference.hpp"
|
||||
#include "worksheet.hpp"
|
||||
|
||||
namespace xlnt {
|
||||
|
||||
enum class major_order
|
||||
{
|
||||
column,
|
||||
row
|
||||
};
|
||||
|
||||
class cell_vector
|
||||
{
|
||||
public:
|
||||
cell_vector(worksheet ws, const range_reference &ref, major_order order = major_order::row);
|
||||
|
||||
std::size_t num_cells() const;
|
||||
|
||||
cell front();
|
||||
|
||||
const cell front() const;
|
||||
|
||||
cell back();
|
||||
|
||||
const cell back() const;
|
||||
|
||||
cell operator[](std::size_t column_index);
|
||||
|
||||
const cell operator[](std::size_t column_index) const;
|
||||
|
||||
cell get_cell(std::size_t column_index);
|
||||
|
||||
const cell get_cell(std::size_t column_index) const;
|
||||
|
||||
class iterator
|
||||
{
|
||||
public:
|
||||
iterator(worksheet ws, const cell_reference &start_cell, major_order order);
|
||||
~iterator();
|
||||
|
||||
bool operator==(const iterator &rhs);
|
||||
bool operator!=(const iterator &rhs) { return !(*this == rhs); }
|
||||
|
||||
iterator operator++(int);
|
||||
iterator &operator++();
|
||||
|
||||
cell operator*();
|
||||
|
||||
private:
|
||||
worksheet ws_;
|
||||
cell_reference current_cell_;
|
||||
range_reference range_;
|
||||
major_order order_;
|
||||
};
|
||||
|
||||
iterator begin();
|
||||
iterator end();
|
||||
|
||||
class const_iterator
|
||||
{
|
||||
public:
|
||||
const_iterator(worksheet ws, const cell_reference &start_cell, major_order order);
|
||||
~const_iterator();
|
||||
|
||||
bool operator==(const const_iterator &rhs);
|
||||
bool operator!=(const const_iterator &rhs) { return !(*this == rhs); }
|
||||
|
||||
const_iterator operator++(int);
|
||||
const_iterator &operator++();
|
||||
|
||||
const cell operator*();
|
||||
|
||||
private:
|
||||
worksheet ws_;
|
||||
cell_reference current_cell_;
|
||||
range_reference range_;
|
||||
major_order order_;
|
||||
};
|
||||
|
||||
const_iterator begin() const { return cbegin(); }
|
||||
const_iterator end() const { return cend(); }
|
||||
|
||||
const_iterator cbegin() const;
|
||||
const_iterator cend() const;
|
||||
|
||||
private:
|
||||
worksheet ws_;
|
||||
range_reference ref_;
|
||||
major_order order_;
|
||||
};
|
||||
|
||||
class range
|
||||
{
|
||||
public:
|
||||
template<bool is_const = true>
|
||||
class common_iterator : public std::iterator<std::bidirectional_iterator_tag, cell>
|
||||
{
|
||||
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)
|
||||
{
|
||||
}
|
||||
|
||||
common_iterator(const common_iterator<false> &other)
|
||||
{
|
||||
*this = other;
|
||||
}
|
||||
|
||||
cell_vector operator*();
|
||||
|
||||
bool operator== (const common_iterator& other) const
|
||||
{
|
||||
return ws_ == other.ws_
|
||||
&& current_cell_ == other.current_cell_
|
||||
&& order_ == other.order_;
|
||||
}
|
||||
|
||||
bool operator!=(const common_iterator& other) const
|
||||
{
|
||||
return !(*this == other);
|
||||
}
|
||||
|
||||
common_iterator &operator--()
|
||||
{
|
||||
if(order_ == major_order::row)
|
||||
{
|
||||
current_cell_.set_row(current_cell_.get_row() - 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
current_cell_.set_column_index(current_cell_.get_column_index() - 1);
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
common_iterator operator--(int)
|
||||
{
|
||||
iterator old = *this;
|
||||
--*this;
|
||||
return old;
|
||||
}
|
||||
|
||||
common_iterator &operator++()
|
||||
{
|
||||
if(order_ == major_order::row)
|
||||
{
|
||||
current_cell_.set_row(current_cell_.get_row() + 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
current_cell_.set_column_index(current_cell_.get_column_index() + 1);
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
common_iterator operator++(int)
|
||||
{
|
||||
iterator old = *this;
|
||||
++*this;
|
||||
return old;
|
||||
}
|
||||
|
||||
friend class common_iterator<true>;
|
||||
|
||||
private:
|
||||
worksheet ws_;
|
||||
cell_reference current_cell_;
|
||||
range_reference range_;
|
||||
major_order order_;
|
||||
};
|
||||
|
||||
using iterator = common_iterator<false>;
|
||||
using const_iterator = common_iterator<true>;
|
||||
|
||||
range(worksheet ws, const range_reference &reference, major_order order = major_order::row);
|
||||
|
||||
~range();
|
||||
|
@ -143,52 +145,12 @@ public:
|
|||
range_reference get_reference() const;
|
||||
|
||||
std::size_t length() const;
|
||||
|
||||
class iterator
|
||||
{
|
||||
public:
|
||||
iterator(worksheet ws, const range_reference &start_cell, major_order order);
|
||||
~iterator();
|
||||
|
||||
bool operator==(const iterator &rhs);
|
||||
bool operator!=(const iterator &rhs) { return !(*this == rhs); }
|
||||
|
||||
iterator operator++(int);
|
||||
iterator &operator++();
|
||||
|
||||
cell_vector operator*();
|
||||
|
||||
private:
|
||||
worksheet ws_;
|
||||
cell_reference current_cell_;
|
||||
range_reference range_;
|
||||
major_order order_;
|
||||
};
|
||||
|
||||
bool contains(const cell_reference &ref);
|
||||
|
||||
iterator begin();
|
||||
iterator end();
|
||||
|
||||
class const_iterator
|
||||
{
|
||||
public:
|
||||
const_iterator(worksheet ws, const range_reference &start_cell, major_order order);
|
||||
~const_iterator();
|
||||
|
||||
bool operator==(const const_iterator &rhs);
|
||||
bool operator!=(const const_iterator &rhs) { return !(*this == rhs); }
|
||||
|
||||
const_iterator operator++(int);
|
||||
const_iterator &operator++();
|
||||
|
||||
const cell_vector operator*();
|
||||
|
||||
private:
|
||||
worksheet ws_;
|
||||
cell_reference current_cell_;
|
||||
range_reference range_;
|
||||
major_order order_;
|
||||
};
|
||||
|
||||
const_iterator begin() const { return cbegin(); }
|
||||
const_iterator end() const { return cend(); }
|
||||
|
||||
|
|
|
@ -56,10 +56,33 @@ public:
|
|||
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 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); }
|
||||
|
||||
private:
|
||||
cell_reference top_left_;
|
||||
cell_reference bottom_right_;
|
||||
};
|
||||
|
||||
inline bool operator==(const std::string &reference_string, const range_reference &ref)
|
||||
{
|
||||
return ref == reference_string;
|
||||
}
|
||||
|
||||
inline bool operator==(const char *reference_string, const range_reference &ref)
|
||||
{
|
||||
return ref == reference_string;
|
||||
}
|
||||
|
||||
inline bool operator!=(const std::string &reference_string, const range_reference &ref)
|
||||
{
|
||||
return ref != reference_string;
|
||||
}
|
||||
|
||||
inline bool operator!=(const char *reference_string, const range_reference &ref)
|
||||
{
|
||||
return ref != reference_string;
|
||||
}
|
||||
|
||||
} // namespace xlnt
|
||||
|
|
|
@ -249,10 +249,15 @@ public:
|
|||
const cell get_cell(const cell_reference &reference) const;
|
||||
range get_range(const range_reference &reference);
|
||||
const range get_range(const range_reference &reference) const;
|
||||
range get_squared_range(column_t min_col, row_t min_row, column_t max_col, row_t max_row);
|
||||
const range get_squared_range(column_t min_col, row_t min_row, column_t max_col, row_t max_row) const;
|
||||
row_properties &get_row_properties(row_t row);
|
||||
const row_properties &get_row_properties(row_t row) const;
|
||||
bool has_row_properties(row_t row) const;
|
||||
range rows() const;
|
||||
range rows(const std::string &range_string) const;
|
||||
range rows(int row_offset, int column_offset) const;
|
||||
range rows(const std::string &range_string, int row_offset, int column_offset) const;
|
||||
range columns() const;
|
||||
std::list<cell> get_cell_collection();
|
||||
|
||||
|
@ -286,16 +291,21 @@ public:
|
|||
|
||||
// cell merge
|
||||
void merge_cells(const range_reference &reference);
|
||||
void merge_cells(column_t start_column, row_t start_row, column_t end_column, row_t end_row);
|
||||
void unmerge_cells(const range_reference &reference);
|
||||
void unmerge_cells(column_t start_column, row_t start_row, column_t end_column, row_t end_row);
|
||||
std::vector<range_reference> get_merged_ranges() const;
|
||||
|
||||
// append
|
||||
void append(const std::vector<std::string> &cells);
|
||||
void append(const std::vector<int> &cells);
|
||||
void append(const std::vector<date> &cells);
|
||||
void append(const std::vector<cell> &cells);
|
||||
void append(const std::unordered_map<std::string, std::string> &cells);
|
||||
void append(const std::unordered_map<int, std::string> &cells);
|
||||
|
||||
|
||||
void append(const std::vector<int>::const_iterator begin, const std::vector<int>::const_iterator end);
|
||||
|
||||
// operators
|
||||
bool operator==(const worksheet &other) const;
|
||||
bool operator!=(const worksheet &other) const;
|
||||
|
|
|
@ -48,5 +48,5 @@ const std::string download_url = "https://github.com/tfussell/xlnt/archive/maste
|
|||
#include "common/string_table.hpp"
|
||||
#include "common/zip_file.hpp"
|
||||
#include "workbook/document_properties.hpp"
|
||||
#include "cell/value.hpp"
|
||||
#include "cell/comment.hpp"
|
||||
#include "common/encoding.hpp"
|
||||
|
|
11
source/borders.cpp
Normal file
11
source/borders.cpp
Normal file
|
@ -0,0 +1,11 @@
|
|||
|
||||
#include <xlnt/styles/borders.hpp>
|
||||
|
||||
namespace xlnt {
|
||||
|
||||
side::side(border_style style, color c) : style_(style), color_(c)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
} // namespace xlnt
|
483
source/cell.cpp
483
source/cell.cpp
|
@ -5,15 +5,16 @@
|
|||
#include <xlnt/cell/cell.hpp>
|
||||
#include <xlnt/cell/cell_reference.hpp>
|
||||
#include <xlnt/cell/comment.hpp>
|
||||
#include <xlnt/cell/value.hpp>
|
||||
#include <xlnt/common/datetime.hpp>
|
||||
#include <xlnt/common/relationship.hpp>
|
||||
#include <xlnt/worksheet/worksheet.hpp>
|
||||
#include <xlnt/common/exceptions.hpp>
|
||||
#include <xlnt/workbook/workbook.hpp>
|
||||
#include <xlnt/workbook/document_properties.hpp>
|
||||
#include <xlnt/common/exceptions.hpp>
|
||||
|
||||
#include "detail/cell_impl.hpp"
|
||||
#include "detail/comment_impl.hpp"
|
||||
|
||||
namespace {
|
||||
|
||||
|
@ -36,7 +37,7 @@ std::string check_string(std::string s)
|
|||
{
|
||||
if (c <= 8 || c == 11 || c == 12 || (c >= 14 && c <= 31))
|
||||
{
|
||||
throw "illegal characters";
|
||||
throw xlnt::illegal_character_error(static_cast<char>(c));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -140,188 +141,244 @@ cell::cell(worksheet worksheet, const cell_reference &reference) : d_(nullptr)
|
|||
cell self = worksheet.get_cell(reference);
|
||||
d_ = self.d_;
|
||||
}
|
||||
|
||||
cell::cell(worksheet worksheet, const cell_reference &reference, const value &initial_value) : cell(worksheet, reference)
|
||||
|
||||
template<typename T>
|
||||
cell::cell(worksheet worksheet, const cell_reference &reference, const T &initial_value) : cell(worksheet, reference)
|
||||
{
|
||||
set_value(initial_value);
|
||||
}
|
||||
|
||||
|
||||
bool cell::garbage_collectible() const
|
||||
{
|
||||
return !(get_value().get_type() != value::type::null || is_merged() || has_comment() || has_formula());
|
||||
return !(get_data_type() != type::null || is_merged() || has_comment() || has_formula());
|
||||
}
|
||||
|
||||
value &cell::get_value()
|
||||
{
|
||||
return d_->value_;
|
||||
}
|
||||
|
||||
const value &cell::get_value() const
|
||||
{
|
||||
return d_->value_;
|
||||
}
|
||||
|
||||
void cell::set_value(const value &v)
|
||||
{
|
||||
d_->value_ = v;
|
||||
}
|
||||
|
||||
void cell::set_value(const std::string &s)
|
||||
{
|
||||
d_->is_date_ = false;
|
||||
auto temp = check_string(s);
|
||||
d_->value_ = value(temp);
|
||||
|
||||
if (temp.size() > 1 && temp.front() == '=')
|
||||
{
|
||||
d_->formula_ = temp;
|
||||
}
|
||||
|
||||
if(get_parent().get_parent().get_guess_types())
|
||||
{
|
||||
auto percentage = cast_percentage(s);
|
||||
if (percentage.first)
|
||||
{
|
||||
d_->value_ = value(percentage.second);
|
||||
get_style().get_number_format().set_format_code(xlnt::number_format::format::percentage);
|
||||
}
|
||||
else
|
||||
{
|
||||
auto time = cast_time(s);
|
||||
if (time.first)
|
||||
{
|
||||
set_value(time.second);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
auto numeric = cast_numeric(s);
|
||||
if (numeric.first)
|
||||
{
|
||||
d_->value_ = value(numeric.second);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void cell::set_value(const char *s)
|
||||
{
|
||||
set_value(std::string(s));
|
||||
}
|
||||
|
||||
template<>
|
||||
void cell::set_value(bool b)
|
||||
{
|
||||
d_->value_ = value(b);
|
||||
d_->is_date_ = false;
|
||||
d_->value_numeric_ = b ? 1 : 0;
|
||||
d_->type_ = type::boolean;
|
||||
}
|
||||
|
||||
template<>
|
||||
void cell::set_value(std::int8_t i)
|
||||
{
|
||||
d_->value_ = value(i);
|
||||
d_->is_date_ = false;
|
||||
d_->value_numeric_ = static_cast<long double>(i);
|
||||
d_->type_ = type::numeric;
|
||||
}
|
||||
|
||||
template<>
|
||||
void cell::set_value(std::int16_t i)
|
||||
{
|
||||
d_->value_ = value(i);
|
||||
d_->is_date_ = false;
|
||||
d_->value_numeric_ = static_cast<long double>(i);
|
||||
d_->type_ = type::numeric;
|
||||
}
|
||||
|
||||
template<>
|
||||
void cell::set_value(std::int32_t i)
|
||||
{
|
||||
d_->value_ = value(i);
|
||||
d_->is_date_ = false;
|
||||
d_->value_numeric_ = static_cast<long double>(i);
|
||||
d_->type_ = type::numeric;
|
||||
}
|
||||
|
||||
template<>
|
||||
void cell::set_value(std::int64_t i)
|
||||
{
|
||||
d_->value_ = value(i);
|
||||
d_->is_date_ = false;
|
||||
d_->value_numeric_ = static_cast<long double>(i);
|
||||
d_->type_ = type::numeric;
|
||||
}
|
||||
|
||||
template<>
|
||||
void cell::set_value(std::uint8_t i)
|
||||
{
|
||||
d_->value_ = value(i);
|
||||
d_->is_date_ = false;
|
||||
d_->value_numeric_ = static_cast<long double>(i);
|
||||
d_->type_ = type::numeric;
|
||||
}
|
||||
|
||||
template<>
|
||||
void cell::set_value(std::uint16_t i)
|
||||
{
|
||||
d_->value_ = value(i);
|
||||
d_->is_date_ = false;
|
||||
d_->value_numeric_ = static_cast<long double>(i);
|
||||
d_->type_ = type::numeric;
|
||||
}
|
||||
|
||||
template<>
|
||||
void cell::set_value(std::uint32_t i)
|
||||
{
|
||||
d_->value_ = value(i);
|
||||
d_->is_date_ = false;
|
||||
d_->value_numeric_ = static_cast<long double>(i);
|
||||
d_->type_ = type::numeric;
|
||||
}
|
||||
|
||||
template<>
|
||||
void cell::set_value(std::uint64_t i)
|
||||
{
|
||||
d_->value_ = value(i);
|
||||
d_->is_date_ = false;
|
||||
d_->value_numeric_ = static_cast<long double>(i);
|
||||
d_->type_ = type::numeric;
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
void cell::set_value(unsigned long i)
|
||||
{
|
||||
d_->value_ = value(i);
|
||||
d_->is_date_ = false;
|
||||
d_->value_numeric_ = static_cast<long double>(i);
|
||||
d_->type_ = type::numeric;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef __linux__
|
||||
void cell::set_value(long long i)
|
||||
{
|
||||
d_->value_ = value(i);
|
||||
d_->is_date_ = false;
|
||||
d_->value_numeric_ = static_cast<long double>(i);
|
||||
d_->type_ = type::numeric;
|
||||
}
|
||||
|
||||
void cell::set_value(unsigned long long i)
|
||||
{
|
||||
d_->value_ = value(i);
|
||||
d_->is_date_ = false;
|
||||
d_->value_numeric_ = static_cast<long double>(i);
|
||||
d_->type_ = type::numeric;
|
||||
}
|
||||
#endif
|
||||
|
||||
template<>
|
||||
void cell::set_value(float f)
|
||||
{
|
||||
d_->value_ = value(f);
|
||||
}
|
||||
|
||||
void cell::set_value(double d)
|
||||
{
|
||||
d_->value_ = value(d);
|
||||
}
|
||||
|
||||
void cell::set_value(long double d)
|
||||
{
|
||||
d_->value_ = value(d);
|
||||
d_->is_date_ = false;
|
||||
d_->value_numeric_ = static_cast<long double>(f);
|
||||
d_->type_ = type::numeric;
|
||||
}
|
||||
|
||||
void cell::set_value(const date &d)
|
||||
template<>
|
||||
void cell::set_value(double d)
|
||||
{
|
||||
d_->is_date_ = false;
|
||||
d_->value_numeric_ = static_cast<long double>(d);
|
||||
d_->type_ = type::numeric;
|
||||
}
|
||||
|
||||
template<>
|
||||
void cell::set_value(long double d)
|
||||
{
|
||||
d_->is_date_ = false;
|
||||
d_->value_numeric_ = static_cast<long double>(d);
|
||||
d_->type_ = type::numeric;
|
||||
}
|
||||
|
||||
template<>
|
||||
void cell::set_value(std::string s)
|
||||
{
|
||||
set_value_guess_type(s);
|
||||
}
|
||||
|
||||
template<>
|
||||
void cell::set_value(char const *c)
|
||||
{
|
||||
set_value(std::string(c));
|
||||
}
|
||||
|
||||
template<>
|
||||
void cell::set_value(date d)
|
||||
{
|
||||
d_->is_date_ = true;
|
||||
auto code = xlnt::number_format::format::date_yyyymmdd2;
|
||||
auto number_format = xlnt::number_format(code);
|
||||
get_style().set_number_format(number_format);
|
||||
auto base_date = get_parent().get_parent().get_properties().excel_base_date;
|
||||
set_value(d.to_number(base_date));
|
||||
d_->value_numeric_ = d.to_number(base_date);
|
||||
d_->type_ = type::numeric;
|
||||
}
|
||||
|
||||
void cell::set_value(const datetime &d)
|
||||
template<>
|
||||
void cell::set_value(datetime d)
|
||||
{
|
||||
d_->is_date_ = true;
|
||||
auto code = xlnt::number_format::format::date_datetime;
|
||||
auto number_format = xlnt::number_format(code);
|
||||
get_style().set_number_format(number_format);
|
||||
auto base_date = get_parent().get_parent().get_properties().excel_base_date;
|
||||
set_value(d.to_number(base_date));
|
||||
d_->value_numeric_ = d.to_number(base_date);
|
||||
d_->type_ = type::numeric;
|
||||
}
|
||||
|
||||
void cell::set_value(const time &t)
|
||||
template<>
|
||||
void cell::set_value(time t)
|
||||
{
|
||||
d_->is_date_ = true;
|
||||
auto code = xlnt::number_format::format::date_time6;
|
||||
auto number_format = xlnt::number_format(code);
|
||||
get_style().set_number_format(number_format);
|
||||
set_value(t.to_number());
|
||||
d_->value_numeric_ = t.to_number();
|
||||
d_->type_ = type::numeric;
|
||||
}
|
||||
|
||||
void cell::set_value(const timedelta &t)
|
||||
template<>
|
||||
void cell::set_value(timedelta t)
|
||||
{
|
||||
d_->is_date_ = true;
|
||||
set_value(t.to_number());
|
||||
auto code = xlnt::number_format::format::date_timedelta;
|
||||
auto number_format = xlnt::number_format(code);
|
||||
get_style().set_number_format(number_format);
|
||||
d_->value_numeric_ = t.to_number();
|
||||
d_->type_ = type::numeric;
|
||||
}
|
||||
|
||||
void cell::set_value_guess_type(const std::string &s)
|
||||
{
|
||||
d_->is_date_ = false;
|
||||
auto temp = check_string(s);
|
||||
d_->value_string_ = temp;
|
||||
d_->type_ = type::string;
|
||||
|
||||
if (temp.size() > 1 && temp.front() == '=')
|
||||
{
|
||||
d_->formula_ = temp;
|
||||
d_->type_ = type::formula;
|
||||
d_->value_string_.clear();
|
||||
}
|
||||
else if(ErrorCodes.find(s) != ErrorCodes.end())
|
||||
{
|
||||
d_->value_string_ = s;
|
||||
d_->type_ = type::error;
|
||||
}
|
||||
else if(get_parent().get_parent().get_guess_types())
|
||||
{
|
||||
auto percentage = cast_percentage(s);
|
||||
|
||||
if (percentage.first)
|
||||
{
|
||||
d_->value_numeric_ = percentage.second;
|
||||
d_->type_ = type::numeric;
|
||||
get_style().get_number_format().set_format_code(xlnt::number_format::format::percentage);
|
||||
}
|
||||
else
|
||||
{
|
||||
auto time = cast_time(s);
|
||||
|
||||
if (time.first)
|
||||
{
|
||||
set_value(time.second);
|
||||
}
|
||||
else
|
||||
{
|
||||
auto numeric = cast_numeric(s);
|
||||
|
||||
if (numeric.first)
|
||||
{
|
||||
set_value(numeric.second);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool cell::has_style() const
|
||||
|
@ -331,22 +388,22 @@ bool cell::has_style() const
|
|||
|
||||
row_t cell::get_row() const
|
||||
{
|
||||
return d_->row_ + 1;
|
||||
return d_->row_;
|
||||
}
|
||||
|
||||
std::string cell::get_column() const
|
||||
{
|
||||
return cell_reference::column_string_from_index(d_->column_ + 1);
|
||||
return cell_reference::column_string_from_index(d_->column_);
|
||||
}
|
||||
|
||||
void cell::set_merged(bool merged)
|
||||
{
|
||||
d_->merged = merged;
|
||||
d_->is_merged_ = merged;
|
||||
}
|
||||
|
||||
bool cell::is_merged() const
|
||||
{
|
||||
return d_->merged;
|
||||
return d_->is_merged_;
|
||||
}
|
||||
|
||||
bool cell::is_date() const
|
||||
|
@ -366,20 +423,16 @@ bool cell::operator==(std::nullptr_t) const
|
|||
|
||||
bool cell::operator==(const cell &comparand) const
|
||||
{
|
||||
if(comparand == nullptr)
|
||||
{
|
||||
return d_ == nullptr;
|
||||
}
|
||||
|
||||
return d_->value_ == comparand.d_->value_;
|
||||
return d_ == comparand.d_;
|
||||
}
|
||||
|
||||
style &cell::get_style()
|
||||
{
|
||||
if(d_->style_ == nullptr)
|
||||
{
|
||||
d_->style_ = new style();
|
||||
d_->style_.reset(new style());
|
||||
}
|
||||
|
||||
return *d_->style_;
|
||||
}
|
||||
|
||||
|
@ -387,8 +440,9 @@ const style &cell::get_style() const
|
|||
{
|
||||
if(d_->style_ == nullptr)
|
||||
{
|
||||
d_->style_ = new style();
|
||||
d_->style_.reset(new style());
|
||||
}
|
||||
|
||||
return *d_->style_;
|
||||
}
|
||||
|
||||
|
@ -399,7 +453,7 @@ void cell::set_style(const xlnt::style &s)
|
|||
|
||||
cell &cell::operator=(const cell &rhs)
|
||||
{
|
||||
d_ = rhs.d_;
|
||||
*d_ = *rhs.d_;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -438,7 +492,7 @@ void cell::set_hyperlink(const std::string &hyperlink)
|
|||
d_->has_hyperlink_ = true;
|
||||
d_->hyperlink_ = worksheet(d_->parent_).create_relationship(relationship::type::hyperlink, hyperlink);
|
||||
|
||||
if(get_value().is(value::type::null))
|
||||
if(get_data_type() == type::null)
|
||||
{
|
||||
set_value(hyperlink);
|
||||
}
|
||||
|
@ -476,12 +530,17 @@ void cell::clear_formula()
|
|||
|
||||
void cell::set_comment(const xlnt::comment &c)
|
||||
{
|
||||
if(c.d_ != d_->comment_.get())
|
||||
{
|
||||
throw xlnt::attribute_error();
|
||||
}
|
||||
|
||||
if(!has_comment())
|
||||
{
|
||||
get_parent().increment_comments();
|
||||
}
|
||||
|
||||
d_->comment_ = c;
|
||||
*get_comment().d_ = *c.d_;
|
||||
}
|
||||
|
||||
void cell::clear_comment()
|
||||
|
@ -491,12 +550,12 @@ void cell::clear_comment()
|
|||
get_parent().decrement_comments();
|
||||
}
|
||||
|
||||
d_->comment_ = comment();
|
||||
d_->comment_ = nullptr;
|
||||
}
|
||||
|
||||
bool cell::has_comment() const
|
||||
{
|
||||
return d_->comment_.get_text() != "";
|
||||
return d_->comment_ != nullptr;
|
||||
}
|
||||
|
||||
void cell::set_error(const std::string &error)
|
||||
|
@ -506,7 +565,8 @@ void cell::set_error(const std::string &error)
|
|||
throw data_type_exception();
|
||||
}
|
||||
|
||||
set_value(value::error(error));
|
||||
d_->value_string_ = error;
|
||||
d_->type_ = type::error;
|
||||
}
|
||||
|
||||
cell cell::offset(column_t column, row_t row)
|
||||
|
@ -524,9 +584,15 @@ const worksheet cell::get_parent() const
|
|||
return worksheet(d_->parent_);
|
||||
}
|
||||
|
||||
comment cell::get_comment() const
|
||||
comment cell::get_comment()
|
||||
{
|
||||
return d_->comment_;
|
||||
if(d_->comment_ == nullptr)
|
||||
{
|
||||
d_->comment_.reset(new detail::comment_impl());
|
||||
get_parent().increment_comments();
|
||||
}
|
||||
|
||||
return comment(d_->comment_.get());
|
||||
}
|
||||
|
||||
std::pair<int, int> cell::get_anchor() const
|
||||
|
@ -536,7 +602,7 @@ std::pair<int, int> cell::get_anchor() const
|
|||
|
||||
auto points_to_pixels = [](double value, double dpi) { return (int)std::ceil(value * dpi / 72); };
|
||||
|
||||
auto left_columns = d_->column_;
|
||||
auto left_columns = d_->column_ - 1;
|
||||
auto &column_dimensions = get_parent().get_column_dimensions();
|
||||
int left_anchor = 0;
|
||||
auto default_width = points_to_pixels(DefaultColumnWidth, 96.0);
|
||||
|
@ -557,7 +623,7 @@ std::pair<int, int> cell::get_anchor() const
|
|||
left_anchor += default_width;
|
||||
}
|
||||
|
||||
auto top_rows = d_->row_;
|
||||
auto top_rows = d_->row_ - 1;
|
||||
auto &row_dimensions = get_parent().get_row_dimensions();
|
||||
int top_anchor = 0;
|
||||
auto default_height = points_to_pixels(DefaultRowHeight, 96.0);
|
||||
|
@ -581,4 +647,185 @@ std::pair<int, int> cell::get_anchor() const
|
|||
return {left_anchor, top_anchor};
|
||||
}
|
||||
|
||||
cell::type cell::get_data_type() const
|
||||
{
|
||||
return d_->type_;
|
||||
}
|
||||
|
||||
void cell::set_data_type(type t)
|
||||
{
|
||||
d_->type_ = t;
|
||||
}
|
||||
|
||||
std::size_t cell::get_xf_index() const
|
||||
{
|
||||
return d_->xf_index_;
|
||||
}
|
||||
|
||||
std::string cell::get_number_format() const
|
||||
{
|
||||
return get_style().get_number_format().get_format_code_string();
|
||||
}
|
||||
|
||||
font cell::get_font() const
|
||||
{
|
||||
return get_style().get_font();
|
||||
}
|
||||
|
||||
fill &cell::get_fill()
|
||||
{
|
||||
return get_style().get_fill();
|
||||
}
|
||||
|
||||
const fill &cell::get_fill() const
|
||||
{
|
||||
return get_style().get_fill();
|
||||
}
|
||||
|
||||
border cell::get_border() const
|
||||
{
|
||||
return get_style().get_border();
|
||||
}
|
||||
|
||||
alignment cell::get_alignment() const
|
||||
{
|
||||
return get_style().get_alignment();
|
||||
}
|
||||
|
||||
protection cell::get_protection() const
|
||||
{
|
||||
return get_style().get_protection();
|
||||
}
|
||||
|
||||
bool cell::pivot_button() const
|
||||
{
|
||||
return get_style().pivot_button();
|
||||
}
|
||||
|
||||
bool cell::quote_prefix() const
|
||||
{
|
||||
return get_style().quote_prefix();
|
||||
}
|
||||
|
||||
void cell::clear_value()
|
||||
{
|
||||
d_->value_numeric_ = 0;
|
||||
d_->value_string_.clear();
|
||||
d_->formula_.clear();
|
||||
d_->type_ = cell::type::null;
|
||||
}
|
||||
|
||||
template<>
|
||||
bool cell::get_value()
|
||||
{
|
||||
return d_->value_numeric_ != 0;
|
||||
}
|
||||
|
||||
template<>
|
||||
std::int8_t cell::get_value()
|
||||
{
|
||||
return static_cast<std::int8_t>(d_->value_numeric_);
|
||||
}
|
||||
|
||||
template<>
|
||||
std::int16_t cell::get_value()
|
||||
{
|
||||
return static_cast<std::int16_t>(d_->value_numeric_);
|
||||
}
|
||||
|
||||
template<>
|
||||
std::int32_t cell::get_value()
|
||||
{
|
||||
return static_cast<std::int32_t>(d_->value_numeric_);
|
||||
}
|
||||
|
||||
template<>
|
||||
std::int64_t cell::get_value()
|
||||
{
|
||||
return static_cast<std::int64_t>(d_->value_numeric_);
|
||||
}
|
||||
|
||||
template<>
|
||||
std::uint8_t cell::get_value()
|
||||
{
|
||||
return static_cast<std::uint8_t>(d_->value_numeric_);
|
||||
}
|
||||
|
||||
template<>
|
||||
std::uint16_t cell::get_value()
|
||||
{
|
||||
return static_cast<std::uint16_t>(d_->value_numeric_);
|
||||
}
|
||||
|
||||
template<>
|
||||
std::uint32_t cell::get_value()
|
||||
{
|
||||
return static_cast<std::uint32_t>(d_->value_numeric_);
|
||||
}
|
||||
|
||||
template<>
|
||||
std::uint64_t cell::get_value()
|
||||
{
|
||||
return static_cast<std::uint64_t>(d_->value_numeric_);
|
||||
}
|
||||
|
||||
template<>
|
||||
float cell::get_value()
|
||||
{
|
||||
return static_cast<float>(d_->value_numeric_);
|
||||
}
|
||||
|
||||
template<>
|
||||
double cell::get_value()
|
||||
{
|
||||
return static_cast<double>(d_->value_numeric_);
|
||||
}
|
||||
|
||||
template<>
|
||||
long double cell::get_value()
|
||||
{
|
||||
return d_->value_numeric_;
|
||||
}
|
||||
|
||||
template<>
|
||||
time cell::get_value()
|
||||
{
|
||||
return time::from_number(d_->value_numeric_);
|
||||
}
|
||||
|
||||
template<>
|
||||
datetime cell::get_value()
|
||||
{
|
||||
return datetime::from_number(d_->value_numeric_, xlnt::calendar::windows_1900);
|
||||
}
|
||||
|
||||
template<>
|
||||
date cell::get_value()
|
||||
{
|
||||
return date::from_number(d_->value_numeric_, xlnt::calendar::windows_1900);
|
||||
}
|
||||
|
||||
template<>
|
||||
timedelta cell::get_value()
|
||||
{
|
||||
return timedelta(0, 0);
|
||||
//return timedelta::from_number(d_->value_numeric_);
|
||||
}
|
||||
|
||||
void cell::set_number_format(const std::string &format_string)
|
||||
{
|
||||
get_style().get_number_format().set_format_code_string(format_string);
|
||||
}
|
||||
|
||||
template<>
|
||||
std::string cell::get_value()
|
||||
{
|
||||
return d_->value_string_;
|
||||
}
|
||||
|
||||
bool cell::has_value() const
|
||||
{
|
||||
return d_->type_ != cell::type::null;
|
||||
}
|
||||
|
||||
} // namespace xlnt
|
||||
|
|
|
@ -10,7 +10,7 @@ namespace xlnt {
|
|||
|
||||
std::size_t cell_reference_hash::operator()(const cell_reference &k) const
|
||||
{
|
||||
return k.get_row_index() * constants::MaxColumn + k.get_column_index();
|
||||
return k.get_row() * constants::MaxColumn + k.get_column_index();
|
||||
}
|
||||
|
||||
cell_reference cell_reference::make_absolute(const cell_reference &relative_reference)
|
||||
|
@ -20,7 +20,7 @@ cell_reference cell_reference::make_absolute(const cell_reference &relative_refe
|
|||
return copy;
|
||||
}
|
||||
|
||||
cell_reference::cell_reference() : cell_reference(0, 0, false)
|
||||
cell_reference::cell_reference() : cell_reference(1, 1, false)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -37,24 +37,24 @@ cell_reference::cell_reference(const char *reference_string) : cell_reference(st
|
|||
}
|
||||
|
||||
cell_reference::cell_reference(const std::string &column, row_t row, bool absolute)
|
||||
: column_index_(column_index_from_string(column) - 1),
|
||||
row_index_(row - 1),
|
||||
: column_(column_index_from_string(column)),
|
||||
row_(row),
|
||||
absolute_(absolute)
|
||||
{
|
||||
if(row == 0 || row_index_ >= constants::MaxRow || column_index_ >= constants::MaxColumn)
|
||||
if(row == 0 || row_ >= constants::MaxRow || column_ >= constants::MaxColumn)
|
||||
{
|
||||
throw cell_coordinates_exception(column_index_, row_index_);
|
||||
throw cell_coordinates_exception(column_, row_);
|
||||
}
|
||||
}
|
||||
|
||||
cell_reference::cell_reference(column_t column_index, row_t row_index, bool absolute)
|
||||
: column_index_(column_index),
|
||||
row_index_(row_index),
|
||||
: column_(column_index),
|
||||
row_(row_index),
|
||||
absolute_(absolute)
|
||||
{
|
||||
if(row_index_ >= constants::MaxRow || column_index_ >= constants::MaxColumn)
|
||||
if(row_ >= constants::MaxRow || column_ >= constants::MaxColumn)
|
||||
{
|
||||
throw cell_coordinates_exception(column_index_, row_index_);
|
||||
throw cell_coordinates_exception(column_, row_);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -67,14 +67,14 @@ std::string cell_reference::to_string() const
|
|||
{
|
||||
if(absolute_)
|
||||
{
|
||||
return std::string("$") + column_string_from_index(column_index_ + 1) + "$" + std::to_string(row_index_ + 1);
|
||||
return std::string("$") + column_string_from_index(column_) + "$" + std::to_string(row_);
|
||||
}
|
||||
return column_string_from_index(column_index_ + 1) + std::to_string(row_index_ + 1);
|
||||
return column_string_from_index(column_) + std::to_string(row_);
|
||||
}
|
||||
|
||||
range_reference cell_reference::to_range() const
|
||||
{
|
||||
return range_reference(column_index_, row_index_, column_index_, row_index_);
|
||||
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)
|
||||
|
@ -139,13 +139,13 @@ std::pair<std::string, row_t> cell_reference::split_reference(const std::string
|
|||
|
||||
cell_reference cell_reference::make_offset(int column_offset, int row_offset) const
|
||||
{
|
||||
return cell_reference(column_index_ + column_offset, row_index_ + row_offset);
|
||||
return cell_reference(column_ + column_offset, row_ + row_offset);
|
||||
}
|
||||
|
||||
bool cell_reference::operator==(const cell_reference &comparand) const
|
||||
{
|
||||
return comparand.column_index_ == column_index_
|
||||
&& comparand.row_index_ == row_index_
|
||||
return comparand.column_ == column_
|
||||
&& comparand.row_ == row_
|
||||
&& absolute_ == comparand.absolute_;
|
||||
}
|
||||
|
||||
|
@ -208,14 +208,44 @@ std::string cell_reference::column_string_from_index(column_t column_index)
|
|||
return column_letter;
|
||||
}
|
||||
|
||||
bool operator<(const cell_reference &left, const cell_reference &right)
|
||||
bool cell_reference::operator<(const cell_reference &other)
|
||||
{
|
||||
if(left.row_index_ != right.row_index_)
|
||||
if(row_ != other.row_)
|
||||
{
|
||||
return left.row_index_ < right.row_index_;
|
||||
return row_ < other.row_;
|
||||
}
|
||||
|
||||
return left.column_index_ < right.column_index_;
|
||||
return column_ < other.column_;
|
||||
}
|
||||
|
||||
bool cell_reference::operator>(const cell_reference &other)
|
||||
{
|
||||
if(row_ != other.row_)
|
||||
{
|
||||
return row_ > other.row_;
|
||||
}
|
||||
|
||||
return column_ > other.column_;
|
||||
}
|
||||
|
||||
bool cell_reference::operator<=(const cell_reference &other)
|
||||
{
|
||||
if(row_ != other.row_)
|
||||
{
|
||||
return row_ < other.row_;
|
||||
}
|
||||
|
||||
return column_ <= other.column_;
|
||||
}
|
||||
|
||||
bool cell_reference::operator>=(const cell_reference &other)
|
||||
{
|
||||
if(row_ != other.row_)
|
||||
{
|
||||
return row_ > other.row_;
|
||||
}
|
||||
|
||||
return column_ >= other.column_;
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace xlnt
|
||||
|
|
|
@ -1,12 +1,20 @@
|
|||
#include <xlnt/cell/comment.hpp>
|
||||
#include <xlnt/cell/cell.hpp>
|
||||
|
||||
#include "detail/comment_impl.hpp"
|
||||
|
||||
namespace xlnt {
|
||||
|
||||
comment::comment(const std::string &text, const std::string &author) : text_(text), author_(author)
|
||||
comment::comment(detail::comment_impl *d) : d_(d)
|
||||
{
|
||||
}
|
||||
|
||||
comment::comment(cell parent, const std::string &text, const std::string &author) : d_(nullptr)
|
||||
{
|
||||
d_ = parent.get_comment().d_;
|
||||
}
|
||||
|
||||
comment::comment()
|
||||
comment::comment() : d_(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -16,12 +24,17 @@ comment::~comment()
|
|||
|
||||
std::string comment::get_author() const
|
||||
{
|
||||
return author_;
|
||||
return d_->author_;
|
||||
}
|
||||
|
||||
std::string comment::get_text() const
|
||||
{
|
||||
return text_;
|
||||
return d_->text_;
|
||||
}
|
||||
|
||||
bool comment::operator==(const xlnt::comment &other) const
|
||||
{
|
||||
return d_ == other.d_;
|
||||
}
|
||||
|
||||
} // namespace xlnt
|
||||
|
|
|
@ -1,18 +1,31 @@
|
|||
#include "cell_impl.hpp"
|
||||
#include <xlnt/worksheet/worksheet.hpp>
|
||||
|
||||
#include "cell_impl.hpp"
|
||||
#include "comment_impl.hpp"
|
||||
|
||||
namespace xlnt {
|
||||
namespace detail {
|
||||
|
||||
cell_impl::cell_impl() : parent_(nullptr), column_(0), row_(0), style_(nullptr), merged(false), is_date_(false), has_hyperlink_(false)
|
||||
cell_impl::cell_impl() : parent_(nullptr), type_(cell::type::null),
|
||||
column_(1), row_(1), style_(nullptr), is_merged_(false),
|
||||
is_date_(false), has_hyperlink_(false), xf_index_(0), comment_(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
cell_impl::cell_impl(worksheet_impl *parent, int column_index, int row_index) : parent_(parent), column_(column_index), row_(row_index), style_(nullptr), merged(false), is_date_(false), has_hyperlink_(false)
|
||||
cell_impl::cell_impl(column_t column, row_t row)
|
||||
: parent_(nullptr), type_(cell::type::null), column_(column), row_(row),
|
||||
style_(nullptr), is_merged_(false), is_date_(false),
|
||||
has_hyperlink_(false), xf_index_(0), comment_(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
cell_impl::cell_impl(worksheet_impl *parent, column_t column, row_t row)
|
||||
: parent_(parent), type_(cell::type::null), column_(column), row_(row), style_(nullptr),
|
||||
is_merged_(false), is_date_(false), has_hyperlink_(false), xf_index_(0), comment_(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
cell_impl::cell_impl(const cell_impl &rhs) : is_date_(false)
|
||||
cell_impl::cell_impl(const cell_impl &rhs)
|
||||
{
|
||||
*this = rhs;
|
||||
}
|
||||
|
@ -20,15 +33,27 @@ cell_impl::cell_impl(const cell_impl &rhs) : is_date_(false)
|
|||
cell_impl &cell_impl::operator=(const cell_impl &rhs)
|
||||
{
|
||||
parent_ = rhs.parent_;
|
||||
value_ = rhs.value_;
|
||||
value_numeric_ = rhs.value_numeric_;
|
||||
value_string_ = rhs.value_string_;
|
||||
hyperlink_ = rhs.hyperlink_;
|
||||
formula_ = rhs.formula_;
|
||||
column_ = rhs.column_;
|
||||
row_ = rhs.row_;
|
||||
style_ = rhs.style_;
|
||||
merged = rhs.merged;
|
||||
is_merged_ = rhs.is_merged_;
|
||||
is_date_ = rhs.is_date_;
|
||||
has_hyperlink_ = rhs.has_hyperlink_;
|
||||
type_ = rhs.type_;
|
||||
|
||||
if(rhs.style_ != nullptr)
|
||||
{
|
||||
style_.reset(new style(*rhs.style_));
|
||||
}
|
||||
|
||||
if(rhs.comment_ != nullptr)
|
||||
{
|
||||
comment_.reset(new comment_impl(*rhs.comment_));
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
|
|
@ -2,10 +2,11 @@
|
|||
|
||||
#include <xlnt/cell/cell.hpp>
|
||||
#include <xlnt/cell/comment.hpp>
|
||||
#include <xlnt/cell/value.hpp>
|
||||
#include <xlnt/common/types.hpp>
|
||||
#include <xlnt/common/relationship.hpp>
|
||||
|
||||
#include "comment_impl.hpp"
|
||||
|
||||
namespace xlnt {
|
||||
|
||||
class style;
|
||||
|
@ -17,21 +18,33 @@ struct worksheet_impl;
|
|||
struct cell_impl
|
||||
{
|
||||
cell_impl();
|
||||
cell_impl(worksheet_impl *parent, int column_index, int row_index);
|
||||
cell_impl(column_t column, row_t row);
|
||||
cell_impl(worksheet_impl *parent, column_t column, row_t row);
|
||||
cell_impl(const cell_impl &rhs);
|
||||
cell_impl &operator=(const cell_impl &rhs);
|
||||
|
||||
cell::type type_;
|
||||
|
||||
worksheet_impl *parent_;
|
||||
value value_;
|
||||
std::string formula_;
|
||||
relationship hyperlink_;
|
||||
|
||||
column_t column_;
|
||||
row_t row_;
|
||||
style *style_;
|
||||
bool merged;
|
||||
bool is_date_;
|
||||
|
||||
std::string value_string_;
|
||||
long double value_numeric_;
|
||||
|
||||
std::string formula_;
|
||||
|
||||
bool has_hyperlink_;
|
||||
comment comment_;
|
||||
relationship hyperlink_;
|
||||
|
||||
bool is_merged_;
|
||||
bool is_date_;
|
||||
|
||||
std::size_t xf_index_;
|
||||
|
||||
std::unique_ptr<style> style_;
|
||||
std::unique_ptr<comment_impl> comment_;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
|
25
source/detail/comment_impl.cpp
Normal file
25
source/detail/comment_impl.cpp
Normal file
|
@ -0,0 +1,25 @@
|
|||
#include "comment_impl.hpp"
|
||||
|
||||
|
||||
namespace xlnt {
|
||||
namespace detail {
|
||||
|
||||
comment_impl::comment_impl()
|
||||
{
|
||||
}
|
||||
|
||||
comment_impl::comment_impl(const comment_impl &rhs)
|
||||
{
|
||||
*this = rhs;
|
||||
}
|
||||
|
||||
comment_impl &comment_impl::operator=(const xlnt::detail::comment_impl &rhs)
|
||||
{
|
||||
text_ = rhs.text_;
|
||||
author_ = rhs.author_;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
} // namespace xlnt
|
22
source/detail/comment_impl.hpp
Normal file
22
source/detail/comment_impl.hpp
Normal file
|
@ -0,0 +1,22 @@
|
|||
#pragma once
|
||||
|
||||
#include <xlnt/cell/comment.hpp>
|
||||
|
||||
namespace xlnt {
|
||||
namespace detail {
|
||||
|
||||
struct cell_impl;
|
||||
|
||||
struct comment_impl
|
||||
{
|
||||
comment_impl();
|
||||
comment_impl(cell_impl *parent, const std::string &text, const std::string &author);
|
||||
comment_impl(const comment_impl &rhs);
|
||||
comment_impl &operator=(const comment_impl &rhs);
|
||||
|
||||
std::string text_;
|
||||
std::string author_;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
} // namespace xlnt
|
|
@ -20,6 +20,12 @@ data_type_exception::data_type_exception()
|
|||
|
||||
}
|
||||
|
||||
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")
|
||||
{
|
||||
|
@ -42,6 +48,12 @@ cell_coordinates_exception::cell_coordinates_exception(const std::string &coord_
|
|||
: 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
|
||||
|
|
|
@ -135,7 +135,7 @@ number_format::format number_format::lookup_format(int code)
|
|||
return match->first;
|
||||
}
|
||||
|
||||
std::string number_format::get_format_code_string()
|
||||
std::string number_format::get_format_code_string() const
|
||||
{
|
||||
if(format_code_ == format::unknown)
|
||||
{
|
||||
|
|
|
@ -2,12 +2,12 @@
|
|||
|
||||
namespace xlnt {
|
||||
|
||||
protection::protection()// : locked_(type::unprotected)
|
||||
protection::protection() : protection(type::unprotected)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protection::protection(type /*t*/)// : locked_(t)
|
||||
protection::protection(type t) : locked_(t), hidden_(type::inherit)
|
||||
{
|
||||
|
||||
}
|
||||
|
|
241
source/range.cpp
241
source/range.cpp
|
@ -5,97 +5,12 @@
|
|||
|
||||
namespace xlnt {
|
||||
|
||||
cell_vector::iterator::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)
|
||||
{
|
||||
}
|
||||
|
||||
cell_vector::iterator::~iterator()
|
||||
{
|
||||
}
|
||||
|
||||
bool cell_vector::iterator::operator==(const iterator &rhs)
|
||||
{
|
||||
return ws_ == rhs.ws_
|
||||
&& current_cell_ == rhs.current_cell_
|
||||
&& order_ == rhs.order_;
|
||||
}
|
||||
|
||||
cell_vector::iterator cell_vector::iterator::operator++(int)
|
||||
{
|
||||
iterator old = *this;
|
||||
++*this;
|
||||
return old;
|
||||
}
|
||||
|
||||
cell_vector::iterator &cell_vector::iterator::operator++()
|
||||
{
|
||||
if(order_ == major_order::row)
|
||||
{
|
||||
current_cell_.set_column_index(current_cell_.get_column_index() + 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
current_cell_.set_row_index(current_cell_.get_row_index() + 1);
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<>
|
||||
cell cell_vector::iterator::operator*()
|
||||
{
|
||||
return ws_[current_cell_];
|
||||
}
|
||||
|
||||
cell_vector::const_iterator::const_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)
|
||||
{
|
||||
}
|
||||
|
||||
cell_vector::const_iterator::~const_iterator()
|
||||
{
|
||||
}
|
||||
|
||||
bool cell_vector::const_iterator::operator==(const const_iterator &rhs)
|
||||
{
|
||||
return ws_ == rhs.ws_
|
||||
&& rhs.current_cell_ == current_cell_
|
||||
&& rhs.order_ == order_;
|
||||
}
|
||||
|
||||
cell_vector::const_iterator cell_vector::const_iterator::operator++(int)
|
||||
{
|
||||
const_iterator old = *this;
|
||||
++*this;
|
||||
return old;
|
||||
}
|
||||
|
||||
cell_vector::const_iterator &cell_vector::const_iterator::operator++()
|
||||
{
|
||||
if(order_ == major_order::row)
|
||||
{
|
||||
current_cell_.set_column_index(current_cell_.get_column_index() + 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
current_cell_.set_row_index(current_cell_.get_row_index() + 1);
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
const cell cell_vector::const_iterator::operator*()
|
||||
{
|
||||
const worksheet ws_const = ws_;
|
||||
return ws_const[current_cell_];
|
||||
}
|
||||
|
||||
|
||||
cell_vector::iterator cell_vector::begin()
|
||||
{
|
||||
return iterator(ws_, ref_.get_top_left(), order_);
|
||||
|
@ -111,7 +26,7 @@ cell_vector::iterator cell_vector::end()
|
|||
}
|
||||
|
||||
auto past_end = ref_.get_bottom_right();
|
||||
past_end.set_row_index(past_end.get_row_index() + 1);
|
||||
past_end.set_row(past_end.get_row() + 1);
|
||||
return iterator(ws_, past_end, order_);
|
||||
}
|
||||
|
||||
|
@ -130,7 +45,7 @@ cell_vector::const_iterator cell_vector::cend() const
|
|||
}
|
||||
|
||||
auto past_end = ref_.get_bottom_right();
|
||||
past_end.set_row_index(past_end.get_row_index() + 1);
|
||||
past_end.set_row(past_end.get_row() + 1);
|
||||
return const_iterator(ws_, past_end, order_);
|
||||
}
|
||||
|
||||
|
@ -163,7 +78,7 @@ cell cell_vector::front()
|
|||
return get_cell(ref_.get_top_left().get_column_index());
|
||||
}
|
||||
|
||||
return get_cell(ref_.get_top_left().get_row_index());
|
||||
return get_cell(ref_.get_top_left().get_row());
|
||||
}
|
||||
|
||||
cell cell_vector::back()
|
||||
|
@ -173,7 +88,7 @@ cell cell_vector::back()
|
|||
return get_cell(ref_.get_bottom_right().get_column_index());
|
||||
}
|
||||
|
||||
return get_cell(ref_.get_top_left().get_row_index());
|
||||
return get_cell(ref_.get_top_left().get_row());
|
||||
}
|
||||
|
||||
cell cell_vector::get_cell(std::size_t index)
|
||||
|
@ -212,7 +127,7 @@ std::size_t range::length() const
|
|||
{
|
||||
if(order_ == major_order::row)
|
||||
{
|
||||
return ref_.get_bottom_right().get_row_index() - ref_.get_top_left().get_row_index() + 1;
|
||||
return ref_.get_bottom_right().get_row() - ref_.get_top_left().get_row() + 1;
|
||||
}
|
||||
|
||||
return ref_.get_bottom_right().get_column_index() - ref_.get_top_left().get_column_index() + 1;
|
||||
|
@ -230,22 +145,27 @@ 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(),
|
||||
ref_.get_top_left().get_row_index() + (int)vector_index,
|
||||
ref_.get_top_left().get_row() + (int)vector_index,
|
||||
ref_.get_bottom_right().get_column_index(),
|
||||
ref_.get_top_left().get_row_index() + (int)vector_index);
|
||||
ref_.get_top_left().get_row() + (int)vector_index);
|
||||
return cell_vector(ws_, reference, order_);
|
||||
}
|
||||
|
||||
range_reference reference(ref_.get_top_left().get_column_index() + (int)vector_index,
|
||||
ref_.get_top_left().get_row_index(),
|
||||
ref_.get_top_left().get_row(),
|
||||
ref_.get_top_left().get_column_index() + (int)vector_index,
|
||||
ref_.get_bottom_right().get_row_index());
|
||||
ref_.get_bottom_right().get_row());
|
||||
return cell_vector(ws_, reference, order_);
|
||||
}
|
||||
|
||||
bool range::contains(const cell_reference &ref)
|
||||
{
|
||||
return ref_.get_top_left().get_column_index() <= ref.get_column_index() && ref_.get_bottom_right().get_column_index() >= ref.get_column_index() && ref_.get_top_left().get_row() <= ref.get_row() && ref_.get_bottom_right().get_row() >= ref.get_row();
|
||||
}
|
||||
|
||||
cell range::get_cell(const cell_reference &ref)
|
||||
{
|
||||
return (*this)[ref.get_row_index()][ref.get_column_index()];
|
||||
return (*this)[ref.get_row()][ref.get_column_index()];
|
||||
}
|
||||
|
||||
range::iterator range::begin()
|
||||
|
@ -253,13 +173,13 @@ 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_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_index());
|
||||
ref_.get_bottom_right().get_row());
|
||||
range_reference row_range(ref_.get_top_left(), bottom_left);
|
||||
return iterator(ws_, row_range, order_);
|
||||
}
|
||||
|
@ -268,15 +188,15 @@ range::iterator range::end()
|
|||
{
|
||||
if(order_ == major_order::row)
|
||||
{
|
||||
auto past_end_row_index = ref_.get_bottom_right().get_row_index() + 1;
|
||||
auto past_end_row_index = ref_.get_bottom_right().get_row() + 1;
|
||||
cell_reference bottom_left(ref_.get_top_left().get_column_index(), past_end_row_index);
|
||||
cell_reference bottom_right(ref_.get_bottom_right().get_column_index(), past_end_row_index);
|
||||
return iterator(ws_, range_reference(bottom_left, bottom_right), order_);
|
||||
}
|
||||
|
||||
auto past_end_column_index = ref_.get_bottom_right().get_column_index() + 1;
|
||||
cell_reference top_right(past_end_column_index, ref_.get_top_left().get_row_index());
|
||||
cell_reference bottom_right(past_end_column_index, ref_.get_bottom_right().get_row_index());
|
||||
cell_reference top_right(past_end_column_index, ref_.get_top_left().get_row());
|
||||
cell_reference bottom_right(past_end_column_index, ref_.get_bottom_right().get_row());
|
||||
return iterator(ws_, range_reference(top_right, bottom_right), order_);
|
||||
}
|
||||
|
||||
|
@ -285,13 +205,13 @@ range::const_iterator range::cbegin() const
|
|||
if(order_ == major_order::row)
|
||||
{
|
||||
cell_reference top_right(ref_.get_bottom_right().get_column_index(),
|
||||
ref_.get_top_left().get_row_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_index());
|
||||
ref_.get_bottom_right().get_row());
|
||||
range_reference row_range(ref_.get_top_left(), bottom_left);
|
||||
return const_iterator(ws_, row_range, order_);
|
||||
}
|
||||
|
@ -300,131 +220,34 @@ range::const_iterator range::cend() const
|
|||
{
|
||||
if(order_ == major_order::row)
|
||||
{
|
||||
auto past_end_row_index = ref_.get_bottom_right().get_row_index() + 1;
|
||||
auto past_end_row_index = ref_.get_bottom_right().get_row() + 1;
|
||||
cell_reference bottom_left(ref_.get_top_left().get_column_index(), past_end_row_index);
|
||||
cell_reference bottom_right(ref_.get_bottom_right().get_column_index(), past_end_row_index);
|
||||
return const_iterator(ws_, range_reference(bottom_left, bottom_right), order_);
|
||||
}
|
||||
|
||||
auto past_end_column_index = ref_.get_bottom_right().get_column_index() + 1;
|
||||
cell_reference top_right(past_end_column_index, ref_.get_top_left().get_row_index());
|
||||
cell_reference bottom_right(past_end_column_index, ref_.get_bottom_right().get_row_index());
|
||||
cell_reference top_right(past_end_column_index, ref_.get_top_left().get_row());
|
||||
cell_reference bottom_right(past_end_column_index, ref_.get_bottom_right().get_row());
|
||||
return const_iterator(ws_, range_reference(top_right, bottom_right), order_);
|
||||
}
|
||||
|
||||
range::iterator::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)
|
||||
{
|
||||
}
|
||||
|
||||
range::iterator::~iterator()
|
||||
{
|
||||
}
|
||||
|
||||
bool range::iterator::operator==(const iterator &rhs)
|
||||
{
|
||||
return ws_ == rhs.ws_
|
||||
&& current_cell_ == rhs.current_cell_
|
||||
&& order_ == rhs.order_;
|
||||
}
|
||||
|
||||
range::iterator range::iterator::operator++(int)
|
||||
{
|
||||
iterator old = *this;
|
||||
++*this;
|
||||
return old;
|
||||
}
|
||||
|
||||
range::iterator &range::iterator::operator++()
|
||||
{
|
||||
if(order_ == major_order::row)
|
||||
{
|
||||
current_cell_.set_row_index(current_cell_.get_row_index() + 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
current_cell_.set_column_index(current_cell_.get_column_index() + 1);
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<>
|
||||
cell_vector range::iterator::operator*()
|
||||
{
|
||||
if(order_ == major_order::row)
|
||||
{
|
||||
range_reference reference(range_.get_top_left().get_column_index(),
|
||||
current_cell_.get_row_index(),
|
||||
current_cell_.get_row(),
|
||||
range_.get_bottom_right().get_column_index(),
|
||||
current_cell_.get_row_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_index(),
|
||||
range_.get_top_left().get_row(),
|
||||
current_cell_.get_column_index(),
|
||||
range_.get_bottom_right().get_row_index());
|
||||
return cell_vector(ws_, reference, order_);
|
||||
}
|
||||
|
||||
range::const_iterator::const_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)
|
||||
{
|
||||
}
|
||||
|
||||
range::const_iterator::~const_iterator()
|
||||
{
|
||||
}
|
||||
|
||||
bool range::const_iterator::operator==(const const_iterator &rhs)
|
||||
{
|
||||
return ws_ == rhs.ws_
|
||||
&& rhs.current_cell_ == current_cell_
|
||||
&& order_ == rhs.order_;
|
||||
}
|
||||
|
||||
range::const_iterator range::const_iterator::operator++(int)
|
||||
{
|
||||
const_iterator old = *this;
|
||||
++*this;
|
||||
return old;
|
||||
}
|
||||
|
||||
range::const_iterator &range::const_iterator::operator++()
|
||||
{
|
||||
if(order_ == major_order::row)
|
||||
{
|
||||
current_cell_.set_row_index(current_cell_.get_row_index() + 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
current_cell_.set_column_index(current_cell_.get_column_index() + 1);
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
const cell_vector range::const_iterator::operator*()
|
||||
{
|
||||
if(order_ == major_order::row)
|
||||
{
|
||||
range_reference reference(range_.get_top_left().get_column_index(),
|
||||
current_cell_.get_row_index(),
|
||||
range_.get_bottom_right().get_column_index(),
|
||||
current_cell_.get_row_index());
|
||||
return cell_vector(ws_, reference, order_);
|
||||
}
|
||||
|
||||
range_reference reference(current_cell_.get_column_index(),
|
||||
range_.get_top_left().get_row_index(),
|
||||
current_cell_.get_column_index(),
|
||||
range_.get_bottom_right().get_row_index());
|
||||
range_.get_bottom_right().get_row());
|
||||
return cell_vector(ws_, reference, order_);
|
||||
}
|
||||
|
||||
|
|
|
@ -59,7 +59,7 @@ range_reference range_reference::make_offset(column_t column_offset, row_t row_o
|
|||
|
||||
row_t range_reference::get_height() const
|
||||
{
|
||||
return bottom_right_.get_row_index() - top_left_.get_row_index();
|
||||
return bottom_right_.get_row() - top_left_.get_row();
|
||||
}
|
||||
|
||||
column_t range_reference::get_width() const
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
#include <xlnt/reader/reader.hpp>
|
||||
#include <xlnt/cell/cell.hpp>
|
||||
#include <xlnt/cell/value.hpp>
|
||||
#include <xlnt/common/datetime.hpp>
|
||||
#include <xlnt/worksheet/range_reference.hpp>
|
||||
#include <xlnt/workbook/workbook.hpp>
|
||||
|
@ -318,7 +317,7 @@ void read_worksheet_common(worksheet ws, const pugi::xml_node &root_node, const
|
|||
}
|
||||
else if(has_type && type == "b") // boolean
|
||||
{
|
||||
ws.get_cell(address).set_value(value(value_string != "0"));
|
||||
ws.get_cell(address).set_value(value_string != "0");
|
||||
}
|
||||
else if(has_type && type == "str")
|
||||
{
|
||||
|
@ -328,7 +327,7 @@ void read_worksheet_common(worksheet ws, const pugi::xml_node &root_node, const
|
|||
{
|
||||
try
|
||||
{
|
||||
ws.get_cell(address).set_value(value(std::stod(value_string)));
|
||||
ws.get_cell(address).set_value(std::stold(value_string));
|
||||
}
|
||||
catch(std::invalid_argument)
|
||||
{
|
||||
|
|
|
@ -15,5 +15,55 @@ void style::set_number_format(xlnt::number_format format)
|
|||
{
|
||||
number_format_ = format;
|
||||
}
|
||||
|
||||
border style::get_border() const
|
||||
{
|
||||
return border_;
|
||||
}
|
||||
|
||||
bool style::pivot_button() const
|
||||
{
|
||||
return pivot_button_;
|
||||
}
|
||||
|
||||
bool style::quote_prefix() const
|
||||
{
|
||||
return quote_prefix_;
|
||||
}
|
||||
|
||||
alignment style::get_alignment() const
|
||||
{
|
||||
return alignment_;
|
||||
}
|
||||
|
||||
fill &style::get_fill()
|
||||
{
|
||||
return fill_;
|
||||
}
|
||||
|
||||
const fill &style::get_fill() const
|
||||
{
|
||||
return fill_;
|
||||
}
|
||||
|
||||
font style::get_font() const
|
||||
{
|
||||
return font_;
|
||||
}
|
||||
|
||||
protection style::get_protection() const
|
||||
{
|
||||
return protection_;
|
||||
}
|
||||
|
||||
void style::set_pivot_button(bool pivot)
|
||||
{
|
||||
pivot_button_ = pivot;
|
||||
}
|
||||
|
||||
void style::set_quote_prefix(bool quote)
|
||||
{
|
||||
quote_prefix_ = quote;
|
||||
}
|
||||
|
||||
} // namespace xlnt
|
||||
|
|
647
source/value.cpp
647
source/value.cpp
|
@ -1,647 +0,0 @@
|
|||
#include <stdexcept>
|
||||
|
||||
#include <xlnt/cell/value.hpp>
|
||||
#include <xlnt/common/datetime.hpp>
|
||||
|
||||
namespace xlnt {
|
||||
|
||||
value value::error(const std::string &error_string)
|
||||
{
|
||||
value v(error_string);
|
||||
v.type_ = type::error;
|
||||
return v;
|
||||
}
|
||||
|
||||
value::value() : type_(type::null), numeric_value_(0)
|
||||
{
|
||||
}
|
||||
|
||||
value::value(value &&v)
|
||||
{
|
||||
swap(*this, v);
|
||||
}
|
||||
|
||||
value::value(const value &v)
|
||||
{
|
||||
type_ = v.type_;
|
||||
numeric_value_ = v.numeric_value_;
|
||||
string_value_ = v.string_value_;
|
||||
}
|
||||
|
||||
value::value(bool b) : type_(type::boolean), numeric_value_(b ? 1 : 0)
|
||||
{
|
||||
}
|
||||
|
||||
value::value(std::int8_t i) : type_(type::numeric), numeric_value_(i)
|
||||
{
|
||||
}
|
||||
|
||||
value::value(std::int16_t i) : type_(type::numeric), numeric_value_(i)
|
||||
{
|
||||
}
|
||||
|
||||
value::value(std::int32_t i) : type_(type::numeric), numeric_value_(i)
|
||||
{
|
||||
}
|
||||
|
||||
value::value(std::int64_t i) : type_(type::numeric), numeric_value_(static_cast<long double>(i))
|
||||
{
|
||||
}
|
||||
|
||||
value::value(std::uint8_t i) : type_(type::numeric), numeric_value_(i)
|
||||
{
|
||||
}
|
||||
|
||||
value::value(std::uint16_t i) : type_(type::numeric), numeric_value_(i)
|
||||
{
|
||||
}
|
||||
|
||||
value::value(std::uint32_t i) : type_(type::numeric), numeric_value_(i)
|
||||
{
|
||||
}
|
||||
|
||||
value::value(std::uint64_t i) : type_(type::numeric), numeric_value_(static_cast<long double>(i))
|
||||
{
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
value::value(unsigned long i) : type_(type::numeric), numeric_value_(i)
|
||||
{
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef __linux__
|
||||
value::value(long long i) : type_(type::numeric), numeric_value_(i)
|
||||
{
|
||||
}
|
||||
|
||||
value::value(unsigned long long i) : type_(type::numeric), numeric_value_(i)
|
||||
{
|
||||
}
|
||||
#endif
|
||||
|
||||
value::value(float f) : type_(type::numeric), numeric_value_(f)
|
||||
{
|
||||
}
|
||||
|
||||
value::value(double d) : type_(type::numeric), numeric_value_(d)
|
||||
{
|
||||
}
|
||||
|
||||
value::value(long double d) : type_(type::numeric), numeric_value_(d)
|
||||
{
|
||||
}
|
||||
|
||||
value::value(const char *s) : value(std::string(s))
|
||||
{
|
||||
}
|
||||
|
||||
value::value(const std::string &s) : type_(type::string), string_value_(s)
|
||||
{
|
||||
}
|
||||
|
||||
value::value(const date &d) : type_(type::numeric), numeric_value_(d.to_number(xlnt::calendar::windows_1900))
|
||||
{
|
||||
}
|
||||
|
||||
value::value(const datetime &d) : type_(type::numeric), numeric_value_(d.to_number(xlnt::calendar::windows_1900))
|
||||
{
|
||||
}
|
||||
|
||||
value::value(const time &t) : type_(type::numeric), numeric_value_(t.to_number())
|
||||
{
|
||||
}
|
||||
|
||||
value &value::operator=(value other)
|
||||
{
|
||||
swap(*this, other);
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool value::is(type t) const
|
||||
{
|
||||
return type_ == t;
|
||||
}
|
||||
|
||||
template<>
|
||||
std::string value::get() const
|
||||
{
|
||||
if(type_ == type::string)
|
||||
{
|
||||
return string_value_;
|
||||
}
|
||||
|
||||
throw std::runtime_error("not a string");
|
||||
}
|
||||
|
||||
template<>
|
||||
double value::as() const
|
||||
{
|
||||
switch(type_)
|
||||
{
|
||||
case type::boolean:
|
||||
case type::numeric:
|
||||
return static_cast<double>(numeric_value_);
|
||||
case type::string:
|
||||
return std::stod(string_value_);
|
||||
case type::error:
|
||||
throw std::runtime_error("invalid");
|
||||
case type::null:
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
template<>
|
||||
long double value::as() const
|
||||
{
|
||||
switch(type_)
|
||||
{
|
||||
case type::boolean:
|
||||
case type::numeric:
|
||||
return numeric_value_;
|
||||
case type::string:
|
||||
return std::stod(string_value_);
|
||||
case type::error:
|
||||
throw std::runtime_error("invalid");
|
||||
case type::null:
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
template<>
|
||||
bool value::as() const
|
||||
{
|
||||
switch(type_)
|
||||
{
|
||||
case type::boolean:
|
||||
case type::numeric:
|
||||
return numeric_value_ != 0;
|
||||
case type::string:
|
||||
return !string_value_.empty();
|
||||
case type::error:
|
||||
throw std::runtime_error("invalid");
|
||||
case type::null:
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
template<>
|
||||
std::int8_t value::as() const
|
||||
{
|
||||
switch (type_)
|
||||
{
|
||||
case type::boolean:
|
||||
case type::numeric:
|
||||
return static_cast<std::int8_t>(numeric_value_);
|
||||
case type::string:
|
||||
return static_cast<std::int8_t>(std::stoi(string_value_));
|
||||
case type::error:
|
||||
throw std::runtime_error("invalid");
|
||||
case type::null:
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
template<>
|
||||
std::int16_t value::as() const
|
||||
{
|
||||
switch (type_)
|
||||
{
|
||||
case type::boolean:
|
||||
case type::numeric:
|
||||
return static_cast<std::int16_t>(numeric_value_);
|
||||
case type::string:
|
||||
return static_cast<std::int16_t>(std::stoi(string_value_));
|
||||
case type::error:
|
||||
throw std::runtime_error("invalid");
|
||||
case type::null:
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
template<>
|
||||
std::int32_t value::as() const
|
||||
{
|
||||
switch (type_)
|
||||
{
|
||||
case type::boolean:
|
||||
case type::numeric:
|
||||
return static_cast<std::int32_t>(numeric_value_);
|
||||
case type::string:
|
||||
return std::stoi(string_value_);
|
||||
case type::error:
|
||||
throw std::runtime_error("invalid");
|
||||
case type::null:
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
template<>
|
||||
std::int64_t value::as() const
|
||||
{
|
||||
switch (type_)
|
||||
{
|
||||
case type::boolean:
|
||||
case type::numeric:
|
||||
return static_cast<std::int64_t>(numeric_value_);
|
||||
case type::string:
|
||||
return std::stoi(string_value_);
|
||||
case type::error:
|
||||
throw std::runtime_error("invalid");
|
||||
case type::null:
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
template<>
|
||||
std::uint8_t value::as() const
|
||||
{
|
||||
switch (type_)
|
||||
{
|
||||
case type::boolean:
|
||||
case type::numeric:
|
||||
return static_cast<std::uint8_t>(numeric_value_);
|
||||
case type::string:
|
||||
return static_cast<std::uint8_t>(std::stoi(string_value_));
|
||||
case type::error:
|
||||
throw std::runtime_error("invalid");
|
||||
case type::null:
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
template<>
|
||||
std::uint16_t value::as() const
|
||||
{
|
||||
switch (type_)
|
||||
{
|
||||
case type::boolean:
|
||||
case type::numeric:
|
||||
return static_cast<std::uint16_t>(numeric_value_);
|
||||
case type::string:
|
||||
return static_cast<std::uint16_t>(std::stoi(string_value_));
|
||||
case type::error:
|
||||
throw std::runtime_error("invalid");
|
||||
case type::null:
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
template<>
|
||||
std::uint32_t value::as() const
|
||||
{
|
||||
switch (type_)
|
||||
{
|
||||
case type::boolean:
|
||||
case type::numeric:
|
||||
return static_cast<std::uint32_t>(numeric_value_);
|
||||
case type::string:
|
||||
return std::stoi(string_value_);
|
||||
case type::error:
|
||||
throw std::runtime_error("invalid");
|
||||
case type::null:
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
template<>
|
||||
std::uint64_t value::as() const
|
||||
{
|
||||
switch (type_)
|
||||
{
|
||||
case type::boolean:
|
||||
case type::numeric:
|
||||
return static_cast<std::uint64_t>(numeric_value_);
|
||||
case type::string:
|
||||
return std::stoi(string_value_);
|
||||
case type::error:
|
||||
throw std::runtime_error("invalid");
|
||||
case type::null:
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
template<>
|
||||
unsigned long value::as() const
|
||||
{
|
||||
switch (type_)
|
||||
{
|
||||
case type::boolean:
|
||||
case type::numeric:
|
||||
return static_cast<unsigned long>(numeric_value_);
|
||||
case type::string:
|
||||
return std::stoi(string_value_);
|
||||
case type::error:
|
||||
throw std::runtime_error("invalid");
|
||||
case type::null:
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef __linux__
|
||||
template<>
|
||||
long long value::as() const
|
||||
{
|
||||
switch (type_)
|
||||
{
|
||||
case type::boolean:
|
||||
case type::numeric:
|
||||
return static_cast<long long>(numeric_value_);
|
||||
case type::string:
|
||||
return std::stoi(string_value_);
|
||||
case type::error:
|
||||
throw std::runtime_error("invalid");
|
||||
case type::null:
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
template<>
|
||||
unsigned long long value::as() const
|
||||
{
|
||||
switch (type_)
|
||||
{
|
||||
case type::boolean:
|
||||
case type::numeric:
|
||||
return static_cast<unsigned long long>(numeric_value_);
|
||||
case type::string:
|
||||
return std::stoi(string_value_);
|
||||
case type::error:
|
||||
throw std::runtime_error("invalid");
|
||||
case type::null:
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
template<>
|
||||
std::string value::as() const
|
||||
{
|
||||
return to_string();
|
||||
}
|
||||
|
||||
bool value::is_integral() const
|
||||
{
|
||||
return type_ == type::numeric && (std::int64_t)numeric_value_ == numeric_value_;
|
||||
}
|
||||
|
||||
value value::null()
|
||||
{
|
||||
return value();
|
||||
}
|
||||
|
||||
value::type value::get_type() const
|
||||
{
|
||||
return type_;
|
||||
}
|
||||
|
||||
std::string value::to_string() const
|
||||
{
|
||||
switch(type_)
|
||||
{
|
||||
case type::boolean:
|
||||
return numeric_value_ != 0 ? "1" : "0";
|
||||
case type::numeric:
|
||||
return std::to_string(numeric_value_);
|
||||
case type::string:
|
||||
case type::error:
|
||||
return string_value_;
|
||||
case type::null:
|
||||
return "";
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
bool value::operator==(bool value) const
|
||||
{
|
||||
return type_ == type::boolean && (numeric_value_ != 0) == value;
|
||||
}
|
||||
|
||||
bool value::operator==(std::int8_t comparand) const
|
||||
{
|
||||
return type_ == type::numeric && numeric_value_ == comparand;
|
||||
}
|
||||
|
||||
bool value::operator==(std::int16_t comparand) const
|
||||
{
|
||||
return type_ == type::numeric && numeric_value_ == comparand;
|
||||
}
|
||||
|
||||
bool value::operator==(std::int32_t comparand) const
|
||||
{
|
||||
return type_ == type::numeric && numeric_value_ == comparand;
|
||||
}
|
||||
|
||||
bool value::operator==(std::int64_t comparand) const
|
||||
{
|
||||
return type_ == type::numeric && numeric_value_ == comparand;
|
||||
}
|
||||
|
||||
bool value::operator==(std::uint8_t comparand) const
|
||||
{
|
||||
return type_ == type::numeric && numeric_value_ == comparand;
|
||||
}
|
||||
|
||||
bool value::operator==(std::uint16_t comparand) const
|
||||
{
|
||||
return type_ == type::numeric && numeric_value_ == comparand;
|
||||
}
|
||||
|
||||
bool value::operator==(std::uint32_t comparand) const
|
||||
{
|
||||
return type_ == type::numeric && numeric_value_ == comparand;
|
||||
}
|
||||
|
||||
bool value::operator==(std::uint64_t comparand) const
|
||||
{
|
||||
return type_ == type::numeric && numeric_value_ == comparand;
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
bool value::operator==(unsigned long comparand) const
|
||||
{
|
||||
return type_ == type::numeric && numeric_value_ == comparand;
|
||||
}
|
||||
#endif
|
||||
|
||||
bool value::operator==(float comparand) const
|
||||
{
|
||||
return type_ == type::numeric && numeric_value_ == comparand;
|
||||
}
|
||||
|
||||
bool value::operator==(double comparand) const
|
||||
{
|
||||
return type_ == type::numeric && numeric_value_ == comparand;
|
||||
}
|
||||
|
||||
bool value::operator==(long double comparand) const
|
||||
{
|
||||
return type_ == type::numeric && numeric_value_ == comparand;
|
||||
}
|
||||
|
||||
bool value::operator==(const std::string &comparand) const
|
||||
{
|
||||
if(type_ == type::string)
|
||||
{
|
||||
return string_value_ == comparand;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool value::operator==(const char *comparand) const
|
||||
{
|
||||
return *this == std::string(comparand);
|
||||
}
|
||||
|
||||
bool value::operator==(const time &comparand) const
|
||||
{
|
||||
if(type_ != type::numeric)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return time::from_number(numeric_value_) == comparand;
|
||||
}
|
||||
|
||||
bool value::operator==(const date &comparand) const
|
||||
{
|
||||
return type_ == type::numeric && comparand.to_number(calendar::windows_1900) == numeric_value_;
|
||||
}
|
||||
|
||||
bool value::operator==(const datetime &comparand) const
|
||||
{
|
||||
return type_ == type::numeric && comparand.to_number(calendar::windows_1900) == numeric_value_;
|
||||
}
|
||||
|
||||
bool value::operator==(const timedelta &comparand) const
|
||||
{
|
||||
return type_ == type::numeric && comparand.to_number() == numeric_value_;
|
||||
}
|
||||
|
||||
bool value::operator==(const value &v) const
|
||||
{
|
||||
if(type_ != v.type_) return false;
|
||||
if(type_ == type::string || type_ == type::error) return string_value_ == v.string_value_;
|
||||
if(type_ == type::numeric || type_ == type::boolean) return numeric_value_ == v.numeric_value_;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool operator==(bool comparand, const xlnt::value &value)
|
||||
{
|
||||
return value == comparand;
|
||||
}
|
||||
|
||||
bool operator==(std::int8_t comparand, const xlnt::value &value)
|
||||
{
|
||||
return value == comparand;
|
||||
}
|
||||
|
||||
bool operator==(std::int16_t comparand, const xlnt::value &value)
|
||||
{
|
||||
return value == comparand;
|
||||
}
|
||||
|
||||
bool operator==(std::int32_t comparand, const xlnt::value &value)
|
||||
{
|
||||
return value == comparand;
|
||||
}
|
||||
|
||||
bool operator==(std::int64_t comparand, const xlnt::value &value)
|
||||
{
|
||||
return value == comparand;
|
||||
}
|
||||
|
||||
bool operator==(std::uint8_t comparand, const xlnt::value &value)
|
||||
{
|
||||
return value == comparand;
|
||||
}
|
||||
|
||||
bool operator==(std::uint16_t comparand, const xlnt::value &value)
|
||||
{
|
||||
return value == comparand;
|
||||
}
|
||||
|
||||
bool operator==(std::uint32_t comparand, const xlnt::value &value)
|
||||
{
|
||||
return value == comparand;
|
||||
}
|
||||
|
||||
bool operator==(std::uint64_t comparand, const xlnt::value &value)
|
||||
{
|
||||
return value == comparand;
|
||||
}
|
||||
|
||||
bool operator==(const char *comparand, const xlnt::value &value)
|
||||
{
|
||||
return value == comparand;
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
bool operator==(unsigned long comparand, const xlnt::value &value)
|
||||
{
|
||||
return value == comparand;
|
||||
}
|
||||
#endif
|
||||
|
||||
bool operator==(const std::string &comparand, const xlnt::value &value)
|
||||
{
|
||||
return value == comparand;
|
||||
}
|
||||
|
||||
bool operator==(const time &comparand, const xlnt::value &value)
|
||||
{
|
||||
return value == comparand;
|
||||
}
|
||||
|
||||
bool operator==(const date &comparand, const xlnt::value &value)
|
||||
{
|
||||
return value == comparand;
|
||||
}
|
||||
|
||||
bool operator==(const datetime &comparand, const xlnt::value &value)
|
||||
{
|
||||
return value == comparand;
|
||||
}
|
||||
|
||||
void swap(value &left, value &right)
|
||||
{
|
||||
using std::swap;
|
||||
swap(left.type_, right.type_);
|
||||
swap(left.string_value_, right.string_value_);
|
||||
swap(left.numeric_value_, right.numeric_value_);
|
||||
}
|
||||
|
||||
} // namespace xlnt
|
||||
|
|
@ -556,9 +556,9 @@ bool workbook::save(const std::string &filename)
|
|||
{
|
||||
for(auto cell : row)
|
||||
{
|
||||
if(cell.get_value().is(value::type::string))
|
||||
if(cell.get_data_type() == cell::type::string)
|
||||
{
|
||||
shared_strings_set.insert(cell.get_value().get<std::string>());
|
||||
shared_strings_set.insert(cell.get_value<std::string>());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -693,5 +693,35 @@ std::size_t workbook::index_from_ws_filename(const std::string &ws_filename)
|
|||
auto sheet_index = std::stoi(sheet_index_string) - 1;
|
||||
return sheet_index;
|
||||
}
|
||||
|
||||
void workbook::add_border(xlnt::border b)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void workbook::add_alignment(xlnt::alignment a)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void workbook::add_protection(xlnt::protection p)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void workbook::add_number_format(const std::string &format)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void workbook::add_fill(xlnt::fill &f)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void workbook::add_font(xlnt::font f)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
#include <xlnt/worksheet/worksheet.hpp>
|
||||
#include <xlnt/cell/cell.hpp>
|
||||
#include <xlnt/cell/value.hpp>
|
||||
#include <xlnt/common/datetime.hpp>
|
||||
#include <xlnt/worksheet/range.hpp>
|
||||
#include <xlnt/worksheet/range_reference.hpp>
|
||||
|
@ -206,16 +205,16 @@ const std::unordered_map<row_t, double> &worksheet::get_row_dimensions() const
|
|||
|
||||
cell worksheet::get_cell(const cell_reference &reference)
|
||||
{
|
||||
if(d_->cell_map_.find(reference.get_row_index()) == d_->cell_map_.end())
|
||||
if(d_->cell_map_.find(reference.get_row()) == d_->cell_map_.end())
|
||||
{
|
||||
d_->cell_map_[reference.get_row_index()] = std::unordered_map<column_t, detail::cell_impl>();
|
||||
d_->cell_map_[reference.get_row()] = std::unordered_map<column_t, detail::cell_impl>();
|
||||
}
|
||||
|
||||
auto &row = d_->cell_map_[reference.get_row_index()];
|
||||
auto &row = d_->cell_map_[reference.get_row()];
|
||||
|
||||
if(row.find(reference.get_column_index()) == row.end())
|
||||
{
|
||||
row[reference.get_column_index()] = detail::cell_impl(d_, reference.get_column_index(), reference.get_row_index());
|
||||
row[reference.get_column_index()] = detail::cell_impl(d_, reference.get_column_index(), reference.get_row());
|
||||
}
|
||||
|
||||
return cell(&row[reference.get_column_index()]);
|
||||
|
@ -223,7 +222,7 @@ cell worksheet::get_cell(const cell_reference &reference)
|
|||
|
||||
const cell worksheet::get_cell(const cell_reference &reference) const
|
||||
{
|
||||
return cell(&d_->cell_map_.at(reference.get_row_index()).at(reference.get_column_index()));
|
||||
return cell(&d_->cell_map_.at(reference.get_row()).at(reference.get_column_index()));
|
||||
}
|
||||
|
||||
row_properties &worksheet::get_row_properties(row_t row)
|
||||
|
@ -263,7 +262,7 @@ column_t worksheet::get_lowest_column() const
|
|||
}
|
||||
}
|
||||
|
||||
return lowest + 1;
|
||||
return lowest;
|
||||
}
|
||||
|
||||
row_t worksheet::get_lowest_row() const
|
||||
|
@ -280,24 +279,24 @@ row_t worksheet::get_lowest_row() const
|
|||
lowest = std::min(lowest, (row_t)row.first);
|
||||
}
|
||||
|
||||
return lowest + 1;
|
||||
return lowest;
|
||||
}
|
||||
|
||||
row_t worksheet::get_highest_row() const
|
||||
{
|
||||
row_t highest = 0;
|
||||
row_t highest = 1;
|
||||
|
||||
for(auto &row : d_->cell_map_)
|
||||
{
|
||||
highest = std::max(highest, (row_t)row.first);
|
||||
}
|
||||
|
||||
return highest + 1;
|
||||
return highest;
|
||||
}
|
||||
|
||||
column_t worksheet::get_highest_column() const
|
||||
{
|
||||
column_t highest = 0;
|
||||
column_t highest = 1;
|
||||
|
||||
for(auto &row : d_->cell_map_)
|
||||
{
|
||||
|
@ -307,7 +306,7 @@ column_t worksheet::get_highest_column() const
|
|||
}
|
||||
}
|
||||
|
||||
return highest + 1;
|
||||
return highest;
|
||||
}
|
||||
|
||||
range_reference worksheet::calculate_dimension() const
|
||||
|
@ -318,7 +317,7 @@ range_reference worksheet::calculate_dimension() const
|
|||
int highest_column = get_highest_column();
|
||||
int highest_row = get_highest_row();
|
||||
|
||||
return range_reference(lowest_column - 1, lowest_row - 1, highest_column - 1, highest_row - 1);
|
||||
return range_reference(lowest_column, lowest_row, highest_column, highest_row);
|
||||
}
|
||||
|
||||
range worksheet::get_range(const range_reference &reference)
|
||||
|
@ -331,6 +330,18 @@ const range worksheet::get_range(const range_reference &reference) const
|
|||
return range(*this, reference);
|
||||
}
|
||||
|
||||
range worksheet::get_squared_range(column_t min_col, row_t min_row, column_t max_col, row_t max_row)
|
||||
{
|
||||
range_reference reference(min_col, min_row, max_col, max_row);
|
||||
return get_range(reference);
|
||||
}
|
||||
|
||||
const range worksheet::get_squared_range(column_t min_col, row_t min_row, column_t max_col, row_t max_row) const
|
||||
{
|
||||
range_reference reference(min_col, min_row, max_col, max_row);
|
||||
return get_range(reference);
|
||||
}
|
||||
|
||||
std::vector<relationship> worksheet::get_relationships()
|
||||
{
|
||||
return d_->relationships_;
|
||||
|
@ -356,13 +367,13 @@ void worksheet::merge_cells(const range_reference &reference)
|
|||
|
||||
if(!first)
|
||||
{
|
||||
if(cell.get_value().is(value::type::string))
|
||||
if(cell.get_data_type() == cell::type::string)
|
||||
{
|
||||
cell.set_value(value(""));
|
||||
cell.set_value("");
|
||||
}
|
||||
else
|
||||
{
|
||||
cell.set_value(value::null());
|
||||
cell.clear_value();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -371,6 +382,11 @@ void worksheet::merge_cells(const range_reference &reference)
|
|||
}
|
||||
}
|
||||
|
||||
void worksheet::merge_cells(column_t start_column, row_t start_row, column_t end_column, row_t end_row)
|
||||
{
|
||||
merge_cells(xlnt::range_reference(start_column, start_row, end_column, end_row));
|
||||
}
|
||||
|
||||
void worksheet::unmerge_cells(const range_reference &reference)
|
||||
{
|
||||
auto match = std::find(d_->merged_cells_.begin(), d_->merged_cells_.end(), reference);
|
||||
|
@ -390,17 +406,22 @@ void worksheet::unmerge_cells(const range_reference &reference)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
void worksheet::unmerge_cells(column_t start_column, row_t start_row, column_t end_column, row_t end_row)
|
||||
{
|
||||
unmerge_cells(xlnt::range_reference(start_column, start_row, end_column, end_row));
|
||||
}
|
||||
|
||||
void worksheet::append(const std::vector<std::string> &cells)
|
||||
{
|
||||
int row = get_highest_row();
|
||||
int row = get_highest_row() + 1;
|
||||
|
||||
if(d_->cell_map_.size() == 0)
|
||||
if(row == 2 && d_->cell_map_.size() == 0)
|
||||
{
|
||||
row--;
|
||||
row = 1;
|
||||
}
|
||||
|
||||
int column = 0;
|
||||
int column = 1;
|
||||
|
||||
for(auto cell : cells)
|
||||
{
|
||||
|
@ -411,30 +432,7 @@ void worksheet::append(const std::vector<std::string> &cells)
|
|||
void worksheet::append(const std::vector<int> &cells)
|
||||
{
|
||||
int row = get_highest_row();
|
||||
|
||||
if(d_->cell_map_.size() == 0)
|
||||
{
|
||||
row--;
|
||||
}
|
||||
|
||||
int column = 0;
|
||||
|
||||
for(auto cell : cells)
|
||||
{
|
||||
get_cell(cell_reference(column++, row)).set_value(value(cell));
|
||||
}
|
||||
}
|
||||
|
||||
void worksheet::append(const std::vector<date> &cells)
|
||||
{
|
||||
int row = get_highest_row();
|
||||
|
||||
if(d_->cell_map_.size() == 0)
|
||||
{
|
||||
row--;
|
||||
}
|
||||
|
||||
int column = 0;
|
||||
int column = 1;
|
||||
|
||||
for(auto cell : cells)
|
||||
{
|
||||
|
@ -442,29 +440,31 @@ void worksheet::append(const std::vector<date> &cells)
|
|||
}
|
||||
}
|
||||
|
||||
void worksheet::append(const std::unordered_map<std::string, std::string> &cells)
|
||||
void worksheet::append(const std::vector<date> &cells)
|
||||
{
|
||||
int row = get_highest_row() - 1;
|
||||
|
||||
if(d_->cell_map_.size() != 0)
|
||||
{
|
||||
row++;
|
||||
}
|
||||
|
||||
int row = get_highest_row();
|
||||
int column = 1;
|
||||
|
||||
for(auto cell : cells)
|
||||
{
|
||||
get_cell(cell_reference(cell.first, row + 1)).set_value(cell.second);
|
||||
get_cell(cell_reference(column++, row)).set_value(cell);
|
||||
}
|
||||
}
|
||||
|
||||
void worksheet::append(const std::unordered_map<int, std::string> &cells)
|
||||
void worksheet::append(const std::vector<cell> &cells)
|
||||
{
|
||||
int row = get_highest_row() - 1;
|
||||
|
||||
if(d_->cell_map_.size() != 0)
|
||||
int row = get_highest_row();
|
||||
int column = 1;
|
||||
|
||||
for(auto cell : cells)
|
||||
{
|
||||
row++;
|
||||
get_cell(cell_reference(column++, row)) = cell;
|
||||
}
|
||||
}
|
||||
|
||||
void worksheet::append(const std::unordered_map<std::string, std::string> &cells)
|
||||
{
|
||||
int row = get_highest_row();
|
||||
|
||||
for(auto cell : cells)
|
||||
{
|
||||
|
@ -472,11 +472,43 @@ void worksheet::append(const std::unordered_map<int, std::string> &cells)
|
|||
}
|
||||
}
|
||||
|
||||
void worksheet::append(const std::unordered_map<int, std::string> &cells)
|
||||
{
|
||||
int row = get_highest_row();
|
||||
|
||||
for(auto cell : cells)
|
||||
{
|
||||
get_cell(cell_reference(cell.first, row)).set_value(cell.second);
|
||||
}
|
||||
}
|
||||
|
||||
void worksheet::append(const std::vector<int>::const_iterator begin, const std::vector<int>::const_iterator end)
|
||||
{
|
||||
int row = get_highest_row();
|
||||
int column = 1;
|
||||
|
||||
for(auto i = begin; i != end; i++)
|
||||
{
|
||||
get_cell(cell_reference(column++, row)).set_value(*i);
|
||||
}
|
||||
}
|
||||
|
||||
xlnt::range worksheet::rows() const
|
||||
{
|
||||
return get_range(calculate_dimension());
|
||||
}
|
||||
|
||||
xlnt::range worksheet::rows(const std::string &range_string) const
|
||||
{
|
||||
return get_range(range_reference(range_string));
|
||||
}
|
||||
|
||||
xlnt::range worksheet::rows(const std::string &range_string, int row_offset, int column_offset) const
|
||||
{
|
||||
range_reference reference(range_string);
|
||||
return get_range(reference.make_offset(column_offset, row_offset));
|
||||
}
|
||||
|
||||
xlnt::range worksheet::columns() const
|
||||
{
|
||||
return range(*this, calculate_dimension(), major_order::column);
|
||||
|
@ -607,8 +639,8 @@ cell_reference worksheet::get_point_pos(int left, int top) const
|
|||
auto default_height = points_to_pixels(DefaultRowHeight, 96.0);
|
||||
auto default_width = points_to_pixels(DefaultColumnWidth, 96.0);
|
||||
|
||||
column_t current_column = 0;
|
||||
row_t current_row = 0;
|
||||
column_t current_column = 1;
|
||||
row_t current_row = 1;
|
||||
|
||||
int left_pos = 0;
|
||||
int top_pos = 0;
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
|
||||
#include <xlnt/writer/writer.hpp>
|
||||
#include <xlnt/cell/cell.hpp>
|
||||
#include <xlnt/cell/value.hpp>
|
||||
#include <xlnt/worksheet/range.hpp>
|
||||
#include <xlnt/worksheet/range_reference.hpp>
|
||||
#include <xlnt/worksheet/worksheet.hpp>
|
||||
|
@ -19,6 +18,15 @@
|
|||
|
||||
#include "constants.hpp"
|
||||
|
||||
namespace {
|
||||
|
||||
bool is_integral(long double d)
|
||||
{
|
||||
return d == static_cast<long long int>(d);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace xlnt {
|
||||
|
||||
std::string writer::write_shared_strings(const std::vector<std::string> &string_table)
|
||||
|
@ -236,19 +244,19 @@ std::string writer::write_worksheet(worksheet ws, const std::vector<std::string>
|
|||
{
|
||||
auto pane_node = sheet_view_node.append_child("pane");
|
||||
|
||||
if(ws.get_frozen_panes().get_column_index() > 0)
|
||||
if(ws.get_frozen_panes().get_column_index() > 1)
|
||||
{
|
||||
pane_node.append_attribute("xSplit").set_value(ws.get_frozen_panes().get_column_index());
|
||||
pane_node.append_attribute("xSplit").set_value(ws.get_frozen_panes().get_column_index() - 1);
|
||||
active_pane = "topRight";
|
||||
}
|
||||
|
||||
if(ws.get_frozen_panes().get_row_index() > 0)
|
||||
if(ws.get_frozen_panes().get_row() > 1)
|
||||
{
|
||||
pane_node.append_attribute("ySplit").set_value(ws.get_frozen_panes().get_row_index());
|
||||
pane_node.append_attribute("ySplit").set_value(ws.get_frozen_panes().get_row() - 1);
|
||||
active_pane = "bottomLeft";
|
||||
}
|
||||
|
||||
if(ws.get_frozen_panes().get_row_index() > 0 && ws.get_frozen_panes().get_column_index() > 0)
|
||||
if(ws.get_frozen_panes().get_row() > 1 && ws.get_frozen_panes().get_column_index() > 1)
|
||||
{
|
||||
auto top_right_node = sheet_view_node.append_child("selection");
|
||||
top_right_node.append_attribute("pane").set_value("topRight");
|
||||
|
@ -265,15 +273,15 @@ std::string writer::write_worksheet(worksheet ws, const std::vector<std::string>
|
|||
auto selection_node = sheet_view_node.append_child("selection");
|
||||
if(ws.has_frozen_panes())
|
||||
{
|
||||
if(ws.get_frozen_panes().get_row_index() > 0 && ws.get_frozen_panes().get_column_index() > 0)
|
||||
if(ws.get_frozen_panes().get_row() > 1 && ws.get_frozen_panes().get_column_index() > 1)
|
||||
{
|
||||
selection_node.append_attribute("pane").set_value("bottomRight");
|
||||
}
|
||||
else if(ws.get_frozen_panes().get_row_index() > 0)
|
||||
else if(ws.get_frozen_panes().get_row() > 1)
|
||||
{
|
||||
selection_node.append_attribute("pane").set_value("bottomLeft");
|
||||
}
|
||||
else if(ws.get_frozen_panes().get_column_index() > 0)
|
||||
else if(ws.get_frozen_panes().get_column_index() > 1)
|
||||
{
|
||||
selection_node.append_attribute("pane").set_value("topRight");
|
||||
}
|
||||
|
@ -368,20 +376,20 @@ std::string writer::write_worksheet(worksheet ws, const std::vector<std::string>
|
|||
auto cell_node = row_node.append_child("c");
|
||||
cell_node.append_attribute("r").set_value(cell.get_reference().to_string().c_str());
|
||||
|
||||
if(cell.get_value().is(value::type::string))
|
||||
if(cell.get_data_type() == cell::type::string)
|
||||
{
|
||||
if(cell.has_formula())
|
||||
{
|
||||
cell_node.append_attribute("t").set_value("str");
|
||||
cell_node.append_child("f").text().set(cell.get_formula().c_str());
|
||||
cell_node.append_child("v").text().set(cell.get_value().to_string().c_str());
|
||||
cell_node.append_child("v").text().set(cell.to_string().c_str());
|
||||
continue;
|
||||
}
|
||||
|
||||
int match_index = -1;
|
||||
for(int i = 0; i < (int)string_table.size(); i++)
|
||||
{
|
||||
if(string_table[i] == cell.get_value().as<std::string>())
|
||||
if(string_table[i] == cell.get_value<std::string>())
|
||||
{
|
||||
match_index = i;
|
||||
break;
|
||||
|
@ -390,7 +398,7 @@ std::string writer::write_worksheet(worksheet ws, const std::vector<std::string>
|
|||
|
||||
if(match_index == -1)
|
||||
{
|
||||
if(cell.get_value().as<std::string>().empty())
|
||||
if(cell.get_value<std::string>().empty())
|
||||
{
|
||||
cell_node.append_attribute("t").set_value("s");
|
||||
}
|
||||
|
@ -398,7 +406,7 @@ std::string writer::write_worksheet(worksheet ws, const std::vector<std::string>
|
|||
{
|
||||
cell_node.append_attribute("t").set_value("inlineStr");
|
||||
auto inline_string_node = cell_node.append_child("is");
|
||||
inline_string_node.append_child("t").text().set(cell.get_value().as<std::string>().c_str());
|
||||
inline_string_node.append_child("t").text().set(cell.get_value<std::string>().c_str());
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -410,32 +418,36 @@ std::string writer::write_worksheet(worksheet ws, const std::vector<std::string>
|
|||
}
|
||||
else
|
||||
{
|
||||
if(!cell.get_value().is(value::type::null))
|
||||
if(cell.get_data_type() != cell::type::null)
|
||||
{
|
||||
if(cell.get_value().is(value::type::boolean))
|
||||
if(cell.get_data_type() == cell::type::boolean)
|
||||
{
|
||||
cell_node.append_attribute("t").set_value("b");
|
||||
auto value_node = cell_node.append_child("v");
|
||||
value_node.text().set(cell.get_value().as<bool>() ? 1 : 0);
|
||||
value_node.text().set(cell.get_value<bool>() ? 1 : 0);
|
||||
}
|
||||
else if(cell.get_value().is(value::type::numeric))
|
||||
else if(cell.get_data_type() == cell::type::numeric)
|
||||
{
|
||||
if(cell.has_formula())
|
||||
{
|
||||
cell_node.append_child("f").text().set(cell.get_formula().c_str());
|
||||
cell_node.append_child("v").text().set(cell.get_value().to_string().c_str());
|
||||
cell_node.append_child("v").text().set(cell.to_string().c_str());
|
||||
continue;
|
||||
}
|
||||
|
||||
cell_node.append_attribute("t").set_value("n");
|
||||
auto value_node = cell_node.append_child("v");
|
||||
if(cell.get_value().is_integral())
|
||||
if(is_integral(cell.get_value<long double>()))
|
||||
{
|
||||
value_node.text().set(cell.get_value().as<long long>());
|
||||
value_node.text().set(cell.get_value<long long>());
|
||||
}
|
||||
else
|
||||
{
|
||||
value_node.text().set(cell.get_value().as<double>());
|
||||
std::stringstream ss;
|
||||
ss.precision(20);
|
||||
ss << cell.get_value<long double>();
|
||||
ss.str();
|
||||
value_node.text().set(ss.str().c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
53
tests/data/reader/bug328_hyperlinks.xml
Normal file
53
tests/data/reader/bug328_hyperlinks.xml
Normal file
|
@ -0,0 +1,53 @@
|
|||
<worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"
|
||||
xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">
|
||||
<sheetPr>
|
||||
<outlinePr summaryRight="1" summaryBelow="1"></outlinePr>
|
||||
</sheetPr>
|
||||
<dimension ref="A1:F1"></dimension>
|
||||
<sheetViews>
|
||||
<sheetView workbookViewId="0">
|
||||
<selection sqref="A1" activeCell="A1"></selection>
|
||||
</sheetView>
|
||||
</sheetViews>
|
||||
<sheetFormatPr defaultRowHeight="15"></sheetFormatPr>
|
||||
<sheetData>
|
||||
<row r="1" spans="1:5">
|
||||
<c s="2" r="A1" t="s">
|
||||
<v>0</v>
|
||||
</c>
|
||||
<c s="2" r="B1" t="s">
|
||||
<v>0</v>
|
||||
</c>
|
||||
<c s="2" r="C1" t="s">
|
||||
<v>0</v>
|
||||
</c>
|
||||
<c s="2" r="D1" t="s">
|
||||
<v>0</v>
|
||||
</c>
|
||||
<c s="2" r="E1" t="s">
|
||||
<v>0</v>
|
||||
</c>
|
||||
</row>
|
||||
<row r="2" spans="1:6">
|
||||
<c r="A2" t="s">
|
||||
<v>0</v>
|
||||
</c>
|
||||
<c r="B2" t="s">
|
||||
<v>0</v>
|
||||
</c>
|
||||
<c r="C2" t="s">
|
||||
<v>0</v>
|
||||
</c>
|
||||
<c r="D2" t="s">
|
||||
<v>0</v>
|
||||
</c>
|
||||
<c r="E2" t="s">
|
||||
<v>0</v>
|
||||
</c>
|
||||
<c r="F2">
|
||||
<f>HYPERLINK("#NoeudLNG!I4", "LINK")</f>
|
||||
<v></v>
|
||||
</c>
|
||||
</row>
|
||||
</sheetData>
|
||||
</worksheet>
|
64
tests/data/reader/bug393-worksheet.xml
Normal file
64
tests/data/reader/bug393-worksheet.xml
Normal file
|
@ -0,0 +1,64 @@
|
|||
<?xml version="1.0"?>
|
||||
<worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
|
||||
<sheetPr>
|
||||
<outlinePr summaryBelow="1" summaryRight="1"/>
|
||||
</sheetPr>
|
||||
<sheetViews>
|
||||
<sheetView workbookViewId="0">
|
||||
<selection activeCell="A1" sqref="A1"/>
|
||||
</sheetView>
|
||||
</sheetViews>
|
||||
<sheetFormatPr baseColWidth="10" defaultRowHeight="15"/>
|
||||
<sheetData>
|
||||
<row r="1" spans="1:5">
|
||||
<c r="A1" t="n">
|
||||
<v>1</v>
|
||||
</c>
|
||||
<c r="B1" t="n">
|
||||
<v>2</v>
|
||||
</c>
|
||||
<c r="C1" t="n">
|
||||
<v>3</v>
|
||||
</c>
|
||||
<c r="D1" t="n">
|
||||
<v>4</v>
|
||||
</c>
|
||||
<c r="E1" t="n">
|
||||
<v>5</v>
|
||||
</c>
|
||||
</row>
|
||||
<row r="2" spans="1:5">
|
||||
<c r="C2" t="n">
|
||||
<v>1</v>
|
||||
</c>
|
||||
<c r="D2" t="n">
|
||||
<v>2</v>
|
||||
</c>
|
||||
<c r="E2" t="n">
|
||||
<v>3</v>
|
||||
</c>
|
||||
</row>
|
||||
<row r="3" spans="1:5">
|
||||
<c r="A3" t="n">
|
||||
<v>1</v>
|
||||
</c>
|
||||
<c r="B3" t="n">
|
||||
<v>2</v>
|
||||
</c>
|
||||
<c r="C3" t="n">
|
||||
<v>3</v>
|
||||
</c>
|
||||
</row>
|
||||
<row r="4" spans="1:5">
|
||||
<c r="A4" t="n">
|
||||
<v>1</v>
|
||||
</c>
|
||||
<c r="B4" t="n">
|
||||
<v>2</v>
|
||||
</c>
|
||||
<c r="E4" t="n">
|
||||
<v>3</v>
|
||||
</c>
|
||||
</row>
|
||||
</sheetData>
|
||||
</worksheet>
|
43
tests/data/reader/empty_rows.xml
Normal file
43
tests/data/reader/empty_rows.xml
Normal file
|
@ -0,0 +1,43 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:x14ac="http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac" mc:Ignorable="x14ac">
|
||||
<dimension ref="A2:A7"/>
|
||||
<sheetViews>
|
||||
<sheetView tabSelected="1" workbookViewId="0">
|
||||
<selection activeCell="A8" sqref="A8"/>
|
||||
</sheetView>
|
||||
</sheetViews>
|
||||
<sheetFormatPr baseColWidth="10" defaultRowHeight="16" x14ac:dyDescent="0"/>
|
||||
<sheetData>
|
||||
<row r="2" spans="1:1">
|
||||
<c r="A2">
|
||||
<v>1</v>
|
||||
</c>
|
||||
</row>
|
||||
<row r="4" spans="1:1">
|
||||
<c r="A4">
|
||||
<v>2</v>
|
||||
</c>
|
||||
</row>
|
||||
<row r="5" spans="1:1">
|
||||
<c r="A5">
|
||||
<v>3</v>
|
||||
</c>
|
||||
</row>
|
||||
<row r="6" spans="1:1">
|
||||
<c r="A6">
|
||||
<v>4</v>
|
||||
</c>
|
||||
</row>
|
||||
<row r="7" spans="1:1">
|
||||
<c r="A7">
|
||||
<v>5</v>
|
||||
</c>
|
||||
</row>
|
||||
</sheetData>
|
||||
<pageMargins left="0.75" right="0.75" top="1" bottom="1" header="0.5" footer="0.5"/>
|
||||
<extLst>
|
||||
<ext xmlns:mx="http://schemas.microsoft.com/office/mac/excel/2008/main" uri="{64002731-A6B0-56B0-2670-7721B7C09600}">
|
||||
<mx:PLV Mode="0" OnePage="0" WScale="0"/>
|
||||
</ext>
|
||||
</extLst>
|
||||
</worksheet>
|
341
tests/data/reader/sheet2_invalid_dimension.xml
Normal file
341
tests/data/reader/sheet2_invalid_dimension.xml
Normal file
|
@ -0,0 +1,341 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">
|
||||
<dimension ref="1:113"/>
|
||||
<sheetFormatPr baseColWidth="10" defaultRowHeight="16" />
|
||||
<sheetData>
|
||||
<row r="1" spans="4:27">
|
||||
<c r="D1">
|
||||
<v>1</v>
|
||||
</c>
|
||||
<c r="K1">
|
||||
<v>0.01</v>
|
||||
</c>
|
||||
<c r="AA1">
|
||||
<v>100</v>
|
||||
</c>
|
||||
</row>
|
||||
<row r="2" spans="4:27">
|
||||
<c r="D2">
|
||||
<v>2</v>
|
||||
</c>
|
||||
<c r="K2">
|
||||
<v>0.02</v>
|
||||
</c>
|
||||
<c r="AA2">
|
||||
<v>101</v>
|
||||
</c>
|
||||
</row>
|
||||
<row r="3" spans="4:27">
|
||||
<c r="D3">
|
||||
<v>3</v>
|
||||
</c>
|
||||
<c r="K3">
|
||||
<v>0.03</v>
|
||||
</c>
|
||||
<c r="AA3">
|
||||
<v>102</v>
|
||||
</c>
|
||||
</row>
|
||||
<row r="4" spans="4:27">
|
||||
<c r="D4">
|
||||
<v>4</v>
|
||||
</c>
|
||||
<c r="K4">
|
||||
<v>0.04</v>
|
||||
</c>
|
||||
<c r="AA4">
|
||||
<v>103</v>
|
||||
</c>
|
||||
</row>
|
||||
<row r="5" spans="4:27">
|
||||
<c r="D5">
|
||||
<v>5</v>
|
||||
</c>
|
||||
<c r="G5" t="s">
|
||||
<v>0</v>
|
||||
</c>
|
||||
<c r="K5">
|
||||
<v>0.05</v>
|
||||
</c>
|
||||
<c r="AA5">
|
||||
<v>104</v>
|
||||
</c>
|
||||
</row>
|
||||
<row r="6" spans="4:27">
|
||||
<c r="D6">
|
||||
<v>6</v>
|
||||
</c>
|
||||
<c r="K6">
|
||||
<v>0.06</v>
|
||||
</c>
|
||||
<c r="AA6">
|
||||
<v>105</v>
|
||||
</c>
|
||||
</row>
|
||||
<row r="7" spans="4:27">
|
||||
<c r="D7">
|
||||
<v>7</v>
|
||||
</c>
|
||||
<c r="K7">
|
||||
<v>7.0000000000000007E-2</v>
|
||||
</c>
|
||||
<c r="AA7">
|
||||
<v>106</v>
|
||||
</c>
|
||||
</row>
|
||||
<row r="8" spans="4:27">
|
||||
<c r="D8">
|
||||
<v>8</v>
|
||||
</c>
|
||||
<c r="K8">
|
||||
<v>0.08</v>
|
||||
</c>
|
||||
<c r="AA8">
|
||||
<v>107</v>
|
||||
</c>
|
||||
</row>
|
||||
<row r="9" spans="4:27">
|
||||
<c r="D9">
|
||||
<v>9</v>
|
||||
</c>
|
||||
<c r="K9">
|
||||
<v>0.09</v>
|
||||
</c>
|
||||
<c r="AA9">
|
||||
<v>108</v>
|
||||
</c>
|
||||
</row>
|
||||
<row r="10" spans="4:27">
|
||||
<c r="D10">
|
||||
<v>10</v>
|
||||
</c>
|
||||
<c r="K10">
|
||||
<v>0.1</v>
|
||||
</c>
|
||||
<c r="AA10">
|
||||
<v>109</v>
|
||||
</c>
|
||||
</row>
|
||||
<row r="11" spans="4:27">
|
||||
<c r="D11">
|
||||
<v>11</v>
|
||||
</c>
|
||||
<c r="K11">
|
||||
<v>0.11</v>
|
||||
</c>
|
||||
<c r="AA11">
|
||||
<v>110</v>
|
||||
</c>
|
||||
</row>
|
||||
<row r="12" spans="4:27">
|
||||
<c r="D12">
|
||||
<v>12</v>
|
||||
</c>
|
||||
<c r="K12">
|
||||
<v>0.12</v>
|
||||
</c>
|
||||
<c r="AA12">
|
||||
<v>111</v>
|
||||
</c>
|
||||
</row>
|
||||
<row r="13" spans="4:27">
|
||||
<c r="D13">
|
||||
<v>13</v>
|
||||
</c>
|
||||
<c r="K13">
|
||||
<v>0.13</v>
|
||||
</c>
|
||||
<c r="AA13">
|
||||
<v>112</v>
|
||||
</c>
|
||||
</row>
|
||||
<row r="14" spans="4:27">
|
||||
<c r="D14">
|
||||
<v>14</v>
|
||||
</c>
|
||||
<c r="K14">
|
||||
<v>0.14000000000000001</v>
|
||||
</c>
|
||||
<c r="AA14">
|
||||
<v>113</v>
|
||||
</c>
|
||||
</row>
|
||||
<row r="15" spans="4:27">
|
||||
<c r="D15">
|
||||
<v>15</v>
|
||||
</c>
|
||||
<c r="K15">
|
||||
<v>0.15</v>
|
||||
</c>
|
||||
<c r="AA15">
|
||||
<v>114</v>
|
||||
</c>
|
||||
</row>
|
||||
<row r="16" spans="4:27">
|
||||
<c r="D16">
|
||||
<v>16</v>
|
||||
</c>
|
||||
<c r="K16">
|
||||
<v>0.16</v>
|
||||
</c>
|
||||
<c r="AA16">
|
||||
<v>115</v>
|
||||
</c>
|
||||
</row>
|
||||
<row r="17" spans="4:27">
|
||||
<c r="D17">
|
||||
<v>17</v>
|
||||
</c>
|
||||
<c r="K17">
|
||||
<v>0.17</v>
|
||||
</c>
|
||||
<c r="AA17">
|
||||
<v>116</v>
|
||||
</c>
|
||||
</row>
|
||||
<row r="18" spans="4:27">
|
||||
<c r="D18">
|
||||
<v>18</v>
|
||||
</c>
|
||||
<c r="K18">
|
||||
<v>0.18</v>
|
||||
</c>
|
||||
<c r="AA18">
|
||||
<v>117</v>
|
||||
</c>
|
||||
</row>
|
||||
<row r="19" spans="4:27">
|
||||
<c r="D19">
|
||||
<v>19</v>
|
||||
</c>
|
||||
<c r="K19">
|
||||
<v>0.19</v>
|
||||
</c>
|
||||
<c r="AA19">
|
||||
<v>118</v>
|
||||
</c>
|
||||
</row>
|
||||
<row r="20" spans="4:27">
|
||||
<c r="D20">
|
||||
<v>20</v>
|
||||
</c>
|
||||
<c r="K20">
|
||||
<v>0.2</v>
|
||||
</c>
|
||||
<c r="AA20">
|
||||
<v>119</v>
|
||||
</c>
|
||||
</row>
|
||||
<row r="21" spans="4:27">
|
||||
<c r="D21">
|
||||
<v>21</v>
|
||||
</c>
|
||||
<c r="K21">
|
||||
<v>0.21</v>
|
||||
</c>
|
||||
<c r="AA21">
|
||||
<v>120</v>
|
||||
</c>
|
||||
</row>
|
||||
<row r="22" spans="4:27">
|
||||
<c r="D22">
|
||||
<v>22</v>
|
||||
</c>
|
||||
<c r="K22">
|
||||
<v>0.22</v>
|
||||
</c>
|
||||
<c r="AA22">
|
||||
<v>121</v>
|
||||
</c>
|
||||
</row>
|
||||
<row r="23" spans="4:27">
|
||||
<c r="D23">
|
||||
<v>23</v>
|
||||
</c>
|
||||
<c r="K23">
|
||||
<v>0.23</v>
|
||||
</c>
|
||||
<c r="AA23">
|
||||
<v>122</v>
|
||||
</c>
|
||||
</row>
|
||||
<row r="24" spans="4:27">
|
||||
<c r="D24">
|
||||
<v>24</v>
|
||||
</c>
|
||||
<c r="K24">
|
||||
<v>0.24</v>
|
||||
</c>
|
||||
<c r="AA24">
|
||||
<v>123</v>
|
||||
</c>
|
||||
</row>
|
||||
<row r="25" spans="4:27">
|
||||
<c r="D25">
|
||||
<v>25</v>
|
||||
</c>
|
||||
<c r="K25">
|
||||
<v>0.25</v>
|
||||
</c>
|
||||
<c r="AA25">
|
||||
<v>124</v>
|
||||
</c>
|
||||
</row>
|
||||
<row r="26" spans="4:27">
|
||||
<c r="D26">
|
||||
<v>26</v>
|
||||
</c>
|
||||
<c r="K26">
|
||||
<v>0.26</v>
|
||||
</c>
|
||||
<c r="AA26">
|
||||
<v>125</v>
|
||||
</c>
|
||||
</row>
|
||||
<row r="27" spans="4:27">
|
||||
<c r="D27">
|
||||
<v>27</v>
|
||||
</c>
|
||||
<c r="K27">
|
||||
<v>0.27</v>
|
||||
</c>
|
||||
<c r="AA27">
|
||||
<v>126</v>
|
||||
</c>
|
||||
</row>
|
||||
<row r="28" spans="4:27">
|
||||
<c r="D28">
|
||||
<v>28</v>
|
||||
</c>
|
||||
<c r="K28">
|
||||
<v>0.28000000000000003</v>
|
||||
</c>
|
||||
<c r="AA28">
|
||||
<v>127</v>
|
||||
</c>
|
||||
</row>
|
||||
<row r="29" spans="4:27">
|
||||
<c r="D29">
|
||||
<v>29</v>
|
||||
</c>
|
||||
<c r="K29">
|
||||
<v>0.28999999999999998</v>
|
||||
</c>
|
||||
<c r="AA29">
|
||||
<v>128</v>
|
||||
</c>
|
||||
</row>
|
||||
<row r="30" spans="4:27">
|
||||
<c r="D30">
|
||||
<v>30</v>
|
||||
</c>
|
||||
<c r="K30">
|
||||
<v>0.3</v>
|
||||
</c>
|
||||
<c r="AA30">
|
||||
<v>129</v>
|
||||
</c>
|
||||
</row>
|
||||
</sheetData>
|
||||
<pageMargins left="0.75" right="0.75" top="1" bottom="1" header="0.5" footer="0.5"/>
|
||||
</worksheet>
|
BIN
tests/data/reader/vba+comments.xlsm
Normal file
BIN
tests/data/reader/vba+comments.xlsm
Normal file
Binary file not shown.
BIN
tests/data/reader/vba-comments-saved.xlsm
Normal file
BIN
tests/data/reader/vba-comments-saved.xlsm
Normal file
Binary file not shown.
20
tests/data/writer/Content_types_vba.xml
Normal file
20
tests/data/writer/Content_types_vba.xml
Normal file
|
@ -0,0 +1,20 @@
|
|||
<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">
|
||||
<Default ContentType="application/vnd.ms-office.activeX" Extension="bin"/>
|
||||
<Default ContentType="image/x-emf" Extension="emf"/>
|
||||
<Default ContentType="application/vnd.openxmlformats-package.relationships+xml" Extension="rels"/>
|
||||
<Default ContentType="application/xml" Extension="xml"/>
|
||||
<Default ContentType="application/vnd.openxmlformats-officedocument.vmlDrawing" Extension="vml"/>
|
||||
<Override ContentType="application/vnd.ms-excel.sheet.macroEnabled.main+xml" PartName="/xl/workbook.xml"/>
|
||||
<Override ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml" PartName="/xl/worksheets/sheet1.xml"/>
|
||||
<Override ContentType="application/vnd.openxmlformats-officedocument.theme+xml" PartName="/xl/theme/theme1.xml"/>
|
||||
<Override ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml" PartName="/xl/styles.xml"/>
|
||||
<Override ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml" PartName="/xl/sharedStrings.xml"/>
|
||||
<Override ContentType="application/vnd.openxmlformats-officedocument.drawing+xml" PartName="/xl/drawings/drawing1.xml"/>
|
||||
<Override ContentType="application/vnd.ms-office.activeX+xml" PartName="/xl/activeX/activeX1.xml"/>
|
||||
<Override ContentType="application/vnd.ms-office.activeX+xml" PartName="/xl/activeX/activeX2.xml"/>
|
||||
<Override ContentType="application/vnd.ms-excel.controlproperties+xml" PartName="/xl/ctrlProps/ctrlProp1.xml"/>
|
||||
<Override ContentType="application/vnd.ms-excel.controlproperties+xml" PartName="/xl/ctrlProps/ctrlProp2.xml"/>
|
||||
<Override ContentType="application/vnd.ms-office.vbaProject" PartName="/xl/vbaProject.bin"/>
|
||||
<Override ContentType="application/vnd.openxmlformats-package.core-properties+xml" PartName="/docProps/core.xml"/>
|
||||
<Override ContentType="application/vnd.openxmlformats-officedocument.extended-properties+xml" PartName="/docProps/app.xml"/>
|
||||
</Types>
|
2
tests/data/writer/expected/app.xml
Normal file
2
tests/data/writer/expected/app.xml
Normal file
|
@ -0,0 +1,2 @@
|
|||
<?xml version='1.0' ?>
|
||||
<Properties xmlns="http://schemas.openxmlformats.org/officeDocument/2006/extended-properties" xmlns:vt="http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes"><Application>Microsoft Excel</Application><DocSecurity>0</DocSecurity><ScaleCrop>false</ScaleCrop><Company /><LinksUpToDate>false</LinksUpToDate><SharedDoc>false</SharedDoc><HyperlinksChanged>false</HyperlinksChanged><AppVersion>12.0000</AppVersion><HeadingPairs><vt:vector baseType="variant" size="2"><vt:variant><vt:lpstr>Worksheets</vt:lpstr></vt:variant><vt:variant><vt:i4>3</vt:i4></vt:variant></vt:vector></HeadingPairs><TitlesOfParts><vt:vector baseType="lpstr" size="3"><vt:lpstr>Sheet</vt:lpstr><vt:lpstr>Sheet1</vt:lpstr><vt:lpstr>Sheet2</vt:lpstr></vt:vector></TitlesOfParts></Properties>
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user