update for xf pivotButton quotedPrefix attributes

This commit is contained in:
sukoi26 2017-02-14 22:02:51 +01:00
parent 8fa929256d
commit bb8202f779
8 changed files with 115 additions and 22 deletions

10
include/xlnt/styles/format.hpp Normal file → Executable file
View File

@ -189,6 +189,16 @@ public:
/// </summary>
bool protection_applied() const;
/// <summary>
///
/// </summary>
bool pivot_button_applied() const;
/// <summary>
///
/// </summary>
bool quote_prefix_applied() const;
// Style
/// <summary>

10
include/xlnt/styles/style.hpp Normal file → Executable file
View File

@ -227,6 +227,16 @@ public:
/// </summary>
bool protection_applied() const;
/// <summary>
///
/// </summary>
bool pivot_button_applied() const;
/// <summary>
///
/// </summary>
bool quote_prefix_applied() const;
/// <summary>
///
/// </summary>

8
source/detail/format_impl.hpp Normal file → Executable file
View File

@ -47,10 +47,14 @@ struct format_impl
optional<std::size_t> protection_id;
bool protection_applied = false;
bool pivot_button_applied = false;
bool quote_prefix_applied = false;
optional<std::string> style;
std::size_t references = 0;
XLNT_API friend bool operator==(const format_impl &left, const format_impl &right)
{
return left.parent == right.parent

4
source/detail/style_impl.hpp Normal file → Executable file
View File

@ -48,6 +48,10 @@ struct style_impl
optional<std::size_t> protection_id;
bool protection_applied = false;
bool pivot_button_applied = false;
bool quote_prefix_applied = false;
};
} // namespace detail

View File

