From 22c1f08b83d1ab0f28fb3ed97f682664ef8150bf Mon Sep 17 00:00:00 2001 From: Thomas Fussell Date: Sat, 21 Jan 2017 10:29:23 -0500 Subject: [PATCH] fix custom property pids --- source/detail/xlsx_producer.cpp | 30 +++++++++++++++++++++++------- source/detail/xlsx_producer.hpp | 2 +- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/source/detail/xlsx_producer.cpp b/source/detail/xlsx_producer.cpp index 954371c3..33ad2e10 100644 --- a/source/detail/xlsx_producer.cpp +++ b/source/detail/xlsx_producer.cpp @@ -166,7 +166,7 @@ void xlsx_producer::write_content_types() write_end_element(xmlns, "Types"); } -void xlsx_producer::write_property(const std::string &name, const variant &value, const std::string &ns, bool custom) +void xlsx_producer::write_property(const std::string &name, const variant &value, const std::string &ns, bool custom, std::size_t pid) { if (custom) { @@ -187,27 +187,41 @@ void xlsx_producer::write_property(const std::string &name, const variant &value if (custom) { write_attribute("fmtid", "{D5CDD505-2E9C-101B-9397-08002B2CF9AE}"); - write_attribute("pid", 2); + write_attribute("pid", pid); + write_start_element(constants::ns("vt"), "bool"); } write_characters(write_bool(value.get())); + + if (custom) + { + write_end_element(constants::ns("vt"), "bool"); + } + break; case variant::type::i4: if (custom) { write_attribute("fmtid", "{D5CDD505-2E9C-101B-9397-08002B2CF9AE}"); - write_attribute("pid", 2); + write_attribute("pid", pid); + write_start_element(constants::ns("vt"), "i4"); } write_characters(value.get()); + + if (custom) + { + write_end_element(constants::ns("vt"), "i4"); + } + break; case variant::type::lpstr: if (custom) { write_attribute("fmtid", "{D5CDD505-2E9C-101B-9397-08002B2CF9AE}"); - write_attribute("pid", 2); + write_attribute("pid", pid); write_start_element(constants::ns("vt"), "lpwstr"); } @@ -328,7 +342,7 @@ void xlsx_producer::write_core_properties(const relationship &/*rel*/) for (const auto &prop : core_properties) { write_property(to_string(prop), source_.core_property(prop), - core_property_namespace(prop).front().first, false); + core_property_namespace(prop).front().first, false, 0); } write_end_element(constants::ns("core-properties"), "coreProperties"); @@ -348,7 +362,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), - constants::ns("extended-properties"), false); + constants::ns("extended-properties"), false, 0); } write_end_element(constants::ns("extended-properties"), "Properties"); @@ -360,10 +374,12 @@ void xlsx_producer::write_custom_properties(const relationship &/*rel*/) write_namespace(constants::ns("custom-properties"), ""); write_namespace(constants::ns("vt"), "vt"); + auto pid = std::size_t(2); // why does this start at 2? + for (const auto &prop : source_.custom_properties()) { write_property(prop, source_.custom_property(prop), - constants::ns("custom-properties"), true); + constants::ns("custom-properties"), true, pid++); } write_end_element(constants::ns("custom-properties"), "Properties"); diff --git a/source/detail/xlsx_producer.hpp b/source/detail/xlsx_producer.hpp index 992f6e6b..dd77c8af 100644 --- a/source/detail/xlsx_producer.hpp +++ b/source/detail/xlsx_producer.hpp @@ -71,7 +71,7 @@ private: // Package Parts void write_content_types(); - void write_property(const std::string &name, const variant &value, const std::string &ns, bool custom); + void write_property(const std::string &name, const variant &value, const std::string &ns, bool custom, std::size_t pid); void write_core_properties(const relationship &rel); void write_extended_properties(const relationship &rel); void write_custom_properties(const relationship &rel);