mirror of
https://github.com/tfussell/xlnt.git
synced 2024-03-22 13:11:17 +08:00
fix -Wall -Wextra -pedantic warnings
This commit is contained in:
parent
d44f8ab49b
commit
9c05e04f70
4
configure
vendored
4
configure
vendored
|
@ -28,7 +28,9 @@ if not os.path.isdir('./build'):
|
|||
|
||||
generator = 'Unix Makefiles'
|
||||
|
||||
if sys.platform == 'darwin':
|
||||
if len(sys.argv) > 1:
|
||||
generator = sys.argv[1]
|
||||
elif sys.platform == 'darwin':
|
||||
generator = 'Unix Makefiles'
|
||||
elif sys.platform == 'win32':
|
||||
generator = 'Visual Studio 14 2015'
|
||||
|
|
|
@ -40,16 +40,16 @@ class color
|
|||
rgb
|
||||
};
|
||||
|
||||
static const color black;
|
||||
static const color white;
|
||||
static const color red;
|
||||
static const color darkred;
|
||||
static const color blue;
|
||||
static const color darkblue;
|
||||
static const color green;
|
||||
static const color darkgreen;
|
||||
static const color yellow;
|
||||
static const color darkyellow;
|
||||
static const color black();
|
||||
static const color white();
|
||||
static const color red();
|
||||
static const color darkred();
|
||||
static const color blue();
|
||||
static const color darkblue();
|
||||
static const color green();
|
||||
static const color darkgreen();
|
||||
static const color yellow();
|
||||
static const color darkyellow();
|
||||
|
||||
color()
|
||||
{
|
||||
|
@ -63,19 +63,19 @@ class color
|
|||
{
|
||||
}
|
||||
|
||||
void set_auto(int auto_index)
|
||||
void set_auto(std::size_t auto_index)
|
||||
{
|
||||
type_ = type::auto_;
|
||||
index_ = auto_index;
|
||||
}
|
||||
|
||||
void set_index(int index)
|
||||
void set_index(std::size_t index)
|
||||
{
|
||||
type_ = type::indexed;
|
||||
index_ = index;
|
||||
}
|
||||
|
||||
void set_theme(int theme)
|
||||
void set_theme(std::size_t theme)
|
||||
{
|
||||
type_ = type::theme;
|
||||
index_ = theme;
|
||||
|
@ -86,7 +86,7 @@ class color
|
|||
return type_;
|
||||
}
|
||||
|
||||
int get_auto() const
|
||||
std::size_t get_auto() const
|
||||
{
|
||||
if (type_ != type::auto_)
|
||||
{
|
||||
|
@ -96,7 +96,7 @@ class color
|
|||
return index_;
|
||||
}
|
||||
|
||||
int get_index() const
|
||||
std::size_t get_index() const
|
||||
{
|
||||
if (type_ != type::indexed)
|
||||
{
|
||||
|
@ -106,7 +106,7 @@ class color
|
|||
return index_;
|
||||
}
|
||||
|
||||
int get_theme() const
|
||||
std::size_t get_theme() const
|
||||
{
|
||||
if (type_ != type::theme)
|
||||
{
|
||||
|
@ -149,7 +149,7 @@ class color
|
|||
|
||||
private:
|
||||
type type_ = type::indexed;
|
||||
int index_ = 0;
|
||||
std::size_t index_ = 0;
|
||||
std::string rgb_string_;
|
||||
};
|
||||
|
||||
|
|
|
@ -321,13 +321,13 @@ class fill
|
|||
gradient_type gradient_type_;
|
||||
double rotation_ = 0;
|
||||
bool foreground_color_assigned_ = false;
|
||||
color foreground_color_ = color::black;
|
||||
color foreground_color_ = color::black();
|
||||
bool background_color_assigned_ = false;
|
||||
color background_color_ = color::white;
|
||||
color background_color_ = color::white();
|
||||
bool start_color_assigned_ = false;
|
||||
color start_color_ = color::white;
|
||||
color start_color_ = color::white();
|
||||
bool end_color_assigned_ = false;
|
||||
color end_color_ = color::black;
|
||||
color end_color_ = color::black();
|
||||
double gradient_path_left_ = 0;
|
||||
double gradient_path_right_ = 0;
|
||||
double gradient_path_top_ = 0;
|
||||
|
|
|
@ -48,6 +48,7 @@ class font
|
|||
{
|
||||
bold_ = bold;
|
||||
}
|
||||
|
||||
bool is_bold() const
|
||||
{
|
||||
return bold_;
|
||||
|
@ -57,6 +58,7 @@ class font
|
|||
{
|
||||
italic_ = italic;
|
||||
}
|
||||
|
||||
bool is_italic() const
|
||||
{
|
||||
return italic_;
|
||||
|
@ -66,6 +68,7 @@ class font
|
|||
{
|
||||
strikethrough_ = strikethrough;
|
||||
}
|
||||
|
||||
bool is_strikethrough() const
|
||||
{
|
||||
return strikethrough_;
|
||||
|
@ -75,20 +78,23 @@ class font
|
|||
{
|
||||
underline_ = new_underline;
|
||||
}
|
||||
|
||||
bool is_underline() const
|
||||
{
|
||||
return underline_ != underline_style::none;
|
||||
}
|
||||
|
||||
underline_style get_underline() const
|
||||
{
|
||||
return underline_;
|
||||
}
|
||||
|
||||
void set_size(int size)
|
||||
void set_size(std::size_t size)
|
||||
{
|
||||
size_ = size;
|
||||
}
|
||||
int get_size() const
|
||||
|
||||
std::size_t get_size() const
|
||||
{
|
||||
return size_;
|
||||
}
|
||||
|
@ -106,11 +112,13 @@ class font
|
|||
{
|
||||
color_ = c;
|
||||
}
|
||||
void set_family(int family)
|
||||
|
||||
void set_family(std::size_t family)
|
||||
{
|
||||
has_family_ = true;
|
||||
family_ = family;
|
||||
}
|
||||
|
||||
void set_scheme(const std::string &scheme)
|
||||
{
|
||||
has_scheme_ = true;
|
||||
|
@ -126,7 +134,8 @@ class font
|
|||
{
|
||||
return has_family_;
|
||||
}
|
||||
int get_family() const
|
||||
|
||||
std::size_t get_family() const
|
||||
{
|
||||
return family_;
|
||||
}
|
||||
|
@ -143,10 +152,12 @@ class font
|
|||
seed = seed << 1 & superscript_;
|
||||
seed = seed << 1 & subscript_;
|
||||
seed = seed << 1 & strikethrough_;
|
||||
|
||||
hash_combine(seed, name_);
|
||||
hash_combine(seed, size_);
|
||||
hash_combine(seed, static_cast<std::size_t>(underline_));
|
||||
hash_combine(seed, static_cast<std::size_t>(color_.get_type()));
|
||||
|
||||
switch (color_.get_type())
|
||||
{
|
||||
case color::type::indexed:
|
||||
|
@ -158,6 +169,7 @@ class font
|
|||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
hash_combine(seed, family_);
|
||||
hash_combine(seed, scheme_);
|
||||
|
||||
|
@ -173,7 +185,7 @@ class font
|
|||
friend class style;
|
||||
|
||||
std::string name_ = "Calibri";
|
||||
int size_ = 11;
|
||||
std::size_t size_ = 11;
|
||||
bool bold_ = false;
|
||||
bool italic_ = false;
|
||||
bool superscript_ = false;
|
||||
|
@ -182,7 +194,7 @@ class font
|
|||
bool strikethrough_ = false;
|
||||
color color_;
|
||||
bool has_family_ = false;
|
||||
int family_;
|
||||
std::size_t family_;
|
||||
bool has_scheme_ = false;
|
||||
std::string scheme_;
|
||||
};
|
||||
|
|
|
@ -67,21 +67,36 @@ class number_format
|
|||
static const number_format currency_usd();
|
||||
static const number_format currency_eur_simple();
|
||||
|
||||
static number_format from_builtin_id(int builtin_id);
|
||||
static number_format from_builtin_id(std::size_t builtin_id);
|
||||
|
||||
number_format();
|
||||
number_format(int builtin_id);
|
||||
number_format(const std::string &code, int custom_id = -1);
|
||||
number_format(std::size_t builtin_id);
|
||||
number_format(const std::string &code);
|
||||
number_format(const std::string &code, std::size_t custom_id);
|
||||
|
||||
void set_format_string(const std::string &format_code);
|
||||
void set_format_string(const std::string &format_code, std::size_t custom_id);
|
||||
|
||||
void set_format_string(const std::string &format_code, int id = -1);
|
||||
std::string get_format_string() const;
|
||||
|
||||
void set_id(int id)
|
||||
bool has_id() const
|
||||
{
|
||||
return id_set_;
|
||||
}
|
||||
|
||||
void set_id(std::size_t id)
|
||||
{
|
||||
id_ = id;
|
||||
id_set_ = true;
|
||||
}
|
||||
int get_id() const
|
||||
|
||||
std::size_t get_id() const
|
||||
{
|
||||
if(!id_set_)
|
||||
{
|
||||
throw std::runtime_error("number format doesn't have an id");
|
||||
}
|
||||
|
||||
return id_;
|
||||
}
|
||||
|
||||
|
@ -93,7 +108,8 @@ class number_format
|
|||
}
|
||||
|
||||
private:
|
||||
int id_;
|
||||
bool id_set_;
|
||||
std::size_t id_;
|
||||
std::string format_string_;
|
||||
};
|
||||
|
||||
|
|
|
@ -114,7 +114,7 @@ class side
|
|||
bool style_assigned_ = false;
|
||||
border_style style_ = border_style::none;
|
||||
bool color_assigned_ = false;
|
||||
color color_ = color::black;
|
||||
color color_ = color::black();
|
||||
};
|
||||
|
||||
} // namespace xlnt
|
||||
|
|
|
@ -28,7 +28,7 @@ namespace xlnt {
|
|||
class column_properties
|
||||
{
|
||||
public:
|
||||
double width;
|
||||
long double width;
|
||||
std::size_t style;
|
||||
bool custom;
|
||||
};
|
||||
|
|
|
@ -28,7 +28,7 @@ namespace xlnt {
|
|||
class row_properties
|
||||
{
|
||||
public:
|
||||
double height;
|
||||
long double height;
|
||||
bool visible;
|
||||
int outline_level;
|
||||
bool collapsed;
|
||||
|
|
|
@ -125,10 +125,18 @@ bool is_date_format(const std::string &format_string)
|
|||
|
||||
bool is_valid_color(const std::string &color)
|
||||
{
|
||||
static const std::vector<std::string> colors = { "Black",
|
||||
static const std::vector<std::string> *colors =
|
||||
new std::vector<std::string>(
|
||||
{
|
||||
"Black",
|
||||
"Green"
|
||||
"White",
|
||||
"Blue", "Magenta", "Yellow", "Cyan", "Red" };
|
||||
"Blue",
|
||||
"Magenta",
|
||||
"Yellow",
|
||||
"Cyan",
|
||||
"Red"
|
||||
});
|
||||
|
||||
auto compare_color = [&](const std::string &other) {
|
||||
if (color.size() != other.size()) return false;
|
||||
|
@ -144,7 +152,7 @@ bool is_valid_color(const std::string &color)
|
|||
return true;
|
||||
};
|
||||
|
||||
return std::find_if(colors.begin(), colors.end(), compare_color) != colors.end();
|
||||
return std::find_if(colors->begin(), colors->end(), compare_color) != colors->end();
|
||||
}
|
||||
|
||||
bool parse_condition(const std::string &string, section &s)
|
||||
|
@ -200,7 +208,12 @@ bool is_hex(char c)
|
|||
return false;
|
||||
}
|
||||
|
||||
const std::unordered_map<int, std::string> known_locales = { { 0x401, "Arabic - Saudi Arabia" },
|
||||
const std::unordered_map<int, std::string> known_locales()
|
||||
{
|
||||
const std::unordered_map<int, std::string> *all =
|
||||
new std::unordered_map<int, std::string>(
|
||||
{
|
||||
{ 0x401, "Arabic - Saudi Arabia" },
|
||||
{ 0x402, "Bulgarian" },
|
||||
{ 0x403, "Catalan" },
|
||||
{ 0x404, "Chinese - Taiwan" },
|
||||
|
@ -304,7 +317,11 @@ const std::unordered_map<int, std::string> known_locales = { { 0x401, "Arabic -
|
|||
{ 0x3401, "Arabic - Kuwait" },
|
||||
{ 0x3409, "English - Phillippines" },
|
||||
{ 0x3801, "Arabic - United Arab Emirates" },
|
||||
{ 0x4001, "Arabic - Qatar" } };
|
||||
{ 0x4001, "Arabic - Qatar" }
|
||||
});
|
||||
|
||||
return *all;
|
||||
}
|
||||
|
||||
bool is_valid_locale(const std::string &locale_string)
|
||||
{
|
||||
|
@ -317,7 +334,7 @@ bool is_valid_locale(const std::string &locale_string)
|
|||
|
||||
for (auto c : country)
|
||||
{
|
||||
if (!is_hex(std::toupper(c)))
|
||||
if (!is_hex(static_cast<char>(std::toupper(c))))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -325,7 +342,9 @@ bool is_valid_locale(const std::string &locale_string)
|
|||
|
||||
auto index = std::stoi(country, 0, 16);
|
||||
|
||||
if (known_locales.find(index) == known_locales.end())
|
||||
auto known_locales_ = known_locales();
|
||||
|
||||
if (known_locales_.find(index) == known_locales_.end())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -359,7 +378,7 @@ section parse_section(const std::string §ion_string)
|
|||
bool in_quotes = false;
|
||||
bool in_brackets = false;
|
||||
|
||||
static const std::vector<std::string> bracket_times = { "h", "hh", "m", "mm", "s", "ss" };
|
||||
const std::vector<std::string> bracket_times = { "h", "hh", "m", "mm", "s", "ss" };
|
||||
|
||||
for (std::size_t i = 0; i < section_string.size(); i++)
|
||||
{
|
||||
|
@ -502,9 +521,6 @@ format_sections parse_format_sections(const std::string &combined)
|
|||
return result;
|
||||
}
|
||||
|
||||
const std::vector<std::string> MonthNames = { "January", "February", "March", "April", "May", "June",
|
||||
"July", "August", "September", "October", "November", "December" };
|
||||
|
||||
std::string format_section(long double number, const section &format, xlnt::calendar base_date)
|
||||
{
|
||||
const std::string unquoted = "$+(:^'{<=-/)!&~}> ";
|
||||
|
@ -516,10 +532,12 @@ std::string format_section(long double number, const section &format, xlnt::cale
|
|||
const std::string date_unquoted = ",-/: ";
|
||||
|
||||
const std::vector<std::string> dates = { "m", "mm", "mmm", "mmmmm", "mmmmmm", "d", "dd", "ddd", "dddd", "yy",
|
||||
"yyyy"
|
||||
"h",
|
||||
"[h]", "hh", "m", "[m]", "mm", "s", "[s]", "ss", "AM/PM", "am/pm",
|
||||
"A/P", "a/p" };
|
||||
"yyyy", "h", "[h]", "hh", "m", "[m]", "mm", "s", "[s]", "ss", "AM/PM",
|
||||
"am/pm", "A/P", "a/p" };
|
||||
|
||||
const std::vector<std::string> MonthNames = { "January", "February", "March",
|
||||
"April", "May", "June", "July", "August", "September", "October", "November", "December" };
|
||||
|
||||
|
||||
auto split = split_string_any(format.value, date_unquoted);
|
||||
std::string::size_type index = 0, prev = 0;
|
||||
|
@ -530,7 +548,7 @@ std::string format_section(long double number, const section &format, xlnt::cale
|
|||
std::string lower;
|
||||
lower.resize(s.size());
|
||||
for (std::size_t i = 0; i < s.size(); i++)
|
||||
lower[i] = std::tolower(s[i]);
|
||||
lower[i] = static_cast<char>(std::tolower(s[i]));
|
||||
return lower;
|
||||
};
|
||||
|
||||
|
@ -563,12 +581,12 @@ std::string format_section(long double number, const section &format, xlnt::cale
|
|||
}
|
||||
else if (part == "mmm" && !processed_month)
|
||||
{
|
||||
result.append(MonthNames.at(d.month - 1).substr(0, 3));
|
||||
result.append(MonthNames.at(static_cast<std::size_t>(d.month - 1)).substr(0, 3));
|
||||
processed_month = true;
|
||||
}
|
||||
else if (part == "mmmm" && !processed_month)
|
||||
{
|
||||
result.append(MonthNames.at(d.month - 1));
|
||||
result.append(MonthNames.at(static_cast<std::size_t>(d.month - 1)));
|
||||
processed_month = true;
|
||||
}
|
||||
else if (part == "d")
|
||||
|
@ -765,11 +783,12 @@ namespace xlnt {
|
|||
|
||||
const std::unordered_map<std::string, int> &cell::error_codes()
|
||||
{
|
||||
static const std::unordered_map<std::string, int> codes = { { "#NULL!", 0 }, { "#DIV/0!", 1 }, { "#VALUE!", 2 },
|
||||
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 } };
|
||||
{ "#N/A!", 6 } });
|
||||
|
||||
return codes;
|
||||
return *codes;
|
||||
};
|
||||
|
||||
cell::cell() : d_(nullptr)
|
||||
|
@ -1177,12 +1196,16 @@ comment cell::get_comment()
|
|||
return comment(d_->comment_.get());
|
||||
}
|
||||
|
||||
//TODO: this shares a lot of code with worksheet::get_point_pos, try to reduce repition
|
||||
std::pair<int, int> cell::get_anchor() const
|
||||
{
|
||||
static const double DefaultColumnWidth = 51.85;
|
||||
static const double DefaultRowHeight = 15.0;
|
||||
|
||||
auto points_to_pixels = [](double value, double dpi) { return (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;
|
||||
|
@ -1208,7 +1231,7 @@ std::pair<int, int> cell::get_anchor() const
|
|||
int top_anchor = 0;
|
||||
auto default_height = points_to_pixels(DefaultRowHeight, 96.0);
|
||||
|
||||
for (int row_index = 1; row_index <= (int)top_rows; row_index++)
|
||||
for (row_t row_index = 1; row_index <= top_rows; row_index++)
|
||||
{
|
||||
if (get_parent().has_row_properties(row_index))
|
||||
{
|
||||
|
@ -1239,16 +1262,10 @@ void cell::set_data_type(type t)
|
|||
|
||||
const number_format &cell::get_number_format() const
|
||||
{
|
||||
static const number_format default_format;
|
||||
|
||||
if (d_->has_style_)
|
||||
{
|
||||
return get_parent().get_parent().get_number_format(d_->style_id_);
|
||||
}
|
||||
else if (get_parent().get_parent().get_number_formats().empty())
|
||||
{
|
||||
return default_format;
|
||||
}
|
||||
else
|
||||
{
|
||||
return get_parent().get_parent().get_number_formats().front();
|
||||
|
|
|
@ -119,7 +119,7 @@ long double time::to_number() const
|
|||
microseconds += static_cast<std::uint64_t>(second * 1e6);
|
||||
microseconds += static_cast<std::uint64_t>(minute * 1e6 * 60);
|
||||
auto microseconds_per_hour = static_cast<std::uint64_t>(1e6) * 60 * 60;
|
||||
microseconds += static_cast<std::uint64_t>(hour * microseconds_per_hour);
|
||||
microseconds += static_cast<std::uint64_t>(hour) * microseconds_per_hour;
|
||||
auto number = microseconds / (24.0L * microseconds_per_hour);
|
||||
auto hundred_billion = static_cast<std::uint64_t>(1e9) * 100;
|
||||
number = std::floor(number * hundred_billion + 0.5L) / hundred_billion;
|
||||
|
@ -182,7 +182,21 @@ double timedelta::to_number() const
|
|||
|
||||
timedelta timedelta::from_number(long double number)
|
||||
{
|
||||
return timedelta(static_cast<long long int>(number), 0);
|
||||
int days = static_cast<int>(number);
|
||||
number -= days;
|
||||
number *= 24;
|
||||
int hours = static_cast<int>(number);
|
||||
number -= hours;
|
||||
number *= 60;
|
||||
int minutes = static_cast<int>(number);
|
||||
number -= minutes;
|
||||
number *= 60;
|
||||
int seconds = static_cast<int>(number);
|
||||
number -= seconds;
|
||||
number *= 1000000;
|
||||
int microseconds = static_cast<int>(number + 0.5);
|
||||
|
||||
return timedelta(days, hours, minutes, seconds, microseconds);
|
||||
}
|
||||
|
||||
} // namespace xlnt
|
||||
|
|
|
@ -13,25 +13,28 @@ const column_t constants::MaxColumn =
|
|||
LimitStyle == limit_style::excel ? (1u << 14) : LimitStyle == limit_style::openpyxl ? 18278 : UINT32_MAX;
|
||||
|
||||
// constants
|
||||
const std::string constants::PackageProps = "docProps";
|
||||
const std::string constants::PackageXl = "xl";
|
||||
const std::string constants::PackageRels = "_rels";
|
||||
const std::string constants::PackageTheme = PackageXl + "/" + "theme";
|
||||
const std::string constants::PackageWorksheets = PackageXl + "/" + "worksheets";
|
||||
const std::string constants::PackageDrawings = PackageXl + "/" + "drawings";
|
||||
const std::string constants::PackageCharts = PackageXl + "/" + "charts";
|
||||
const std::string constants::PackageProps() { return "docProps"; }
|
||||
const std::string constants::PackageXl() { return "xl"; }
|
||||
const std::string constants::PackageRels() { return "_rels"; }
|
||||
const std::string constants::PackageTheme() { return PackageXl() + "/" + "theme"; }
|
||||
const std::string constants::PackageWorksheets() { return PackageXl() + "/" + "worksheets"; }
|
||||
const std::string constants::PackageDrawings() { return PackageXl() + "/" + "drawings"; }
|
||||
const std::string constants::PackageCharts() { return PackageXl() + "/" + "charts"; }
|
||||
|
||||
const std::string constants::ArcContentTypes = "[Content_Types].xml";
|
||||
const std::string constants::ArcRootRels = PackageRels + "/.rels";
|
||||
const std::string constants::ArcWorkbookRels = PackageXl + "/" + PackageRels + "/workbook.xml.rels";
|
||||
const std::string constants::ArcCore = PackageProps + "/core.xml";
|
||||
const std::string constants::ArcApp = PackageProps + "/app.xml";
|
||||
const std::string constants::ArcWorkbook = PackageXl + "/workbook.xml";
|
||||
const std::string constants::ArcStyles = PackageXl + "/styles.xml";
|
||||
const std::string constants::ArcTheme = PackageTheme + "/theme1.xml";
|
||||
const std::string constants::ArcSharedString = PackageXl + "/sharedStrings.xml";
|
||||
const std::string constants::ArcContentTypes() { return "[Content_Types].xml"; }
|
||||
const std::string constants::ArcRootRels() { return PackageRels() + "/.rels"; }
|
||||
const std::string constants::ArcWorkbookRels() { return PackageXl() + "/" + PackageRels() + "/workbook.xml.rels"; }
|
||||
const std::string constants::ArcCore() { return PackageProps() + "/core.xml"; }
|
||||
const std::string constants::ArcApp() { return PackageProps() + "/app.xml"; }
|
||||
const std::string constants::ArcWorkbook() { return PackageXl() + "/workbook.xml"; }
|
||||
const std::string constants::ArcStyles() { return PackageXl() + "/styles.xml"; }
|
||||
const std::string constants::ArcTheme() { return PackageTheme() + "/theme1.xml"; }
|
||||
const std::string constants::ArcSharedString() { return PackageXl() + "/sharedStrings.xml"; }
|
||||
|
||||
const std::unordered_map<std::string, std::string> constants::Namespaces = {
|
||||
const std::unordered_map<std::string, std::string> constants::Namespaces()
|
||||
{
|
||||
const std::unordered_map<std::string, std::string> namespaces =
|
||||
{
|
||||
{ "spreadsheetml", "http://schemas.openxmlformats.org/spreadsheetml/2006/main" },
|
||||
{ "content-types", "http://schemas.openxmlformats.org/package/2006/content-types" },
|
||||
{ "relationships", "http://schemas.openxmlformats.org/package/2006/relationships" },
|
||||
|
@ -44,5 +47,14 @@ const std::unordered_map<std::string, std::string> constants::Namespaces = {
|
|||
{ "xsi", "http://www.w3.org/2001/XMLSchema-instance" },
|
||||
{ "vt", "http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes" },
|
||||
{ "xml", "http://www.w3.org/XML/1998/namespace" }
|
||||
};
|
||||
};
|
||||
|
||||
return namespaces;
|
||||
}
|
||||
|
||||
const std::string constants::Namespace(const std::string &id)
|
||||
{
|
||||
return Namespaces().find(id)->second;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -15,25 +15,27 @@ struct constants
|
|||
static const column_t MaxColumn;
|
||||
|
||||
// constants
|
||||
static const std::string PackageProps;
|
||||
static const std::string PackageXl;
|
||||
static const std::string PackageRels;
|
||||
static const std::string PackageTheme;
|
||||
static const std::string PackageWorksheets;
|
||||
static const std::string PackageDrawings;
|
||||
static const std::string PackageCharts;
|
||||
static const std::string PackageProps();
|
||||
static const std::string PackageXl();
|
||||
static const std::string PackageRels();
|
||||
static const std::string PackageTheme();
|
||||
static const std::string PackageWorksheets();
|
||||
static const std::string PackageDrawings();
|
||||
static const std::string PackageCharts();
|
||||
|
||||
static const std::string ArcContentTypes;
|
||||
static const std::string ArcRootRels;
|
||||
static const std::string ArcWorkbookRels;
|
||||
static const std::string ArcCore;
|
||||
static const std::string ArcApp;
|
||||
static const std::string ArcWorkbook;
|
||||
static const std::string ArcStyles;
|
||||
static const std::string ArcTheme;
|
||||
static const std::string ArcSharedString;
|
||||
static const std::string ArcContentTypes();
|
||||
static const std::string ArcRootRels();
|
||||
static const std::string ArcWorkbookRels();
|
||||
static const std::string ArcCore();
|
||||
static const std::string ArcApp();
|
||||
static const std::string ArcWorkbook();
|
||||
static const std::string ArcStyles();
|
||||
static const std::string ArcTheme();
|
||||
static const std::string ArcSharedString();
|
||||
|
||||
static const std::unordered_map<std::string, std::string> Namespaces;
|
||||
static const std::unordered_map<std::string, std::string> Namespaces();
|
||||
|
||||
static const std::string Namespace(const std::string &id);
|
||||
};
|
||||
|
||||
} // namespace xlnt
|
||||
|
|
|
@ -44,14 +44,14 @@ bool load_workbook(xlnt::zip_file &archive, bool guess_types, bool data_only, xl
|
|||
wb.set_guess_types(guess_types);
|
||||
wb.set_data_only(data_only);
|
||||
|
||||
if(!archive.has_file(xlnt::constants::ArcContentTypes))
|
||||
if(!archive.has_file(xlnt::constants::ArcContentTypes()))
|
||||
{
|
||||
throw xlnt::invalid_file_exception("missing [Content Types].xml");
|
||||
}
|
||||
|
||||
xlnt::manifest_serializer ms(wb.get_manifest());
|
||||
xlnt::xml_document manifest_xml;
|
||||
manifest_xml.from_string(archive.read(xlnt::constants::ArcContentTypes));
|
||||
manifest_xml.from_string(archive.read(xlnt::constants::ArcContentTypes()));
|
||||
ms.read_manifest(manifest_xml);
|
||||
|
||||
if (ms.determine_document_type() != "excel")
|
||||
|
@ -61,16 +61,16 @@ bool load_workbook(xlnt::zip_file &archive, bool guess_types, bool data_only, xl
|
|||
|
||||
wb.clear();
|
||||
|
||||
if(archive.has_file(xlnt::constants::ArcCore))
|
||||
if(archive.has_file(xlnt::constants::ArcCore()))
|
||||
{
|
||||
xlnt::workbook_serializer workbook_serializer_(wb);
|
||||
xlnt::xml_document core_properties_xml;
|
||||
core_properties_xml.from_string(archive.read(xlnt::constants::ArcCore));
|
||||
core_properties_xml.from_string(archive.read(xlnt::constants::ArcCore()));
|
||||
workbook_serializer_.read_properties_core(core_properties_xml);
|
||||
}
|
||||
|
||||
auto workbook_relationships =
|
||||
xlnt::relationship_serializer::read_relationships(archive, xlnt::constants::ArcWorkbook);
|
||||
xlnt::relationship_serializer::read_relationships(archive, xlnt::constants::ArcWorkbook());
|
||||
|
||||
for (const auto &relationship : workbook_relationships)
|
||||
{
|
||||
|
@ -78,7 +78,7 @@ bool load_workbook(xlnt::zip_file &archive, bool guess_types, bool data_only, xl
|
|||
}
|
||||
|
||||
xlnt::xml_document xml;
|
||||
xml.from_string(archive.read(xlnt::constants::ArcWorkbook));
|
||||
xml.from_string(archive.read(xlnt::constants::ArcWorkbook()));
|
||||
|
||||
auto root_node = xml.get_child("workbook");
|
||||
|
||||
|
@ -88,12 +88,12 @@ bool load_workbook(xlnt::zip_file &archive, bool guess_types, bool data_only, xl
|
|||
? xlnt::calendar::mac_1904
|
||||
: xlnt::calendar::windows_1900;
|
||||
|
||||
if(archive.has_file(xlnt::constants::ArcSharedString))
|
||||
if(archive.has_file(xlnt::constants::ArcSharedString()))
|
||||
{
|
||||
xlnt::shared_strings_serializer shared_strings_serializer_;
|
||||
std::vector<std::string> shared_strings;
|
||||
xlnt::xml_document shared_strings_xml;
|
||||
shared_strings_xml.from_string(archive.read(xlnt::constants::ArcSharedString));
|
||||
shared_strings_xml.from_string(archive.read(xlnt::constants::ArcSharedString()));
|
||||
shared_strings_serializer_.read_shared_strings(shared_strings_xml, shared_strings);
|
||||
|
||||
for (auto shared_string : shared_strings)
|
||||
|
@ -104,7 +104,7 @@ bool load_workbook(xlnt::zip_file &archive, bool guess_types, bool data_only, xl
|
|||
|
||||
xlnt::style_serializer style_reader_(wb);
|
||||
xlnt::xml_document style_xml;
|
||||
style_xml.from_string(archive.read(xlnt::constants::ArcStyles));
|
||||
style_xml.from_string(archive.read(xlnt::constants::ArcStyles()));
|
||||
style_reader_.read_stylesheet(style_xml);
|
||||
|
||||
auto sheets_node = root_node.get_child("sheets");
|
||||
|
@ -113,12 +113,16 @@ bool load_workbook(xlnt::zip_file &archive, bool guess_types, bool data_only, xl
|
|||
{
|
||||
auto rel = wb.get_relationship(sheet_node.get_attribute("r:id"));
|
||||
auto ws = wb.create_sheet(sheet_node.get_attribute("name"), rel);
|
||||
|
||||
//TODO: this is really bad
|
||||
auto ws_filename = (rel.get_target_uri().substr(0, 3) != "xl/" ? "xl/" : "") + rel.get_target_uri();
|
||||
|
||||
auto sheet_type = wb.get_manifest().get_override_type(ws_filename);
|
||||
|
||||
if(sheet_type != "application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml") continue;
|
||||
if(rel.get_type() != xlnt::relationship::type::worksheet)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
xlnt::worksheet_serializer worksheet_serializer(ws);
|
||||
xlnt::xml_document worksheet_xml;
|
||||
|
@ -154,9 +158,10 @@ bool excel_serializer::load_stream_workbook(std::istream &stream, bool guess_typ
|
|||
{
|
||||
std::vector<std::uint8_t> bytes;
|
||||
|
||||
//TODO: inefficient?
|
||||
while (stream.good())
|
||||
{
|
||||
bytes.push_back(stream.get());
|
||||
bytes.push_back(static_cast<std::uint8_t>(stream.get()));
|
||||
}
|
||||
|
||||
return load_virtual_workbook(bytes, guess_types, data_only);
|
||||
|
@ -192,28 +197,28 @@ void excel_serializer::write_data(bool /*as_template*/)
|
|||
relationship_serializer relationship_serializer_;
|
||||
|
||||
relationship_serializer_.write_relationships(workbook_.get_root_relationships(), "", archive_);
|
||||
relationship_serializer_.write_relationships(workbook_.get_relationships(), constants::ArcWorkbook, archive_);
|
||||
relationship_serializer_.write_relationships(workbook_.get_relationships(), constants::ArcWorkbook(), archive_);
|
||||
|
||||
xml_document properties_app_xml;
|
||||
workbook_serializer workbook_serializer_(workbook_);
|
||||
archive_.writestr(constants::ArcApp, xml_serializer::serialize(workbook_serializer_.write_properties_app()));
|
||||
archive_.writestr(constants::ArcCore, xml_serializer::serialize(workbook_serializer_.write_properties_core()));
|
||||
archive_.writestr(constants::ArcApp(), xml_serializer::serialize(workbook_serializer_.write_properties_app()));
|
||||
archive_.writestr(constants::ArcCore(), xml_serializer::serialize(workbook_serializer_.write_properties_core()));
|
||||
|
||||
theme_serializer theme_serializer_;
|
||||
archive_.writestr(constants::ArcTheme, theme_serializer_.write_theme(workbook_.get_loaded_theme()).to_string());
|
||||
archive_.writestr(constants::ArcTheme(), theme_serializer_.write_theme(workbook_.get_loaded_theme()).to_string());
|
||||
|
||||
xlnt::shared_strings_serializer shared_strings_serializer_;
|
||||
archive_.writestr(
|
||||
constants::ArcSharedString,
|
||||
constants::ArcSharedString(),
|
||||
xml_serializer::serialize(shared_strings_serializer_.write_shared_strings(workbook_.get_shared_strings())));
|
||||
|
||||
archive_.writestr(constants::ArcWorkbook, xml_serializer::serialize(workbook_serializer_.write_workbook()));
|
||||
archive_.writestr(constants::ArcWorkbook(), xml_serializer::serialize(workbook_serializer_.write_workbook()));
|
||||
|
||||
style_serializer style_serializer_(workbook_);
|
||||
archive_.writestr(constants::ArcStyles, style_serializer_.write_stylesheet().to_string());
|
||||
archive_.writestr(constants::ArcStyles(), style_serializer_.write_stylesheet().to_string());
|
||||
|
||||
manifest_serializer manifest_serializer_(workbook_.get_manifest());
|
||||
archive_.writestr(constants::ArcContentTypes, manifest_serializer_.write_manifest().to_string());
|
||||
archive_.writestr(constants::ArcContentTypes(), manifest_serializer_.write_manifest().to_string());
|
||||
|
||||
write_worksheets();
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ xml_document manifest_serializer::write_manifest() const
|
|||
xml_document xml;
|
||||
|
||||
auto root_node = xml.add_child("Types");
|
||||
xml.add_namespace("", constants::Namespaces.at("content-types"));
|
||||
xml.add_namespace("", constants::Namespace("content-types"));
|
||||
|
||||
for (const auto default_type : manifest_.get_default_types())
|
||||
{
|
||||
|
@ -54,12 +54,12 @@ xml_document manifest_serializer::write_manifest() const
|
|||
|
||||
std::string manifest_serializer::determine_document_type() const
|
||||
{
|
||||
if (!manifest_.has_override_type(constants::ArcWorkbook))
|
||||
if (!manifest_.has_override_type(constants::ArcWorkbook()))
|
||||
{
|
||||
return "unsupported";
|
||||
}
|
||||
|
||||
std::string type = manifest_.get_override_type(constants::ArcWorkbook);
|
||||
std::string type = manifest_.get_override_type(constants::ArcWorkbook());
|
||||
|
||||
if (type == "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml")
|
||||
{
|
||||
|
|
|
@ -46,9 +46,9 @@ std::vector<relationship> relationship_serializer::read_relationships(zip_file &
|
|||
|
||||
std::string id = relationship_node.get_attribute("Id");
|
||||
std::string type = relationship_node.get_attribute("Type");
|
||||
std::string target = relationship_node.get_attribute("Target");
|
||||
std::string rel_target = relationship_node.get_attribute("Target");
|
||||
|
||||
relationships.push_back(xlnt::relationship(type, id, target));
|
||||
relationships.push_back(xlnt::relationship(type, id, rel_target));
|
||||
}
|
||||
|
||||
return relationships;
|
||||
|
@ -61,16 +61,14 @@ bool relationship_serializer::write_relationships(const std::vector<relationship
|
|||
|
||||
auto root_node = xml.add_child("Relationships");
|
||||
|
||||
xml.add_namespace("", constants::Namespaces.at("relationships"));
|
||||
xml.add_namespace("", constants::Namespace("relationships"));
|
||||
|
||||
for (const auto &relationship : relationships)
|
||||
{
|
||||
auto target = relationship.get_target_uri();
|
||||
|
||||
auto relationship_node = root_node.add_child("Relationship");
|
||||
|
||||
relationship_node.add_attribute("Id", relationship.get_id());
|
||||
relationship_node.add_attribute("Target", target);
|
||||
relationship_node.add_attribute("Target", relationship.get_target_uri());
|
||||
relationship_node.add_attribute("Type", relationship.get_type_string());
|
||||
|
||||
if (relationship.get_target_mode() == target_mode::external)
|
||||
|
|
|
@ -340,7 +340,7 @@ font style_serializer::read_font(const xlnt::xml_node &font_node)
|
|||
{
|
||||
font new_font;
|
||||
|
||||
new_font.set_size(std::stoi(font_node.get_child("sz").get_attribute("val")));
|
||||
new_font.set_size(std::stoull(font_node.get_child("sz").get_attribute("val")));
|
||||
new_font.set_name(font_node.get_child("name").get_attribute("val"));
|
||||
|
||||
if (font_node.has_child("color"))
|
||||
|
@ -552,7 +552,6 @@ color style_serializer::read_color(const xml_node &color_node)
|
|||
}
|
||||
|
||||
throw std::runtime_error("bad color");
|
||||
return color();
|
||||
}
|
||||
|
||||
xml_document style_serializer::write_stylesheet() const
|
||||
|
|
|
@ -12,7 +12,7 @@ xml_document theme_serializer::write_theme(const theme &) const
|
|||
xml_document xml;
|
||||
|
||||
auto theme_node = xml.add_child("a:theme");
|
||||
xml.add_namespace("a", constants::Namespaces.at("drawingml"));
|
||||
xml.add_namespace("a", constants::Namespace("drawingml"));
|
||||
theme_node.add_attribute("name", "Office Theme");
|
||||
|
||||
auto theme_elements_node = theme_node.add_child("a:themeElements");
|
||||
|
|
|
@ -222,8 +222,8 @@ xml_document worksheet_serializer::write_worksheet() const
|
|||
|
||||
auto root_node = xml.add_child("worksheet");
|
||||
|
||||
xml.add_namespace("", constants::Namespaces.at("spreadsheetml"));
|
||||
xml.add_namespace("r", constants::Namespaces.at("r"));
|
||||
xml.add_namespace("", constants::Namespace("spreadsheetml"));
|
||||
xml.add_namespace("r", constants::Namespace("r"));
|
||||
|
||||
auto sheet_pr_node = root_node.add_child("sheetPr");
|
||||
|
||||
|
|
|
@ -6,9 +6,11 @@
|
|||
|
||||
namespace {
|
||||
|
||||
const std::unordered_map<int, std::string> &builtin_formats()
|
||||
const std::unordered_map<std::size_t, std::string> &builtin_formats()
|
||||
{
|
||||
static const std::unordered_map<int, std::string> formats = {
|
||||
static const std::unordered_map<std::size_t, std::string> *formats =
|
||||
new std::unordered_map<std::size_t, std::string>
|
||||
({
|
||||
{ 0, "General" },
|
||||
{ 1, "0" },
|
||||
{ 2, "0.00" },
|
||||
|
@ -58,9 +60,9 @@ const std::unordered_map<int, std::string> &builtin_formats()
|
|||
//{40, "#,##0.00_);[Red]"},
|
||||
//{47, "mm:ss.0"},
|
||||
//{55, "yyyy/mm/dd"}
|
||||
};
|
||||
});
|
||||
|
||||
return formats;
|
||||
return *formats;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
@ -69,222 +71,227 @@ namespace xlnt {
|
|||
|
||||
const number_format number_format::general()
|
||||
{
|
||||
static const number_format format(builtin_formats().at(0), 0);
|
||||
return format;
|
||||
static const number_format *format = new number_format(builtin_formats().at(0), 0);
|
||||
return *format;
|
||||
}
|
||||
|
||||
const number_format number_format::text()
|
||||
{
|
||||
static const number_format format(builtin_formats().at(49), 49);
|
||||
return format;
|
||||
static const number_format *format = new number_format(builtin_formats().at(49), 49);
|
||||
return *format;
|
||||
}
|
||||
|
||||
const number_format number_format::number()
|
||||
{
|
||||
static const number_format format(builtin_formats().at(1), 1);
|
||||
return format;
|
||||
static const number_format *format = new number_format(builtin_formats().at(1), 1);
|
||||
return *format;
|
||||
}
|
||||
|
||||
const number_format number_format::number_00()
|
||||
{
|
||||
static const number_format format(builtin_formats().at(2), 2);
|
||||
return format;
|
||||
static const number_format *format = new number_format(builtin_formats().at(2), 2);
|
||||
return *format;
|
||||
}
|
||||
|
||||
const number_format number_format::number_comma_separated1()
|
||||
{
|
||||
static const number_format format(builtin_formats().at(4), 4);
|
||||
return format;
|
||||
static const number_format *format = new number_format(builtin_formats().at(4), 4);
|
||||
return *format;
|
||||
}
|
||||
|
||||
const number_format number_format::number_comma_separated2()
|
||||
{
|
||||
static const number_format format("#,##0.00_-");
|
||||
return format;
|
||||
static const number_format *format = new number_format("#,##0.00_-");
|
||||
return *format;
|
||||
}
|
||||
|
||||
const number_format number_format::percentage()
|
||||
{
|
||||
static const number_format format(builtin_formats().at(9), 9);
|
||||
return format;
|
||||
static const number_format *format = new number_format(builtin_formats().at(9), 9);
|
||||
return *format;
|
||||
}
|
||||
|
||||
const number_format number_format::percentage_00()
|
||||
{
|
||||
static const number_format format(builtin_formats().at(10), 10);
|
||||
return format;
|
||||
static const number_format *format = new number_format(builtin_formats().at(10), 10);
|
||||
return *format;
|
||||
}
|
||||
|
||||
const number_format number_format::date_yyyymmdd2()
|
||||
{
|
||||
static const number_format format("yyyy-mm-dd");
|
||||
return format;
|
||||
static const number_format *format = new number_format("yyyy-mm-dd");
|
||||
return *format;
|
||||
}
|
||||
|
||||
const number_format number_format::date_yyyymmdd()
|
||||
{
|
||||
static const number_format format("yy-mm-dd");
|
||||
return format;
|
||||
static const number_format *format = new number_format("yy-mm-dd");
|
||||
return *format;
|
||||
}
|
||||
|
||||
const number_format number_format::date_ddmmyyyy()
|
||||
{
|
||||
static const number_format format("dd/mm/yy");
|
||||
return format;
|
||||
static const number_format *format = new number_format("dd/mm/yy");
|
||||
return *format;
|
||||
}
|
||||
|
||||
const number_format number_format::date_dmyslash()
|
||||
{
|
||||
static const number_format format("d/m/y");
|
||||
return format;
|
||||
static const number_format *format = new number_format("d/m/y");
|
||||
return *format;
|
||||
}
|
||||
|
||||
const number_format number_format::date_dmyminus()
|
||||
{
|
||||
static const number_format format("d-m-y");
|
||||
return format;
|
||||
static const number_format *format = new number_format("d-m-y");
|
||||
return *format;
|
||||
}
|
||||
|
||||
const number_format number_format::date_dmminus()
|
||||
{
|
||||
static const number_format format("d-m");
|
||||
return format;
|
||||
static const number_format *format = new number_format("d-m");
|
||||
return *format;
|
||||
}
|
||||
|
||||
const number_format number_format::date_myminus()
|
||||
{
|
||||
static const number_format format("m-y");
|
||||
return format;
|
||||
static const number_format *format = new number_format("m-y");
|
||||
return *format;
|
||||
}
|
||||
|
||||
const number_format number_format::date_xlsx14()
|
||||
{
|
||||
static const number_format format(builtin_formats().at(14), 14);
|
||||
return format;
|
||||
static const number_format *format = new number_format(builtin_formats().at(14), 14);
|
||||
return *format;
|
||||
}
|
||||
|
||||
const number_format number_format::date_xlsx15()
|
||||
{
|
||||
static const number_format format(builtin_formats().at(15), 15);
|
||||
return format;
|
||||
static const number_format *format = new number_format(builtin_formats().at(15), 15);
|
||||
return *format;
|
||||
}
|
||||
|
||||
const number_format number_format::date_xlsx16()
|
||||
{
|
||||
static const number_format format(builtin_formats().at(16), 16);
|
||||
return format;
|
||||
static const number_format *format = new number_format(builtin_formats().at(16), 16);
|
||||
return *format;
|
||||
}
|
||||
|
||||
const number_format number_format::date_xlsx17()
|
||||
{
|
||||
static const number_format format(builtin_formats().at(17), 17);
|
||||
return format;
|
||||
static const number_format *format = new number_format(builtin_formats().at(17), 17);
|
||||
return *format;
|
||||
}
|
||||
|
||||
const number_format number_format::date_xlsx22()
|
||||
{
|
||||
static const number_format format(builtin_formats().at(22), 22);
|
||||
return format;
|
||||
static const number_format *format = new number_format(builtin_formats().at(22), 22);
|
||||
return *format;
|
||||
}
|
||||
|
||||
const number_format number_format::date_datetime()
|
||||
{
|
||||
static const number_format format("yyyy-mm-dd h:mm:ss");
|
||||
return format;
|
||||
static const number_format *format = new number_format("yyyy-mm-dd h:mm:ss");
|
||||
return *format;
|
||||
}
|
||||
|
||||
const number_format number_format::date_time1()
|
||||
{
|
||||
static const number_format format(builtin_formats().at(18), 18);
|
||||
return format;
|
||||
static const number_format *format = new number_format(builtin_formats().at(18), 18);
|
||||
return *format;
|
||||
}
|
||||
|
||||
const number_format number_format::date_time2()
|
||||
{
|
||||
static const number_format format(builtin_formats().at(19), 19);
|
||||
return format;
|
||||
static const number_format *format = new number_format(builtin_formats().at(19), 19);
|
||||
return *format;
|
||||
}
|
||||
|
||||
const number_format number_format::date_time3()
|
||||
{
|
||||
static const number_format format(builtin_formats().at(20), 20);
|
||||
return format;
|
||||
static const number_format *format = new number_format(builtin_formats().at(20), 20);
|
||||
return *format;
|
||||
}
|
||||
|
||||
const number_format number_format::date_time4()
|
||||
{
|
||||
static const number_format format(builtin_formats().at(21), 21);
|
||||
return format;
|
||||
static const number_format *format = new number_format(builtin_formats().at(21), 21);
|
||||
return *format;
|
||||
}
|
||||
|
||||
const number_format number_format::date_time5()
|
||||
{
|
||||
static const number_format format(builtin_formats().at(45), 45);
|
||||
return format;
|
||||
static const number_format *format = new number_format(builtin_formats().at(45), 45);
|
||||
return *format;
|
||||
}
|
||||
|
||||
const number_format number_format::date_time6()
|
||||
{
|
||||
static const number_format format(builtin_formats().at(21), 21);
|
||||
return format;
|
||||
static const number_format *format = new number_format(builtin_formats().at(21), 21);
|
||||
return *format;
|
||||
}
|
||||
|
||||
const number_format number_format::date_time7()
|
||||
{
|
||||
static const number_format format("i:s.S");
|
||||
return format;
|
||||
static const number_format *format = new number_format("i:s.S");
|
||||
return *format;
|
||||
}
|
||||
|
||||
const number_format number_format::date_time8()
|
||||
{
|
||||
static const number_format format("h:mm:ss@");
|
||||
return format;
|
||||
static const number_format *format = new number_format("h:mm:ss@");
|
||||
return *format;
|
||||
}
|
||||
|
||||
const number_format number_format::date_timedelta()
|
||||
{
|
||||
static const number_format format("[hh]:mm:ss");
|
||||
return format;
|
||||
static const number_format *format = new number_format("[hh]:mm:ss");
|
||||
return *format;
|
||||
}
|
||||
|
||||
const number_format number_format::date_yyyymmddslash()
|
||||
{
|
||||
static const number_format format("yy/mm/dd@");
|
||||
return format;
|
||||
static const number_format *format = new number_format("yy/mm/dd@");
|
||||
return *format;
|
||||
}
|
||||
|
||||
const number_format number_format::currency_usd_simple()
|
||||
{
|
||||
static const number_format format("\"$\"#,##0.00_-");
|
||||
return format;
|
||||
static const number_format *format = new number_format("\"$\"#,##0.00_-");
|
||||
return *format;
|
||||
}
|
||||
|
||||
const number_format number_format::currency_usd()
|
||||
{
|
||||
static const number_format format("$#,##0_-");
|
||||
return format;
|
||||
static const number_format *format = new number_format("$#,##0_-");
|
||||
return *format;
|
||||
}
|
||||
|
||||
const number_format number_format::currency_eur_simple()
|
||||
{
|
||||
static const number_format format("[$EUR ]#,##0.00_-");
|
||||
return format;
|
||||
static const number_format *format = new number_format("[$EUR ]#,##0.00_-");
|
||||
return *format;
|
||||
}
|
||||
|
||||
number_format::number_format() : number_format(general())
|
||||
{
|
||||
}
|
||||
|
||||
number_format::number_format(int id) : number_format(from_builtin_id(id))
|
||||
number_format::number_format(std::size_t id) : number_format(from_builtin_id(id))
|
||||
{
|
||||
}
|
||||
|
||||
number_format::number_format(const std::string &format_string, int id)
|
||||
number_format::number_format(const std::string &format_string) : id_set_(false), id_(0)
|
||||
{
|
||||
set_format_string(format_string);
|
||||
}
|
||||
|
||||
number_format::number_format(const std::string &format_string, std::size_t id) : id_set_(false), id_(0)
|
||||
{
|
||||
set_format_string(format_string, id);
|
||||
}
|
||||
|
||||
number_format number_format::from_builtin_id(int builtin_id)
|
||||
number_format number_format::from_builtin_id(std::size_t builtin_id)
|
||||
{
|
||||
if (builtin_formats().find(builtin_id) == builtin_formats().end())
|
||||
{
|
||||
|
@ -302,28 +309,35 @@ std::string number_format::get_format_string() const
|
|||
|
||||
std::size_t number_format::hash() const
|
||||
{
|
||||
std::size_t seed = static_cast<std::size_t>(id_);
|
||||
std::size_t seed = id_;
|
||||
hash_combine(seed, format_string_);
|
||||
|
||||
return seed;
|
||||
}
|
||||
|
||||
void number_format::set_format_string(const std::string &format_string, int id)
|
||||
|
||||
void number_format::set_format_string(const std::string &format_string)
|
||||
{
|
||||
format_string_ = format_string;
|
||||
id_ = id;
|
||||
id_ = 0;
|
||||
id_set_ = false;
|
||||
|
||||
if (id_ == -1)
|
||||
{
|
||||
for (const auto &pair : builtin_formats())
|
||||
{
|
||||
if (pair.second == format_string)
|
||||
{
|
||||
id_ = pair.first;
|
||||
id_set_ = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void number_format::set_format_string(const std::string &format_string, std::size_t id)
|
||||
{
|
||||
format_string_ = format_string;
|
||||
id_ = id;
|
||||
id_set_ = true;
|
||||
}
|
||||
|
||||
} // namespace xlnt
|
||||
|
|
|
@ -16,8 +16,15 @@ void hash_combine(std::size_t &seed, const T &v)
|
|||
|
||||
namespace xlnt {
|
||||
|
||||
const color color::black = color(color::type::indexed, 0);
|
||||
const color color::white = color(color::type::indexed, 0);
|
||||
const color color::black()
|
||||
{
|
||||
return color(color::type::rgb, "ff000000");
|
||||
}
|
||||
|
||||
const color color::white()
|
||||
{
|
||||
return color(color::type::rgb, "ffffffff");
|
||||
}
|
||||
|
||||
style::style()
|
||||
: id_(0),
|
||||
|
|
|
@ -47,6 +47,8 @@ workbook::workbook() : d_(new detail::workbook_impl())
|
|||
create_relationship("rId3", "styles.xml", relationship::type::styles);
|
||||
create_relationship("rId4", "theme/theme1.xml", relationship::type::theme);
|
||||
|
||||
add_number_format(number_format::general());
|
||||
|
||||
d_->manifest_.add_default_type("rels", "application/vnd.openxmlformats-package.relationships+xml");
|
||||
d_->manifest_.add_default_type("xml", "application/xml");
|
||||
|
||||
|
@ -572,9 +574,16 @@ void workbook::add_font(const font &font_)
|
|||
|
||||
void workbook::add_number_format(const number_format &number_format_)
|
||||
{
|
||||
if (d_->number_formats_.size() == 1 && d_->number_formats_.front() == number_format::general())
|
||||
{
|
||||
d_->number_formats_.front() = number_format_;
|
||||
}
|
||||
else
|
||||
{
|
||||
d_->number_formats_.push_back(number_format_);
|
||||
}
|
||||
|
||||
if(number_format_.get_id() == -1)
|
||||
if(!number_format_.has_id())
|
||||
{
|
||||
d_->number_formats_.back().set_id(d_->next_custom_format_id_++);
|
||||
}
|
||||
|
@ -623,13 +632,13 @@ const number_format &workbook::get_number_format(std::size_t style_id) const
|
|||
|
||||
for (const auto &number_format_ : d_->number_formats_)
|
||||
{
|
||||
if (static_cast<std::size_t>(number_format_.get_id()) == number_format_id)
|
||||
if (number_format_.has_id() && number_format_.get_id() == number_format_id)
|
||||
{
|
||||
return number_format_;
|
||||
}
|
||||
}
|
||||
|
||||
auto nf = number_format::from_builtin_id(static_cast<int>(number_format_id));
|
||||
auto nf = number_format::from_builtin_id(number_format_id);
|
||||
d_->number_formats_.push_back(nf);
|
||||
|
||||
return d_->number_formats_.back();
|
||||
|
@ -652,7 +661,7 @@ std::size_t workbook::set_font(const font &font_, std::size_t style_id)
|
|||
}
|
||||
else
|
||||
{
|
||||
font_index = match - d_->fonts_.begin();
|
||||
font_index = static_cast<std::size_t>(match - d_->fonts_.begin());
|
||||
}
|
||||
|
||||
auto existing_style = d_->styles_[style_id];
|
||||
|
@ -670,7 +679,7 @@ std::size_t workbook::set_font(const font &font_, std::size_t style_id)
|
|||
|
||||
if (style_match != d_->styles_.end())
|
||||
{
|
||||
return style_match - d_->styles_.begin();
|
||||
return static_cast<std::size_t>(style_match - d_->styles_.begin());
|
||||
}
|
||||
|
||||
d_->styles_.push_back(new_style);
|
||||
|
@ -737,7 +746,7 @@ std::size_t workbook::set_number_format(const xlnt::number_format &format, std::
|
|||
{
|
||||
d_->number_formats_.push_back(format);
|
||||
|
||||
if (format.get_id() == -1)
|
||||
if (!format.has_id())
|
||||
{
|
||||
d_->number_formats_.back().set_id(d_->next_custom_format_id_++);
|
||||
}
|
||||
|
|
|
@ -641,7 +641,10 @@ cell_reference worksheet::get_point_pos(int left, int top) const
|
|||
static const double DefaultColumnWidth = 51.85;
|
||||
static const double DefaultRowHeight = 15.0;
|
||||
|
||||
auto points_to_pixels = [](double value, double dpi) { return (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 default_height = points_to_pixels(DefaultRowHeight, 96.0);
|
||||
auto default_width = points_to_pixels(DefaultColumnWidth, 96.0);
|
||||
|
|
Loading…
Reference in New Issue
Block a user