improve property handling, comment serialization

This commit is contained in:
Thomas Fussell 2017-02-25 08:55:11 -06:00
parent 9535f94e38
commit 0db50a7b15
3 changed files with 40 additions and 29 deletions

View File

@ -56,10 +56,13 @@ struct workbook_impl
shared_strings_(other.shared_strings_),
stylesheet_(other.stylesheet_),
manifest_(other.manifest_),
theme_(other.theme_),
view_(other.view_),
code_name_(other.code_name_),
file_version_(other.file_version_)
theme_(other.theme_),
core_properties_(other.core_properties_),
extended_properties_(other.extended_properties_),
custom_properties_(other.custom_properties_),
view_(other.view_),
code_name_(other.code_name_),
file_version_(other.file_version_)
{
}
@ -78,6 +81,10 @@ struct workbook_impl
code_name_ = other.code_name_;
file_version_ = other.file_version_;
core_properties_ = other.core_properties_;
extended_properties_ = other.extended_properties_;
custom_properties_ = other.custom_properties_;
return *this;
}

View File

@ -331,6 +331,8 @@ void xlsx_producer::write_core_properties(const relationship &/*rel*/)
auto core_properties = source_.core_properties();
std::unordered_map<std::string, std::string> namespaces;
write_namespace(constants::ns("core-properties"), "cp");
for (const auto &prop : core_properties)
{
for (const auto &ns : core_property_namespace(prop))
@ -525,11 +527,6 @@ void xlsx_producer::write_workbook(const relationship &rel)
write_start_element(xmlns, "sheets");
if (any_defined_names)
{
write_element(xmlns, "definedNames", "");
}
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wrange-loop-analysis"
for (const auto ws : source_)
@ -547,26 +544,25 @@ void xlsx_producer::write_workbook(const relationship &rel)
}
write_attribute(xml::qname(xmlns_r, "id"), sheet_rel_id);
if (ws.has_auto_filter())
{
write_start_element(xmlns, "definedName");
write_attribute("name", "_xlnm._FilterDatabase");
write_attribute("hidden", write_bool(true));
write_attribute("localSheetId", "0");
write_characters(
"'" + ws.title() + "'!" + range_reference::make_absolute(ws.auto_filter()).to_string());
write_end_element(xmlns, "definedName");
}
write_end_element(xmlns, "sheet");
}
#pragma clang diagnostic pop
write_end_element(xmlns, "sheets");
if (any_defined_names)
{
write_start_element(xmlns, "definedNames");
/*
write_attribute("name", "_xlnm._FilterDatabase");
write_attribute("hidden", write_bool(true));
write_attribute("localSheetId", "0");
write_characters("'" + ws.title() + "'!" +
range_reference::make_absolute(ws.auto_filter()).to_string());
*/
write_end_element(xmlns, "definedNames");
}
if (source_.has_calculation_properties())
{
write_start_element(xmlns, "calcPr");
@ -709,6 +705,14 @@ void xlsx_producer::write_workbook(const relationship &rel)
void xlsx_producer::write_calculation_chain(const relationship & /*rel*/)
{
write_start_element(constants::ns("spreadsheetml"), "calcChain");
write_namespace(constants::ns("spreadsheetml"), "");
/*
write_start_element(constants::ns("spreadsheetml"), "c");
write_attribute("r", "B2");
write_attribute("i", "1");
write_attribute("l", "1");
write_end_element(constants::ns("spreadsheetml"), "c");
*/
write_end_element(constants::ns("spreadsheetml"), "calcChain");
}
@ -2835,10 +2839,10 @@ void xlsx_producer::write_vml_drawings(const relationship &rel, worksheet ws, co
std::vector<std::pair<std::string, std::string>> style;
style.push_back({"position", "absolute"});
style.push_back({"margin-left", std::to_string(comment.left())});
style.push_back({"margin-top", std::to_string(comment.top())});
style.push_back({"width", std::to_string(comment.width())});
style.push_back({"height", std::to_string(comment.height())});
style.push_back({"margin-left", std::to_string(comment.left()) + "pt"});
style.push_back({"margin-top", std::to_string(comment.top()) + "pt"});
style.push_back({"width", std::to_string(comment.width()) + "pt"});
style.push_back({"height", std::to_string(comment.height()) + "pt"});
style.push_back({"z-index", std::to_string(comment_index + 1)});
style.push_back({"visibility", comment.visible() ? "visible" : "hidden"});

View File

@ -45,7 +45,7 @@ public:
return xml_helper::xlsx_archives_match(source_decrypted, destination);
}
void test_round_trip_empty_excel_rw()
void test_round_trip_rw()
{
const auto files = std::vector<std::string>
{
@ -64,7 +64,7 @@ public:
}
}
void test_round_trip_empty_excel_rw_encrypted()
void test_round_trip_rw_encrypted()
{
const auto files = std::vector<std::string>
{