2014-08-14 06:56:34 +08:00
|
|
|
#include <xlnt/worksheet/worksheet.hpp>
|
2014-05-31 06:42:25 +08:00
|
|
|
|
2015-10-14 01:56:07 +08:00
|
|
|
#include "cell_impl.hpp"
|
|
|
|
#include "comment_impl.hpp"
|
|
|
|
|
2014-05-31 06:42:25 +08:00
|
|
|
namespace xlnt {
|
|
|
|
namespace detail {
|
2015-11-01 22:43:01 +08:00
|
|
|
|
2015-11-04 03:53:48 +08:00
|
|
|
cell_impl::cell_impl() : cell_impl(column_t(1), 1)
|
2014-05-31 06:42:25 +08:00
|
|
|
{
|
|
|
|
}
|
2015-11-01 22:43:01 +08:00
|
|
|
|
2015-10-15 06:05:13 +08:00
|
|
|
cell_impl::cell_impl(column_t column, row_t row) : cell_impl(nullptr, column, row)
|
|
|
|
{
|
|
|
|
}
|
2015-11-01 22:43:01 +08:00
|
|
|
|
2015-10-14 01:56:07 +08:00
|
|
|
cell_impl::cell_impl(worksheet_impl *parent, column_t column, row_t row)
|
2015-10-15 06:05:13 +08:00
|
|
|
: type_(cell::type::null),
|
|
|
|
parent_(parent),
|
|
|
|
column_(column),
|
|
|
|
row_(row),
|
|
|
|
value_numeric_(0),
|
|
|
|
has_hyperlink_(false),
|
|
|
|
is_merged_(false),
|
2015-10-21 01:53:47 +08:00
|
|
|
has_style_(false),
|
|
|
|
style_id_(0),
|
2015-10-15 06:05:13 +08:00
|
|
|
comment_(nullptr)
|
2014-05-31 06:42:25 +08:00
|
|
|
{
|
|
|
|
}
|
2015-11-01 22:43:01 +08:00
|
|
|
|
2015-10-14 01:56:07 +08:00
|
|
|
cell_impl::cell_impl(const cell_impl &rhs)
|
2014-06-13 05:04:37 +08:00
|
|
|
{
|
|
|
|
*this = rhs;
|
|
|
|
}
|
2015-11-01 22:43:01 +08:00
|
|
|
|
2014-06-13 05:04:37 +08:00
|
|
|
cell_impl &cell_impl::operator=(const cell_impl &rhs)
|
|
|
|
{
|
|
|
|
parent_ = rhs.parent_;
|
2015-10-14 01:56:07 +08:00
|
|
|
value_numeric_ = rhs.value_numeric_;
|
|
|
|
value_string_ = rhs.value_string_;
|
2014-06-13 05:04:37 +08:00
|
|
|
hyperlink_ = rhs.hyperlink_;
|
2014-07-26 04:39:25 +08:00
|
|
|
formula_ = rhs.formula_;
|
|
|
|
column_ = rhs.column_;
|
|
|
|
row_ = rhs.row_;
|
2015-10-14 01:56:07 +08:00
|
|
|
is_merged_ = rhs.is_merged_;
|
2014-06-13 05:04:37 +08:00
|
|
|
has_hyperlink_ = rhs.has_hyperlink_;
|
2015-10-14 01:56:07 +08:00
|
|
|
type_ = rhs.type_;
|
2015-10-19 03:30:46 +08:00
|
|
|
style_id_ = rhs.style_id_;
|
2015-10-26 12:26:48 +08:00
|
|
|
has_style_ = rhs.has_style_;
|
2015-11-01 22:43:01 +08:00
|
|
|
|
|
|
|
if (rhs.comment_ != nullptr)
|
2015-10-14 01:56:07 +08:00
|
|
|
{
|
|
|
|
comment_.reset(new comment_impl(*rhs.comment_));
|
|
|
|
}
|
2015-11-01 22:43:01 +08:00
|
|
|
|
2014-06-13 05:04:37 +08:00
|
|
|
return *this;
|
|
|
|
}
|
2014-05-31 06:42:25 +08:00
|
|
|
|
2015-11-23 01:41:27 +08:00
|
|
|
cell cell_impl::self()
|
|
|
|
{
|
|
|
|
return xlnt::cell(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void cell_impl::set_string(const std::string &s, bool guess_types)
|
|
|
|
{
|
|
|
|
value_string_ = s;
|
|
|
|
type_ = cell::type::string;
|
|
|
|
|
|
|
|
if (value_string_.size() > 1 && value_string_.front() == '=')
|
|
|
|
{
|
|
|
|
formula_ = value_string_;
|
|
|
|
type_ = cell::type::formula;
|
|
|
|
value_string_.clear();
|
|
|
|
}
|
|
|
|
else if (cell::error_codes().find(s) != cell::error_codes().end())
|
|
|
|
{
|
|
|
|
type_ = cell::type::error;
|
|
|
|
}
|
|
|
|
else if (guess_types)
|
|
|
|
{
|
|
|
|
auto percentage = cast_percentage(s);
|
|
|
|
|
|
|
|
if (percentage.first)
|
|
|
|
{
|
|
|
|
value_numeric_ = percentage.second;
|
|
|
|
type_ = cell::type::numeric;
|
|
|
|
self().set_number_format(xlnt::number_format::percentage());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
auto time = cast_time(s);
|
|
|
|
|
|
|
|
if (time.first)
|
|
|
|
{
|
|
|
|
type_ = cell::type::numeric;
|
|
|
|
self().set_number_format(number_format::date_time6());
|
|
|
|
value_numeric_ = time.second.to_number();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
auto numeric = cast_numeric(s);
|
|
|
|
|
|
|
|
if (numeric.first)
|
|
|
|
{
|
|
|
|
value_numeric_ = numeric.second;
|
|
|
|
type_ = cell::type::numeric;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-31 06:42:25 +08:00
|
|
|
} // namespace detail
|
|
|
|
} // namespace xlnt
|