mirror of
https://github.com/tfussell/xlnt.git
synced 2024-03-22 13:11:17 +08:00
reformat cell.cpp
This commit is contained in:
parent
dab1b0218d
commit
d393343c2e
|
@ -21,6 +21,7 @@
|
|||
//
|
||||
// @license: http://www.opensource.org/licenses/mit-license.php
|
||||
// @author: see AUTHORS file
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <sstream>
|
||||
|
@ -43,9 +44,9 @@
|
|||
#include <xlnt/styles/style.hpp>
|
||||
#include <xlnt/utils/date.hpp>
|
||||
#include <xlnt/utils/datetime.hpp>
|
||||
#include <xlnt/utils/exceptions.hpp>
|
||||
#include <xlnt/utils/time.hpp>
|
||||
#include <xlnt/utils/timedelta.hpp>
|
||||
#include <xlnt/utils/exceptions.hpp>
|
||||
#include <xlnt/workbook/workbook.hpp>
|
||||
#include <xlnt/worksheet/column_properties.hpp>
|
||||
#include <xlnt/worksheet/row_properties.hpp>
|
||||
|
@ -58,8 +59,8 @@ std::pair<bool, long double> cast_numeric(const std::string &s)
|
|||
const char *str = s.c_str();
|
||||
char *str_end = nullptr;
|
||||
auto result = std::strtold(str, &str_end);
|
||||
if (str_end != str + s.size()) return{ false, 0 };
|
||||
return{ true, result };
|
||||
if (str_end != str + s.size()) return {false, 0};
|
||||
return {true, result};
|
||||
}
|
||||
|
||||
std::pair<bool, long double> cast_percentage(const std::string &s)
|
||||
|
@ -70,11 +71,11 @@ std::pair<bool, long double> cast_percentage(const std::string &s)
|
|||
|
||||
if (number.first)
|
||||
{
|
||||
return{ true, number.second / 100 };
|
||||
return {true, number.second / 100};
|
||||
}
|
||||
}
|
||||
|
||||
return{ false, 0 };
|
||||
return {false, 0};
|
||||
}
|
||||
|
||||
std::pair<bool, xlnt::time> cast_time(const std::string &s)
|
||||
|
@ -96,7 +97,7 @@ std::pair<bool, xlnt::time> cast_time(const std::string &s)
|
|||
|
||||
if (time_components.size() < 2 || time_components.size() > 3)
|
||||
{
|
||||
return{ false, result };
|
||||
return {false, result};
|
||||
}
|
||||
|
||||
std::vector<double> numeric_components;
|
||||
|
@ -105,14 +106,14 @@ std::pair<bool, xlnt::time> cast_time(const std::string &s)
|
|||
{
|
||||
if (component.empty() || (component.substr(0, component.find('.')).size() > 2))
|
||||
{
|
||||
return{ false, result };
|
||||
return {false, result};
|
||||
}
|
||||
|
||||
for (auto d : component)
|
||||
{
|
||||
if (!(d >= '0' && d <= '9') && d != '.')
|
||||
{
|
||||
return{ false, result };
|
||||
return {false, result};
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -138,7 +139,7 @@ std::pair<bool, xlnt::time> cast_time(const std::string &s)
|
|||
result.microsecond = static_cast<int>((numeric_components[2] - result.second) * 1E6);
|
||||
}
|
||||
|
||||
return{ true, result };
|
||||
return {true, result};
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
@ -147,16 +148,16 @@ namespace xlnt {
|
|||
|
||||
const std::unordered_map<std::string, int> &cell::error_codes()
|
||||
{
|
||||
static const std::unordered_map<std::string, int> *codes =
|
||||
new std::unordered_map<std::string, int>({
|
||||
{ "#NULL!", 0 },
|
||||
{ "#DIV/0!", 1 },
|
||||
{ "#VALUE!", 2 },
|
||||
{ "#REF!", 3 },
|
||||
{ "#NAME?", 4 },
|
||||
{ "#NUM!", 5 },
|
||||
{ "#N/A!", 6 }
|
||||
});
|
||||
static const auto *codes = new std::unordered_map<std::string, int>
|
||||
{
|
||||
{"#NULL!", 0},
|
||||
{"#DIV/0!", 1},
|
||||
{"#VALUE!", 2},
|
||||
{"#REF!", 3},
|
||||
{"#NAME?", 4},
|
||||
{"#NUM!", 5},
|
||||
{"#N/A!", 6}
|
||||
};
|
||||
|
||||
return *codes;
|
||||
}
|
||||
|
@ -427,14 +428,12 @@ bool cell::is_merged() const
|
|||
|
||||
bool cell::is_date() const
|
||||
{
|
||||
return get_data_type() == type::numeric
|
||||
&& has_format()
|
||||
&& get_number_format().is_date_format();
|
||||
return get_data_type() == type::numeric && has_format() && get_number_format().is_date_format();
|
||||
}
|
||||
|
||||
cell_reference cell::get_reference() const
|
||||
{
|
||||
return { d_->column_, d_->row_ };
|
||||
return {d_->column_, d_->row_};
|
||||
}
|
||||
|
||||
bool cell::operator==(std::nullptr_t) const
|
||||
|
@ -556,16 +555,14 @@ const workbook &cell::get_workbook() const
|
|||
return get_worksheet().get_workbook();
|
||||
}
|
||||
|
||||
//TODO: this shares a lot of code with worksheet::get_point_pos, try to reduce repetion
|
||||
// TODO: this shares a lot of code with worksheet::get_point_pos, try to reduce repetion
|
||||
std::pair<int, int> cell::get_anchor() const
|
||||
{
|
||||
static const auto DefaultColumnWidth = 51.85L;
|
||||
static const auto DefaultRowHeight = 15.0L;
|
||||
|
||||
auto points_to_pixels = [](long double value, long double dpi)
|
||||
{
|
||||
return static_cast<int>(std::ceil(value * dpi / 72));
|
||||
};
|
||||
auto points_to_pixels = [](
|
||||
long double value, long double dpi) { return static_cast<int>(std::ceil(value * dpi / 72)); };
|
||||
|
||||
auto left_columns = d_->column_ - 1;
|
||||
int left_anchor = 0;
|
||||
|
@ -607,7 +604,7 @@ std::pair<int, int> cell::get_anchor() const
|
|||
top_anchor += default_height;
|
||||
}
|
||||
|
||||
return { left_anchor, top_anchor };
|
||||
return {left_anchor, top_anchor};
|
||||
}
|
||||
|
||||
cell::type cell::get_data_type() const
|
||||
|
|
Loading…
Reference in New Issue
Block a user