mirror of
https://github.com/tfussell/xlnt.git
synced 2024-03-22 13:11:17 +08:00
the library compiles now. tests don't
This commit is contained in:
parent
9bd6e92297
commit
198483c88e
|
@ -203,6 +203,8 @@ public:
|
|||
/// Return a reference to the style applied to this cell.
|
||||
/// </summary>
|
||||
const cell_style &get_style() const;
|
||||
|
||||
void set_style(const cell_style &style);
|
||||
|
||||
/// <summary>
|
||||
/// Return the number format of this cell.
|
||||
|
@ -371,9 +373,12 @@ public:
|
|||
friend XLNT_FUNCTION std::ostream &operator<<(std::ostream &stream, const xlnt::cell &cell);
|
||||
|
||||
private:
|
||||
std::size_t get_style_id() const;
|
||||
|
||||
// make these friends so they can use the private constructor
|
||||
friend class style;
|
||||
friend class worksheet;
|
||||
friend class worksheet_serializer;
|
||||
friend struct detail::cell_impl;
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -254,6 +254,8 @@ public:
|
|||
|
||||
bool write_colors(xml_node &colors_node) const;
|
||||
|
||||
bool write_ext_list(xml_node &ext_list_node) const;
|
||||
|
||||
private:
|
||||
void initialize_vectors();
|
||||
|
||||
|
|
|
@ -27,6 +27,8 @@
|
|||
|
||||
namespace xlnt {
|
||||
|
||||
class named_style;
|
||||
|
||||
/// <summary>
|
||||
/// Describes the formatting of a particular cell.
|
||||
/// </summary>
|
||||
|
|
|
@ -87,7 +87,6 @@ public:
|
|||
protected:
|
||||
std::string to_hash_string() const override;
|
||||
|
||||
private:
|
||||
alignment alignment_;
|
||||
border border_;
|
||||
fill fill_;
|
||||
|
|
|
@ -55,7 +55,7 @@ protected:
|
|||
private:
|
||||
std::string name_;
|
||||
bool hidden_;
|
||||
std::size_t builtin_id;
|
||||
std::size_t builtin_id_;
|
||||
};
|
||||
|
||||
} // namespace xlnt
|
||||
|
|
|
@ -181,6 +181,10 @@ public:
|
|||
bool has_loaded_theme() const;
|
||||
const theme &get_loaded_theme() const;
|
||||
|
||||
cell_style &get_style(std::size_t style_index);
|
||||
const cell_style &get_style(std::size_t style_index) const;
|
||||
std::size_t add_style(const cell_style &style);
|
||||
|
||||
// Named Styles
|
||||
bool has_named_style(const std::string &name);
|
||||
named_style &get_named_style(const std::string &name);
|
||||
|
|
|
@ -34,13 +34,13 @@
|
|||
#include <xlnt/serialization/encoding.hpp>
|
||||
#include <xlnt/styles/alignment.hpp>
|
||||
#include <xlnt/styles/border.hpp>
|
||||
#include <xlnt/styles/cell_style.hpp>
|
||||
#include <xlnt/styles/color.hpp>
|
||||
#include <xlnt/styles/fill.hpp>
|
||||
#include <xlnt/styles/font.hpp>
|
||||
#include <xlnt/styles/number_format.hpp>
|
||||
#include <xlnt/styles/protection.hpp>
|
||||
#include <xlnt/styles/side.hpp>
|
||||
#include <xlnt/styles/style.hpp>
|
||||
#include <xlnt/utils/date.hpp>
|
||||
#include <xlnt/utils/datetime.hpp>
|
||||
#include <xlnt/utils/time.hpp>
|
||||
|
|
|
@ -584,11 +584,11 @@ const number_format &cell::get_number_format() const
|
|||
{
|
||||
if (d_->has_style_)
|
||||
{
|
||||
return get_parent().get_parent().get_number_format(d_->style_id_);
|
||||
return get_parent().get_parent().get_style(d_->style_id_).get_number_format();
|
||||
}
|
||||
else
|
||||
{
|
||||
return get_parent().get_parent().get_number_formats().front();
|
||||
return get_parent().get_parent().get_style(0).get_number_format();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -596,43 +596,60 @@ const font &cell::get_font() const
|
|||
{
|
||||
if (d_->has_style_)
|
||||
{
|
||||
auto font_id = get_parent().get_parent().get_cell_formats()[d_->style_id_].get_font_id();
|
||||
return get_parent().get_parent().get_font(font_id);
|
||||
return get_parent().get_parent().get_style(d_->style_id_).get_font();
|
||||
}
|
||||
else
|
||||
{
|
||||
return get_parent().get_parent().get_font(0);
|
||||
return get_parent().get_parent().get_style(0).get_font();
|
||||
}
|
||||
}
|
||||
|
||||
const fill &cell::get_fill() const
|
||||
{
|
||||
return get_parent().get_parent().get_fill(get_parent().get_parent().get_cell_format(d_->style_id_).get_fill_id());
|
||||
if (d_->has_style_)
|
||||
{
|
||||
return get_parent().get_parent().get_style(d_->style_id_).get_fill();
|
||||
}
|
||||
else
|
||||
{
|
||||
return get_parent().get_parent().get_style(0).get_fill();
|
||||
}
|
||||
}
|
||||
|
||||
const border &cell::get_border() const
|
||||
{
|
||||
return get_parent().get_parent().get_border(get_parent().get_parent().get_cell_format(d_->style_id_).get_border_id());
|
||||
if (d_->has_style_)
|
||||
{
|
||||
return get_parent().get_parent().get_style(d_->style_id_).get_border();
|
||||
}
|
||||
else
|
||||
{
|
||||
return get_parent().get_parent().get_style(0).get_border();
|
||||
}
|
||||
}
|
||||
|
||||
const alignment &cell::get_alignment() const
|
||||
{
|
||||
return get_parent().get_parent().get_alignment(d_->style_id_);
|
||||
if (d_->has_style_)
|
||||
{
|
||||
return get_parent().get_parent().get_style(d_->style_id_).get_alignment();
|
||||
}
|
||||
else
|
||||
{
|
||||
return get_parent().get_parent().get_style(0).get_alignment();
|
||||
}
|
||||
}
|
||||
|
||||
const protection &cell::get_protection() const
|
||||
{
|
||||
return get_parent().get_parent().get_protection(d_->style_id_);
|
||||
}
|
||||
|
||||
bool cell::pivot_button() const
|
||||
{
|
||||
return d_->pivot_button_;
|
||||
}
|
||||
|
||||
bool cell::quote_prefix() const
|
||||
{
|
||||
return d_->quote_prefix_;
|
||||
if (d_->has_style_)
|
||||
{
|
||||
return get_parent().get_parent().get_style(d_->style_id_).get_protection();
|
||||
}
|
||||
else
|
||||
{
|
||||
return get_parent().get_parent().get_style(0).get_protection();
|
||||
}
|
||||
}
|
||||
|
||||
void cell::clear_value()
|
||||
|
@ -750,37 +767,49 @@ XLNT_FUNCTION timedelta cell::get_value() const
|
|||
void cell::set_border(const xlnt::border &border_)
|
||||
{
|
||||
d_->has_style_ = true;
|
||||
d_->style_id_ = get_parent().get_parent().set_border(border_, d_->style_id_);
|
||||
auto style_copy = get_parent().get_parent().get_style(d_->style_id_);
|
||||
style_copy.set_border(border_);
|
||||
d_->style_id_ = get_parent().get_parent().add_style(style_copy);
|
||||
}
|
||||
|
||||
void cell::set_fill(const xlnt::fill &fill_)
|
||||
{
|
||||
d_->has_style_ = true;
|
||||
d_->style_id_ = get_parent().get_parent().set_fill(fill_, d_->style_id_);
|
||||
auto style_copy = get_parent().get_parent().get_style(d_->style_id_);
|
||||
style_copy.set_fill(fill_);
|
||||
d_->style_id_ = get_parent().get_parent().add_style(style_copy);
|
||||
}
|
||||
|
||||
void cell::set_font(const font &font_)
|
||||
{
|
||||
d_->has_style_ = true;
|
||||
d_->style_id_ = get_parent().get_parent().set_font(font_, d_->style_id_);
|
||||
auto style_copy = get_parent().get_parent().get_style(d_->style_id_);
|
||||
style_copy.set_font(font_);
|
||||
d_->style_id_ = get_parent().get_parent().add_style(style_copy);
|
||||
}
|
||||
|
||||
void cell::set_number_format(const number_format &number_format_)
|
||||
{
|
||||
d_->has_style_ = true;
|
||||
d_->style_id_ = get_parent().get_parent().set_number_format(number_format_, d_->style_id_);
|
||||
auto style_copy = get_parent().get_parent().get_style(d_->style_id_);
|
||||
style_copy.set_number_format(number_format_);
|
||||
d_->style_id_ = get_parent().get_parent().add_style(style_copy);
|
||||
}
|
||||
|
||||
void cell::set_alignment(const xlnt::alignment &alignment_)
|
||||
{
|
||||
d_->has_style_ = true;
|
||||
d_->style_id_ = get_parent().get_parent().set_alignment(alignment_, d_->style_id_);
|
||||
auto style_copy = get_parent().get_parent().get_style(d_->style_id_);
|
||||
style_copy.set_alignment(alignment_);
|
||||
d_->style_id_ = get_parent().get_parent().add_style(style_copy);
|
||||
}
|
||||
|
||||
void cell::set_protection(const xlnt::protection &protection_)
|
||||
{
|
||||
d_->has_style_ = true;
|
||||
d_->style_id_ = get_parent().get_parent().set_protection(protection_, d_->style_id_);
|
||||
auto style_copy = get_parent().get_parent().get_style(d_->style_id_);
|
||||
style_copy.set_protection(protection_);
|
||||
d_->style_id_ = get_parent().get_parent().add_style(style_copy);
|
||||
}
|
||||
|
||||
template <>
|
||||
|
@ -815,9 +844,9 @@ std::string cell::to_string() const
|
|||
}
|
||||
}
|
||||
|
||||
std::size_t cell::get_style_id() const
|
||||
cell_style &cell::get_style()
|
||||
{
|
||||
return d_->style_id_;
|
||||
return get_parent().get_parent().get_style(d_->style_id_);
|
||||
}
|
||||
|
||||
bool cell::has_style() const
|
||||
|
@ -825,9 +854,9 @@ bool cell::has_style() const
|
|||
return d_->has_style_;
|
||||
}
|
||||
|
||||
void cell::set_style_id(std::size_t style_id)
|
||||
void cell::set_style(const cell_style &style)
|
||||
{
|
||||
d_->style_id_ = style_id;
|
||||
d_->style_id_ = get_parent().get_parent().add_style(style);
|
||||
d_->has_style_ = true;
|
||||
}
|
||||
|
||||
|
@ -841,14 +870,9 @@ std::ostream &operator<<(std::ostream &stream, const xlnt::cell &cell)
|
|||
return stream << cell.to_string();
|
||||
}
|
||||
|
||||
void cell::set_pivot_button(bool b)
|
||||
std::size_t cell::get_style_id() const
|
||||
{
|
||||
d_->pivot_button_ = b;
|
||||
}
|
||||
|
||||
void cell::set_quote_prefix(bool b)
|
||||
{
|
||||
d_->quote_prefix_ = b;
|
||||
return d_->style_id_;
|
||||
}
|
||||
|
||||
} // namespace xlnt
|
||||
|
|
|
@ -44,12 +44,8 @@ struct workbook_impl
|
|||
guess_types_(other.guess_types_),
|
||||
data_only_(other.data_only_),
|
||||
read_only_(other.read_only_),
|
||||
styles_(other.styles_),
|
||||
colors_(other.colors_),
|
||||
borders_(other.borders_),
|
||||
fills_(other.fills_),
|
||||
fonts_(other.fonts_),
|
||||
number_formats_(other.number_formats_),
|
||||
cell_styles_(other.cell_styles_),
|
||||
named_styles_(other.named_styles_),
|
||||
manifest_(other.manifest_)
|
||||
{
|
||||
}
|
||||
|
@ -92,7 +88,8 @@ struct workbook_impl
|
|||
bool data_only_;
|
||||
bool read_only_;
|
||||
|
||||
std::vector<style> styles_;
|
||||
std::vector<cell_style> cell_styles_;
|
||||
std::vector<named_style> named_styles_;
|
||||
std::size_t next_custom_format_id_;
|
||||
|
||||
manifest manifest_;
|
||||
|
|
|
@ -37,6 +37,8 @@
|
|||
#include <xlnt/serialization/xml_serializer.hpp>
|
||||
#include <xlnt/packaging/document_properties.hpp>
|
||||
#include <xlnt/packaging/manifest.hpp>
|
||||
#include <xlnt/styles/cell_style.hpp>
|
||||
#include <xlnt/styles/named_style.hpp>
|
||||
#include <xlnt/utils/exceptions.hpp>
|
||||
#include <xlnt/workbook/workbook.hpp>
|
||||
#include <xlnt/workbook/worksheet_iterator.hpp>
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
#include <xlnt/styles/cell_style.hpp>
|
||||
#include <xlnt/styles/fill.hpp>
|
||||
#include <xlnt/styles/font.hpp>
|
||||
#include <xlnt/styles/named_style.hpp>
|
||||
#include <xlnt/styles/number_format.hpp>
|
||||
#include <xlnt/styles/protection.hpp>
|
||||
#include <xlnt/workbook/worksheet_iterator.hpp>
|
||||
|
@ -1180,7 +1181,7 @@ bool style_serializer::write_colors(xlnt::xml_node &colors_node) const
|
|||
return true;
|
||||
}
|
||||
|
||||
bool write_colors(xlnt::xml_node &ext_list_node)
|
||||
bool style_serializer::write_ext_list(xlnt::xml_node &ext_list_node) const
|
||||
{
|
||||
auto ext_node = ext_list_node.add_child("ext");
|
||||
ext_node.add_attribute("uri", "{EB79DEF2-80B8-43e5-95BD-54CBDDF9020C}");
|
||||
|
@ -1252,4 +1253,9 @@ bool style_serializer::write_number_formats(xml_node &number_formats_node) const
|
|||
return true;
|
||||
}
|
||||
|
||||
bool style_serializer::read_named_styles(const xlnt::xml_node &named_styles_node, const xlnt::xml_node &cell_styles_node)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace xlnt
|
||||
|
|
|
@ -197,7 +197,7 @@ bool worksheet_serializer::read_worksheet(const xml_document &xml)
|
|||
|
||||
if (has_style)
|
||||
{
|
||||
cell.set_style_id(style_id);
|
||||
cell.set_style(sheet_.get_parent().get_style(style_id));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -90,4 +90,14 @@ std::string alignment::to_hash_string() const
|
|||
return hash_string;
|
||||
}
|
||||
|
||||
bool alignment::apply() const
|
||||
{
|
||||
return apply_;
|
||||
}
|
||||
|
||||
void alignment::apply(bool value)
|
||||
{
|
||||
apply_ = value;
|
||||
}
|
||||
|
||||
} // namespace xlnt
|
||||
|
|
|
@ -149,4 +149,14 @@ std::string border::to_hash_string() const
|
|||
return hash_string;
|
||||
}
|
||||
|
||||
bool border::apply() const
|
||||
{
|
||||
return apply_;
|
||||
}
|
||||
|
||||
void border::apply(bool value)
|
||||
{
|
||||
apply_ = value;
|
||||
}
|
||||
|
||||
} // namespace xlnt
|
||||
|
|
|
@ -30,17 +30,12 @@
|
|||
|
||||
namespace xlnt {
|
||||
|
||||
cell_style::cell_style(cell parent) : parent_(parent)
|
||||
cell_style::cell_style()
|
||||
{
|
||||
}
|
||||
|
||||
cell_style::cell_style(const cell_style &other)
|
||||
: alignment_(other.alignment_),
|
||||
border_(other.border_),
|
||||
fill_(other.fill_),
|
||||
font_(other.font_),
|
||||
number_format_(other.number_format_),
|
||||
protection_(other.protection_)
|
||||
: common_style(other)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -59,36 +54,6 @@ cell_style &cell_style::operator=(const cell_style &other)
|
|||
return *this;
|
||||
}
|
||||
|
||||
const alignment &cell_style::get_alignment() const
|
||||
{
|
||||
return alignment_;
|
||||
}
|
||||
|
||||
const number_format &cell_style::get_number_format() const
|
||||
{
|
||||
return number_format_;
|
||||
}
|
||||
|
||||
const border &cell_style::get_border() const
|
||||
{
|
||||
return border_;
|
||||
}
|
||||
|
||||
const fill &cell_style::get_fill() const
|
||||
{
|
||||
return fill_;
|
||||
}
|
||||
|
||||
const font &cell_style::get_font() const
|
||||
{
|
||||
return font_;
|
||||
}
|
||||
|
||||
const protection &cell_style::get_protection() const
|
||||
{
|
||||
return protection_;
|
||||
}
|
||||
|
||||
std::string cell_style::to_hash_string() const
|
||||
{
|
||||
std::string hash_string("style");
|
||||
|
|
131
source/styles/common_style.cpp
Normal file
131
source/styles/common_style.cpp
Normal file
|
@ -0,0 +1,131 @@
|
|||
// Copyright (c) 2014-2016 Thomas Fussell
|
||||
// Copyright (c) 2010-2015 openpyxl
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, WRISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE
|
||||
//
|
||||
// @license: http://www.opensource.org/licenses/mit-license.php
|
||||
// @author: see AUTHORS file
|
||||
#include <xlnt/styles/common_style.hpp>
|
||||
|
||||
namespace xlnt {
|
||||
|
||||
common_style::common_style()
|
||||
{
|
||||
}
|
||||
|
||||
common_style::common_style(const common_style &other)
|
||||
{
|
||||
}
|
||||
|
||||
alignment &common_style::get_alignment()
|
||||
{
|
||||
return alignment_;
|
||||
}
|
||||
|
||||
const alignment &common_style::get_alignment() const
|
||||
{
|
||||
return alignment_;
|
||||
}
|
||||
|
||||
void common_style::set_alignment(const xlnt::alignment &new_alignment)
|
||||
{
|
||||
alignment_ = new_alignment;
|
||||
}
|
||||
|
||||
number_format &common_style::get_number_format()
|
||||
{
|
||||
return number_format_;
|
||||
}
|
||||
|
||||
const number_format &common_style::get_number_format() const
|
||||
{
|
||||
return number_format_;
|
||||
}
|
||||
|
||||
void common_style::set_number_format(const xlnt::number_format &new_number_format)
|
||||
{
|
||||
number_format_ = new_number_format;
|
||||
}
|
||||
|
||||
border &common_style::get_border()
|
||||
{
|
||||
return border_;
|
||||
}
|
||||
|
||||
const border &common_style::get_border() const
|
||||
{
|
||||
return border_;
|
||||
}
|
||||
|
||||
void common_style::set_border(const xlnt::border &new_border)
|
||||
{
|
||||
border_ = new_border;
|
||||
}
|
||||
|
||||
fill &common_style::get_fill()
|
||||
{
|
||||
return fill_;
|
||||
}
|
||||
|
||||
const fill &common_style::get_fill() const
|
||||
{
|
||||
return fill_;
|
||||
}
|
||||
|
||||
void common_style::set_fill(const xlnt::fill &new_fill)
|
||||
{
|
||||
fill_ = new_fill;
|
||||
}
|
||||
|
||||
font &common_style::get_font()
|
||||
{
|
||||
return font_;
|
||||
}
|
||||
|
||||
const font &common_style::get_font() const
|
||||
{
|
||||
return font_;
|
||||
}
|
||||
|
||||
void common_style::set_font(const xlnt::font &new_font)
|
||||
{
|
||||
font_ = new_font;
|
||||
}
|
||||
|
||||
protection &common_style::get_protection()
|
||||
{
|
||||
return protection_;
|
||||
}
|
||||
|
||||
const protection &common_style::get_protection() const
|
||||
{
|
||||
return protection_;
|
||||
}
|
||||
|
||||
void common_style::set_protection(const xlnt::protection &new_protection)
|
||||
{
|
||||
protection_ = new_protection;
|
||||
}
|
||||
|
||||
std::string common_style::to_hash_string() const
|
||||
{
|
||||
return "common_style";
|
||||
}
|
||||
|
||||
} // namespace xlnt
|
|
@ -267,4 +267,14 @@ double fill::get_gradient_bottom() const
|
|||
return gradient_path_bottom_;
|
||||
}
|
||||
|
||||
bool fill::apply() const
|
||||
{
|
||||
return apply_;
|
||||
}
|
||||
|
||||
void fill::apply(bool value)
|
||||
{
|
||||
apply_ = value;
|
||||
}
|
||||
|
||||
} // namespace xlnt
|
||||
|
|
|
@ -146,4 +146,14 @@ std::string font::to_hash_string() const
|
|||
return hash_string;
|
||||
}
|
||||
|
||||
bool font::apply() const
|
||||
{
|
||||
return apply_;
|
||||
}
|
||||
|
||||
void font::apply(bool value)
|
||||
{
|
||||
apply_ = value;
|
||||
}
|
||||
|
||||
} // namespace xlnt
|
||||
|
|
71
source/styles/named_style.cpp
Normal file
71
source/styles/named_style.cpp
Normal file
|
@ -0,0 +1,71 @@
|
|||
// Copyright (c) 2014-2016 Thomas Fussell
|
||||
// Copyright (c) 2010-2015 openpyxl
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, WRISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE
|
||||
//
|
||||
// @license: http://www.opensource.org/licenses/mit-license.php
|
||||
// @author: see AUTHORS file
|
||||
#include <xlnt/styles/named_style.hpp>
|
||||
|
||||
namespace xlnt {
|
||||
|
||||
named_style::named_style()
|
||||
{
|
||||
}
|
||||
|
||||
named_style::named_style(const named_style &other)
|
||||
{
|
||||
}
|
||||
|
||||
bool named_style::get_hidden() const
|
||||
{
|
||||
return hidden_;
|
||||
}
|
||||
|
||||
void named_style::set_hidden(bool value)
|
||||
{
|
||||
hidden_ = value;
|
||||
}
|
||||
|
||||
std::size_t named_style::get_builtin_id() const
|
||||
{
|
||||
return builtin_id_;
|
||||
}
|
||||
|
||||
void named_style::set_builtin_id(std::size_t builtin_id)
|
||||
{
|
||||
builtin_id_ = builtin_id;
|
||||
}
|
||||
|
||||
std::string named_style::get_name() const
|
||||
{
|
||||
return name_;
|
||||
}
|
||||
|
||||
void named_style::set_name(const std::string &name)
|
||||
{
|
||||
name_ = name;
|
||||
}
|
||||
|
||||
std::string named_style::to_hash_string() const
|
||||
{
|
||||
return common_style::to_hash_string() + name_;
|
||||
}
|
||||
|
||||
} // namespace xlnt
|
|
@ -1175,4 +1175,14 @@ std::string number_format::format(long double number, calendar base_date) const
|
|||
return format_number(number, format_string_, base_date);
|
||||
}
|
||||
|
||||
bool number_format::apply() const
|
||||
{
|
||||
return apply_;
|
||||
}
|
||||
|
||||
void number_format::apply(bool value)
|
||||
{
|
||||
apply_ = value;
|
||||
}
|
||||
|
||||
} // namespace xlnt
|
||||
|
|
|
@ -54,4 +54,14 @@ std::string protection::to_hash_string() const
|
|||
return hash_string;
|
||||
}
|
||||
|
||||
bool protection::apply() const
|
||||
{
|
||||
return apply_;
|
||||
}
|
||||
|
||||
void protection::apply(bool value)
|
||||
{
|
||||
apply_ = value;
|
||||
}
|
||||
|
||||
} // namespace xlnt
|
||||
|
|
|
@ -37,12 +37,12 @@
|
|||
#include <xlnt/serialization/excel_serializer.hpp>
|
||||
#include <xlnt/styles/alignment.hpp>
|
||||
#include <xlnt/styles/border.hpp>
|
||||
#include <xlnt/styles/cell_style.hpp>
|
||||
#include <xlnt/styles/fill.hpp>
|
||||
#include <xlnt/styles/font.hpp>
|
||||
#include <xlnt/styles/format.hpp>
|
||||
#include <xlnt/styles/named_style.hpp>
|
||||
#include <xlnt/styles/number_format.hpp>
|
||||
#include <xlnt/styles/protection.hpp>
|
||||
#include <xlnt/styles/style.hpp>
|
||||
#include <xlnt/utils/exceptions.hpp>
|
||||
#include <xlnt/workbook/const_worksheet_iterator.hpp>
|
||||
#include <xlnt/workbook/named_range.hpp>
|
||||
|
@ -75,8 +75,6 @@ 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_->encoding_ = encoding::utf8;
|
||||
|
||||
d_->manifest_.add_default_type("rels", "application/vnd.openxmlformats-package.relationships+xml");
|
||||
|
@ -569,48 +567,6 @@ void workbook::set_read_only(bool read_only)
|
|||
d_->read_only_ = read_only;
|
||||
}
|
||||
|
||||
void workbook::add_border(const xlnt::border &border_)
|
||||
{
|
||||
d_->borders_.push_back(border_);
|
||||
}
|
||||
|
||||
void workbook::add_fill(const fill &fill_)
|
||||
{
|
||||
d_->fills_.push_back(fill_);
|
||||
}
|
||||
|
||||
void workbook::add_font(const font &font_)
|
||||
{
|
||||
d_->fonts_.push_back(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_.has_id())
|
||||
{
|
||||
d_->number_formats_.back().set_id(d_->next_custom_format_id_++);
|
||||
}
|
||||
}
|
||||
|
||||
void workbook::add_protection(const xlnt::protection &p)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void workbook::add_alignment(const xlnt::alignment &a)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void workbook::set_code_name(const std::string & /*code_name*/)
|
||||
{
|
||||
}
|
||||
|
@ -640,520 +596,20 @@ std::vector<named_range> workbook::get_named_ranges() const
|
|||
return named_ranges;
|
||||
}
|
||||
|
||||
std::size_t workbook::add_cell_style_format(const xlnt::format &format_)
|
||||
std::size_t workbook::add_style(const cell_style &style)
|
||||
{
|
||||
d_->cell_style_formats_.push_back(format_);
|
||||
d_->cell_style_formats_.back().id_ = d_->cell_style_formats_.size() - 1;
|
||||
|
||||
return d_->cell_style_formats_.back().id_;
|
||||
d_->cell_styles_.push_back(style);
|
||||
return d_->cell_styles_.size();
|
||||
}
|
||||
|
||||
std::size_t workbook::add_cell_format(const xlnt::format &format_)
|
||||
cell_style &workbook::get_style(std::size_t style_index)
|
||||
{
|
||||
d_->cell_formats_.push_back(format_);
|
||||
d_->cell_formats_.back().id_ = d_->cell_formats_.size() - 1;
|
||||
|
||||
return d_->cell_formats_.back().id_;
|
||||
return d_->cell_styles_.at(style_index);
|
||||
}
|
||||
|
||||
std::size_t workbook::add_style(const xlnt::style &style_)
|
||||
const cell_style &workbook::get_style(std::size_t style_index) const
|
||||
{
|
||||
d_->styles_.push_back(style_);
|
||||
d_->styles_.back().id_ = d_->styles_.size() - 1;
|
||||
|
||||
return d_->styles_.back().id_;
|
||||
}
|
||||
|
||||
const std::vector<style> &workbook::get_named_styles() const
|
||||
{
|
||||
static std::vector<style> named_styles;
|
||||
return named_styles;
|
||||
}
|
||||
|
||||
color workbook::add_indexed_color(const color &rgb_color)
|
||||
{
|
||||
std::size_t index = 0;
|
||||
|
||||
for (auto &c : d_->colors_)
|
||||
{
|
||||
if (c.get_rgb_string() == rgb_color.get_rgb_string())
|
||||
{
|
||||
return color(color::type::indexed, index);
|
||||
}
|
||||
|
||||
index++;
|
||||
}
|
||||
|
||||
d_->colors_.push_back(rgb_color);
|
||||
|
||||
return color(color::type::indexed, index);
|
||||
}
|
||||
|
||||
color workbook::get_indexed_color(const color &indexed_color) const
|
||||
{
|
||||
return d_->colors_.at(indexed_color.get_index());
|
||||
}
|
||||
|
||||
const number_format &workbook::get_number_format(std::size_t format_id) const
|
||||
{
|
||||
auto number_format_id = d_->cell_formats_[format_id].number_format_id_;
|
||||
|
||||
for (const auto &number_format_ : d_->number_formats_)
|
||||
{
|
||||
if (number_format_.has_id() && number_format_.get_id() == number_format_id)
|
||||
{
|
||||
return number_format_;
|
||||
}
|
||||
}
|
||||
|
||||
auto nf = number_format::from_builtin_id(number_format_id);
|
||||
d_->number_formats_.push_back(nf);
|
||||
|
||||
return d_->number_formats_.back();
|
||||
}
|
||||
|
||||
const font &workbook::get_font(std::size_t font_id) const
|
||||
{
|
||||
return d_->fonts_[font_id];
|
||||
}
|
||||
|
||||
format &workbook::add_default_cell_format()
|
||||
{
|
||||
format new_format;
|
||||
|
||||
new_format.id_ = 0;
|
||||
new_format.border_id_ = 0;
|
||||
new_format.fill_id_ = 0;
|
||||
new_format.font_id_ = 0;
|
||||
new_format.number_format_id_ = 0;
|
||||
|
||||
if (d_->borders_.empty())
|
||||
{
|
||||
d_->borders_.push_back(new_format.get_border());
|
||||
}
|
||||
|
||||
if (d_->fills_.empty())
|
||||
{
|
||||
d_->fills_.push_back(new_format.get_fill());
|
||||
}
|
||||
|
||||
if (d_->fonts_.empty())
|
||||
{
|
||||
d_->fonts_.push_back(new_format.get_font());
|
||||
}
|
||||
|
||||
if (d_->number_formats_.empty())
|
||||
{
|
||||
d_->number_formats_.push_back(new_format.get_number_format());
|
||||
}
|
||||
|
||||
d_->cell_formats_.push_back(new_format);
|
||||
|
||||
return d_->cell_formats_[0];
|
||||
}
|
||||
|
||||
// find font in font list
|
||||
// if not found, add to font list and make font_id equal to list length - 1
|
||||
// otherwise, font_id is the index of the matching font in font list
|
||||
// if there are no cell formats defined yet, create a new format with components set to default and font as parameter font, return 0
|
||||
// if the font is identical to the font for the cell's format, just return the provided cell format id
|
||||
// make a new cell format based on the existing cell format
|
||||
// set font on this style to the parameter font
|
||||
// see if this modified format already exists in the font list, if so return its id
|
||||
// otherwise, add the new cell format to the list of formats and return its id
|
||||
std::size_t workbook::set_font(const font &font_, std::size_t format_id)
|
||||
{
|
||||
auto match = std::find(d_->fonts_.begin(), d_->fonts_.end(), font_);
|
||||
std::size_t font_id = 0;
|
||||
|
||||
if (match == d_->fonts_.end())
|
||||
{
|
||||
d_->fonts_.push_back(font_);
|
||||
font_id = d_->fonts_.size() - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
font_id = match - d_->fonts_.begin();
|
||||
}
|
||||
|
||||
if (d_->cell_formats_.empty())
|
||||
{
|
||||
auto &added = add_default_cell_format();
|
||||
|
||||
added.font_id_ = font_id;
|
||||
added.font_ = font_;
|
||||
added.font_apply_ = true;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
auto &existing_format = d_->cell_formats_[format_id];
|
||||
existing_format.font_apply_ = true;
|
||||
|
||||
// If the style is unchanged, just return it.
|
||||
if (font_id == existing_format.font_id_)
|
||||
{
|
||||
return format_id;
|
||||
}
|
||||
|
||||
// Make a new format based on existing format.
|
||||
auto new_format = existing_format;
|
||||
|
||||
new_format.font_id_ = font_id;
|
||||
new_format.font_ = font_;
|
||||
|
||||
// Check if the new modified style is already applied to a different cell. If so, reuse it.
|
||||
auto format_match = std::find(d_->cell_formats_.begin(), d_->cell_formats_.end(), new_format);
|
||||
|
||||
if (format_match != d_->cell_formats_.end())
|
||||
{
|
||||
return format_match->get_id();
|
||||
}
|
||||
|
||||
// No match found, so add it.
|
||||
new_format.id_ = d_->cell_formats_.size();
|
||||
d_->cell_formats_.push_back(new_format);
|
||||
|
||||
return new_format.id_;
|
||||
}
|
||||
|
||||
const format &workbook::get_cell_format(std::size_t format_id) const
|
||||
{
|
||||
return d_->cell_formats_.at(format_id);
|
||||
}
|
||||
|
||||
const fill &workbook::get_fill(std::size_t fill_id) const
|
||||
{
|
||||
return d_->fills_[fill_id];
|
||||
}
|
||||
|
||||
std::size_t workbook::set_fill(const fill & fill_, std::size_t format_id)
|
||||
{
|
||||
auto match = std::find(d_->fills_.begin(), d_->fills_.end(), fill_);
|
||||
std::size_t fill_id = 0;
|
||||
|
||||
if (match == d_->fills_.end())
|
||||
{
|
||||
d_->fills_.push_back(fill_);
|
||||
fill_id = d_->fills_.size() - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
fill_id = match - d_->fills_.begin();
|
||||
}
|
||||
|
||||
if (d_->cell_formats_.empty())
|
||||
{
|
||||
auto &added = add_default_cell_format();
|
||||
|
||||
added.fill_id_ = fill_id;
|
||||
added.fill_ = fill_;
|
||||
added.fill_apply_ = true;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
auto &existing_format = d_->cell_formats_[format_id];
|
||||
existing_format.fill_apply_ = true;
|
||||
|
||||
// If the style is unchanged, just return it.
|
||||
if (fill_id == existing_format.fill_id_)
|
||||
{
|
||||
return format_id;
|
||||
}
|
||||
|
||||
// Make a new format based on existing format.
|
||||
auto new_format = existing_format;
|
||||
|
||||
new_format.fill_id_ = fill_id;
|
||||
new_format.fill_ = fill_;
|
||||
|
||||
// Check if the new modified style is already applied to a different cell. If so, reuse it.
|
||||
auto format_match = std::find(d_->cell_formats_.begin(), d_->cell_formats_.end(), new_format);
|
||||
|
||||
if (format_match != d_->cell_formats_.end())
|
||||
{
|
||||
return format_match->get_id();
|
||||
}
|
||||
|
||||
// No match found, so add it.
|
||||
new_format.id_ = d_->cell_formats_.size();
|
||||
d_->cell_formats_.push_back(new_format);
|
||||
|
||||
return new_format.id_;
|
||||
}
|
||||
|
||||
const border &workbook::get_border(std::size_t border_id) const
|
||||
{
|
||||
return d_->borders_[border_id];
|
||||
}
|
||||
|
||||
std::size_t workbook::set_border(const border & border_, std::size_t format_id)
|
||||
{
|
||||
auto match = std::find(d_->borders_.begin(), d_->borders_.end(), border_);
|
||||
std::size_t border_id = 0;
|
||||
|
||||
if (match == d_->borders_.end())
|
||||
{
|
||||
d_->borders_.push_back(border_);
|
||||
border_id = d_->borders_.size() - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
border_id = match - d_->borders_.begin();
|
||||
}
|
||||
|
||||
if (d_->cell_formats_.empty())
|
||||
{
|
||||
auto &added = add_default_cell_format();
|
||||
|
||||
added.border_id_ = border_id;
|
||||
added.border_ = border_;
|
||||
added.border_apply_ = true;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
auto &existing_format = d_->cell_formats_[format_id];
|
||||
existing_format.border_apply_ = true;
|
||||
|
||||
// If the style is unchanged, just return it.
|
||||
if (border_id == existing_format.border_id_)
|
||||
{
|
||||
return format_id;
|
||||
}
|
||||
|
||||
// Make a new format based on existing format.
|
||||
auto new_format = existing_format;
|
||||
|
||||
new_format.border_id_ = border_id;
|
||||
new_format.border_ = border_;
|
||||
|
||||
// Check if the new modified style is already applied to a different cell. If so, reuse it.
|
||||
auto format_match = std::find(d_->cell_formats_.begin(), d_->cell_formats_.end(), new_format);
|
||||
|
||||
if (format_match != d_->cell_formats_.end())
|
||||
{
|
||||
return format_match->get_id();
|
||||
}
|
||||
|
||||
// No match found, so add it.
|
||||
new_format.id_ = d_->cell_formats_.size();
|
||||
d_->cell_formats_.push_back(new_format);
|
||||
|
||||
return new_format.id_;
|
||||
}
|
||||
|
||||
const alignment &workbook::get_alignment(std::size_t format_id) const
|
||||
{
|
||||
return d_->cell_formats_[format_id].alignment_;
|
||||
}
|
||||
|
||||
// differs from border, fill, font, number_format because alignment is a member of format
|
||||
std::size_t workbook::set_alignment(const alignment & alignment_, std::size_t format_id)
|
||||
{
|
||||
if (d_->cell_formats_.empty())
|
||||
{
|
||||
auto &added = add_default_cell_format();
|
||||
|
||||
added.alignment_ = alignment_;
|
||||
added.alignment_apply_ = true;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
auto &existing_format = d_->cell_formats_[format_id];
|
||||
existing_format.alignment_apply_ = true;
|
||||
|
||||
// If the style is unchanged, just return it.
|
||||
if (alignment_ == existing_format.alignment_)
|
||||
{
|
||||
return format_id;
|
||||
}
|
||||
|
||||
// Make a new format based on existing format.
|
||||
auto new_format = existing_format;
|
||||
|
||||
new_format.alignment_ = alignment_;
|
||||
|
||||
// Check if the new modified style is already applied to a different cell. If so, reuse it.
|
||||
auto format_match = std::find(d_->cell_formats_.begin(), d_->cell_formats_.end(), new_format);
|
||||
|
||||
if (format_match != d_->cell_formats_.end())
|
||||
{
|
||||
return format_match->get_id();
|
||||
}
|
||||
|
||||
// No match found, so add it.
|
||||
new_format.id_ = d_->cell_formats_.size();
|
||||
d_->cell_formats_.push_back(new_format);
|
||||
|
||||
return new_format.id_;
|
||||
}
|
||||
|
||||
const protection &workbook::get_protection(std::size_t format_id) const
|
||||
{
|
||||
return d_->cell_formats_[format_id].protection_;
|
||||
}
|
||||
|
||||
// differs from border, fill, font, number_format because protection is a member of format
|
||||
std::size_t workbook::set_protection(const protection & protection_, std::size_t format_id)
|
||||
{
|
||||
if (d_->cell_formats_.empty())
|
||||
{
|
||||
auto &added = add_default_cell_format();
|
||||
|
||||
added.protection_ = protection_;
|
||||
added.protection_apply_ = true;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
auto &existing_format = d_->cell_formats_[format_id];
|
||||
existing_format.protection_apply_ = true;
|
||||
|
||||
// If the style is unchanged, just return it.
|
||||
if (protection_ == existing_format.protection_)
|
||||
{
|
||||
return format_id;
|
||||
}
|
||||
|
||||
// Make a new format based on existing format.
|
||||
auto new_format = existing_format;
|
||||
|
||||
new_format.protection_ = protection_;
|
||||
|
||||
// Check if the new modified style is already applied to a different cell. If so, reuse it.
|
||||
auto format_match = std::find(d_->cell_formats_.begin(), d_->cell_formats_.end(), new_format);
|
||||
|
||||
if (format_match != d_->cell_formats_.end())
|
||||
{
|
||||
return format_match->get_id();
|
||||
}
|
||||
|
||||
// No match found, so add it.
|
||||
new_format.id_ = d_->cell_formats_.size();
|
||||
d_->cell_formats_.push_back(new_format);
|
||||
|
||||
return new_format.id_;
|
||||
}
|
||||
|
||||
bool workbook::get_pivot_button(std::size_t format_id) const
|
||||
{
|
||||
return d_->cell_formats_[format_id].pivot_button_;
|
||||
}
|
||||
|
||||
bool workbook::get_quote_prefix(std::size_t format_id) const
|
||||
{
|
||||
return d_->cell_formats_[format_id].quote_prefix_;
|
||||
}
|
||||
|
||||
//TODO: this is terrible!
|
||||
std::size_t workbook::set_number_format(const xlnt::number_format &number_format_, std::size_t format_id)
|
||||
{
|
||||
auto match = std::find(d_->number_formats_.begin(), d_->number_formats_.end(), number_format_);
|
||||
std::size_t number_format_id = 0;
|
||||
|
||||
if (match == d_->number_formats_.end())
|
||||
{
|
||||
d_->number_formats_.push_back(number_format_);
|
||||
|
||||
if (!number_format_.has_id())
|
||||
{
|
||||
d_->number_formats_.back().set_id(d_->next_custom_format_id_++);
|
||||
}
|
||||
|
||||
number_format_id = d_->number_formats_.back().get_id();
|
||||
}
|
||||
else
|
||||
{
|
||||
number_format_id = match->get_id();
|
||||
}
|
||||
|
||||
if (d_->cell_formats_.empty())
|
||||
{
|
||||
auto &added = add_default_cell_format();
|
||||
|
||||
added.number_format_id_ = number_format_id;
|
||||
added.number_format_ = number_format_;
|
||||
added.number_format_apply_ = true;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
auto &existing_format = d_->cell_formats_[format_id];
|
||||
existing_format.number_format_apply_ = true;
|
||||
|
||||
// If the style is unchanged, just return it.
|
||||
if (number_format_id == existing_format.number_format_id_)
|
||||
{
|
||||
return format_id;
|
||||
}
|
||||
|
||||
// Make a new format based on existing format.
|
||||
auto new_format = existing_format;
|
||||
|
||||
new_format.number_format_id_ = number_format_id;
|
||||
new_format.number_format_ = number_format_;
|
||||
|
||||
// Check if the new modified style is already applied to a different cell. If so, reuse it.
|
||||
auto format_match = std::find(d_->cell_formats_.begin(), d_->cell_formats_.end(), new_format);
|
||||
|
||||
if (format_match != d_->cell_formats_.end())
|
||||
{
|
||||
return format_match->get_id();
|
||||
}
|
||||
|
||||
// No match found, so add it.
|
||||
new_format.id_ = d_->cell_formats_.size();
|
||||
d_->cell_formats_.push_back(new_format);
|
||||
|
||||
return new_format.id_;
|
||||
}
|
||||
|
||||
const std::vector<format> &workbook::get_cell_formats() const
|
||||
{
|
||||
return d_->cell_formats_;
|
||||
}
|
||||
|
||||
const std::vector<format> &workbook::get_cell_style_formats() const
|
||||
{
|
||||
return d_->cell_style_formats_;
|
||||
}
|
||||
|
||||
const std::vector<style> &workbook::get_styles() const
|
||||
{
|
||||
return d_->styles_;
|
||||
}
|
||||
|
||||
const std::vector<number_format> &workbook::get_number_formats() const
|
||||
{
|
||||
return d_->number_formats_;
|
||||
}
|
||||
|
||||
const std::vector<font> &workbook::get_fonts() const
|
||||
{
|
||||
return d_->fonts_;
|
||||
}
|
||||
|
||||
const std::vector<border> &workbook::get_borders() const
|
||||
{
|
||||
return d_->borders_;
|
||||
}
|
||||
|
||||
const std::vector<fill> &workbook::get_fills() const
|
||||
{
|
||||
return d_->fills_;
|
||||
}
|
||||
|
||||
void workbook::add_color(const color &rgb)
|
||||
{
|
||||
d_->colors_.push_back(rgb);
|
||||
}
|
||||
|
||||
const std::vector<color> &workbook::get_colors() const
|
||||
{
|
||||
return d_->colors_;
|
||||
return d_->cell_styles_.at(style_index);
|
||||
}
|
||||
|
||||
manifest &workbook::get_manifest()
|
||||
|
|
Loading…
Reference in New Issue
Block a user