2020-02-09 01:12:59 +08:00
|
|
|
// Copyright (c) 2014-2020 Thomas Fussell
|
2016-05-01 04:19:45 +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
|
2016-05-15 01:57:07 +08:00
|
|
|
|
2019-12-27 01:03:12 +08:00
|
|
|
// detail imports must come first in this file.
|
2017-04-21 02:03:03 +08:00
|
|
|
#include <detail/implementations/format_impl.hpp>
|
|
|
|
#include <detail/implementations/stylesheet.hpp>
|
2019-12-27 01:03:12 +08:00
|
|
|
|
2016-08-18 19:34:18 +08:00
|
|
|
#include <xlnt/styles/format.hpp>
|
|
|
|
#include <xlnt/styles/style.hpp>
|
2016-05-01 04:19:45 +08:00
|
|
|
|
|
|
|
namespace xlnt {
|
|
|
|
|
2016-12-24 23:04:57 +08:00
|
|
|
format::format(detail::format_impl *d)
|
|
|
|
: d_(d)
|
2016-08-18 19:34:18 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-11-03 10:04:51 +08:00
|
|
|
void format::clear_style()
|
2016-11-01 20:50:29 +08:00
|
|
|
{
|
2016-11-03 10:04:51 +08:00
|
|
|
d_->style.clear();
|
2016-11-01 20:50:29 +08:00
|
|
|
}
|
|
|
|
|
2016-11-08 10:11:30 +08:00
|
|
|
format format::style(const xlnt::style &new_style)
|
2016-08-18 19:34:18 +08:00
|
|
|
{
|
2016-12-24 23:04:57 +08:00
|
|
|
d_ = d_->parent->find_or_create_with(d_, new_style.name());
|
2016-11-08 10:11:30 +08:00
|
|
|
return format(d_);
|
2016-08-18 19:34:18 +08:00
|
|
|
}
|
|
|
|
|
2016-11-08 10:11:30 +08:00
|
|
|
format format::style(const std::string &new_style)
|
2016-08-18 19:34:18 +08:00
|
|
|
{
|
2016-12-24 23:04:57 +08:00
|
|
|
d_->style = new_style;
|
2016-11-08 10:11:30 +08:00
|
|
|
return format(d_);
|
2016-11-03 10:04:51 +08:00
|
|
|
}
|
2016-08-18 19:34:18 +08:00
|
|
|
|
2016-11-03 10:04:51 +08:00
|
|
|
bool format::has_style() const
|
|
|
|
{
|
2016-12-26 22:38:26 +08:00
|
|
|
return d_->style.is_set();
|
2016-11-03 10:04:51 +08:00
|
|
|
}
|
2016-08-18 19:34:18 +08:00
|
|
|
|
2017-03-26 22:30:26 +08:00
|
|
|
style format::style()
|
2016-11-03 10:04:51 +08:00
|
|
|
{
|
2016-12-24 23:04:57 +08:00
|
|
|
if (!has_style())
|
|
|
|
{
|
|
|
|
throw invalid_attribute();
|
|
|
|
}
|
2016-08-18 19:34:18 +08:00
|
|
|
|
2016-12-24 23:04:57 +08:00
|
|
|
return d_->parent->style(d_->style.get());
|
2016-11-08 10:11:30 +08:00
|
|
|
}
|
|
|
|
|
2017-03-26 22:30:26 +08:00
|
|
|
const style format::style() const
|
|
|
|
{
|
2019-12-27 01:03:12 +08:00
|
|
|
if (!has_style())
|
|
|
|
{
|
|
|
|
throw invalid_attribute();
|
|
|
|
}
|
2017-03-26 22:30:26 +08:00
|
|
|
|
2019-12-27 01:03:12 +08:00
|
|
|
return d_->parent->style(d_->style.get());
|
2017-03-26 22:30:26 +08:00
|
|
|
}
|
|
|
|
|
2017-03-31 11:52:57 +08:00
|
|
|
xlnt::alignment format::alignment() const
|
2016-11-08 10:11:30 +08:00
|
|
|
{
|
2016-12-24 23:04:57 +08:00
|
|
|
return d_->parent->alignments.at(d_->alignment_id.get());
|
2016-11-08 10:11:30 +08:00
|
|
|
}
|
|
|
|
|
2018-04-25 05:58:17 +08:00
|
|
|
format format::alignment(const xlnt::alignment &new_alignment, optional<bool> applied)
|
2016-11-08 10:11:30 +08:00
|
|
|
{
|
|
|
|
d_ = d_->parent->find_or_create_with(d_, new_alignment, applied);
|
|
|
|
return format(d_);
|
2016-08-18 19:34:18 +08:00
|
|
|
}
|
|
|
|
|
2017-03-31 11:52:57 +08:00
|
|
|
xlnt::border format::border() const
|
2016-09-10 22:05:06 +08:00
|
|
|
{
|
2016-12-24 23:04:57 +08:00
|
|
|
return d_->parent->borders.at(d_->border_id.get());
|
2016-09-10 22:05:06 +08:00
|
|
|
}
|
|
|
|
|
2018-04-25 05:58:17 +08:00
|
|
|
format format::border(const xlnt::border &new_border, optional<bool> applied)
|
2016-09-10 22:05:06 +08:00
|
|
|
{
|
2016-11-08 10:11:30 +08:00
|
|
|
d_ = d_->parent->find_or_create_with(d_, new_border, applied);
|
|
|
|
return format(d_);
|
2016-09-10 22:05:06 +08:00
|
|
|
}
|
|
|
|
|
2017-03-31 11:52:57 +08:00
|
|
|
xlnt::fill format::fill() const
|
2016-09-10 22:05:06 +08:00
|
|
|
{
|
2016-12-24 23:04:57 +08:00
|
|
|
return d_->parent->fills.at(d_->fill_id.get());
|
2016-09-10 22:05:06 +08:00
|
|
|
}
|
|
|
|
|
2018-04-25 05:58:17 +08:00
|
|
|
format format::fill(const xlnt::fill &new_fill, optional<bool> applied)
|
2016-09-10 22:05:06 +08:00
|
|
|
{
|
2016-11-08 10:11:30 +08:00
|
|
|
d_ = d_->parent->find_or_create_with(d_, new_fill, applied);
|
|
|
|
return format(d_);
|
2016-09-10 22:05:06 +08:00
|
|
|
}
|
|
|
|
|
2017-03-31 11:52:57 +08:00
|
|
|
xlnt::font format::font() const
|
2016-09-08 06:02:46 +08:00
|
|
|
{
|
2016-12-24 23:04:57 +08:00
|
|
|
return d_->parent->fonts.at(d_->font_id.get());
|
2016-09-08 06:02:46 +08:00
|
|
|
}
|
|
|
|
|
2018-04-25 05:58:17 +08:00
|
|
|
format format::font(const xlnt::font &new_font, optional<bool> applied)
|
2016-09-08 06:02:46 +08:00
|
|
|
{
|
2016-11-08 10:11:30 +08:00
|
|
|
d_ = d_->parent->find_or_create_with(d_, new_font, applied);
|
|
|
|
return format(d_);
|
2016-09-08 06:02:46 +08:00
|
|
|
}
|
|
|
|
|
2017-03-31 11:52:57 +08:00
|
|
|
xlnt::number_format format::number_format() const
|
2016-08-18 19:34:18 +08:00
|
|
|
{
|
2016-12-30 07:36:29 +08:00
|
|
|
if (number_format::is_builtin_format(d_->number_format_id.get()))
|
|
|
|
{
|
|
|
|
return number_format::from_builtin_id(d_->number_format_id.get());
|
|
|
|
}
|
|
|
|
|
|
|
|
return *std::find_if(d_->parent->number_formats.begin(), d_->parent->number_formats.end(),
|
|
|
|
[&](const xlnt::number_format nf) { return nf.id() == d_->number_format_id.get(); });
|
2016-08-18 19:34:18 +08:00
|
|
|
}
|
|
|
|
|
2018-04-25 05:58:17 +08:00
|
|
|
format format::number_format(const xlnt::number_format &new_number_format, optional<bool> applied)
|
2016-08-18 19:34:18 +08:00
|
|
|
{
|
2016-12-24 23:04:57 +08:00
|
|
|
auto copy = new_number_format;
|
2016-08-18 19:34:18 +08:00
|
|
|
|
2016-12-24 23:04:57 +08:00
|
|
|
if (!copy.has_id())
|
|
|
|
{
|
|
|
|
copy.id(d_->parent->next_custom_number_format_id());
|
|
|
|
d_->parent->number_formats.push_back(copy);
|
|
|
|
}
|
2016-08-18 19:34:18 +08:00
|
|
|
|
2016-11-08 10:11:30 +08:00
|
|
|
d_ = d_->parent->find_or_create_with(d_, copy, applied);
|
|
|
|
return format(d_);
|
|
|
|
}
|
|
|
|
|
2017-03-31 11:52:57 +08:00
|
|
|
xlnt::protection format::protection() const
|
2016-11-08 10:11:30 +08:00
|
|
|
{
|
2016-12-24 23:04:57 +08:00
|
|
|
return d_->parent->protections.at(d_->protection_id.get());
|
2016-11-08 10:11:30 +08:00
|
|
|
}
|
|
|
|
|
2018-04-25 05:58:17 +08:00
|
|
|
format format::protection(const xlnt::protection &new_protection, optional<bool> applied)
|
2016-11-08 10:11:30 +08:00
|
|
|
{
|
|
|
|
d_ = d_->parent->find_or_create_with(d_, new_protection, applied);
|
|
|
|
return format(d_);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool format::alignment_applied() const
|
|
|
|
{
|
2018-04-25 05:58:17 +08:00
|
|
|
return d_->alignment_applied.is_set()
|
|
|
|
? d_->alignment_applied.get()
|
|
|
|
: d_->alignment_id.is_set();
|
2016-11-08 10:11:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool format::border_applied() const
|
|
|
|
{
|
2018-04-25 05:58:17 +08:00
|
|
|
return d_->border_applied.is_set()
|
|
|
|
? d_->border_applied.get()
|
|
|
|
: d_->border_id.is_set();
|
2016-11-08 10:11:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool format::fill_applied() const
|
|
|
|
{
|
2018-04-25 05:58:17 +08:00
|
|
|
return d_->fill_applied.is_set()
|
|
|
|
? d_->fill_applied.get()
|
|
|
|
: d_->fill_id.is_set();
|
2016-08-18 19:34:18 +08:00
|
|
|
}
|
|
|
|
|
2016-11-08 10:11:30 +08:00
|
|
|
bool format::font_applied() const
|
2016-09-10 22:05:06 +08:00
|
|
|
{
|
2018-04-25 05:58:17 +08:00
|
|
|
return d_->font_applied.is_set()
|
|
|
|
? d_->font_applied.get()
|
|
|
|
: d_->font_id.is_set();
|
2016-09-10 22:05:06 +08:00
|
|
|
}
|
|
|
|
|
2016-11-08 10:11:30 +08:00
|
|
|
bool format::number_format_applied() const
|
2016-09-10 22:05:06 +08:00
|
|
|
{
|
2018-04-25 05:58:17 +08:00
|
|
|
return d_->number_format_applied.is_set()
|
|
|
|
? d_->number_format_applied.get()
|
|
|
|
: d_->number_format_id.is_set();
|
2016-09-10 22:05:06 +08:00
|
|
|
}
|
|
|
|
|
2016-11-08 10:11:30 +08:00
|
|
|
bool format::protection_applied() const
|
2016-09-08 06:02:46 +08:00
|
|
|
{
|
2018-04-25 05:58:17 +08:00
|
|
|
return d_->protection_applied.is_set()
|
|
|
|
? d_->protection_applied.get()
|
|
|
|
: d_->protection_id.is_set();
|
2016-09-08 06:02:46 +08:00
|
|
|
}
|
2017-02-19 10:33:59 +08:00
|
|
|
|
|
|
|
bool format::pivot_button() const
|
|
|
|
{
|
|
|
|
return d_->pivot_button_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void format::pivot_button(bool show)
|
2017-02-15 05:02:51 +08:00
|
|
|
{
|
2017-02-19 10:33:59 +08:00
|
|
|
d_->pivot_button_ = show;
|
2017-02-15 05:02:51 +08:00
|
|
|
}
|
|
|
|
|
2017-02-19 10:33:59 +08:00
|
|
|
bool format::quote_prefix() const
|
2017-02-15 05:02:51 +08:00
|
|
|
{
|
2017-02-19 10:33:59 +08:00
|
|
|
return d_->quote_prefix_;
|
2017-02-15 05:02:51 +08:00
|
|
|
}
|
2016-09-08 06:02:46 +08:00
|
|
|
|
2017-02-19 10:33:59 +08:00
|
|
|
void format::quote_prefix(bool quote)
|
|
|
|
{
|
|
|
|
d_->quote_prefix_ = quote;
|
|
|
|
}
|
|
|
|
|
2016-05-01 04:19:45 +08:00
|
|
|
} // namespace xlnt
|