@ -1488,10 +1488,7 @@ void xlsx_consumer::read_stylesheet()
while (in_element(current_style_element))
{
expect_start_element(qn("spreadsheetml", "xf"), xml::content::complex);
// temporary to analyse
skip_attribute("pivotButton");
skip_attribute("quotePrefix");
auto &record = *(!in_style_records
? format_records.emplace(format_records.end())
: style_records.emplace(style_records.end()));
@ -1524,6 +1521,14 @@ void xlsx_consumer::read_stylesheet()
record.first.protection_applied = apply_protection_present
&& is_true(parser().attribute("applyProtection"));
auto pivot_button_present = parser().attribute_present("pivotButton");
record.first.pivot_button_applied = pivot_button_present
&& is_true(parser().attribute("pivotButton"));
auto quote_prefix_present = parser().attribute_present("quotePrefix");
record.first.quote_prefix_applied = quote_prefix_present
&& is_true(parser().attribute("quotePrefix"));
if (parser().attribute_present("xfId") && parser().name() == "cellXfs")
{
record.second = parser().attribute<std::size_t>("xfId");
@ -1738,6 +1743,8 @@ void xlsx_consumer::read_stylesheet()
new_format.number_format_applied = record.first.number_format_applied;
new_format.protection_id = record.first.protection_id;
new_format.protection_applied = record.first.protection_applied;
new_format.pivot_button_applied = record.first.pivot_button_applied;
new_format.quote_prefix_applied = record.first.quote_prefix_applied;
}
}
@ -2136,8 +2143,19 @@ void xlsx_consumer::read_worksheet(const std::string &rel_id)
else if (current_worksheet_element == qn("spreadsheetml", "autoFilter")) // CT_AutoFilter 0-1
{
ws.auto_filter(xlnt::range_reference(parser().attribute("ref")));
// complex type
skip_remaining_content(current_worksheet_element);
//while (in_element(qn("spreadsheetml", "autoFilter")))
//{
skip_remaining_content(current_worksheet_element);
//}
//auto fste = expect_start_element(xml::content::simple);
//if (parser().element_present("filterColumn"))
//if(fste == qn("spreadsheetml", "filterColumn"))
//{
//skip_attributes({"colId", "showButton"});
// skip_remaining_content(fste);
//expect_end_element(qn("spreadsheetml", "filterColumn"));
//}
//expect_end_element(qn("spreadsheetml", "autoFilter"));
}
else if (current_worksheet_element == qn("spreadsheetml", "sortState")) // CT_SortState 0-1
{
@ -2466,7 +2484,7 @@ void xlsx_consumer::read_comments(worksheet ws)
expect_start_element(qn("spreadsheetml", "comment"), xml::content::complex);
skip_attribute("shapeId");
auto cell_ref = parser().attribute("ref");
auto cell_ref = parser().attribute("ref");
auto author_id = parser().attribute<std::size_t>("authorId");
expect_start_element(qn("spreadsheetml", "text"), xml::content::complex);
@ -2535,7 +2553,11 @@ variant xlsx_consumer::read_variant()
}
if (element == qn("vt", "bool"))
{
value = variant(is_true(text));
// bool could be "0" or "false"
bool bvalue;
if (text[0] == '0' or text[0] == 'f' or text[0]=='F') bvalue = false;
else bvalue = true;
value = variant(bvalue);
}
else if (element == qn("vt", "vector"))
{
@ -2651,8 +2673,12 @@ std::vector<std::string> xlsx_consumer::read_namespaces()
bool xlsx_consumer::in_element(const xml::qname &name)
{
return parser().peek() != xml::parser::event_type::end_element
&& stack_.back() == name;
if ((parser().peek() == xml::parser::event_type::end_element ) && (stack_.back() == name ))
{
return false;
}
return true;
}
xml::qname xlsx_consumer::expect_start_element(xml::content content)
@ -2747,13 +2773,13 @@ rich_text xlsx_consumer::read_rich_text(const xml::qname &parent)
}
else if (current_run_property_element == xml::qname(xmlns, "b"))
{
run.second.get().bold(parser().attribute_present("val")
? is_true(parser().attribute("val")) : true);
run.second.get().bold(
parser().attribute_present("val") ? is_true(parser().attribute("val")) : true);
}
else if (current_run_property_element == xml::qname(xmlns, "i"))
{
run.second.get().italic(parser().attribute_present("val")
? is_true(parser().attribute("val")) : true);
run.second.get().bold(
parser().attribute_present("val") ? is_true(parser().attribute("val")) : true);
}
else if (current_run_property_element == xml::qname(xmlns, "u"))
{

32
source/detail/xlsx_producer.cpp Normal file → Executable file
View File

@ -58,15 +58,15 @@ std::vector<std::pair<std::string, std::string>> core_property_namespace(xlnt::c
using xlnt::core_property;
using xlnt::constants;
if (type == core_property::created
if (type == core_property::created
|| type == core_property::modified)
{
return {{constants::ns("dcterms"), "dcterms"},
{constants::ns("xsi"), "xsi"}};
}
else if (type == core_property::title
|| type == core_property::subject
|| type == core_property::creator
else if (type == core_property::title
|| type == core_property::subject
|| type == core_property::creator
|| type == core_property::description)
{
return {{constants::ns("dc"), "dc"}};
@ -363,7 +363,7 @@ void xlsx_producer::write_extended_properties(const relationship &/*rel*/)
for (const auto &prop : source_.extended_properties())
{
write_property(to_string(prop), source_.extended_property(prop),
write_property(to_string(prop), source_.extended_property(prop),
constants::ns("extended-properties"), false, 0);
}
@ -1174,6 +1174,16 @@ void xlsx_producer::write_styles(const relationship & /*rel*/)
write_attribute("applyProtection", write_bool(true));
}
if (current_style_impl.pivot_button_applied)
{
write_attribute("pivotButton", write_bool(true));
}
if (current_style_impl.quote_prefix_applied)
{
write_attribute("quotePrefix", write_bool(true));
}
if (current_style_impl.alignment_id.is_set())
{
const auto &current_alignment = stylesheet.alignments[current_style_impl.alignment_id.get()];
@ -1228,7 +1238,7 @@ void xlsx_producer::write_styles(const relationship & /*rel*/)
write_end_element(xmlns, "cellStyleXfs");
}
// Format XFs
write_start_element(xmlns, "cellXfs");
@ -1282,6 +1292,16 @@ void xlsx_producer::write_styles(const relationship & /*rel*/)
write_attribute("applyProtection", write_bool(true));
}
if (current_format_impl.pivot_button_applied)
{
write_attribute("pivotButton", write_bool(true));
}
if (current_format_impl.quote_prefix_applied)
{
write_attribute("quotePrefix", write_bool(true));
}
if (current_format_impl.style.is_set())
{
write_attribute("xfId", stylesheet.style_index(current_format_impl.style.get()));

9
source/styles/format.cpp Normal file → Executable file
View File

@ -210,5 +210,14 @@ bool format::protection_applied() const
{
return d_->protection_applied;
}
bool format::pivot_button_applied() const
{
return d_->pivot_button_applied;
}
bool format::quote_prefix_applied() const
{
return d_->quote_prefix_applied;
}
} // namespace xlnt

10
source/styles/style.cpp Normal file → Executable file
View File

@ -238,4 +238,14 @@ bool style::protection_applied() const
return d_->protection_applied;
}
bool style::pivot_button_applied() const
{
return d_->pivot_button_applied;
}
bool style::quote_prefix_applied() const
{
return d_->quote_prefix_applied;
}
} // namespace xlnt