mirror of
https://github.com/tfussell/xlnt.git
synced 2024-03-22 13:11:17 +08:00
add more functionality for printing cells
This commit is contained in:
parent
301e81d698
commit
c7c5eec2ab
|
@ -79,9 +79,7 @@ public:
|
||||||
bool has_value() const;
|
bool has_value() const;
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
T get_value();
|
T get_value() const;
|
||||||
template<typename T>
|
|
||||||
const T get_value() const;
|
|
||||||
|
|
||||||
void clear_value();
|
void clear_value();
|
||||||
|
|
||||||
|
@ -154,6 +152,8 @@ public:
|
||||||
// operators
|
// operators
|
||||||
cell &operator=(const cell &rhs);
|
cell &operator=(const cell &rhs);
|
||||||
|
|
||||||
|
std::ostream &print(std::ostream &stream, bool convert) const;
|
||||||
|
|
||||||
bool operator==(const cell &comparand) const;
|
bool operator==(const cell &comparand) const;
|
||||||
bool operator==(std::nullptr_t) const;
|
bool operator==(std::nullptr_t) const;
|
||||||
|
|
||||||
|
@ -169,7 +169,7 @@ private:
|
||||||
|
|
||||||
inline std::ostream &operator<<(std::ostream &stream, const xlnt::cell &cell)
|
inline std::ostream &operator<<(std::ostream &stream, const xlnt::cell &cell)
|
||||||
{
|
{
|
||||||
return stream << cell.to_string();
|
return cell.print(stream, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace xlnt
|
} // namespace xlnt
|
||||||
|
|
|
@ -133,6 +133,7 @@ struct datetime
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string to_string(calendar base_date) const;
|
||||||
long double to_number(calendar base_date) const;
|
long double to_number(calendar base_date) const;
|
||||||
bool operator==(const datetime &comparand) const;
|
bool operator==(const datetime &comparand) const;
|
||||||
|
|
||||||
|
|
|
@ -716,116 +716,149 @@ void cell::clear_value()
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
bool cell::get_value()
|
bool cell::get_value() const
|
||||||
{
|
{
|
||||||
return d_->value_numeric_ != 0;
|
return d_->value_numeric_ != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
std::int8_t cell::get_value()
|
std::int8_t cell::get_value() const
|
||||||
{
|
{
|
||||||
return static_cast<std::int8_t>(d_->value_numeric_);
|
return static_cast<std::int8_t>(d_->value_numeric_);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
std::int16_t cell::get_value()
|
std::int16_t cell::get_value() const
|
||||||
{
|
{
|
||||||
return static_cast<std::int16_t>(d_->value_numeric_);
|
return static_cast<std::int16_t>(d_->value_numeric_);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
std::int32_t cell::get_value()
|
std::int32_t cell::get_value() const
|
||||||
{
|
{
|
||||||
return static_cast<std::int32_t>(d_->value_numeric_);
|
return static_cast<std::int32_t>(d_->value_numeric_);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
std::int64_t cell::get_value()
|
std::int64_t cell::get_value() const
|
||||||
{
|
{
|
||||||
return static_cast<std::int64_t>(d_->value_numeric_);
|
return static_cast<std::int64_t>(d_->value_numeric_);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
std::uint8_t cell::get_value()
|
std::uint8_t cell::get_value() const
|
||||||
{
|
{
|
||||||
return static_cast<std::uint8_t>(d_->value_numeric_);
|
return static_cast<std::uint8_t>(d_->value_numeric_);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
std::uint16_t cell::get_value()
|
std::uint16_t cell::get_value() const
|
||||||
{
|
{
|
||||||
return static_cast<std::uint16_t>(d_->value_numeric_);
|
return static_cast<std::uint16_t>(d_->value_numeric_);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
std::uint32_t cell::get_value()
|
std::uint32_t cell::get_value() const
|
||||||
{
|
{
|
||||||
return static_cast<std::uint32_t>(d_->value_numeric_);
|
return static_cast<std::uint32_t>(d_->value_numeric_);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
std::uint64_t cell::get_value()
|
std::uint64_t cell::get_value() const
|
||||||
{
|
{
|
||||||
return static_cast<std::uint64_t>(d_->value_numeric_);
|
return static_cast<std::uint64_t>(d_->value_numeric_);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
float cell::get_value()
|
float cell::get_value() const
|
||||||
{
|
{
|
||||||
return static_cast<float>(d_->value_numeric_);
|
return static_cast<float>(d_->value_numeric_);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
double cell::get_value()
|
double cell::get_value() const
|
||||||
{
|
{
|
||||||
return static_cast<double>(d_->value_numeric_);
|
return static_cast<double>(d_->value_numeric_);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
long double cell::get_value()
|
long double cell::get_value() const
|
||||||
{
|
{
|
||||||
return d_->value_numeric_;
|
return d_->value_numeric_;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
time cell::get_value()
|
time cell::get_value() const
|
||||||
{
|
{
|
||||||
return time::from_number(d_->value_numeric_);
|
return time::from_number(d_->value_numeric_);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
datetime cell::get_value()
|
datetime cell::get_value() const
|
||||||
{
|
{
|
||||||
return datetime::from_number(d_->value_numeric_, xlnt::calendar::windows_1900);
|
return datetime::from_number(d_->value_numeric_, xlnt::calendar::windows_1900);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
date cell::get_value()
|
date cell::get_value() const
|
||||||
{
|
{
|
||||||
return date::from_number(d_->value_numeric_, xlnt::calendar::windows_1900);
|
return date::from_number(d_->value_numeric_, xlnt::calendar::windows_1900);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
timedelta cell::get_value()
|
timedelta cell::get_value() const
|
||||||
{
|
{
|
||||||
return timedelta(0, 0);
|
return timedelta(0, 0);
|
||||||
//return timedelta::from_number(d_->value_numeric_);
|
//return timedelta::from_number(d_->value_numeric_);
|
||||||
}
|
}
|
||||||
|
|
||||||
void cell::set_number_format(const std::string &format_string)
|
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() const
|
||||||
|
{
|
||||||
|
return d_->value_string_;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool cell::has_value() const
|
||||||
|
{
|
||||||
|
return d_->type_ != cell::type::null;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::ostream &cell::print(std::ostream &stream, bool convert) const
|
||||||
|
{
|
||||||
|
if(!convert)
|
||||||
{
|
{
|
||||||
get_style().get_number_format().set_format_code_string(format_string);
|
return stream << get_value<std::string>();
|
||||||
}
|
}
|
||||||
|
else
|
||||||
template<>
|
|
||||||
std::string cell::get_value()
|
|
||||||
{
|
{
|
||||||
return d_->value_string_;
|
switch(get_data_type())
|
||||||
}
|
{
|
||||||
|
case type::null:
|
||||||
bool cell::has_value() const
|
return stream << "";
|
||||||
{
|
case type::string:
|
||||||
return d_->type_ != cell::type::null;
|
return stream << get_value<std::string>();
|
||||||
|
case type::numeric:
|
||||||
|
if(is_date())
|
||||||
|
{
|
||||||
|
return stream << get_value<datetime>().to_string(get_parent().get_parent().get_properties().excel_base_date);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return stream << get_value<long double>();
|
||||||
|
}
|
||||||
|
case type::error:
|
||||||
|
return stream << get_value<std::string>();
|
||||||
|
case type::formula:
|
||||||
|
return stream << d_->formula_;
|
||||||
|
default:
|
||||||
|
return stream;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace xlnt
|
} // namespace xlnt
|
||||||
|
|
|
@ -163,6 +163,11 @@ long double datetime::to_number(calendar base_date) const
|
||||||
+ time(hour, minute, second, microsecond).to_number();
|
+ time(hour, minute, second, microsecond).to_number();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string datetime::to_string(xlnt::calendar base_date) const
|
||||||
|
{
|
||||||
|
return std::to_string(year) + "/" + std::to_string(month) + "/" + std::to_string(day) + " " +std::to_string(hour) + ":" + std::to_string(minute) + ":" + std::to_string(second) + ":" + std::to_string(microsecond);
|
||||||
|
}
|
||||||
|
|
||||||
date date::today()
|
date date::today()
|
||||||
{
|
{
|
||||||
std::time_t raw_time = std::time(0);
|
std::time_t raw_time = std::time(0);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user