2018-01-22 22:38:48 +08:00
|
|
|
// Copyright (c) 2014-2018 Thomas Fussell
|
2016-06-11 01:40:50 +08:00
|
|
|
// 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
|
|
|
|
#pragma once
|
|
|
|
|
2016-08-18 19:34:18 +08:00
|
|
|
#include <list>
|
2016-06-11 01:40:50 +08:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2017-04-21 02:03:03 +08:00
|
|
|
#include <detail/implementations/conditional_format_impl.hpp>
|
|
|
|
#include <detail/implementations/format_impl.hpp>
|
|
|
|
#include <detail/implementations/style_impl.hpp>
|
2016-11-04 07:26:11 +08:00
|
|
|
#include <xlnt/cell/cell.hpp>
|
2017-04-04 07:24:36 +08:00
|
|
|
#include <xlnt/styles/conditional_format.hpp>
|
2016-06-11 01:40:50 +08:00
|
|
|
#include <xlnt/styles/format.hpp>
|
|
|
|
#include <xlnt/styles/style.hpp>
|
2016-08-16 12:23:49 +08:00
|
|
|
#include <xlnt/utils/exceptions.hpp>
|
2016-11-04 07:26:11 +08:00
|
|
|
#include <xlnt/workbook/workbook.hpp>
|
|
|
|
#include <xlnt/workbook/worksheet_iterator.hpp>
|
2017-04-04 07:24:36 +08:00
|
|
|
#include <xlnt/worksheet/worksheet.hpp>
|
2016-06-11 01:40:50 +08:00
|
|
|
|
|
|
|
namespace xlnt {
|
|
|
|
namespace detail {
|
|
|
|
|
|
|
|
struct stylesheet
|
|
|
|
{
|
2016-12-03 23:35:48 +08:00
|
|
|
class format create_format(bool default_format)
|
2016-06-11 01:40:50 +08:00
|
|
|
{
|
2016-11-03 10:04:51 +08:00
|
|
|
format_impls.push_back(format_impl());
|
|
|
|
auto &impl = format_impls.back();
|
2016-11-04 07:26:11 +08:00
|
|
|
|
2016-11-03 10:04:51 +08:00
|
|
|
impl.parent = this;
|
|
|
|
impl.id = format_impls.size() - 1;
|
2019-03-06 17:45:08 +08:00
|
|
|
|
2016-11-10 08:52:18 +08:00
|
|
|
impl.references = default_format ? 1 : 0;
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
return xlnt::format(&impl);
|
2016-06-11 01:40:50 +08:00
|
|
|
}
|
2016-08-16 12:23:49 +08:00
|
|
|
|
2016-12-03 23:35:48 +08:00
|
|
|
class xlnt::format format(std::size_t index)
|
2016-11-10 08:52:18 +08:00
|
|
|
{
|
2016-11-08 10:11:30 +08:00
|
|
|
auto iter = format_impls.begin();
|
2016-11-10 08:52:18 +08:00
|
|
|
std::advance(iter, static_cast<std::list<format_impl>::difference_type>(index));
|
2017-04-04 07:49:38 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
return xlnt::format(&*iter);
|
2016-11-10 08:52:18 +08:00
|
|
|
}
|
|
|
|
|
2016-11-08 10:11:30 +08:00
|
|
|
class style create_style(const std::string &name)
|
2016-06-11 01:40:50 +08:00
|
|
|
{
|
2016-11-08 10:11:30 +08:00
|
|
|
auto &impl = style_impls.emplace(name, style_impl()).first->second;
|
|
|
|
|
2016-08-18 19:34:18 +08:00
|
|
|
impl.parent = this;
|
2016-11-08 10:11:30 +08:00
|
|
|
impl.name = name;
|
|
|
|
|
|
|
|
impl.border_id = 0;
|
|
|
|
impl.fill_id = 0;
|
|
|
|
impl.font_id = 0;
|
|
|
|
impl.number_format_id = 0;
|
|
|
|
|
|
|
|
style_names.push_back(name);
|
|
|
|
return xlnt::style(&impl);
|
2016-08-16 12:23:49 +08:00
|
|
|
}
|
2016-06-11 01:40:50 +08:00
|
|
|
|
2017-03-26 22:30:26 +08:00
|
|
|
class style create_builtin_style(const std::size_t builtin_id)
|
|
|
|
{
|
|
|
|
// From Annex G.2
|
|
|
|
static const auto *names = new std::unordered_map<std::size_t , std::string>
|
|
|
|
{
|
|
|
|
{ 0, "Normal" },
|
|
|
|
{ 1, "RowLevel_1" },
|
|
|
|
{ 2, "ColLevel_1" },
|
|
|
|
{ 3, "Comma" },
|
|
|
|
{ 4, "Currency" },
|
|
|
|
{ 5, "Percent" },
|
|
|
|
{ 6, "Comma [0]" },
|
|
|
|
{ 7, "Currency [0]" },
|
|
|
|
{ 8, "Hyperlink" },
|
|
|
|
{ 9, "Followed Hyperlink" },
|
|
|
|
{ 10, "Note" },
|
|
|
|
{ 11, "Warning Text" },
|
|
|
|
{ 15, "Title" },
|
|
|
|
{ 16, "Heading 1" },
|
|
|
|
{ 17, "Heading 2" },
|
|
|
|
{ 18, "Heading 3" },
|
|
|
|
{ 19, "Heading 4" },
|
|
|
|
{ 20, "Input" },
|
|
|
|
{ 21, "Output"},
|
|
|
|
{ 22, "Calculation"},
|
|
|
|
{ 22, "Calculation" },
|
|
|
|
{ 23, "Check Cell" },
|
|
|
|
{ 24, "Linked Cell" },
|
|
|
|
{ 25, "Total" },
|
|
|
|
{ 26, "Good" },
|
|
|
|
{ 27, "Bad" },
|
|
|
|
{ 28, "Neutral" },
|
|
|
|
{ 29, "Accent1" },
|
|
|
|
{ 30, "20% - Accent1" },
|
|
|
|
{ 31, "40% - Accent1" },
|
|
|
|
{ 32, "60% - Accent1" },
|
|
|
|
{ 33, "Accent2" },
|
|
|
|
{ 34, "20% - Accent2" },
|
|
|
|
{ 35, "40% - Accent2" },
|
|
|
|
{ 36, "60% - Accent2" },
|
|
|
|
{ 37, "Accent3" },
|
|
|
|
{ 38, "20% - Accent3" },
|
|
|
|
{ 39, "40% - Accent3" },
|
|
|
|
{ 40, "60% - Accent3" },
|
|
|
|
{ 41, "Accent4" },
|
|
|
|
{ 42, "20% - Accent4" },
|
|
|
|
{ 43, "40% - Accent4" },
|
|
|
|
{ 44, "60% - Accent4" },
|
|
|
|
{ 45, "Accent5" },
|
|
|
|
{ 46, "20% - Accent5" },
|
|
|
|
{ 47, "40% - Accent5" },
|
|
|
|
{ 48, "60% - Accent5" },
|
|
|
|
{ 49, "Accent6" },
|
|
|
|
{ 50, "20% - Accent6" },
|
|
|
|
{ 51, "40% - Accent6" },
|
|
|
|
{ 52, "60% - Accent6" },
|
|
|
|
{ 53, "Explanatory Text" }
|
|
|
|
};
|
|
|
|
|
|
|
|
auto new_style = create_style(names->at(builtin_id));
|
|
|
|
new_style.d_->builtin_id = builtin_id;
|
|
|
|
|
|
|
|
return new_style;
|
|
|
|
}
|
|
|
|
|
2016-11-08 10:11:30 +08:00
|
|
|
class style style(const std::string &name)
|
2016-08-16 12:23:49 +08:00
|
|
|
{
|
2016-11-08 10:11:30 +08:00
|
|
|
if (!has_style(name)) throw key_not_found();
|
|
|
|
return xlnt::style(&style_impls[name]);
|
2016-08-16 12:23:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool has_style(const std::string &name)
|
|
|
|
{
|
2016-11-08 10:11:30 +08:00
|
|
|
return style_impls.count(name) > 0;
|
2016-08-16 12:23:49 +08:00
|
|
|
}
|
|
|
|
|
2016-08-18 19:34:18 +08:00
|
|
|
std::size_t next_custom_number_format_id() const
|
|
|
|
{
|
|
|
|
std::size_t id = 164;
|
|
|
|
|
|
|
|
for (const auto &nf : number_formats)
|
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
if (nf.id() >= id)
|
2016-08-18 19:34:18 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
id = nf.id() + 1;
|
2016-08-18 19:34:18 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return id;
|
|
|
|
}
|
2016-09-08 06:02:46 +08:00
|
|
|
|
2016-11-08 10:11:30 +08:00
|
|
|
template<typename T, typename C>
|
2018-07-29 12:48:18 +08:00
|
|
|
std::size_t find_or_add(C &container, const T &item)
|
2016-09-10 22:05:06 +08:00
|
|
|
{
|
2018-07-29 13:07:21 +08:00
|
|
|
#pragma GCC diagnostic push
|
|
|
|
#pragma GCC diagnostic ignored "-Wsign-conversion"
|
2018-07-29 12:48:18 +08:00
|
|
|
auto iter = std::find(container.begin(), container.end(), item);
|
|
|
|
if (iter != container.end())
|
2016-12-30 07:36:29 +08:00
|
|
|
{
|
2018-07-29 13:07:21 +08:00
|
|
|
return std::size_t(iter - container.begin());
|
2016-12-30 07:36:29 +08:00
|
|
|
}
|
2018-07-29 13:07:21 +08:00
|
|
|
iter = container.emplace(container.end(), item);
|
|
|
|
return std::size_t(iter - container.begin());
|
|
|
|
#pragma GCC diagnostic pop
|
2016-09-10 22:05:06 +08:00
|
|
|
}
|
|
|
|
|
2016-11-08 10:11:30 +08:00
|
|
|
template<typename T>
|
|
|
|
std::unordered_map<std::size_t, std::size_t> garbage_collect(
|
|
|
|
const std::unordered_map<std::size_t, std::size_t> &reference_counts,
|
|
|
|
std::vector<T> &container)
|
2016-09-10 22:05:06 +08:00
|
|
|
{
|
2016-11-08 10:11:30 +08:00
|
|
|
std::unordered_map<std::size_t, std::size_t> id_map;
|
|
|
|
std::size_t unreferenced = 0;
|
|
|
|
const auto original_size = container.size();
|
|
|
|
|
|
|
|
for (std::size_t i = 0; i < original_size; ++i)
|
2016-09-10 22:05:06 +08:00
|
|
|
{
|
2016-11-08 10:11:30 +08:00
|
|
|
id_map[i] = i - unreferenced;
|
|
|
|
|
|
|
|
if (reference_counts.count(i) == 0 || reference_counts.at(i) == 0)
|
2016-09-10 22:05:06 +08:00
|
|
|
{
|
2016-11-10 08:52:18 +08:00
|
|
|
container.erase(container.begin() + static_cast<typename std::vector<T>::difference_type>(i - unreferenced));
|
2016-11-08 10:11:30 +08:00
|
|
|
unreferenced++;
|
2016-09-10 22:05:06 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-08 10:11:30 +08:00
|
|
|
return id_map;
|
2016-09-10 22:05:06 +08:00
|
|
|
}
|
|
|
|
|
2016-11-10 08:52:18 +08:00
|
|
|
void garbage_collect()
|
2016-09-08 06:02:46 +08:00
|
|
|
{
|
2016-11-08 10:11:30 +08:00
|
|
|
if (!garbage_collection_enabled) return;
|
|
|
|
|
2016-11-10 08:52:18 +08:00
|
|
|
auto format_iter = format_impls.begin();
|
|
|
|
while (format_iter != format_impls.end())
|
2016-11-08 10:11:30 +08:00
|
|
|
{
|
2016-11-10 08:52:18 +08:00
|
|
|
auto &impl = *format_iter;
|
|
|
|
|
|
|
|
if (impl.references != 0)
|
2016-11-08 10:11:30 +08:00
|
|
|
{
|
2016-11-10 08:52:18 +08:00
|
|
|
++format_iter;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
format_iter = format_impls.erase(format_iter);
|
2016-11-08 10:11:30 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::size_t new_id = 0;
|
|
|
|
|
|
|
|
std::unordered_map<std::size_t, std::size_t> alignment_reference_counts;
|
|
|
|
std::unordered_map<std::size_t, std::size_t> border_reference_counts;
|
|
|
|
std::unordered_map<std::size_t, std::size_t> fill_reference_counts;
|
|
|
|
std::unordered_map<std::size_t, std::size_t> font_reference_counts;
|
|
|
|
std::unordered_map<std::size_t, std::size_t> number_format_reference_counts;
|
|
|
|
std::unordered_map<std::size_t, std::size_t> protection_reference_counts;
|
|
|
|
|
2016-11-10 08:52:18 +08:00
|
|
|
fill_reference_counts[0]++;
|
|
|
|
fill_reference_counts[1]++;
|
|
|
|
|
2016-11-08 10:11:30 +08:00
|
|
|
for (auto &impl : format_impls)
|
|
|
|
{
|
|
|
|
impl.id = new_id++;
|
|
|
|
|
|
|
|
if (impl.alignment_id.is_set())
|
|
|
|
{
|
|
|
|
alignment_reference_counts[impl.alignment_id.get()]++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (impl.border_id.is_set())
|
|
|
|
{
|
|
|
|
border_reference_counts[impl.border_id.get()]++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (impl.fill_id.is_set())
|
|
|
|
{
|
|
|
|
fill_reference_counts[impl.fill_id.get()]++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (impl.font_id.is_set())
|
|
|
|
{
|
|
|
|
font_reference_counts[impl.font_id.get()]++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (impl.number_format_id.is_set())
|
|
|
|
{
|
|
|
|
number_format_reference_counts[impl.number_format_id.get()]++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (impl.protection_id.is_set())
|
|
|
|
{
|
|
|
|
protection_reference_counts[impl.protection_id.get()]++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto &name_impl_pair : style_impls)
|
|
|
|
{
|
|
|
|
auto &impl = name_impl_pair.second;
|
|
|
|
|
|
|
|
if (impl.alignment_id.is_set())
|
|
|
|
{
|
|
|
|
alignment_reference_counts[impl.alignment_id.get()]++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (impl.border_id.is_set())
|
|
|
|
{
|
|
|
|
border_reference_counts[impl.border_id.get()]++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (impl.fill_id.is_set())
|
|
|
|
{
|
|
|
|
fill_reference_counts[impl.fill_id.get()]++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (impl.font_id.is_set())
|
|
|
|
{
|
|
|
|
font_reference_counts[impl.font_id.get()]++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (impl.number_format_id.is_set())
|
|
|
|
{
|
|
|
|
number_format_reference_counts[impl.number_format_id.get()]++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (impl.protection_id.is_set())
|
|
|
|
{
|
|
|
|
protection_reference_counts[impl.protection_id.get()]++;
|
|
|
|
}
|
|
|
|
}
|
2016-09-08 06:02:46 +08:00
|
|
|
|
2016-11-08 10:11:30 +08:00
|
|
|
auto alignment_id_map = garbage_collect(alignment_reference_counts, alignments);
|
|
|
|
auto border_id_map = garbage_collect(border_reference_counts, borders);
|
|
|
|
auto fill_id_map = garbage_collect(fill_reference_counts, fills);
|
|
|
|
auto font_id_map = garbage_collect(font_reference_counts, fonts);
|
|
|
|
auto protection_id_map = garbage_collect(protection_reference_counts, protections);
|
|
|
|
|
|
|
|
for (auto &impl : format_impls)
|
2016-09-08 06:02:46 +08:00
|
|
|
{
|
2016-11-08 10:11:30 +08:00
|
|
|
if (impl.alignment_id.is_set())
|
2016-09-08 06:02:46 +08:00
|
|
|
{
|
2016-11-08 10:11:30 +08:00
|
|
|
impl.alignment_id = alignment_id_map[impl.alignment_id.get()];
|
2016-09-08 06:02:46 +08:00
|
|
|
}
|
|
|
|
|
2016-11-08 10:11:30 +08:00
|
|
|
if (impl.border_id.is_set())
|
|
|
|
{
|
|
|
|
impl.border_id = border_id_map[impl.border_id.get()];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (impl.fill_id.is_set())
|
|
|
|
{
|
|
|
|
impl.fill_id = fill_id_map[impl.fill_id.get()];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (impl.font_id.is_set())
|
|
|
|
{
|
|
|
|
impl.font_id = font_id_map[impl.font_id.get()];
|
|
|
|
}
|
|
|
|
|
2016-11-10 08:52:18 +08:00
|
|
|
if (impl.protection_id.is_set())
|
2016-11-08 10:11:30 +08:00
|
|
|
{
|
2016-11-10 08:52:18 +08:00
|
|
|
impl.protection_id = protection_id_map[impl.protection_id.get()];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto &name_impl : style_impls)
|
|
|
|
{
|
|
|
|
auto &impl = name_impl.second;
|
|
|
|
|
|
|
|
if (impl.alignment_id.is_set())
|
|
|
|
{
|
|
|
|
impl.alignment_id = alignment_id_map[impl.alignment_id.get()];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (impl.border_id.is_set())
|
|
|
|
{
|
|
|
|
impl.border_id = border_id_map[impl.border_id.get()];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (impl.fill_id.is_set())
|
|
|
|
{
|
|
|
|
impl.fill_id = fill_id_map[impl.fill_id.get()];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (impl.font_id.is_set())
|
|
|
|
{
|
|
|
|
impl.font_id = font_id_map[impl.font_id.get()];
|
2016-11-08 10:11:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (impl.protection_id.is_set())
|
|
|
|
{
|
|
|
|
impl.protection_id = protection_id_map[impl.protection_id.get()];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-10 08:52:18 +08:00
|
|
|
format_impl *find_or_create(format_impl &pattern)
|
2016-11-08 10:11:30 +08:00
|
|
|
{
|
2018-03-21 21:03:37 +08:00
|
|
|
pattern.references = 0;
|
2018-07-29 13:07:21 +08:00
|
|
|
std::size_t id = 0;
|
2018-07-29 12:48:18 +08:00
|
|
|
auto iter = format_impls.begin();
|
|
|
|
while (iter != format_impls.end() && !(*iter == pattern))
|
|
|
|
{
|
|
|
|
++id;
|
|
|
|
++iter;
|
|
|
|
}
|
|
|
|
if (iter == format_impls.end())
|
|
|
|
{
|
|
|
|
iter = format_impls.emplace(format_impls.end(), pattern);
|
|
|
|
}
|
2016-11-08 10:11:30 +08:00
|
|
|
auto &result = *iter;
|
|
|
|
|
|
|
|
result.parent = this;
|
|
|
|
result.id = id;
|
2016-12-30 07:36:29 +08:00
|
|
|
result.references++;
|
2016-11-08 10:11:30 +08:00
|
|
|
|
|
|
|
if (id != pattern.id)
|
|
|
|
{
|
2018-03-21 21:03:37 +08:00
|
|
|
iter = format_impls.begin();
|
|
|
|
std::advance(iter, static_cast<std::list<format_impl>::difference_type>(pattern.id));
|
|
|
|
iter->references -= iter->references > 0 ? 1 : 0;
|
2016-11-10 08:52:18 +08:00
|
|
|
garbage_collect();
|
2016-09-08 06:02:46 +08:00
|
|
|
}
|
2016-11-08 10:11:30 +08:00
|
|
|
|
|
|
|
return &result;
|
|
|
|
}
|
|
|
|
|
2016-11-10 08:52:18 +08:00
|
|
|
format_impl *find_or_create_with(format_impl *pattern, const std::string &style_name)
|
|
|
|
{
|
|
|
|
format_impl new_format = *pattern;
|
|
|
|
new_format.style = style_name;
|
2018-07-29 18:10:56 +08:00
|
|
|
if (pattern->references == 0)
|
|
|
|
{
|
|
|
|
*pattern = new_format;
|
|
|
|
}
|
2016-11-10 08:52:18 +08:00
|
|
|
return find_or_create(new_format);
|
|
|
|
}
|
|
|
|
|
2018-04-25 05:58:17 +08:00
|
|
|
format_impl *find_or_create_with(format_impl *pattern, const alignment &new_alignment, optional<bool> applied)
|
2016-11-08 10:11:30 +08:00
|
|
|
{
|
|
|
|
format_impl new_format = *pattern;
|
|
|
|
new_format.alignment_id = find_or_add(alignments, new_alignment);
|
|
|
|
new_format.alignment_applied = applied;
|
2018-07-29 18:10:56 +08:00
|
|
|
if (pattern->references == 0)
|
|
|
|
{
|
|
|
|
*pattern = new_format;
|
|
|
|
}
|
2016-11-08 10:11:30 +08:00
|
|
|
return find_or_create(new_format);
|
|
|
|
}
|
2016-09-08 06:02:46 +08:00
|
|
|
|
2018-04-25 05:58:17 +08:00
|
|
|
format_impl *find_or_create_with(format_impl *pattern, const border &new_border, optional<bool> applied)
|
2016-11-08 10:11:30 +08:00
|
|
|
{
|
|
|
|
format_impl new_format = *pattern;
|
|
|
|
new_format.border_id = find_or_add(borders, new_border);
|
|
|
|
new_format.border_applied = applied;
|
2018-07-29 18:10:56 +08:00
|
|
|
if (pattern->references == 0)
|
|
|
|
{
|
|
|
|
*pattern = new_format;
|
|
|
|
}
|
2016-11-08 10:11:30 +08:00
|
|
|
return find_or_create(new_format);
|
|
|
|
}
|
|
|
|
|
2018-04-25 05:58:17 +08:00
|
|
|
format_impl *find_or_create_with(format_impl *pattern, const fill &new_fill, optional<bool> applied)
|
2016-11-08 10:11:30 +08:00
|
|
|
{
|
|
|
|
format_impl new_format = *pattern;
|
|
|
|
new_format.fill_id = find_or_add(fills, new_fill);
|
|
|
|
new_format.fill_applied = applied;
|
2018-07-29 18:10:56 +08:00
|
|
|
if (pattern->references == 0)
|
|
|
|
{
|
|
|
|
*pattern = new_format;
|
|
|
|
}
|
2016-11-08 10:11:30 +08:00
|
|
|
return find_or_create(new_format);
|
|
|
|
}
|
|
|
|
|
2018-04-25 05:58:17 +08:00
|
|
|
format_impl *find_or_create_with(format_impl *pattern, const font &new_font, optional<bool> applied)
|
2016-11-08 10:11:30 +08:00
|
|
|
{
|
|
|
|
format_impl new_format = *pattern;
|
|
|
|
new_format.font_id = find_or_add(fonts, new_font);
|
|
|
|
new_format.font_applied = applied;
|
2018-07-29 18:10:56 +08:00
|
|
|
if (pattern->references == 0)
|
|
|
|
{
|
|
|
|
*pattern = new_format;
|
|
|
|
}
|
2016-11-08 10:11:30 +08:00
|
|
|
return find_or_create(new_format);
|
|
|
|
}
|
|
|
|
|
2018-04-25 05:58:17 +08:00
|
|
|
format_impl *find_or_create_with(format_impl *pattern, const number_format &new_number_format, optional<bool> applied)
|
2016-11-08 10:11:30 +08:00
|
|
|
{
|
|
|
|
format_impl new_format = *pattern;
|
2016-12-30 07:36:29 +08:00
|
|
|
if (new_number_format.id() >= 164)
|
|
|
|
{
|
|
|
|
find_or_add(number_formats, new_number_format);
|
|
|
|
}
|
|
|
|
new_format.number_format_id = new_number_format.id();
|
2016-11-08 10:11:30 +08:00
|
|
|
new_format.number_format_applied = applied;
|
2018-07-29 18:10:56 +08:00
|
|
|
if (pattern->references == 0)
|
|
|
|
{
|
|
|
|
*pattern = new_format;
|
|
|
|
}
|
2016-11-08 10:11:30 +08:00
|
|
|
return find_or_create(new_format);
|
|
|
|
}
|
|
|
|
|
2018-04-25 05:58:17 +08:00
|
|
|
format_impl *find_or_create_with(format_impl *pattern, const protection &new_protection, optional<bool> applied)
|
2016-11-08 10:11:30 +08:00
|
|
|
{
|
|
|
|
format_impl new_format = *pattern;
|
|
|
|
new_format.protection_id = find_or_add(protections, new_protection);
|
|
|
|
new_format.protection_applied = applied;
|
2018-07-29 18:10:56 +08:00
|
|
|
if (pattern->references == 0)
|
|
|
|
{
|
|
|
|
*pattern = new_format;
|
|
|
|
}
|
2016-11-08 10:11:30 +08:00
|
|
|
return find_or_create(new_format);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::size_t style_index(const std::string &name) const
|
|
|
|
{
|
2016-11-10 08:52:18 +08:00
|
|
|
return static_cast<std::size_t>(std::distance(style_names.begin(),
|
|
|
|
std::find(style_names.begin(), style_names.end(), name)));
|
2016-09-08 06:02:46 +08:00
|
|
|
}
|
2016-09-10 22:05:06 +08:00
|
|
|
|
|
|
|
void clear()
|
|
|
|
{
|
2017-04-04 07:49:38 +08:00
|
|
|
conditional_format_impls.clear();
|
2016-09-10 22:05:06 +08:00
|
|
|
format_impls.clear();
|
|
|
|
|
|
|
|
style_impls.clear();
|
2016-11-08 10:11:30 +08:00
|
|
|
style_names.clear();
|
2016-09-10 22:05:06 +08:00
|
|
|
|
|
|
|
alignments.clear();
|
|
|
|
borders.clear();
|
|
|
|
fills.clear();
|
|
|
|
fonts.clear();
|
|
|
|
number_formats.clear();
|
|
|
|
protections.clear();
|
|
|
|
|
|
|
|
colors.clear();
|
|
|
|
}
|
2016-11-04 07:26:11 +08:00
|
|
|
|
2017-04-04 07:24:36 +08:00
|
|
|
conditional_format add_conditional_format_rule(worksheet_impl *ws, const range_reference &ref, const condition &when)
|
|
|
|
{
|
|
|
|
conditional_format_impls.push_back(conditional_format_impl());
|
|
|
|
|
|
|
|
auto &impl = conditional_format_impls.back();
|
|
|
|
impl.when = when;
|
|
|
|
impl.parent = this;
|
|
|
|
impl.target_sheet = ws;
|
|
|
|
impl.target_range = ref;
|
|
|
|
impl.differential_format_id = conditional_format_impls.size() - 1;
|
|
|
|
|
|
|
|
return xlnt::conditional_format(&impl);
|
|
|
|
}
|
|
|
|
|
2016-11-04 07:26:11 +08:00
|
|
|
workbook *parent;
|
2018-07-03 10:05:07 +08:00
|
|
|
|
|
|
|
bool operator==(const stylesheet& rhs) const
|
|
|
|
{
|
|
|
|
// no equality on parent as there is only 1 stylesheet per borkbook hence would always be false
|
|
|
|
return garbage_collection_enabled == rhs.garbage_collection_enabled
|
|
|
|
&& known_fonts_enabled == rhs.known_fonts_enabled
|
|
|
|
&& conditional_format_impls == rhs.conditional_format_impls
|
|
|
|
&& format_impls == rhs.format_impls
|
|
|
|
&& style_impls == rhs.style_impls
|
|
|
|
&& style_names == rhs.style_names
|
|
|
|
&& default_slicer_style == rhs.default_slicer_style
|
|
|
|
&& alignments == rhs.alignments
|
|
|
|
&& borders == rhs.borders
|
|
|
|
&& fills == rhs.fills
|
|
|
|
&& fonts == rhs.fonts
|
|
|
|
&& number_formats == rhs.number_formats
|
|
|
|
&& protections == rhs.protections
|
|
|
|
&& colors == rhs.colors;
|
|
|
|
}
|
2016-11-08 10:11:30 +08:00
|
|
|
|
2017-07-31 00:48:57 +08:00
|
|
|
bool garbage_collection_enabled = true;
|
2018-03-17 09:21:16 +08:00
|
|
|
bool known_fonts_enabled = false;
|
2016-11-04 07:26:11 +08:00
|
|
|
|
2017-04-04 07:24:36 +08:00
|
|
|
std::list<conditional_format_impl> conditional_format_impls;
|
2016-08-18 19:34:18 +08:00
|
|
|
std::list<format_impl> format_impls;
|
2016-11-08 10:11:30 +08:00
|
|
|
std::unordered_map<std::string, style_impl> style_impls;
|
|
|
|
std::vector<std::string> style_names;
|
2018-03-17 09:21:16 +08:00
|
|
|
optional<std::string> default_slicer_style;
|
2016-06-11 01:40:50 +08:00
|
|
|
|
2016-08-16 12:23:49 +08:00
|
|
|
std::vector<alignment> alignments;
|
2016-06-11 01:40:50 +08:00
|
|
|
std::vector<border> borders;
|
|
|
|
std::vector<fill> fills;
|
|
|
|
std::vector<font> fonts;
|
2016-11-03 10:04:51 +08:00
|
|
|
std::vector<number_format> number_formats;
|
2016-08-16 12:23:49 +08:00
|
|
|
std::vector<protection> protections;
|
2016-06-11 01:40:50 +08:00
|
|
|
|
|
|
|
std::vector<color> colors;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace detail
|
|
|
|
} // namespace xlnt
|