2016-10-25 10:09:15 +08:00
|
|
|
// Copyright (c) 2014-2016 Thomas Fussell
|
|
|
|
//
|
|
|
|
// 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-09-06 11:30:25 +08:00
|
|
|
#include <cmath>
|
2016-09-19 09:49:37 +08:00
|
|
|
#include <string>
|
2016-08-05 13:52:05 +08:00
|
|
|
|
2016-09-18 23:32:59 +08:00
|
|
|
#include <detail/custom_value_traits.hpp>
|
2016-09-06 11:30:25 +08:00
|
|
|
#include <detail/xlsx_producer.hpp>
|
2016-08-05 13:52:05 +08:00
|
|
|
#include <detail/constants.hpp>
|
|
|
|
#include <detail/workbook_impl.hpp>
|
2016-08-18 19:34:18 +08:00
|
|
|
#include <xlnt/cell/cell.hpp>
|
2016-08-05 13:52:05 +08:00
|
|
|
#include <xlnt/utils/path.hpp>
|
|
|
|
#include <xlnt/packaging/manifest.hpp>
|
|
|
|
#include <xlnt/packaging/zip_file.hpp>
|
|
|
|
#include <xlnt/workbook/const_worksheet_iterator.hpp>
|
|
|
|
#include <xlnt/workbook/workbook.hpp>
|
2016-08-14 02:45:26 +08:00
|
|
|
#include <xlnt/workbook/workbook_view.hpp>
|
2016-08-05 13:52:05 +08:00
|
|
|
#include <xlnt/worksheet/worksheet.hpp>
|
|
|
|
|
2016-09-19 09:49:37 +08:00
|
|
|
using namespace std::string_literals;
|
|
|
|
|
2016-08-05 13:52:05 +08:00
|
|
|
namespace {
|
|
|
|
|
2016-09-20 06:52:11 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Some XML elements do unknown things and will be skipped during writing if this is true.
|
|
|
|
/// </summary>
|
|
|
|
const bool skip_unknown_elements = true;
|
|
|
|
|
2016-08-05 13:52:05 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Returns true if d is exactly equal to an integer.
|
|
|
|
/// </summary>
|
|
|
|
bool is_integral(long double d)
|
|
|
|
{
|
|
|
|
return d == static_cast<long long int>(d);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string fill(const std::string &string, std::size_t length = 2)
|
|
|
|
{
|
|
|
|
if (string.size() >= length)
|
|
|
|
{
|
|
|
|
return string;
|
|
|
|
}
|
|
|
|
|
|
|
|
return std::string(length - string.size(), '0') + string;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string datetime_to_w3cdtf(const xlnt::datetime &dt)
|
|
|
|
{
|
2016-09-18 23:32:59 +08:00
|
|
|
return std::to_string(dt.year) + "-"
|
|
|
|
+ fill(std::to_string(dt.month)) + "-"
|
|
|
|
+ fill(std::to_string(dt.day)) + "T"
|
|
|
|
+ fill(std::to_string(dt.hour)) + ":"
|
|
|
|
+ fill(std::to_string(dt.minute)) + ":"
|
|
|
|
+ fill(std::to_string(dt.second)) + "Z";
|
2016-08-05 13:52:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
namespace xlnt {
|
|
|
|
namespace detail {
|
|
|
|
|
|
|
|
xlsx_producer::xlsx_producer(const workbook &target) : source_(target)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void xlsx_producer::write(const path &destination)
|
|
|
|
{
|
2016-08-06 22:40:17 +08:00
|
|
|
populate_archive();
|
|
|
|
destination_.save(destination);
|
2016-08-05 13:52:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void xlsx_producer::write(std::ostream &destination)
|
|
|
|
{
|
2016-08-06 22:40:17 +08:00
|
|
|
populate_archive();
|
|
|
|
destination_.save(destination);
|
2016-08-05 13:52:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void xlsx_producer::write(std::vector<std::uint8_t> &destination)
|
|
|
|
{
|
2016-08-06 22:40:17 +08:00
|
|
|
populate_archive();
|
|
|
|
destination_.save(destination);
|
2016-08-05 13:52:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Part Writing Methods
|
|
|
|
|
2016-08-06 22:40:17 +08:00
|
|
|
void xlsx_producer::populate_archive()
|
2016-08-05 13:52:05 +08:00
|
|
|
{
|
2016-09-18 23:32:59 +08:00
|
|
|
write_content_types();
|
|
|
|
|
|
|
|
const auto root_rels = source_.get_manifest().get_relationships(path("/"));
|
|
|
|
write_relationships(root_rels, path("/"));
|
2016-08-05 13:52:05 +08:00
|
|
|
|
2016-09-18 23:32:59 +08:00
|
|
|
for (auto &rel : root_rels)
|
2016-08-05 13:52:05 +08:00
|
|
|
{
|
2016-09-17 10:59:13 +08:00
|
|
|
std::ostringstream serializer_stream;
|
|
|
|
xml::serializer serializer(serializer_stream, rel.get_target().get_path().string());
|
2016-09-18 23:32:59 +08:00
|
|
|
serializer_ = &serializer;
|
2016-09-17 10:59:13 +08:00
|
|
|
|
2016-08-12 12:22:14 +08:00
|
|
|
bool write_document = true;
|
2016-08-06 22:40:17 +08:00
|
|
|
|
2016-08-05 13:52:05 +08:00
|
|
|
switch (rel.get_type())
|
|
|
|
{
|
|
|
|
case relationship::type::core_properties:
|
2016-09-18 23:32:59 +08:00
|
|
|
write_core_properties(rel);
|
2016-08-05 13:52:05 +08:00
|
|
|
break;
|
2016-08-12 12:22:14 +08:00
|
|
|
|
2016-08-05 13:52:05 +08:00
|
|
|
case relationship::type::extended_properties:
|
2016-09-18 23:32:59 +08:00
|
|
|
write_extended_properties(rel);
|
2016-08-05 13:52:05 +08:00
|
|
|
break;
|
2016-08-12 12:22:14 +08:00
|
|
|
|
2016-08-05 13:52:05 +08:00
|
|
|
case relationship::type::custom_properties:
|
2016-09-18 23:32:59 +08:00
|
|
|
write_custom_properties(rel);
|
2016-08-06 22:40:17 +08:00
|
|
|
break;
|
2016-08-12 12:22:14 +08:00
|
|
|
|
2016-08-06 22:40:17 +08:00
|
|
|
case relationship::type::office_document:
|
2016-09-18 23:32:59 +08:00
|
|
|
write_workbook(rel);
|
2016-08-05 13:52:05 +08:00
|
|
|
break;
|
2016-08-12 12:22:14 +08:00
|
|
|
|
2016-08-06 22:40:17 +08:00
|
|
|
case relationship::type::thumbnail:
|
2016-08-12 12:22:14 +08:00
|
|
|
write_thumbnail(rel);
|
|
|
|
write_document = false;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (write_document)
|
|
|
|
{
|
2016-09-17 10:59:13 +08:00
|
|
|
destination_.write_string(serializer_stream.str(), rel.get_target().get_path());
|
2016-08-12 12:22:14 +08:00
|
|
|
}
|
2016-08-06 22:40:17 +08:00
|
|
|
}
|
2016-08-05 13:52:05 +08:00
|
|
|
|
|
|
|
// Unknown Parts
|
|
|
|
|
|
|
|
void write_unknown_parts();
|
|
|
|
void write_unknown_relationships();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Package Parts
|
|
|
|
|
2016-09-18 23:32:59 +08:00
|
|
|
void xlsx_producer::write_content_types()
|
2016-08-05 13:52:05 +08:00
|
|
|
{
|
2016-09-17 10:59:13 +08:00
|
|
|
std::ostringstream content_types_stream;
|
|
|
|
xml::serializer content_types_serializer(content_types_stream, "[Content_Types].xml");
|
|
|
|
|
2016-09-19 09:49:37 +08:00
|
|
|
const auto xmlns = "http://schemas.openxmlformats.org/package/2006/content-types"s;
|
2016-08-05 13:52:05 +08:00
|
|
|
|
2016-09-17 10:59:13 +08:00
|
|
|
content_types_serializer.start_element(xmlns, "Types");
|
|
|
|
content_types_serializer.namespace_decl(xmlns, "");
|
2016-08-05 13:52:05 +08:00
|
|
|
|
2016-08-12 12:22:14 +08:00
|
|
|
for (const auto &extension : source_.get_manifest().get_extensions_with_default_types())
|
2016-08-05 13:52:05 +08:00
|
|
|
{
|
2016-09-17 10:59:13 +08:00
|
|
|
content_types_serializer.start_element(xmlns, "Default");
|
|
|
|
content_types_serializer.attribute("Extension", extension);
|
|
|
|
content_types_serializer.attribute("ContentType",
|
|
|
|
source_.get_manifest().get_default_type(extension));
|
|
|
|
content_types_serializer.end_element(xmlns, "Default");
|
2016-08-05 13:52:05 +08:00
|
|
|
}
|
|
|
|
|
2016-08-12 12:22:14 +08:00
|
|
|
for (const auto &part : source_.get_manifest().get_parts_with_overriden_types())
|
2016-08-05 13:52:05 +08:00
|
|
|
{
|
2016-09-17 10:59:13 +08:00
|
|
|
content_types_serializer.start_element(xmlns, "Override");
|
|
|
|
content_types_serializer.attribute("PartName", part.resolve(path("/")).string());
|
|
|
|
content_types_serializer.attribute("ContentType",
|
|
|
|
source_.get_manifest().get_override_type(part));
|
|
|
|
content_types_serializer.end_element(xmlns, "Override");
|
2016-08-05 13:52:05 +08:00
|
|
|
}
|
2016-09-17 10:59:13 +08:00
|
|
|
|
|
|
|
content_types_serializer.end_element(xmlns, "Types");
|
|
|
|
destination_.write_string(content_types_stream.str(), path("[Content_Types].xml"));
|
2016-08-05 13:52:05 +08:00
|
|
|
}
|
|
|
|
|
2016-09-18 23:32:59 +08:00
|
|
|
void xlsx_producer::write_extended_properties(const relationship &rel)
|
2016-08-05 13:52:05 +08:00
|
|
|
{
|
2016-09-19 09:49:37 +08:00
|
|
|
const auto xmlns = "http://schemas.openxmlformats.org/officeDocument/2006/extended-properties"s;
|
|
|
|
const auto xmlns_vt = "http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes"s;
|
|
|
|
|
|
|
|
serializer().start_element(xmlns, "Properties");
|
|
|
|
serializer().namespace_decl(xmlns, "");
|
|
|
|
serializer().namespace_decl(xmlns_vt, "vt");
|
|
|
|
|
|
|
|
serializer().element(xmlns, "Application", source_.get_application());
|
2016-09-20 06:52:11 +08:00
|
|
|
serializer().element(xmlns, "DocSecurity", source_.get_doc_security());
|
2016-09-19 09:49:37 +08:00
|
|
|
serializer().element(xmlns, "ScaleCrop", source_.get_scale_crop() ? "true" : "false");
|
|
|
|
|
|
|
|
serializer().start_element(xmlns, "HeadingPairs");
|
|
|
|
serializer().start_element(xmlns_vt, "vector");
|
|
|
|
serializer().attribute("size", "2");
|
|
|
|
serializer().attribute("baseType", "variant");
|
|
|
|
serializer().start_element(xmlns_vt, "variant");
|
|
|
|
serializer().element(xmlns_vt, "lpstr", "Worksheets");
|
|
|
|
serializer().end_element(xmlns_vt, "variant");
|
|
|
|
serializer().start_element(xmlns_vt, "variant");
|
2016-09-20 06:52:11 +08:00
|
|
|
serializer().element(xmlns_vt, "i4", source_.get_sheet_titles().size());
|
2016-09-19 09:49:37 +08:00
|
|
|
serializer().end_element(xmlns_vt, "variant");
|
|
|
|
serializer().end_element(xmlns_vt, "vector");
|
|
|
|
serializer().end_element(xmlns, "HeadingPairs");
|
|
|
|
|
|
|
|
serializer().start_element(xmlns, "TitlesOfParts");
|
|
|
|
serializer().start_element(xmlns_vt, "vector");
|
2016-09-20 06:52:11 +08:00
|
|
|
serializer().attribute("size", source_.get_sheet_titles().size());
|
2016-09-19 09:49:37 +08:00
|
|
|
serializer().attribute("baseType", "lpstr");
|
2016-08-05 13:52:05 +08:00
|
|
|
|
|
|
|
for (auto ws : source_)
|
|
|
|
{
|
2016-09-19 09:49:37 +08:00
|
|
|
serializer().element(xmlns_vt, "lpstr", ws.get_title());
|
2016-08-05 13:52:05 +08:00
|
|
|
}
|
2016-08-13 11:06:25 +08:00
|
|
|
|
2016-09-19 09:49:37 +08:00
|
|
|
serializer().end_element(xmlns_vt, "vector");
|
|
|
|
serializer().end_element(xmlns, "TitlesOfParts");
|
|
|
|
|
|
|
|
serializer().start_element(xmlns, "Company");
|
2016-08-13 11:06:25 +08:00
|
|
|
|
|
|
|
if (!source_.get_company().empty())
|
|
|
|
{
|
2016-09-19 09:49:37 +08:00
|
|
|
serializer().characters(source_.get_company());
|
2016-08-13 11:06:25 +08:00
|
|
|
}
|
2016-09-19 09:49:37 +08:00
|
|
|
|
|
|
|
serializer().end_element(xmlns, "Company");
|
2016-08-13 11:06:25 +08:00
|
|
|
|
2016-09-19 09:49:37 +08:00
|
|
|
serializer().element(xmlns, "LinksUpToDate", source_.links_up_to_date() ? "true" : "false");
|
|
|
|
serializer().element(xmlns, "SharedDoc", source_.is_shared_doc() ? "true" : "false");
|
|
|
|
serializer().element(xmlns, "HyperlinksChanged", source_.hyperlinks_changed() ? "true" : "false");
|
|
|
|
serializer().element(xmlns, "AppVersion", source_.get_app_version());
|
2016-09-22 07:04:16 +08:00
|
|
|
|
|
|
|
serializer().end_element(xmlns, "Properties");
|
2016-08-05 13:52:05 +08:00
|
|
|
}
|
|
|
|
|
2016-09-18 23:32:59 +08:00
|
|
|
void xlsx_producer::write_core_properties(const relationship &rel)
|
2016-08-05 13:52:05 +08:00
|
|
|
{
|
2016-09-22 07:04:16 +08:00
|
|
|
static const auto xmlns_cp = constants::get_namespace("core-properties");
|
|
|
|
static const auto xmlns_dc = constants::get_namespace("dc");
|
|
|
|
static const auto xmlns_dcterms = constants::get_namespace("dcterms");
|
|
|
|
static const auto xmlns_dcmitype = constants::get_namespace("dcmitype");
|
|
|
|
static const auto xmlns_xsi = constants::get_namespace("xsi");
|
2016-09-19 09:49:37 +08:00
|
|
|
|
|
|
|
serializer().start_element(xmlns_cp, "coreProperties");
|
|
|
|
serializer().namespace_decl(xmlns_cp, "cp");
|
|
|
|
serializer().namespace_decl(xmlns_dc, "dc");
|
|
|
|
serializer().namespace_decl(xmlns_dcterms, "dcterms");
|
|
|
|
serializer().namespace_decl(xmlns_dcmitype, "dcmitype");
|
|
|
|
serializer().namespace_decl(xmlns_xsi, "xsi");
|
|
|
|
|
|
|
|
serializer().element(xmlns_dc, "creator", source_.get_creator());
|
|
|
|
serializer().element(xmlns_cp, "lastModifiedBy", source_.get_last_modified_by());
|
|
|
|
serializer().start_element(xmlns_dcterms, "created");
|
|
|
|
serializer().attribute(xmlns_xsi, "type", "dcterms:W3CDTF");
|
|
|
|
serializer().characters(datetime_to_w3cdtf(source_.get_created()));
|
|
|
|
serializer().end_element(xmlns_dcterms, "created");
|
|
|
|
serializer().start_element(xmlns_dcterms, "modified");
|
|
|
|
serializer().attribute(xmlns_xsi, "type", "dcterms:W3CDTF");
|
|
|
|
serializer().characters(datetime_to_w3cdtf(source_.get_modified()));
|
|
|
|
serializer().end_element(xmlns_dcterms, "modified");
|
2016-08-13 11:06:25 +08:00
|
|
|
|
|
|
|
if (!source_.get_title().empty())
|
|
|
|
{
|
2016-09-19 09:49:37 +08:00
|
|
|
serializer().element(xmlns_dc, "title", source_.get_title());
|
2016-08-13 11:06:25 +08:00
|
|
|
}
|
2016-09-19 09:49:37 +08:00
|
|
|
|
2016-09-20 06:52:11 +08:00
|
|
|
if (!skip_unknown_elements)
|
2016-09-19 09:49:37 +08:00
|
|
|
{
|
|
|
|
serializer().element(xmlns_dc, "description", "");
|
|
|
|
serializer().element(xmlns_dc, "subject", "");
|
|
|
|
serializer().element(xmlns_cp, "keywords", "");
|
|
|
|
serializer().element(xmlns_cp, "category", "");
|
|
|
|
}
|
|
|
|
|
|
|
|
serializer().end_element(xmlns_cp, "coreProperties");
|
2016-08-05 13:52:05 +08:00
|
|
|
}
|
|
|
|
|
2016-09-18 23:32:59 +08:00
|
|
|
void xlsx_producer::write_custom_properties(const relationship &rel)
|
2016-08-05 13:52:05 +08:00
|
|
|
{
|
2016-09-18 23:32:59 +08:00
|
|
|
serializer().element("Properties");
|
2016-08-05 13:52:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Write SpreadsheetML-Specific Package Parts
|
|
|
|
|
2016-09-18 23:32:59 +08:00
|
|
|
void xlsx_producer::write_workbook(const relationship &rel)
|
2016-08-05 13:52:05 +08:00
|
|
|
{
|
|
|
|
std::size_t num_visible = 0;
|
2016-08-13 11:06:25 +08:00
|
|
|
bool any_defined_names = false;
|
2016-08-05 13:52:05 +08:00
|
|
|
|
|
|
|
for (auto ws : source_)
|
|
|
|
{
|
2016-08-14 02:45:26 +08:00
|
|
|
if (!ws.has_page_setup() || ws.get_page_setup().get_sheet_state() == sheet_state::visible)
|
2016-08-05 13:52:05 +08:00
|
|
|
{
|
|
|
|
num_visible++;
|
|
|
|
}
|
2016-08-13 11:06:25 +08:00
|
|
|
|
|
|
|
if (ws.has_auto_filter())
|
|
|
|
{
|
|
|
|
any_defined_names = true;
|
|
|
|
}
|
2016-08-05 13:52:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (num_visible == 0)
|
|
|
|
{
|
2016-08-16 12:23:49 +08:00
|
|
|
throw no_visible_worksheets();
|
2016-08-05 13:52:05 +08:00
|
|
|
}
|
|
|
|
|
2016-09-22 07:04:16 +08:00
|
|
|
static const auto xmlns = constants::get_namespace("workbook");
|
|
|
|
static const auto xmlns_mc = constants::get_namespace("mc");
|
|
|
|
static const auto xmlns_mx = constants::get_namespace("mx");
|
|
|
|
static const auto xmlns_r = constants::get_namespace("r");
|
|
|
|
static const auto xmlns_s = constants::get_namespace("worksheet");
|
|
|
|
static const auto xmlns_x15 = constants::get_namespace("x15");
|
|
|
|
static const auto xmlns_x15ac = constants::get_namespace("x15ac");
|
2016-08-05 13:52:05 +08:00
|
|
|
|
2016-09-18 23:32:59 +08:00
|
|
|
serializer().start_element(xmlns, "workbook");
|
|
|
|
serializer().namespace_decl(xmlns, "");
|
2016-09-19 09:49:37 +08:00
|
|
|
serializer().namespace_decl(xmlns_r, "r");
|
2016-08-05 13:52:05 +08:00
|
|
|
|
2016-08-14 02:45:26 +08:00
|
|
|
if (source_.x15_enabled())
|
|
|
|
{
|
2016-09-19 09:49:37 +08:00
|
|
|
serializer().namespace_decl(xmlns_mc, "mc");
|
|
|
|
serializer().namespace_decl(xmlns_x15, "x15");
|
|
|
|
serializer().attribute(xmlns_mc, "Ignorable", "x15");
|
2016-08-14 02:45:26 +08:00
|
|
|
}
|
2016-09-19 09:49:37 +08:00
|
|
|
|
2016-08-14 02:45:26 +08:00
|
|
|
if (source_.has_file_version())
|
|
|
|
{
|
2016-09-19 09:49:37 +08:00
|
|
|
serializer().start_element(xmlns, "fileVersion");
|
2016-08-14 02:45:26 +08:00
|
|
|
|
2016-09-19 09:49:37 +08:00
|
|
|
serializer().attribute("appName", source_.get_app_name());
|
2016-09-20 06:52:11 +08:00
|
|
|
serializer().attribute("lastEdited", source_.get_last_edited());
|
|
|
|
serializer().attribute("lowestEdited", source_.get_lowest_edited());
|
|
|
|
serializer().attribute("rupBuild", source_.get_rup_build());
|
2016-09-19 09:49:37 +08:00
|
|
|
|
|
|
|
serializer().end_element(xmlns, "fileVersion");
|
2016-08-14 02:45:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (source_.has_properties())
|
|
|
|
{
|
2016-09-19 09:49:37 +08:00
|
|
|
serializer().start_element(xmlns, "workbookPr");
|
2016-08-13 11:06:25 +08:00
|
|
|
|
2016-08-14 02:45:26 +08:00
|
|
|
if (source_.has_code_name())
|
|
|
|
{
|
2016-09-19 09:49:37 +08:00
|
|
|
serializer().attribute("codeName", source_.get_code_name());
|
2016-08-14 02:45:26 +08:00
|
|
|
}
|
|
|
|
|
2016-09-20 06:52:11 +08:00
|
|
|
if (!skip_unknown_elements)
|
2016-09-19 09:49:37 +08:00
|
|
|
{
|
|
|
|
serializer().attribute("defaultThemeVersion", "124226");
|
|
|
|
serializer().attribute("date1904", source_.get_base_date() == calendar::mac_1904 ? "1" : "0");
|
|
|
|
}
|
|
|
|
|
|
|
|
serializer().end_element(xmlns, "workbookPr");
|
2016-08-14 02:45:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (source_.has_absolute_path())
|
|
|
|
{
|
2016-09-19 09:49:37 +08:00
|
|
|
serializer().start_element(xmlns_mc, "AlternateContent");
|
|
|
|
serializer().namespace_decl(xmlns_mc, "mc");
|
2016-08-14 02:45:26 +08:00
|
|
|
|
2016-09-19 09:49:37 +08:00
|
|
|
serializer().start_element(xmlns_mc, "Choice");
|
|
|
|
serializer().attribute("Requires", "x15");
|
2016-08-14 02:45:26 +08:00
|
|
|
|
2016-09-19 09:49:37 +08:00
|
|
|
serializer().start_element(xmlns_x15ac, "absPath");
|
|
|
|
serializer().namespace_decl(xmlns_x15ac, "x15ac");
|
|
|
|
serializer().attribute("url", source_.get_absolute_path().string());
|
|
|
|
|
|
|
|
serializer().end_element(xmlns_x15ac, "absPath");
|
|
|
|
serializer().end_element(xmlns_mc, "Choice");
|
|
|
|
serializer().end_element(xmlns_mc, "AlternateContent");
|
2016-08-14 02:45:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (source_.has_view())
|
|
|
|
{
|
2016-09-19 09:49:37 +08:00
|
|
|
serializer().start_element(xmlns, "bookViews");
|
|
|
|
serializer().start_element(xmlns, "workbookView");
|
2016-08-14 02:45:26 +08:00
|
|
|
|
|
|
|
const auto &view = source_.get_view();
|
|
|
|
|
2016-09-20 06:52:11 +08:00
|
|
|
if (!skip_unknown_elements)
|
|
|
|
{
|
|
|
|
serializer().attribute("activeTab", "0");
|
|
|
|
serializer().attribute("autoFilterDateGrouping", "1");
|
|
|
|
serializer().attribute("firstSheet", "0");
|
|
|
|
serializer().attribute("minimized", "0");
|
|
|
|
serializer().attribute("showHorizontalScroll", "1");
|
|
|
|
serializer().attribute("showSheetTabs", "1");
|
|
|
|
serializer().attribute("showVerticalScroll", "1");
|
|
|
|
serializer().attribute("tabRatio", "600");
|
|
|
|
serializer().attribute("visibility", "visible");
|
|
|
|
}
|
|
|
|
|
|
|
|
serializer().attribute("xWindow", view.x_window);
|
|
|
|
serializer().attribute("yWindow", view.y_window);
|
|
|
|
serializer().attribute("windowWidth", view.window_width);
|
|
|
|
serializer().attribute("windowHeight", view.window_height);
|
|
|
|
serializer().attribute("tabRatio", view.tab_ratio);
|
2016-09-19 09:49:37 +08:00
|
|
|
|
|
|
|
serializer().end_element(xmlns, "workbookView");
|
|
|
|
serializer().end_element(xmlns, "bookViews");
|
2016-08-14 02:45:26 +08:00
|
|
|
}
|
2016-08-05 13:52:05 +08:00
|
|
|
|
2016-09-18 23:32:59 +08:00
|
|
|
serializer().start_element(xmlns, "sheets");
|
2016-09-19 09:49:37 +08:00
|
|
|
|
2016-08-13 11:06:25 +08:00
|
|
|
if (any_defined_names)
|
|
|
|
{
|
2016-09-19 09:49:37 +08:00
|
|
|
serializer().element(xmlns, "definedNames", "");
|
2016-08-13 11:06:25 +08:00
|
|
|
}
|
2016-08-06 22:40:17 +08:00
|
|
|
|
2016-08-05 13:52:05 +08:00
|
|
|
for (const auto ws : source_)
|
|
|
|
{
|
2016-08-06 22:40:17 +08:00
|
|
|
auto sheet_rel_id = source_.d_->sheet_title_rel_id_map_[ws.get_title()];
|
2016-10-10 19:28:49 +08:00
|
|
|
auto sheet_rel = source_.d_->manifest_.get_relationship(rel.get_target().get_path(), sheet_rel_id);
|
2016-08-05 13:52:05 +08:00
|
|
|
|
2016-09-18 23:32:59 +08:00
|
|
|
serializer().start_element(xmlns, "sheet");
|
|
|
|
serializer().attribute("name", ws.get_title());
|
2016-09-20 06:52:11 +08:00
|
|
|
serializer().attribute("sheetId", ws.get_id());
|
2016-08-05 13:52:05 +08:00
|
|
|
|
2016-08-14 02:45:26 +08:00
|
|
|
if (ws.has_page_setup() && ws.get_sheet_state() == xlnt::sheet_state::hidden)
|
2016-08-06 22:40:17 +08:00
|
|
|
{
|
2016-09-18 23:32:59 +08:00
|
|
|
serializer().attribute("state", "hidden");
|
2016-08-06 22:40:17 +08:00
|
|
|
}
|
2016-08-05 13:52:05 +08:00
|
|
|
|
2016-09-19 09:49:37 +08:00
|
|
|
serializer().attribute(xmlns_r, "id", sheet_rel_id);
|
|
|
|
|
2016-08-06 22:40:17 +08:00
|
|
|
if (ws.has_auto_filter())
|
|
|
|
{
|
2016-09-19 09:49:37 +08:00
|
|
|
serializer().start_element(xmlns, "definedName");
|
|
|
|
|
|
|
|
serializer().attribute("name", "_xlnm._FilterDatabase");
|
|
|
|
serializer().attribute("hidden", write_bool(true));
|
|
|
|
serializer().attribute("localSheetId", "0");
|
|
|
|
serializer().characters("'" + ws.get_title() + "'!"
|
|
|
|
+ range_reference::make_absolute(ws.get_auto_filter()).to_string());
|
|
|
|
|
|
|
|
serializer().end_element(xmlns, "definedName");
|
2016-08-05 13:52:05 +08:00
|
|
|
}
|
2016-09-17 10:59:13 +08:00
|
|
|
|
2016-09-18 23:32:59 +08:00
|
|
|
serializer().end_element(xmlns, "sheet");
|
2016-08-05 13:52:05 +08:00
|
|
|
}
|
2016-09-19 09:49:37 +08:00
|
|
|
|
|
|
|
serializer().end_element(xmlns, "sheets");
|
|
|
|
|
2016-08-14 02:45:26 +08:00
|
|
|
if (source_.has_calculation_properties())
|
|
|
|
{
|
2016-09-19 09:49:37 +08:00
|
|
|
serializer().start_element(xmlns, "calcPr");
|
|
|
|
serializer().attribute("calcId", 150000);
|
2016-09-20 06:52:11 +08:00
|
|
|
|
|
|
|
if (!skip_unknown_elements)
|
|
|
|
{
|
|
|
|
serializer().attribute("calcMode", "auto");
|
|
|
|
serializer().attribute("fullCalcOnLoad", "1");
|
|
|
|
}
|
|
|
|
|
2016-09-19 09:49:37 +08:00
|
|
|
serializer().attribute("concurrentCalc", "0");
|
|
|
|
serializer().end_element(xmlns, "calcPr");
|
2016-08-14 02:45:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!source_.get_named_ranges().empty())
|
|
|
|
{
|
2016-09-19 09:49:37 +08:00
|
|
|
serializer().start_element(xmlns, "definedNames");
|
2016-08-05 13:52:05 +08:00
|
|
|
|
2016-08-14 02:45:26 +08:00
|
|
|
for (auto &named_range : source_.get_named_ranges())
|
|
|
|
{
|
2016-09-19 09:49:37 +08:00
|
|
|
serializer().start_element(xmlns_s, "definedName");
|
|
|
|
serializer().namespace_decl(xmlns_s, "s");
|
|
|
|
serializer().attribute("name", named_range.get_name());
|
2016-08-14 02:45:26 +08:00
|
|
|
const auto &target = named_range.get_targets().front();
|
2016-09-19 09:49:37 +08:00
|
|
|
serializer().characters("'" + target.first.get_title()
|
|
|
|
+ "\'!" + target.second.to_string());
|
|
|
|
serializer().end_element(xmlns_s, "definedName");
|
2016-08-14 02:45:26 +08:00
|
|
|
}
|
2016-09-19 09:49:37 +08:00
|
|
|
|
|
|
|
serializer().end_element(xmlns, "definedNames");
|
2016-08-05 13:52:05 +08:00
|
|
|
}
|
2016-08-13 11:06:25 +08:00
|
|
|
|
2016-08-14 02:45:26 +08:00
|
|
|
if (source_.has_arch_id())
|
|
|
|
{
|
2016-09-19 09:49:37 +08:00
|
|
|
serializer().start_element(xmlns, "extLst");
|
|
|
|
serializer().start_element(xmlns, "ext");
|
|
|
|
serializer().namespace_decl(xmlns_mx, "mx");
|
|
|
|
serializer().attribute("uri", "{7523E5D3-25F3-A5E0-1632-64F254C22452}");
|
|
|
|
serializer().start_element(xmlns_mx, "ArchID");
|
|
|
|
serializer().attribute("Flags", 2);
|
|
|
|
serializer().end_element(xmlns_mx, "ArchID");
|
|
|
|
serializer().end_element(xmlns, "ext");
|
|
|
|
serializer().end_element(xmlns, "extLst");
|
2016-08-14 02:45:26 +08:00
|
|
|
}
|
2016-09-19 09:49:37 +08:00
|
|
|
|
2016-09-18 23:32:59 +08:00
|
|
|
serializer().end_element(xmlns, "workbook");
|
|
|
|
|
|
|
|
auto workbook_rels = source_.get_manifest().get_relationships(rel.get_target().get_path());
|
|
|
|
write_relationships(workbook_rels, rel.get_target().get_path());
|
2016-08-12 12:22:14 +08:00
|
|
|
|
2016-09-18 23:32:59 +08:00
|
|
|
for (const auto &child_rel : workbook_rels)
|
2016-08-12 12:22:14 +08:00
|
|
|
{
|
2016-09-17 10:59:13 +08:00
|
|
|
std::ostringstream child_stream;
|
|
|
|
xml::serializer child_serializer(child_stream, child_rel.get_target().get_path().string());
|
2016-09-18 23:32:59 +08:00
|
|
|
serializer_ = &child_serializer;
|
2016-08-12 12:22:14 +08:00
|
|
|
|
|
|
|
switch (child_rel.get_type())
|
|
|
|
{
|
|
|
|
case relationship::type::calculation_chain:
|
2016-09-18 23:32:59 +08:00
|
|
|
write_calculation_chain(child_rel);
|
2016-08-12 12:22:14 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case relationship::type::chartsheet:
|
2016-09-18 23:32:59 +08:00
|
|
|
write_chartsheet(child_rel);
|
2016-08-12 12:22:14 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case relationship::type::connections:
|
2016-09-18 23:32:59 +08:00
|
|
|
write_connections(child_rel);
|
2016-08-12 12:22:14 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case relationship::type::custom_xml_mappings:
|
2016-09-18 23:32:59 +08:00
|
|
|
write_custom_xml_mappings(child_rel);
|
2016-08-12 12:22:14 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case relationship::type::dialogsheet:
|
2016-09-18 23:32:59 +08:00
|
|
|
write_dialogsheet(child_rel);
|
2016-08-12 12:22:14 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case relationship::type::external_workbook_references:
|
2016-09-18 23:32:59 +08:00
|
|
|
write_external_workbook_references(child_rel);
|
2016-08-12 12:22:14 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case relationship::type::metadata:
|
2016-09-18 23:32:59 +08:00
|
|
|
write_metadata(child_rel);
|
2016-08-12 12:22:14 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case relationship::type::pivot_table:
|
2016-09-18 23:32:59 +08:00
|
|
|
write_pivot_table(child_rel);
|
2016-08-12 12:22:14 +08:00
|
|
|
break;
|
2016-08-18 19:34:18 +08:00
|
|
|
|
2016-08-12 12:22:14 +08:00
|
|
|
case relationship::type::shared_string_table:
|
2016-09-18 23:32:59 +08:00
|
|
|
write_shared_string_table(child_rel);
|
2016-08-12 12:22:14 +08:00
|
|
|
break;
|
2016-08-18 19:34:18 +08:00
|
|
|
|
2016-08-12 12:22:14 +08:00
|
|
|
case relationship::type::shared_workbook_revision_headers:
|
2016-09-18 23:32:59 +08:00
|
|
|
write_shared_workbook_revision_headers(child_rel);
|
2016-08-12 12:22:14 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case relationship::type::styles:
|
2016-09-18 23:32:59 +08:00
|
|
|
write_styles(child_rel);
|
2016-08-12 12:22:14 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case relationship::type::theme:
|
2016-09-18 23:32:59 +08:00
|
|
|
write_theme(child_rel);
|
2016-08-12 12:22:14 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case relationship::type::volatile_dependencies:
|
2016-09-18 23:32:59 +08:00
|
|
|
write_volatile_dependencies(child_rel);
|
2016-08-12 12:22:14 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case relationship::type::worksheet:
|
2016-09-18 23:32:59 +08:00
|
|
|
write_worksheet(child_rel);
|
2016-08-12 12:22:14 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-08-14 07:44:45 +08:00
|
|
|
path archive_path(child_rel.get_source().get_path().parent().append(child_rel.get_target().get_path()));
|
2016-09-17 10:59:13 +08:00
|
|
|
destination_.write_string(child_stream.str(), archive_path);
|
2016-08-12 12:22:14 +08:00
|
|
|
}
|
2016-08-05 13:52:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Write Workbook Relationship Target Parts
|
|
|
|
|
2016-09-18 23:32:59 +08:00
|
|
|
void xlsx_producer::write_calculation_chain(const relationship &rel)
|
2016-08-05 13:52:05 +08:00
|
|
|
{
|
2016-09-18 23:32:59 +08:00
|
|
|
serializer().start_element("calcChain");
|
2016-08-05 13:52:05 +08:00
|
|
|
}
|
|
|
|
|
2016-09-18 23:32:59 +08:00
|
|
|
void xlsx_producer::write_chartsheet(const relationship &rel)
|
2016-08-05 13:52:05 +08:00
|
|
|
{
|
2016-09-18 23:32:59 +08:00
|
|
|
serializer().start_element("chartsheet");
|
2016-08-05 13:52:05 +08:00
|
|
|
}
|
|
|
|
|
2016-09-18 23:32:59 +08:00
|
|
|
void xlsx_producer::write_connections(const relationship &rel)
|
2016-08-05 13:52:05 +08:00
|
|
|
{
|
2016-09-18 23:32:59 +08:00
|
|
|
serializer().start_element("connections");
|
2016-08-05 13:52:05 +08:00
|
|
|
}
|
|
|
|
|
2016-09-18 23:32:59 +08:00
|
|
|
void xlsx_producer::write_custom_xml_mappings(const relationship &rel)
|
2016-08-05 13:52:05 +08:00
|
|
|
{
|
2016-09-18 23:32:59 +08:00
|
|
|
serializer().start_element("MapInfo");
|
2016-08-05 13:52:05 +08:00
|
|
|
}
|
|
|
|
|
2016-09-18 23:32:59 +08:00
|
|
|
void xlsx_producer::write_dialogsheet(const relationship &rel)
|
2016-08-05 13:52:05 +08:00
|
|
|
{
|
2016-09-18 23:32:59 +08:00
|
|
|
serializer().start_element("dialogsheet");
|
2016-08-05 13:52:05 +08:00
|
|
|
}
|
|
|
|
|
2016-09-18 23:32:59 +08:00
|
|
|
void xlsx_producer::write_external_workbook_references(const relationship &rel)
|
2016-08-05 13:52:05 +08:00
|
|
|
{
|
2016-09-18 23:32:59 +08:00
|
|
|
serializer().start_element("externalLink");
|
2016-08-05 13:52:05 +08:00
|
|
|
}
|
|
|
|
|
2016-09-18 23:32:59 +08:00
|
|
|
void xlsx_producer::write_metadata(const relationship &rel)
|
2016-08-05 13:52:05 +08:00
|
|
|
{
|
2016-09-18 23:32:59 +08:00
|
|
|
serializer().start_element("metadata");
|
2016-08-05 13:52:05 +08:00
|
|
|
}
|
|
|
|
|
2016-09-18 23:32:59 +08:00
|
|
|
void xlsx_producer::write_pivot_table(const relationship &rel)
|
2016-08-05 13:52:05 +08:00
|
|
|
{
|
2016-09-18 23:32:59 +08:00
|
|
|
serializer().start_element("pivotTableDefinition");
|
2016-08-05 13:52:05 +08:00
|
|
|
}
|
|
|
|
|
2016-09-18 23:32:59 +08:00
|
|
|
void xlsx_producer::write_shared_string_table(const relationship &rel)
|
2016-08-05 13:52:05 +08:00
|
|
|
{
|
2016-09-22 07:04:16 +08:00
|
|
|
static const auto xmlns = constants::get_namespace("worksheet");
|
2016-09-19 09:49:37 +08:00
|
|
|
|
|
|
|
serializer().start_element(xmlns, "sst");
|
|
|
|
serializer().namespace_decl(xmlns, "");
|
|
|
|
|
|
|
|
// todo: is there a more elegant way to get this number?
|
2016-09-12 02:57:34 +08:00
|
|
|
std::size_t string_count = 0;
|
2016-08-05 13:52:05 +08:00
|
|
|
|
2016-09-12 02:57:34 +08:00
|
|
|
for (const auto ws : source_)
|
|
|
|
{
|
2016-10-26 08:01:09 +08:00
|
|
|
auto dimension = ws.calculate_dimension();
|
|
|
|
|
|
|
|
for (xlnt::row_t row = dimension.get_top_left().get_row();
|
|
|
|
row <= dimension.get_bottom_right().get_row(); ++row)
|
2016-09-12 02:57:34 +08:00
|
|
|
{
|
2016-10-26 08:01:09 +08:00
|
|
|
for (xlnt::column_t column = dimension.get_top_left().get_column();
|
|
|
|
column <= dimension.get_bottom_right().get_column(); ++column)
|
2016-09-12 02:57:34 +08:00
|
|
|
{
|
2016-10-26 08:01:09 +08:00
|
|
|
if (ws.has_cell(xlnt::cell_reference(column, row)))
|
2016-09-12 02:57:34 +08:00
|
|
|
{
|
2016-10-26 08:01:09 +08:00
|
|
|
string_count += (ws.get_cell(xlnt::cell_reference(column, row))
|
|
|
|
.get_data_type() == cell::type::string) ? 1 : 0;
|
2016-09-12 02:57:34 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-19 09:49:37 +08:00
|
|
|
serializer().attribute("count", string_count);
|
|
|
|
serializer().attribute("uniqueCount", source_.get_shared_strings().size());
|
2016-08-05 13:52:05 +08:00
|
|
|
|
|
|
|
for (const auto &string : source_.get_shared_strings())
|
|
|
|
{
|
2016-10-29 22:23:04 +08:00
|
|
|
if (string.runs().size() == 1 && !string.runs().at(0).has_formatting())
|
2016-08-05 13:52:05 +08:00
|
|
|
{
|
2016-09-19 09:49:37 +08:00
|
|
|
serializer().start_element(xmlns, "si");
|
2016-10-29 22:23:04 +08:00
|
|
|
serializer().element(xmlns, "t", string.plain_text());
|
2016-09-19 09:49:37 +08:00
|
|
|
serializer().end_element(xmlns, "si");
|
|
|
|
|
|
|
|
continue;
|
2016-08-05 13:52:05 +08:00
|
|
|
}
|
|
|
|
|
2016-09-19 09:49:37 +08:00
|
|
|
serializer().start_element(xmlns, "si");
|
2016-08-05 13:52:05 +08:00
|
|
|
|
2016-10-29 22:23:04 +08:00
|
|
|
for (const auto &run : string.runs())
|
2016-09-19 09:49:37 +08:00
|
|
|
{
|
|
|
|
serializer().start_element(xmlns, "r");
|
2016-08-05 13:52:05 +08:00
|
|
|
|
2016-09-19 09:49:37 +08:00
|
|
|
if (run.has_formatting())
|
|
|
|
{
|
|
|
|
serializer().start_element(xmlns, "rPr");
|
2016-08-05 13:52:05 +08:00
|
|
|
|
2016-09-19 09:49:37 +08:00
|
|
|
if (run.has_size())
|
|
|
|
{
|
|
|
|
serializer().start_element(xmlns, "sz");
|
|
|
|
serializer().attribute("val", run.get_size());
|
|
|
|
serializer().end_element(xmlns, "sz");
|
|
|
|
}
|
2016-08-05 13:52:05 +08:00
|
|
|
|
2016-09-19 09:49:37 +08:00
|
|
|
if (run.has_color())
|
|
|
|
{
|
|
|
|
serializer().start_element(xmlns, "color");
|
2016-10-29 22:23:04 +08:00
|
|
|
write_color(run.get_color());
|
2016-09-19 09:49:37 +08:00
|
|
|
serializer().end_element(xmlns, "color");
|
|
|
|
}
|
2016-08-05 13:52:05 +08:00
|
|
|
|
2016-09-19 09:49:37 +08:00
|
|
|
if (run.has_font())
|
|
|
|
{
|
|
|
|
serializer().start_element(xmlns, "rFont");
|
|
|
|
serializer().attribute("val", run.get_font());
|
|
|
|
serializer().end_element(xmlns, "rFont");
|
|
|
|
}
|
2016-08-05 13:52:05 +08:00
|
|
|
|
2016-09-19 09:49:37 +08:00
|
|
|
if (run.has_family())
|
|
|
|
{
|
|
|
|
serializer().start_element(xmlns, "family");
|
|
|
|
serializer().attribute("val", run.get_family());
|
|
|
|
serializer().end_element(xmlns, "family");
|
|
|
|
}
|
2016-08-05 13:52:05 +08:00
|
|
|
|
2016-09-19 09:49:37 +08:00
|
|
|
if (run.has_scheme())
|
|
|
|
{
|
|
|
|
serializer().start_element(xmlns, "scheme");
|
|
|
|
serializer().attribute("val", run.get_scheme());
|
|
|
|
serializer().end_element(xmlns, "scheme");
|
|
|
|
}
|
|
|
|
|
|
|
|
serializer().end_element(xmlns, "rPr");
|
|
|
|
}
|
|
|
|
|
|
|
|
serializer().element(xmlns, "t", run.get_string());
|
|
|
|
serializer().end_element(xmlns, "r");
|
|
|
|
}
|
|
|
|
|
|
|
|
serializer().end_element(xmlns, "si");
|
2016-08-05 13:52:05 +08:00
|
|
|
}
|
2016-09-19 09:49:37 +08:00
|
|
|
|
|
|
|
serializer().end_element(xmlns, "sst");
|
2016-08-05 13:52:05 +08:00
|
|
|
}
|
|
|
|
|
2016-09-18 23:32:59 +08:00
|
|
|
void xlsx_producer::write_shared_workbook_revision_headers(const relationship &rel)
|
2016-08-05 13:52:05 +08:00
|
|
|
{
|
2016-09-18 23:32:59 +08:00
|
|
|
serializer().start_element("headers");
|
2016-08-05 13:52:05 +08:00
|
|
|
}
|
|
|
|
|
2016-09-18 23:32:59 +08:00
|
|
|
void xlsx_producer::write_shared_workbook(const relationship &rel)
|
2016-08-05 13:52:05 +08:00
|
|
|
{
|
2016-09-18 23:32:59 +08:00
|
|
|
serializer().start_element("revisions");
|
2016-08-05 13:52:05 +08:00
|
|
|
}
|
|
|
|
|
2016-09-18 23:32:59 +08:00
|
|
|
void xlsx_producer::write_shared_workbook_user_data(const relationship &rel)
|
2016-08-05 13:52:05 +08:00
|
|
|
{
|
2016-09-18 23:32:59 +08:00
|
|
|
serializer().start_element("users");
|
2016-08-05 13:52:05 +08:00
|
|
|
}
|
|
|
|
|
2016-09-18 23:32:59 +08:00
|
|
|
void xlsx_producer::write_styles(const relationship &rel)
|
2016-08-05 13:52:05 +08:00
|
|
|
{
|
2016-09-22 07:04:16 +08:00
|
|
|
static const auto xmlns = constants::get_namespace("worksheet");
|
|
|
|
static const auto xmlns_mc = constants::get_namespace("mc");
|
|
|
|
static const auto xmlns_x14 = constants::get_namespace("x14");
|
|
|
|
static const auto xmlns_x14ac = constants::get_namespace("x14ac");
|
2016-09-19 09:49:37 +08:00
|
|
|
|
|
|
|
serializer().start_element(xmlns, "styleSheet");
|
|
|
|
serializer().namespace_decl(xmlns, "");
|
2016-08-18 19:34:18 +08:00
|
|
|
|
|
|
|
if (source_.x15_enabled())
|
|
|
|
{
|
2016-09-19 09:49:37 +08:00
|
|
|
serializer().namespace_decl(xmlns_mc, "mc");
|
|
|
|
serializer().namespace_decl(xmlns_x14ac, "x14ac");
|
|
|
|
serializer().attribute(xmlns_mc, "Ignorable", "x14ac");
|
2016-08-18 19:34:18 +08:00
|
|
|
}
|
2016-08-05 13:52:05 +08:00
|
|
|
|
|
|
|
const auto &stylesheet = source_.impl().stylesheet_;
|
|
|
|
|
2016-08-18 19:34:18 +08:00
|
|
|
// Number Formats
|
|
|
|
|
2016-08-05 13:52:05 +08:00
|
|
|
if (!stylesheet.number_formats.empty())
|
|
|
|
{
|
2016-09-19 09:49:37 +08:00
|
|
|
const auto &number_formats = stylesheet.number_formats;
|
2016-08-18 19:34:18 +08:00
|
|
|
|
2016-09-19 09:49:37 +08:00
|
|
|
serializer().start_element(xmlns, "numFmts");
|
|
|
|
serializer().attribute("count", number_formats.size());
|
2016-08-18 19:34:18 +08:00
|
|
|
|
|
|
|
for (const auto &num_fmt : number_formats)
|
|
|
|
{
|
2016-09-19 09:49:37 +08:00
|
|
|
serializer().start_element(xmlns, "numFmt");
|
|
|
|
serializer().attribute("numFmtId", num_fmt.get_id());
|
|
|
|
serializer().attribute("formatCode", num_fmt.get_format_string());
|
|
|
|
serializer().end_element(xmlns, "numFmt");
|
2016-08-18 19:34:18 +08:00
|
|
|
}
|
2016-09-19 09:49:37 +08:00
|
|
|
|
|
|
|
serializer().end_element(xmlns, "numFmts");
|
2016-08-05 13:52:05 +08:00
|
|
|
}
|
|
|
|
|
2016-08-18 19:34:18 +08:00
|
|
|
// Fonts
|
|
|
|
|
2016-08-05 13:52:05 +08:00
|
|
|
if (!stylesheet.fonts.empty())
|
|
|
|
{
|
2016-08-18 19:34:18 +08:00
|
|
|
const auto &fonts = stylesheet.fonts;
|
|
|
|
|
2016-09-19 09:49:37 +08:00
|
|
|
serializer().start_element(xmlns, "fonts");
|
|
|
|
serializer().attribute("count", fonts.size());
|
2016-08-18 19:34:18 +08:00
|
|
|
|
2016-10-14 08:11:02 +08:00
|
|
|
auto num_known_fonts = std::count_if(fonts.begin(), fonts.end(), [](const xlnt::font &f)
|
|
|
|
{
|
|
|
|
static const auto known_fonts = std::vector<xlnt::font>
|
|
|
|
{
|
|
|
|
xlnt::font().color(xlnt::theme_color(1)).scheme("minor").family(2)
|
|
|
|
};
|
|
|
|
|
|
|
|
return std::find(known_fonts.begin(), known_fonts.end(), f) != known_fonts.end();
|
|
|
|
});
|
|
|
|
|
2016-08-18 19:34:18 +08:00
|
|
|
if (source_.x15_enabled())
|
|
|
|
{
|
2016-10-14 08:11:02 +08:00
|
|
|
serializer().attribute(xmlns_x14ac, "knownFonts", num_known_fonts);
|
2016-08-18 19:34:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for (const auto ¤t_font : fonts)
|
|
|
|
{
|
2016-09-19 09:49:37 +08:00
|
|
|
serializer().start_element(xmlns, "font");
|
2016-08-18 19:34:18 +08:00
|
|
|
|
|
|
|
if (current_font.bold())
|
|
|
|
{
|
2016-09-19 09:49:37 +08:00
|
|
|
serializer().start_element(xmlns, "b");
|
|
|
|
serializer().attribute("val", write_bool(true));
|
|
|
|
serializer().end_element(xmlns, "b");
|
2016-08-18 19:34:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (current_font.italic())
|
|
|
|
{
|
2016-09-19 09:49:37 +08:00
|
|
|
serializer().start_element(xmlns, "i");
|
|
|
|
serializer().attribute("val", write_bool(true));
|
|
|
|
serializer().end_element(xmlns, "i");
|
2016-08-18 19:34:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (current_font.underlined())
|
|
|
|
{
|
2016-09-19 09:49:37 +08:00
|
|
|
serializer().start_element(xmlns, "u");
|
|
|
|
serializer().attribute("val", current_font.underline());
|
|
|
|
serializer().end_element(xmlns, "u");
|
2016-08-18 19:34:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (current_font.strikethrough())
|
|
|
|
{
|
2016-09-19 09:49:37 +08:00
|
|
|
serializer().start_element(xmlns, "strike");
|
|
|
|
serializer().attribute("val", write_bool(true));
|
|
|
|
serializer().end_element(xmlns, "strike");
|
2016-08-18 19:34:18 +08:00
|
|
|
}
|
|
|
|
|
2016-09-19 09:49:37 +08:00
|
|
|
serializer().start_element(xmlns, "sz");
|
|
|
|
serializer().attribute("val", current_font.size());
|
|
|
|
serializer().end_element(xmlns, "sz");
|
2016-08-18 19:34:18 +08:00
|
|
|
|
|
|
|
if (current_font.color())
|
|
|
|
{
|
2016-09-19 09:49:37 +08:00
|
|
|
serializer().start_element(xmlns, "color");
|
|
|
|
write_color(*current_font.color());
|
|
|
|
serializer().end_element(xmlns, "color");
|
2016-08-18 19:34:18 +08:00
|
|
|
}
|
|
|
|
|
2016-09-19 09:49:37 +08:00
|
|
|
serializer().start_element(xmlns, "name");
|
|
|
|
serializer().attribute("val", current_font.name());
|
|
|
|
serializer().end_element(xmlns, "name");
|
2016-08-18 19:34:18 +08:00
|
|
|
|
|
|
|
if (current_font.family())
|
|
|
|
{
|
2016-09-19 09:49:37 +08:00
|
|
|
serializer().start_element(xmlns, "family");
|
|
|
|
serializer().attribute("val", *current_font.family());
|
|
|
|
serializer().end_element(xmlns, "family");
|
2016-08-18 19:34:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (current_font.scheme())
|
|
|
|
{
|
2016-09-19 09:49:37 +08:00
|
|
|
serializer().start_element(xmlns, "scheme");
|
|
|
|
serializer().attribute("val", *current_font.scheme());
|
|
|
|
serializer().end_element(xmlns, "scheme");
|
2016-08-18 19:34:18 +08:00
|
|
|
}
|
2016-09-20 06:52:11 +08:00
|
|
|
|
|
|
|
serializer().end_element(xmlns, "font");
|
2016-08-18 19:34:18 +08:00
|
|
|
}
|
2016-09-20 06:52:11 +08:00
|
|
|
|
|
|
|
serializer().end_element(xmlns, "fonts");
|
2016-08-05 13:52:05 +08:00
|
|
|
}
|
2016-09-20 06:52:11 +08:00
|
|
|
|
2016-08-18 19:34:18 +08:00
|
|
|
// Fills
|
|
|
|
|
2016-08-05 13:52:05 +08:00
|
|
|
if (!stylesheet.fills.empty())
|
|
|
|
{
|
2016-08-18 19:34:18 +08:00
|
|
|
const auto &fills = stylesheet.fills;
|
|
|
|
|
2016-09-20 06:52:11 +08:00
|
|
|
serializer().start_element(xmlns, "fills");
|
|
|
|
serializer().attribute("count", fills.size());
|
2016-08-18 19:34:18 +08:00
|
|
|
|
|
|
|
for (auto &fill_ : fills)
|
|
|
|
{
|
2016-09-20 06:52:11 +08:00
|
|
|
serializer().start_element(xmlns, "fill");
|
2016-08-18 19:34:18 +08:00
|
|
|
|
|
|
|
if (fill_.type() == xlnt::fill_type::pattern)
|
|
|
|
{
|
|
|
|
const auto &pattern = fill_.pattern_fill();
|
|
|
|
|
2016-09-20 06:52:11 +08:00
|
|
|
serializer().start_element(xmlns, "patternFill");
|
|
|
|
serializer().attribute("patternType", pattern.type());
|
2016-08-18 19:34:18 +08:00
|
|
|
|
|
|
|
if (pattern.foreground())
|
|
|
|
{
|
2016-09-20 06:52:11 +08:00
|
|
|
serializer().start_element(xmlns, "fgColor");
|
|
|
|
write_color(*pattern.foreground());
|
|
|
|
serializer().end_element(xmlns, "fgColor");
|
2016-08-18 19:34:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (pattern.background())
|
|
|
|
{
|
2016-09-20 06:52:11 +08:00
|
|
|
serializer().start_element(xmlns, "bgColor");
|
|
|
|
write_color(*pattern.background());
|
|
|
|
serializer().end_element(xmlns, "bgColor");
|
2016-08-18 19:34:18 +08:00
|
|
|
}
|
2016-09-20 06:52:11 +08:00
|
|
|
|
|
|
|
serializer().end_element(xmlns, "patternFill");
|
2016-08-18 19:34:18 +08:00
|
|
|
}
|
|
|
|
else if (fill_.type() == xlnt::fill_type::gradient)
|
|
|
|
{
|
|
|
|
const auto &gradient = fill_.gradient_fill();
|
|
|
|
|
2016-09-20 06:52:11 +08:00
|
|
|
serializer().start_element(xmlns, "gradientFill");
|
|
|
|
serializer().attribute("gradientType", gradient.type());
|
2016-08-18 19:34:18 +08:00
|
|
|
|
|
|
|
if (gradient.degree() != 0)
|
|
|
|
{
|
2016-09-20 06:52:11 +08:00
|
|
|
serializer().attribute("degree", gradient.degree());
|
2016-08-18 19:34:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (gradient.left() != 0)
|
|
|
|
{
|
2016-09-20 06:52:11 +08:00
|
|
|
serializer().attribute("left", gradient.left());
|
2016-08-18 19:34:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (gradient.right() != 0)
|
|
|
|
{
|
2016-09-20 06:52:11 +08:00
|
|
|
serializer().attribute("right", gradient.right());
|
2016-08-18 19:34:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (gradient.top() != 0)
|
|
|
|
{
|
2016-09-20 06:52:11 +08:00
|
|
|
serializer().attribute("top", gradient.top());
|
2016-08-18 19:34:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (gradient.bottom() != 0)
|
|
|
|
{
|
2016-09-20 06:52:11 +08:00
|
|
|
serializer().attribute("bottom", gradient.bottom());
|
2016-08-18 19:34:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for (const auto &stop : gradient.stops())
|
|
|
|
{
|
2016-09-20 06:52:11 +08:00
|
|
|
serializer().start_element(xmlns, "stop");
|
|
|
|
serializer().attribute("position", stop.first);
|
|
|
|
serializer().start_element(xmlns, "color");
|
|
|
|
write_color(stop.second);
|
|
|
|
serializer().end_element(xmlns, "color");
|
|
|
|
serializer().end_element(xmlns, "stop");
|
2016-08-18 19:34:18 +08:00
|
|
|
}
|
2016-09-20 06:52:11 +08:00
|
|
|
|
|
|
|
serializer().end_element(xmlns, "gradientFill");
|
2016-08-18 19:34:18 +08:00
|
|
|
}
|
2016-09-20 06:52:11 +08:00
|
|
|
|
|
|
|
serializer().end_element(xmlns, "fill");
|
2016-08-18 19:34:18 +08:00
|
|
|
}
|
2016-09-20 06:52:11 +08:00
|
|
|
|
|
|
|
serializer().end_element(xmlns, "fills");
|
2016-08-05 13:52:05 +08:00
|
|
|
}
|
|
|
|
|
2016-08-18 19:34:18 +08:00
|
|
|
// Borders
|
|
|
|
|
2016-08-05 13:52:05 +08:00
|
|
|
if (!stylesheet.borders.empty())
|
|
|
|
{
|
2016-08-18 19:34:18 +08:00
|
|
|
const auto &borders = stylesheet.borders;
|
|
|
|
|
2016-09-20 06:52:11 +08:00
|
|
|
serializer().start_element(xmlns, "borders");
|
|
|
|
serializer().attribute("count", borders.size());
|
2016-08-18 19:34:18 +08:00
|
|
|
|
|
|
|
for (const auto ¤t_border : borders)
|
|
|
|
{
|
2016-09-20 06:52:11 +08:00
|
|
|
serializer().start_element(xmlns, "border");
|
2016-08-18 19:34:18 +08:00
|
|
|
|
|
|
|
if (current_border.diagonal())
|
|
|
|
{
|
|
|
|
auto up = *current_border.diagonal() == diagonal_direction::both
|
|
|
|
|| *current_border.diagonal() == diagonal_direction::up;
|
2016-09-20 06:52:11 +08:00
|
|
|
serializer().attribute("diagonalUp", up ? "true" : "false");
|
2016-08-18 19:34:18 +08:00
|
|
|
|
|
|
|
auto down = *current_border.diagonal() == diagonal_direction::both
|
|
|
|
|| *current_border.diagonal() == diagonal_direction::down;
|
2016-09-20 06:52:11 +08:00
|
|
|
serializer().attribute("diagonalDown", down ? "true" : "false");
|
2016-08-18 19:34:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for (const auto &side : xlnt::border::all_sides())
|
|
|
|
{
|
|
|
|
if (current_border.side(side))
|
|
|
|
{
|
|
|
|
const auto current_side = *current_border.side(side);
|
|
|
|
|
|
|
|
auto side_name = to_string(side);
|
2016-09-20 06:52:11 +08:00
|
|
|
serializer().start_element(xmlns, side_name);
|
2016-08-18 19:34:18 +08:00
|
|
|
|
|
|
|
if (current_side.style())
|
|
|
|
{
|
2016-09-20 06:52:11 +08:00
|
|
|
serializer().attribute("style", *current_side.style());
|
2016-08-18 19:34:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (current_side.color())
|
|
|
|
{
|
2016-09-20 06:52:11 +08:00
|
|
|
serializer().start_element(xmlns, "color");
|
|
|
|
write_color(*current_side.color());
|
|
|
|
serializer().end_element(xmlns, "color");
|
2016-08-18 19:34:18 +08:00
|
|
|
}
|
2016-09-20 06:52:11 +08:00
|
|
|
|
|
|
|
serializer().end_element(xmlns, side_name);
|
2016-08-18 19:34:18 +08:00
|
|
|
}
|
|
|
|
}
|
2016-09-20 06:52:11 +08:00
|
|
|
|
|
|
|
serializer().end_element(xmlns, "border");
|
2016-08-18 19:34:18 +08:00
|
|
|
}
|
2016-09-20 06:52:11 +08:00
|
|
|
|
|
|
|
serializer().end_element(xmlns, "borders");
|
2016-08-05 13:52:05 +08:00
|
|
|
}
|
|
|
|
|
2016-09-20 06:52:11 +08:00
|
|
|
// Style XFs
|
|
|
|
|
|
|
|
serializer().start_element(xmlns, "cellStyleXfs");
|
|
|
|
serializer().attribute("count", stylesheet.styles.size());
|
2016-08-18 19:34:18 +08:00
|
|
|
|
2016-09-20 06:52:11 +08:00
|
|
|
for (auto ¤t_style : stylesheet.styles)
|
2016-08-18 19:34:18 +08:00
|
|
|
{
|
2016-09-20 06:52:11 +08:00
|
|
|
serializer().start_element(xmlns, "xf");
|
|
|
|
serializer().attribute("numFmtId", current_style.number_format().get_id());
|
|
|
|
serializer().attribute("fontId", std::distance(stylesheet.fonts.begin(),
|
|
|
|
std::find(stylesheet.fonts.begin(), stylesheet.fonts.end(), current_style.font())));
|
|
|
|
serializer().attribute("fillId", std::distance(stylesheet.fills.begin(),
|
|
|
|
std::find(stylesheet.fills.begin(), stylesheet.fills.end(), current_style.fill())));
|
|
|
|
serializer().attribute("borderId", std::distance(stylesheet.borders.begin(),
|
|
|
|
std::find(stylesheet.borders.begin(), stylesheet.borders.end(), current_style.border())));
|
|
|
|
|
|
|
|
if (current_style.number_format_applied()) serializer().attribute("applyNumberFormat", write_bool(true));
|
|
|
|
if (current_style.fill_applied()) serializer().attribute("applyFill", write_bool(true));
|
|
|
|
if (current_style.font_applied()) serializer().attribute("applyFont", write_bool(true));
|
|
|
|
if (current_style.border_applied()) serializer().attribute("applyBorder", write_bool(true));
|
|
|
|
if (current_style.alignment_applied()) serializer().attribute("applyAlignment", write_bool(true));
|
|
|
|
if (current_style.protection_applied()) serializer().attribute("applyProtection", write_bool(true));
|
2016-08-18 19:34:18 +08:00
|
|
|
|
2016-09-20 06:52:11 +08:00
|
|
|
if (current_style.alignment_applied())
|
2016-08-18 19:34:18 +08:00
|
|
|
{
|
2016-09-20 06:52:11 +08:00
|
|
|
const auto current_alignment = current_style.alignment();
|
|
|
|
|
2016-10-14 08:11:02 +08:00
|
|
|
serializer().start_element(xmlns, "alignment");
|
2016-08-18 19:34:18 +08:00
|
|
|
|
|
|
|
if (current_alignment.vertical())
|
|
|
|
{
|
2016-09-20 06:52:11 +08:00
|
|
|
serializer().attribute("vertical", *current_alignment.vertical());
|
2016-08-18 19:34:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (current_alignment.horizontal())
|
|
|
|
{
|
2016-09-20 06:52:11 +08:00
|
|
|
serializer().attribute("horizontal", *current_alignment.horizontal());
|
2016-08-18 19:34:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (current_alignment.rotation())
|
|
|
|
{
|
2016-09-20 06:52:11 +08:00
|
|
|
serializer().attribute("textRotation", *current_alignment.rotation());
|
2016-08-18 19:34:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (current_alignment.wrap())
|
|
|
|
{
|
2016-09-20 06:52:11 +08:00
|
|
|
serializer().attribute("wrapText", write_bool(*current_alignment.wrap()));
|
2016-08-18 19:34:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (current_alignment.indent())
|
|
|
|
{
|
2016-09-20 06:52:11 +08:00
|
|
|
serializer().attribute("indent", *current_alignment.indent());
|
2016-08-18 19:34:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (current_alignment.shrink())
|
|
|
|
{
|
2016-09-20 06:52:11 +08:00
|
|
|
serializer().attribute("shrinkToFit", write_bool(*current_alignment.shrink()));
|
2016-08-18 19:34:18 +08:00
|
|
|
}
|
2016-09-20 06:52:11 +08:00
|
|
|
|
2016-10-14 08:11:02 +08:00
|
|
|
serializer().end_element(xmlns, "alignment");
|
2016-08-18 19:34:18 +08:00
|
|
|
}
|
|
|
|
|
2016-09-20 06:52:11 +08:00
|
|
|
if (current_style.protection_applied())
|
2016-08-18 19:34:18 +08:00
|
|
|
{
|
2016-09-20 06:52:11 +08:00
|
|
|
const auto current_protection = current_style.protection();
|
2016-08-18 19:34:18 +08:00
|
|
|
|
2016-10-14 08:11:02 +08:00
|
|
|
serializer().start_element(xmlns, "protection");
|
2016-09-20 06:52:11 +08:00
|
|
|
serializer().attribute("locked", write_bool(current_protection.locked()));
|
|
|
|
serializer().attribute("hidden", write_bool(current_protection.hidden()));
|
2016-10-14 08:11:02 +08:00
|
|
|
serializer().end_element(xmlns, "protection");
|
2016-08-18 19:34:18 +08:00
|
|
|
}
|
2016-09-20 06:52:11 +08:00
|
|
|
|
|
|
|
serializer().end_element(xmlns, "xf");
|
2016-08-18 19:34:18 +08:00
|
|
|
}
|
2016-09-20 06:52:11 +08:00
|
|
|
|
|
|
|
serializer().end_element(xmlns, "cellStyleXfs");
|
2016-08-18 19:34:18 +08:00
|
|
|
|
2016-09-20 06:52:11 +08:00
|
|
|
// Format XFs
|
2016-08-05 13:52:05 +08:00
|
|
|
|
2016-09-20 06:52:11 +08:00
|
|
|
serializer().start_element(xmlns, "cellXfs");
|
|
|
|
serializer().attribute("count", stylesheet.formats.size());
|
2016-08-18 19:34:18 +08:00
|
|
|
|
2016-09-20 06:52:11 +08:00
|
|
|
for (auto ¤t_format : stylesheet.formats)
|
2016-08-18 19:34:18 +08:00
|
|
|
{
|
2016-09-20 06:52:11 +08:00
|
|
|
serializer().start_element(xmlns, "xf");
|
|
|
|
serializer().attribute("numFmtId", current_format.number_format().get_id());
|
|
|
|
serializer().attribute("fontId", std::distance(stylesheet.fonts.begin(),
|
|
|
|
std::find(stylesheet.fonts.begin(), stylesheet.fonts.end(), current_format.font())));
|
|
|
|
serializer().attribute("fillId", std::distance(stylesheet.fills.begin(),
|
|
|
|
std::find(stylesheet.fills.begin(), stylesheet.fills.end(), current_format.fill())));
|
|
|
|
serializer().attribute("borderId", std::distance(stylesheet.borders.begin(),
|
|
|
|
std::find(stylesheet.borders.begin(), stylesheet.borders.end(), current_format.border())));
|
|
|
|
|
|
|
|
if (current_format.number_format_applied()) serializer().attribute("applyNumberFormat", write_bool(true));
|
|
|
|
if (current_format.fill_applied()) serializer().attribute("applyFill", write_bool(true));
|
|
|
|
if (current_format.font_applied()) serializer().attribute("applyFont", write_bool(true));
|
|
|
|
if (current_format.border_applied()) serializer().attribute("applyBorder", write_bool(true));
|
|
|
|
if (current_format.alignment_applied()) serializer().attribute("applyAlignment", write_bool(true));
|
|
|
|
if (current_format.protection_applied()) serializer().attribute("applyProtection", write_bool(true));
|
2016-08-18 19:34:18 +08:00
|
|
|
|
2016-10-14 08:11:02 +08:00
|
|
|
if (current_format.has_style())
|
|
|
|
{
|
|
|
|
serializer().attribute("xfId", std::distance(stylesheet.styles.begin(),
|
|
|
|
std::find_if(stylesheet.styles.begin(), stylesheet.styles.end(),
|
|
|
|
[&](const xlnt::style &s) { return s.name() == current_format.style().name(); })));
|
|
|
|
}
|
|
|
|
|
2016-09-20 06:52:11 +08:00
|
|
|
if (current_format.alignment_applied())
|
2016-08-18 19:34:18 +08:00
|
|
|
{
|
2016-09-20 06:52:11 +08:00
|
|
|
const auto current_alignment = current_format.alignment();
|
2016-08-18 19:34:18 +08:00
|
|
|
|
2016-10-14 08:11:02 +08:00
|
|
|
serializer().start_element(xmlns, "alignment");
|
2016-08-18 19:34:18 +08:00
|
|
|
|
|
|
|
if (current_alignment.vertical())
|
|
|
|
{
|
2016-09-20 06:52:11 +08:00
|
|
|
serializer().attribute("vertical", *current_alignment.vertical());
|
2016-08-18 19:34:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (current_alignment.horizontal())
|
|
|
|
{
|
2016-09-20 06:52:11 +08:00
|
|
|
serializer().attribute("horizontal", *current_alignment.horizontal());
|
2016-08-18 19:34:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (current_alignment.rotation())
|
|
|
|
{
|
2016-09-20 06:52:11 +08:00
|
|
|
serializer().attribute("textRotation", *current_alignment.rotation());
|
2016-08-18 19:34:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (current_alignment.wrap())
|
|
|
|
{
|
2016-09-20 06:52:11 +08:00
|
|
|
serializer().attribute("wrapText", write_bool(*current_alignment.wrap()));
|
2016-08-18 19:34:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (current_alignment.indent())
|
|
|
|
{
|
2016-09-20 06:52:11 +08:00
|
|
|
serializer().attribute("indent", *current_alignment.indent());
|
2016-08-18 19:34:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (current_alignment.shrink())
|
|
|
|
{
|
2016-09-20 06:52:11 +08:00
|
|
|
serializer().attribute("shrinkToFit", write_bool(*current_alignment.shrink()));
|
2016-08-18 19:34:18 +08:00
|
|
|
}
|
2016-09-20 06:52:11 +08:00
|
|
|
|
2016-10-14 08:11:02 +08:00
|
|
|
serializer().end_element(xmlns, "alignment");
|
2016-08-18 19:34:18 +08:00
|
|
|
}
|
|
|
|
|
2016-09-20 06:52:11 +08:00
|
|
|
if (current_format.protection_applied())
|
2016-08-18 19:34:18 +08:00
|
|
|
{
|
2016-09-20 06:52:11 +08:00
|
|
|
const auto current_protection = current_format.protection();
|
2016-08-18 19:34:18 +08:00
|
|
|
|
2016-10-14 08:11:02 +08:00
|
|
|
serializer().start_element(xmlns, "protection");
|
2016-09-20 06:52:11 +08:00
|
|
|
serializer().attribute("locked", write_bool(current_protection.locked()));
|
|
|
|
serializer().attribute("hidden", write_bool(current_protection.hidden()));
|
2016-10-14 08:11:02 +08:00
|
|
|
serializer().end_element(xmlns, "protection");
|
2016-09-20 06:52:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
serializer().end_element(xmlns, "xf");
|
2016-08-18 19:34:18 +08:00
|
|
|
}
|
2016-09-20 06:52:11 +08:00
|
|
|
|
|
|
|
serializer().end_element(xmlns, "cellXfs");
|
2016-08-18 19:34:18 +08:00
|
|
|
|
2016-09-20 06:52:11 +08:00
|
|
|
// Styles
|
2016-08-05 13:52:05 +08:00
|
|
|
|
2016-09-20 06:52:11 +08:00
|
|
|
serializer().start_element(xmlns, "cellStyles");
|
|
|
|
serializer().attribute("count", stylesheet.styles.size());
|
|
|
|
std::size_t style_index = 0;
|
2016-08-05 13:52:05 +08:00
|
|
|
|
2016-09-20 06:52:11 +08:00
|
|
|
for (auto ¤t_style : stylesheet.styles)
|
|
|
|
{
|
|
|
|
serializer().start_element(xmlns, "cellStyle");
|
2016-08-18 19:34:18 +08:00
|
|
|
|
2016-09-20 06:52:11 +08:00
|
|
|
serializer().attribute("name", current_style.name());
|
|
|
|
serializer().attribute("xfId", style_index++);
|
2016-08-05 13:52:05 +08:00
|
|
|
|
2016-09-20 06:52:11 +08:00
|
|
|
if (current_style.builtin_id())
|
|
|
|
{
|
|
|
|
serializer().attribute("builtinId", *current_style.builtin_id());
|
|
|
|
}
|
2016-08-18 19:34:18 +08:00
|
|
|
|
2016-09-20 06:52:11 +08:00
|
|
|
if (current_style.hidden())
|
|
|
|
{
|
|
|
|
serializer().attribute("hidden", write_bool(true));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (current_style.custom())
|
|
|
|
{
|
|
|
|
serializer().attribute("customBuiltin", write_bool(*current_style.custom()));
|
|
|
|
}
|
|
|
|
|
|
|
|
serializer().end_element(xmlns, "cellStyle");
|
2016-08-05 13:52:05 +08:00
|
|
|
}
|
2016-09-20 06:52:11 +08:00
|
|
|
|
|
|
|
serializer().end_element(xmlns, "cellStyles");
|
2016-08-13 11:06:25 +08:00
|
|
|
|
2016-09-20 06:52:11 +08:00
|
|
|
serializer().start_element(xmlns, "dxfs");
|
|
|
|
serializer().attribute("count", "0");
|
|
|
|
serializer().end_element(xmlns, "dxfs");
|
|
|
|
|
|
|
|
serializer().start_element(xmlns, "tableStyles");
|
|
|
|
serializer().attribute("count", "0");
|
|
|
|
serializer().attribute("defaultTableStyle", "TableStyleMedium9");
|
|
|
|
serializer().attribute("defaultPivotStyle", "PivotStyleMedium7");
|
|
|
|
serializer().end_element(xmlns, "tableStyles");
|
|
|
|
|
|
|
|
if (!stylesheet.colors.empty())
|
|
|
|
{
|
|
|
|
serializer().start_element(xmlns, "indexedColors");
|
2016-08-18 19:34:18 +08:00
|
|
|
|
2016-09-20 06:52:11 +08:00
|
|
|
for (auto &c : stylesheet.colors)
|
|
|
|
{
|
|
|
|
serializer().start_element(xmlns, "rgbColor");
|
|
|
|
serializer().attribute("rgb", c.get_rgb().get_hex_string());
|
|
|
|
serializer().end_element(xmlns, "rgbColor");
|
|
|
|
}
|
|
|
|
|
|
|
|
serializer().end_element(xmlns, "indexedColors");
|
|
|
|
}
|
|
|
|
|
|
|
|
serializer().start_element(xmlns, "extLst");
|
|
|
|
serializer().start_element(xmlns, "ext");
|
|
|
|
serializer().namespace_decl(xmlns_x14, "x14");
|
|
|
|
serializer().attribute("uri", "{EB79DEF2-80B8-43e5-95BD-54CBDDF9020C}");
|
|
|
|
serializer().start_element(xmlns_x14, "slicerStyles");
|
|
|
|
serializer().attribute("defaultSlicerStyle", "SlicerStyleLight1");
|
|
|
|
serializer().end_element(xmlns_x14, "slicerStyles");
|
|
|
|
serializer().end_element(xmlns, "ext");
|
|
|
|
serializer().end_element(xmlns, "extLst");
|
|
|
|
|
|
|
|
serializer().end_element(xmlns, "styleSheet");
|
2016-08-05 13:52:05 +08:00
|
|
|
}
|
|
|
|
|
2016-09-18 23:32:59 +08:00
|
|
|
void xlsx_producer::write_theme(const relationship &rel)
|
2016-08-05 13:52:05 +08:00
|
|
|
{
|
2016-09-19 09:49:37 +08:00
|
|
|
static const auto xmlns_a = constants::get_namespace("drawingml");
|
2016-09-22 07:04:16 +08:00
|
|
|
static const auto xmlns_thm15 = constants::get_namespace("thm15");
|
2016-09-19 09:49:37 +08:00
|
|
|
|
|
|
|
serializer().start_element(xmlns_a, "theme");
|
|
|
|
serializer().namespace_decl(xmlns_a, "a");
|
|
|
|
serializer().attribute("name", "Office Theme");
|
2016-08-05 13:52:05 +08:00
|
|
|
|
2016-09-19 09:49:37 +08:00
|
|
|
serializer().start_element(xmlns_a, "themeElements");
|
|
|
|
serializer().start_element(xmlns_a, "clrScheme");
|
|
|
|
serializer().attribute("name", "Office");
|
2016-08-05 13:52:05 +08:00
|
|
|
|
|
|
|
struct scheme_element
|
|
|
|
{
|
|
|
|
std::string name;
|
|
|
|
std::string sub_element_name;
|
|
|
|
std::string val;
|
|
|
|
};
|
|
|
|
|
|
|
|
std::vector<scheme_element> scheme_elements = {
|
2016-09-19 09:49:37 +08:00
|
|
|
{ "dk1", "sysClr", "windowText" },
|
|
|
|
{ "lt1", "sysClr", "window" },
|
|
|
|
{ "dk2", "srgbClr", "44546A" },
|
|
|
|
{ "lt2", "srgbClr", "E7E6E6" },
|
|
|
|
{ "accent1", "srgbClr", "5B9BD5" },
|
|
|
|
{ "accent2", "srgbClr", "ED7D31" },
|
|
|
|
{ "accent3", "srgbClr", "A5A5A5" },
|
|
|
|
{ "accent4", "srgbClr", "FFC000" },
|
|
|
|
{ "accent5", "srgbClr", "4472C4" },
|
|
|
|
{ "accent6", "srgbClr", "70AD47" },
|
|
|
|
{ "hlink", "srgbClr", "0563C1" },
|
|
|
|
{ "folHlink", "srgbClr", "954F72" },
|
2016-08-05 13:52:05 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
for (auto element : scheme_elements)
|
|
|
|
{
|
2016-09-19 09:49:37 +08:00
|
|
|
serializer().start_element(xmlns_a, element.name);
|
|
|
|
serializer().start_element(xmlns_a, element.sub_element_name);
|
|
|
|
serializer().attribute("val", element.val);
|
2016-08-05 13:52:05 +08:00
|
|
|
|
2016-09-19 09:49:37 +08:00
|
|
|
if (element.name == "dk1")
|
2016-08-05 13:52:05 +08:00
|
|
|
{
|
2016-09-19 09:49:37 +08:00
|
|
|
serializer().attribute("lastClr", "000000");
|
2016-08-05 13:52:05 +08:00
|
|
|
}
|
2016-09-19 09:49:37 +08:00
|
|
|
else if (element.name == "lt1")
|
2016-08-05 13:52:05 +08:00
|
|
|
{
|
2016-09-19 09:49:37 +08:00
|
|
|
serializer().attribute("lastClr", "FFFFFF");
|
2016-08-05 13:52:05 +08:00
|
|
|
}
|
2016-09-19 09:49:37 +08:00
|
|
|
|
|
|
|
serializer().end_element(xmlns_a, element.sub_element_name);
|
|
|
|
serializer().end_element(xmlns_a, element.name);
|
2016-08-05 13:52:05 +08:00
|
|
|
}
|
2016-09-19 09:49:37 +08:00
|
|
|
|
|
|
|
serializer().end_element(xmlns_a, "clrScheme");
|
2016-08-05 13:52:05 +08:00
|
|
|
|
|
|
|
struct font_scheme
|
|
|
|
{
|
|
|
|
bool typeface;
|
|
|
|
std::string script;
|
|
|
|
std::string major;
|
|
|
|
std::string minor;
|
|
|
|
};
|
|
|
|
|
2016-09-19 09:49:37 +08:00
|
|
|
static const std::vector<font_scheme> font_schemes = {
|
|
|
|
{ true, "latin", "Calibri Light", "Calibri" },
|
|
|
|
{ true, "ea", "", "" },
|
|
|
|
{ true, "cs", "", "" },
|
2016-08-13 11:06:25 +08:00
|
|
|
{ false, "Jpan", "Yu Gothic Light", "Yu Gothic" },
|
2016-08-05 13:52:05 +08:00
|
|
|
{ false, "Hang", "\xeb\xa7\x91\xec\x9d\x80 \xea\xb3\xa0\xeb\x94\x95",
|
|
|
|
"\xeb\xa7\x91\xec\x9d\x80 \xea\xb3\xa0\xeb\x94\x95" },
|
2016-08-13 11:06:25 +08:00
|
|
|
{ false, "Hans", "DengXian Light", "DengXian" },
|
2016-08-05 13:52:05 +08:00
|
|
|
{ false, "Hant", "\xe6\x96\xb0\xe7\xb4\xb0\xe6\x98\x8e\xe9\xab\x94",
|
|
|
|
"\xe6\x96\xb0\xe7\xb4\xb0\xe6\x98\x8e\xe9\xab\x94" },
|
|
|
|
{ false, "Arab", "Times New Roman", "Arial" },
|
|
|
|
{ false, "Hebr", "Times New Roman", "Arial" },
|
|
|
|
{ false, "Thai", "Tahoma", "Tahoma" },
|
|
|
|
{ false, "Ethi", "Nyala", "Nyala" },
|
|
|
|
{ false, "Beng", "Vrinda", "Vrinda" },
|
|
|
|
{ false, "Gujr", "Shruti", "Shruti" },
|
|
|
|
{ false, "Khmr", "MoolBoran", "DaunPenh" },
|
|
|
|
{ false, "Knda", "Tunga", "Tunga" },
|
|
|
|
{ false, "Guru", "Raavi", "Raavi" },
|
|
|
|
{ false, "Cans", "Euphemia", "Euphemia" },
|
|
|
|
{ false, "Cher", "Plantagenet Cherokee", "Plantagenet Cherokee" },
|
|
|
|
{ false, "Yiii", "Microsoft Yi Baiti", "Microsoft Yi Baiti" },
|
|
|
|
{ false, "Tibt", "Microsoft Himalaya", "Microsoft Himalaya" },
|
|
|
|
{ false, "Thaa", "MV Boli", "MV Boli" },
|
|
|
|
{ false, "Deva", "Mangal", "Mangal" },
|
|
|
|
{ false, "Telu", "Gautami", "Gautami" },
|
|
|
|
{ false, "Taml", "Latha", "Latha" },
|
|
|
|
{ false, "Syrc", "Estrangelo Edessa", "Estrangelo Edessa" },
|
|
|
|
{ false, "Orya", "Kalinga", "Kalinga" },
|
|
|
|
{ false, "Mlym", "Kartika", "Kartika" },
|
|
|
|
{ false, "Laoo", "DokChampa", "DokChampa" },
|
|
|
|
{ false, "Sinh", "Iskoola Pota", "Iskoola Pota" },
|
|
|
|
{ false, "Mong", "Mongolian Baiti", "Mongolian Baiti" },
|
|
|
|
{ false, "Viet", "Times New Roman", "Arial" },
|
2016-08-13 11:06:25 +08:00
|
|
|
{ false, "Uigh", "Microsoft Uighur", "Microsoft Uighur" },
|
|
|
|
{ false, "Geor", "Sylfaen", "Sylfaen" }
|
2016-08-05 13:52:05 +08:00
|
|
|
};
|
|
|
|
|
2016-09-19 09:49:37 +08:00
|
|
|
serializer().start_element(xmlns_a, "fontScheme");
|
|
|
|
serializer().attribute("name", "Office");
|
2016-08-05 13:52:05 +08:00
|
|
|
|
2016-09-19 09:49:37 +08:00
|
|
|
for (auto major : {true, false})
|
|
|
|
{
|
|
|
|
serializer().start_element(xmlns_a, major ? "majorFont" : "minorFont");
|
|
|
|
|
|
|
|
for (const auto scheme : font_schemes)
|
|
|
|
{
|
|
|
|
const auto scheme_value = major ? scheme.major : scheme.minor;
|
2016-08-05 13:52:05 +08:00
|
|
|
|
2016-09-19 09:49:37 +08:00
|
|
|
if (scheme.typeface)
|
|
|
|
{
|
|
|
|
serializer().start_element(xmlns_a, scheme.script);
|
|
|
|
serializer().attribute("typeface", scheme_value);
|
2016-08-05 13:52:05 +08:00
|
|
|
|
2016-09-19 09:49:37 +08:00
|
|
|
if (scheme_value == "Calibri Light")
|
|
|
|
{
|
|
|
|
serializer().attribute("panose", "020F0302020204030204");
|
|
|
|
}
|
|
|
|
else if (scheme_value == "Calibri")
|
|
|
|
{
|
|
|
|
serializer().attribute("panose", "020F0502020204030204");
|
|
|
|
}
|
|
|
|
|
|
|
|
serializer().end_element(xmlns_a, scheme.script);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
serializer().start_element(xmlns_a, "font");
|
|
|
|
serializer().attribute("script", scheme.script);
|
|
|
|
serializer().attribute("typeface", scheme_value);
|
|
|
|
serializer().end_element(xmlns_a, "font");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
serializer().end_element(xmlns_a, major ? "majorFont" : "minorFont");
|
|
|
|
}
|
|
|
|
|
|
|
|
serializer().end_element(xmlns_a, "fontScheme");
|
2016-08-13 11:06:25 +08:00
|
|
|
|
2016-09-19 09:49:37 +08:00
|
|
|
serializer().start_element(xmlns_a, "fmtScheme");
|
|
|
|
serializer().attribute("name", "Office");
|
2016-08-13 11:06:25 +08:00
|
|
|
|
2016-09-19 09:49:37 +08:00
|
|
|
serializer().start_element(xmlns_a, "fillStyleLst");
|
|
|
|
serializer().start_element(xmlns_a, "solidFill");
|
|
|
|
serializer().start_element(xmlns_a, "schemeClr");
|
|
|
|
serializer().attribute("val", "phClr");
|
|
|
|
serializer().end_element(xmlns_a, "schemeClr");
|
|
|
|
serializer().end_element(xmlns_a, "solidFill");
|
2016-08-05 13:52:05 +08:00
|
|
|
|
2016-09-19 09:49:37 +08:00
|
|
|
serializer().start_element(xmlns_a, "gradFill");
|
|
|
|
serializer().attribute("rotWithShape", "1");
|
|
|
|
serializer().start_element(xmlns_a, "gsLst");
|
|
|
|
|
|
|
|
serializer().start_element(xmlns_a, "gs");
|
|
|
|
serializer().attribute("pos", "0");
|
|
|
|
serializer().start_element(xmlns_a, "schemeClr");
|
|
|
|
serializer().attribute("val", "phClr");
|
|
|
|
serializer().start_element(xmlns_a, "lumMod");
|
|
|
|
serializer().attribute("val", "110000");
|
|
|
|
serializer().end_element(xmlns_a, "lumMod");
|
|
|
|
serializer().start_element(xmlns_a, "satMod");
|
|
|
|
serializer().attribute("val", "105000");
|
|
|
|
serializer().end_element(xmlns_a, "satMod");
|
|
|
|
serializer().start_element(xmlns_a, "tint");
|
|
|
|
serializer().attribute("val", "67000");
|
|
|
|
serializer().end_element(xmlns_a, "tint");
|
|
|
|
serializer().end_element(xmlns_a, "schemeClr");
|
|
|
|
serializer().end_element(xmlns_a, "gs");
|
|
|
|
|
|
|
|
serializer().start_element(xmlns_a, "gs");
|
|
|
|
serializer().attribute("pos", "50000");
|
|
|
|
serializer().start_element(xmlns_a, "schemeClr");
|
|
|
|
serializer().attribute("val", "phClr");
|
|
|
|
serializer().start_element(xmlns_a, "lumMod");
|
|
|
|
serializer().attribute("val", "105000");
|
|
|
|
serializer().end_element(xmlns_a, "lumMod");
|
|
|
|
serializer().start_element(xmlns_a, "satMod");
|
|
|
|
serializer().attribute("val", "103000");
|
|
|
|
serializer().end_element(xmlns_a, "satMod");
|
|
|
|
serializer().start_element(xmlns_a, "tint");
|
|
|
|
serializer().attribute("val", "73000");
|
|
|
|
serializer().end_element(xmlns_a, "tint");
|
|
|
|
serializer().end_element(xmlns_a, "schemeClr");
|
|
|
|
serializer().end_element(xmlns_a, "gs");
|
|
|
|
|
|
|
|
serializer().start_element(xmlns_a, "gs");
|
|
|
|
serializer().attribute("pos", "100000");
|
|
|
|
serializer().start_element(xmlns_a, "schemeClr");
|
|
|
|
serializer().attribute("val", "phClr");
|
|
|
|
serializer().start_element(xmlns_a, "lumMod");
|
|
|
|
serializer().attribute("val", "105000");
|
|
|
|
serializer().end_element(xmlns_a, "lumMod");
|
|
|
|
serializer().start_element(xmlns_a, "satMod");
|
|
|
|
serializer().attribute("val", "109000");
|
|
|
|
serializer().end_element(xmlns_a, "satMod");
|
|
|
|
serializer().start_element(xmlns_a, "tint");
|
|
|
|
serializer().attribute("val", "81000");
|
|
|
|
serializer().end_element(xmlns_a, "tint");
|
|
|
|
serializer().end_element(xmlns_a, "schemeClr");
|
|
|
|
serializer().end_element(xmlns_a, "gs");
|
|
|
|
|
|
|
|
serializer().end_element(xmlns_a, "gsLst");
|
2016-08-05 13:52:05 +08:00
|
|
|
|
2016-09-19 09:49:37 +08:00
|
|
|
serializer().start_element(xmlns_a, "lin");
|
|
|
|
serializer().attribute("ang", "5400000");
|
|
|
|
serializer().attribute("scaled", "0");
|
|
|
|
serializer().end_element(xmlns_a, "lin");
|
|
|
|
|
|
|
|
serializer().end_element(xmlns_a, "gradFill");
|
|
|
|
|
|
|
|
serializer().start_element(xmlns_a, "gradFill");
|
|
|
|
serializer().attribute("rotWithShape", "1");
|
|
|
|
serializer().start_element(xmlns_a, "gsLst");
|
|
|
|
|
|
|
|
serializer().start_element(xmlns_a, "gs");
|
|
|
|
serializer().attribute("pos", "0");
|
|
|
|
serializer().start_element(xmlns_a, "schemeClr");
|
|
|
|
serializer().attribute("val", "phClr");
|
|
|
|
serializer().start_element(xmlns_a, "satMod");
|
|
|
|
serializer().attribute("val", "103000");
|
|
|
|
serializer().end_element(xmlns_a, "satMod");
|
|
|
|
serializer().start_element(xmlns_a, "lumMod");
|
|
|
|
serializer().attribute("val", "102000");
|
|
|
|
serializer().end_element(xmlns_a, "lumMod");
|
|
|
|
serializer().start_element(xmlns_a, "tint");
|
|
|
|
serializer().attribute("val", "94000");
|
|
|
|
serializer().end_element(xmlns_a, "tint");
|
|
|
|
serializer().end_element(xmlns_a, "schemeClr");
|
|
|
|
serializer().end_element(xmlns_a, "gs");
|
|
|
|
|
|
|
|
serializer().start_element(xmlns_a, "gs");
|
|
|
|
serializer().attribute("pos", "50000");
|
|
|
|
serializer().start_element(xmlns_a, "schemeClr");
|
|
|
|
serializer().attribute("val", "phClr");
|
|
|
|
serializer().start_element(xmlns_a, "satMod");
|
|
|
|
serializer().attribute("val", "110000");
|
|
|
|
serializer().end_element(xmlns_a, "satMod");
|
|
|
|
serializer().start_element(xmlns_a, "lumMod");
|
|
|
|
serializer().attribute("val", "100000");
|
|
|
|
serializer().end_element(xmlns_a, "lumMod");
|
|
|
|
serializer().start_element(xmlns_a, "shade");
|
|
|
|
serializer().attribute("val", "100000");
|
|
|
|
serializer().end_element(xmlns_a, "shade");
|
|
|
|
serializer().end_element(xmlns_a, "schemeClr");
|
|
|
|
serializer().end_element(xmlns_a, "gs");
|
|
|
|
|
|
|
|
serializer().start_element(xmlns_a, "gs");
|
|
|
|
serializer().attribute("pos", "100000");
|
|
|
|
serializer().start_element(xmlns_a, "schemeClr");
|
|
|
|
serializer().attribute("val", "phClr");
|
|
|
|
serializer().start_element(xmlns_a, "lumMod");
|
|
|
|
serializer().attribute("val", "99000");
|
|
|
|
serializer().end_element(xmlns_a, "lumMod");
|
|
|
|
serializer().start_element(xmlns_a, "satMod");
|
|
|
|
serializer().attribute("val", "120000");
|
|
|
|
serializer().end_element(xmlns_a, "satMod");
|
|
|
|
serializer().start_element(xmlns_a, "shade");
|
|
|
|
serializer().attribute("val", "78000");
|
|
|
|
serializer().end_element(xmlns_a, "shade");
|
|
|
|
serializer().end_element(xmlns_a, "schemeClr");
|
|
|
|
serializer().end_element(xmlns_a, "gs");
|
|
|
|
|
|
|
|
serializer().end_element(xmlns_a, "gsLst");
|
|
|
|
|
|
|
|
serializer().start_element(xmlns_a, "lin");
|
|
|
|
serializer().attribute("ang", "5400000");
|
|
|
|
serializer().attribute("scaled", "0");
|
|
|
|
serializer().end_element(xmlns_a, "lin");
|
|
|
|
|
|
|
|
serializer().end_element(xmlns_a, "gradFill");
|
|
|
|
serializer().end_element(xmlns_a, "fillStyleLst");
|
|
|
|
|
|
|
|
serializer().start_element(xmlns_a, "lnStyleLst");
|
|
|
|
|
|
|
|
serializer().start_element(xmlns_a, "ln");
|
|
|
|
serializer().attribute("w", "6350");
|
|
|
|
serializer().attribute("cap", "flat");
|
|
|
|
serializer().attribute("cmpd", "sng");
|
|
|
|
serializer().attribute("algn", "ctr");
|
|
|
|
serializer().start_element(xmlns_a, "solidFill");
|
|
|
|
serializer().start_element(xmlns_a, "schemeClr");
|
|
|
|
serializer().attribute("val", "phClr");
|
|
|
|
serializer().end_element(xmlns_a, "schemeClr");
|
|
|
|
serializer().end_element(xmlns_a, "solidFill");
|
|
|
|
serializer().start_element(xmlns_a, "prstDash");
|
|
|
|
serializer().attribute("val", "solid");
|
|
|
|
serializer().end_element(xmlns_a, "prstDash");
|
|
|
|
serializer().start_element(xmlns_a, "miter");
|
|
|
|
serializer().attribute("lim", "800000");
|
|
|
|
serializer().end_element(xmlns_a, "miter");
|
|
|
|
serializer().end_element(xmlns_a, "ln");
|
|
|
|
|
|
|
|
serializer().start_element(xmlns_a, "ln");
|
|
|
|
serializer().attribute("w", "12700");
|
|
|
|
serializer().attribute("cap", "flat");
|
|
|
|
serializer().attribute("cmpd", "sng");
|
|
|
|
serializer().attribute("algn", "ctr");
|
|
|
|
serializer().start_element(xmlns_a, "solidFill");
|
|
|
|
serializer().start_element(xmlns_a, "schemeClr");
|
|
|
|
serializer().attribute("val", "phClr");
|
|
|
|
serializer().end_element(xmlns_a, "schemeClr");
|
|
|
|
serializer().end_element(xmlns_a, "solidFill");
|
|
|
|
serializer().start_element(xmlns_a, "prstDash");
|
|
|
|
serializer().attribute("val", "solid");
|
|
|
|
serializer().end_element(xmlns_a, "prstDash");
|
|
|
|
serializer().start_element(xmlns_a, "miter");
|
|
|
|
serializer().attribute("lim", "800000");
|
|
|
|
serializer().end_element(xmlns_a, "miter");
|
|
|
|
serializer().end_element(xmlns_a, "ln");
|
|
|
|
|
|
|
|
serializer().start_element(xmlns_a, "ln");
|
|
|
|
serializer().attribute("w", "19050");
|
|
|
|
serializer().attribute("cap", "flat");
|
|
|
|
serializer().attribute("cmpd", "sng");
|
|
|
|
serializer().attribute("algn", "ctr");
|
|
|
|
serializer().start_element(xmlns_a, "solidFill");
|
|
|
|
serializer().start_element(xmlns_a, "schemeClr");
|
|
|
|
serializer().attribute("val", "phClr");
|
|
|
|
serializer().end_element(xmlns_a, "schemeClr");
|
|
|
|
serializer().end_element(xmlns_a, "solidFill");
|
|
|
|
serializer().start_element(xmlns_a, "prstDash");
|
|
|
|
serializer().attribute("val", "solid");
|
|
|
|
serializer().end_element(xmlns_a, "prstDash");
|
|
|
|
serializer().start_element(xmlns_a, "miter");
|
|
|
|
serializer().attribute("lim", "800000");
|
|
|
|
serializer().end_element(xmlns_a, "miter");
|
|
|
|
serializer().end_element(xmlns_a, "ln");
|
|
|
|
|
|
|
|
serializer().end_element(xmlns_a, "lnStyleLst");
|
|
|
|
|
|
|
|
serializer().start_element(xmlns_a, "effectStyleLst");
|
|
|
|
|
|
|
|
serializer().start_element(xmlns_a, "effectStyle");
|
|
|
|
serializer().element(xmlns_a, "effectLst", "");
|
|
|
|
serializer().end_element(xmlns_a, "effectStyle");
|
|
|
|
|
|
|
|
serializer().start_element(xmlns_a, "effectStyle");
|
|
|
|
serializer().element(xmlns_a, "effectLst", "");
|
|
|
|
serializer().end_element(xmlns_a, "effectStyle");
|
|
|
|
|
|
|
|
serializer().start_element(xmlns_a, "effectStyle");
|
|
|
|
serializer().start_element(xmlns_a, "effectLst");
|
|
|
|
serializer().start_element(xmlns_a, "outerShdw");
|
|
|
|
serializer().attribute("blurRad", "57150");
|
|
|
|
serializer().attribute("dist", "19050");
|
|
|
|
serializer().attribute("dir", "5400000");
|
|
|
|
serializer().attribute("algn", "ctr");
|
|
|
|
serializer().attribute("rotWithShape", "0");
|
|
|
|
serializer().start_element(xmlns_a, "srgbClr");
|
|
|
|
serializer().attribute("val", "000000");
|
|
|
|
serializer().start_element(xmlns_a, "alpha");
|
|
|
|
serializer().attribute("val", "63000");
|
|
|
|
serializer().end_element(xmlns_a, "alpha");
|
|
|
|
serializer().end_element(xmlns_a, "srgbClr");
|
|
|
|
serializer().end_element(xmlns_a, "outerShdw");
|
|
|
|
serializer().end_element(xmlns_a, "effectLst");
|
|
|
|
serializer().end_element(xmlns_a, "effectStyle");
|
|
|
|
|
|
|
|
serializer().end_element(xmlns_a, "effectStyleLst");
|
|
|
|
|
|
|
|
serializer().start_element(xmlns_a, "bgFillStyleLst");
|
|
|
|
|
|
|
|
serializer().start_element(xmlns_a, "solidFill");
|
|
|
|
serializer().start_element(xmlns_a, "schemeClr");
|
|
|
|
serializer().attribute("val", "phClr");
|
|
|
|
serializer().end_element(xmlns_a, "schemeClr");
|
|
|
|
serializer().end_element(xmlns_a, "solidFill");
|
|
|
|
|
|
|
|
serializer().start_element(xmlns_a, "solidFill");
|
|
|
|
serializer().start_element(xmlns_a, "schemeClr");
|
|
|
|
serializer().attribute("val", "phClr");
|
|
|
|
serializer().start_element(xmlns_a, "tint");
|
|
|
|
serializer().attribute("val", "95000");
|
|
|
|
serializer().end_element(xmlns_a, "tint");
|
|
|
|
serializer().start_element(xmlns_a, "satMod");
|
|
|
|
serializer().attribute("val", "170000");
|
|
|
|
serializer().end_element(xmlns_a, "satMod");
|
|
|
|
serializer().end_element(xmlns_a, "schemeClr");
|
|
|
|
serializer().end_element(xmlns_a, "solidFill");
|
|
|
|
|
|
|
|
serializer().start_element(xmlns_a, "gradFill");
|
|
|
|
serializer().attribute("rotWithShape", "1");
|
|
|
|
serializer().start_element(xmlns_a, "gsLst");
|
|
|
|
|
|
|
|
serializer().start_element(xmlns_a, "gs");
|
|
|
|
serializer().attribute("pos", "0");
|
|
|
|
serializer().start_element(xmlns_a, "schemeClr");
|
|
|
|
serializer().attribute("val", "phClr");
|
|
|
|
serializer().start_element(xmlns_a, "tint");
|
|
|
|
serializer().attribute("val", "93000");
|
|
|
|
serializer().end_element(xmlns_a, "tint");
|
|
|
|
serializer().start_element(xmlns_a, "satMod");
|
|
|
|
serializer().attribute("val", "150000");
|
|
|
|
serializer().end_element(xmlns_a, "satMod");
|
|
|
|
serializer().start_element(xmlns_a, "shade");
|
|
|
|
serializer().attribute("val", "98000");
|
|
|
|
serializer().end_element(xmlns_a, "shade");
|
|
|
|
serializer().start_element(xmlns_a, "lumMod");
|
|
|
|
serializer().attribute("val", "102000");
|
|
|
|
serializer().end_element(xmlns_a, "lumMod");
|
|
|
|
serializer().end_element(xmlns_a, "schemeClr");
|
|
|
|
serializer().end_element(xmlns_a, "gs");
|
|
|
|
|
|
|
|
serializer().start_element(xmlns_a, "gs");
|
|
|
|
serializer().attribute("pos", "50000");
|
|
|
|
serializer().start_element(xmlns_a, "schemeClr");
|
|
|
|
serializer().attribute("val", "phClr");
|
|
|
|
serializer().start_element(xmlns_a, "tint");
|
|
|
|
serializer().attribute("val", "98000");
|
|
|
|
serializer().end_element(xmlns_a, "tint");
|
|
|
|
serializer().start_element(xmlns_a, "satMod");
|
|
|
|
serializer().attribute("val", "130000");
|
|
|
|
serializer().end_element(xmlns_a, "satMod");
|
|
|
|
serializer().start_element(xmlns_a, "shade");
|
|
|
|
serializer().attribute("val", "90000");
|
|
|
|
serializer().end_element(xmlns_a, "shade");
|
|
|
|
serializer().start_element(xmlns_a, "lumMod");
|
|
|
|
serializer().attribute("val", "103000");
|
|
|
|
serializer().end_element(xmlns_a, "lumMod");
|
|
|
|
serializer().end_element(xmlns_a, "schemeClr");
|
|
|
|
serializer().end_element(xmlns_a, "gs");
|
|
|
|
|
|
|
|
serializer().start_element(xmlns_a, "gs");
|
|
|
|
serializer().attribute("pos", "100000");
|
|
|
|
serializer().start_element(xmlns_a, "schemeClr");
|
|
|
|
serializer().attribute("val", "phClr");
|
|
|
|
serializer().start_element(xmlns_a, "shade");
|
|
|
|
serializer().attribute("val", "63000");
|
|
|
|
serializer().end_element(xmlns_a, "shade");
|
|
|
|
serializer().start_element(xmlns_a, "satMod");
|
|
|
|
serializer().attribute("val", "120000");
|
|
|
|
serializer().end_element(xmlns_a, "satMod");
|
|
|
|
serializer().end_element(xmlns_a, "schemeClr");
|
|
|
|
serializer().end_element(xmlns_a, "gs");
|
|
|
|
|
|
|
|
serializer().end_element(xmlns_a, "gsLst");
|
|
|
|
|
|
|
|
serializer().start_element(xmlns_a, "lin");
|
|
|
|
serializer().attribute("ang", "5400000");
|
|
|
|
serializer().attribute("scaled", "0");
|
|
|
|
serializer().end_element(xmlns_a, "lin");
|
|
|
|
|
|
|
|
serializer().end_element(xmlns_a, "gradFill");
|
|
|
|
|
|
|
|
serializer().end_element(xmlns_a, "bgFillStyleLst");
|
|
|
|
serializer().end_element(xmlns_a, "fmtScheme");
|
|
|
|
serializer().end_element(xmlns_a, "themeElements");
|
|
|
|
|
|
|
|
serializer().element(xmlns_a, "objectDefaults", "");
|
|
|
|
serializer().element(xmlns_a, "extraClrSchemeLst", "");
|
|
|
|
|
|
|
|
serializer().start_element(xmlns_a, "extLst");
|
|
|
|
serializer().start_element(xmlns_a, "ext");
|
|
|
|
serializer().attribute("uri", "{05A4C25C-085E-4340-85A3-A5531E510DB2}");
|
|
|
|
serializer().start_element(xmlns_thm15, "themeFamily");
|
|
|
|
serializer().namespace_decl(xmlns_thm15, "thm15");
|
|
|
|
serializer().attribute("name", "Office Theme");
|
|
|
|
serializer().attribute("id", "{62F939B6-93AF-4DB8-9C6B-D6C7DFDC589F}");
|
|
|
|
serializer().attribute("vid", "{4A3C46E8-61CC-4603-A589-7422A47A8E4A}");
|
|
|
|
serializer().end_element(xmlns_thm15, "themeFamily");
|
|
|
|
serializer().end_element(xmlns_a, "ext");
|
|
|
|
serializer().end_element(xmlns_a, "extLst");
|
|
|
|
|
|
|
|
serializer().end_element(xmlns_a, "theme");
|
2016-08-05 13:52:05 +08:00
|
|
|
}
|
|
|
|
|
2016-09-18 23:32:59 +08:00
|
|
|
void xlsx_producer::write_volatile_dependencies(const relationship &rel)
|
2016-08-05 13:52:05 +08:00
|
|
|
{
|
2016-09-18 23:32:59 +08:00
|
|
|
serializer().start_element("volTypes");
|
2016-08-05 13:52:05 +08:00
|
|
|
}
|
|
|
|
|
2016-09-18 23:32:59 +08:00
|
|
|
void xlsx_producer::write_worksheet(const relationship &rel)
|
2016-08-05 13:52:05 +08:00
|
|
|
{
|
2016-08-06 22:40:17 +08:00
|
|
|
auto title = std::find_if(source_.d_->sheet_title_rel_id_map_.begin(),
|
|
|
|
source_.d_->sheet_title_rel_id_map_.end(),
|
|
|
|
[&](const std::pair<std::string, std::string> &p)
|
|
|
|
{
|
|
|
|
return p.second == rel.get_id();
|
|
|
|
})->first;
|
|
|
|
|
|
|
|
auto ws = source_.get_sheet_by_title(title);
|
2016-08-05 13:52:05 +08:00
|
|
|
|
2016-09-22 07:04:16 +08:00
|
|
|
static const auto xmlns = constants::get_namespace("worksheet");
|
|
|
|
static const auto xmlns_r = constants::get_namespace("r");
|
|
|
|
static const auto xmlns_mc = constants::get_namespace("mc");
|
|
|
|
static const auto xmlns_x14ac = constants::get_namespace("x14ac");
|
2016-09-17 10:59:13 +08:00
|
|
|
|
2016-09-18 23:32:59 +08:00
|
|
|
serializer().start_element(xmlns, "worksheet");
|
|
|
|
serializer().namespace_decl(xmlns, "");
|
2016-09-19 09:49:37 +08:00
|
|
|
serializer().namespace_decl(xmlns_r, "r");
|
2016-08-14 02:45:26 +08:00
|
|
|
|
|
|
|
if (ws.x14ac_enabled())
|
|
|
|
{
|
2016-09-19 09:49:37 +08:00
|
|
|
serializer().namespace_decl(xmlns_mc, "mc");
|
|
|
|
serializer().namespace_decl(xmlns_x14ac, "x14ac");
|
|
|
|
serializer().attribute(xmlns_mc, "Ignorable", "x14ac");
|
2016-08-14 02:45:26 +08:00
|
|
|
}
|
2016-09-20 06:52:11 +08:00
|
|
|
|
2016-08-14 02:45:26 +08:00
|
|
|
if (ws.has_page_setup())
|
2016-08-05 13:52:05 +08:00
|
|
|
{
|
2016-09-20 06:52:11 +08:00
|
|
|
serializer().start_element(xmlns, "sheetPr");
|
|
|
|
|
|
|
|
serializer().start_element(xmlns, "outlinePr");
|
|
|
|
serializer().attribute("summaryBelow", "1");
|
|
|
|
serializer().attribute("summaryRight", "1");
|
|
|
|
serializer().end_element(xmlns, "outlinePr");
|
2016-08-13 11:06:25 +08:00
|
|
|
|
2016-09-20 06:52:11 +08:00
|
|
|
serializer().start_element(xmlns, "pageSetUpPr");
|
|
|
|
serializer().attribute("fitToPage", write_bool(ws.get_page_setup().fit_to_page()));
|
|
|
|
serializer().end_element(xmlns, "pageSetUpPr");
|
2016-08-13 11:06:25 +08:00
|
|
|
|
2016-09-20 06:52:11 +08:00
|
|
|
serializer().end_element(xmlns, "sheetPr");
|
2016-08-05 13:52:05 +08:00
|
|
|
}
|
|
|
|
|
2016-08-14 02:45:26 +08:00
|
|
|
if (ws.has_dimension())
|
|
|
|
{
|
2016-09-20 06:52:11 +08:00
|
|
|
serializer().start_element(xmlns, "dimension");
|
|
|
|
const auto dimension = ws.calculate_dimension();
|
|
|
|
serializer().attribute("ref", dimension.is_single_cell()
|
|
|
|
? dimension.get_top_left().to_string() : dimension.to_string());
|
|
|
|
serializer().end_element(xmlns, "dimension");
|
2016-08-14 02:45:26 +08:00
|
|
|
}
|
2016-08-05 13:52:05 +08:00
|
|
|
|
2016-08-14 02:45:26 +08:00
|
|
|
if (ws.has_view())
|
|
|
|
{
|
2016-09-20 06:52:11 +08:00
|
|
|
serializer().start_element(xmlns, "sheetViews");
|
|
|
|
serializer().start_element(xmlns, "sheetView");
|
2016-08-05 13:52:05 +08:00
|
|
|
|
2016-08-14 02:45:26 +08:00
|
|
|
const auto view = ws.get_view();
|
2016-08-05 13:52:05 +08:00
|
|
|
|
2016-09-20 06:52:11 +08:00
|
|
|
serializer().attribute("tabSelected", "1");
|
|
|
|
serializer().attribute("workbookViewId", "0");
|
2016-08-05 13:52:05 +08:00
|
|
|
|
2016-09-08 06:48:08 +08:00
|
|
|
if (!view.get_selections().empty() && !ws.has_frozen_panes())
|
2016-08-05 13:52:05 +08:00
|
|
|
{
|
2016-09-20 06:52:11 +08:00
|
|
|
serializer().start_element(xmlns, "selection");
|
2016-08-05 13:52:05 +08:00
|
|
|
|
2016-08-14 02:45:26 +08:00
|
|
|
const auto &first_selection = view.get_selections().front();
|
|
|
|
|
|
|
|
if (first_selection.has_active_cell())
|
|
|
|
{
|
|
|
|
auto active_cell = first_selection.get_active_cell();
|
2016-09-20 06:52:11 +08:00
|
|
|
serializer().attribute("activeCell", active_cell.to_string());
|
|
|
|
serializer().attribute("sqref", active_cell.to_string());
|
2016-08-14 02:45:26 +08:00
|
|
|
}
|
2016-09-20 06:52:11 +08:00
|
|
|
|
|
|
|
serializer().end_element(xmlns, "selection");
|
2016-08-05 13:52:05 +08:00
|
|
|
}
|
|
|
|
|
2016-09-20 06:52:11 +08:00
|
|
|
auto active_pane = "bottomRight"s;
|
2016-08-14 02:45:26 +08:00
|
|
|
|
|
|
|
if (ws.has_frozen_panes())
|
2016-08-05 13:52:05 +08:00
|
|
|
{
|
2016-09-20 06:52:11 +08:00
|
|
|
serializer().start_element(xmlns, "pane");
|
2016-08-05 13:52:05 +08:00
|
|
|
|
2016-08-14 02:45:26 +08:00
|
|
|
if (ws.get_frozen_panes().get_column_index() > 1)
|
|
|
|
{
|
2016-09-20 06:52:11 +08:00
|
|
|
serializer().attribute("xSplit", ws.get_frozen_panes().get_column_index().index - 1);
|
2016-08-14 02:45:26 +08:00
|
|
|
active_pane = "topRight";
|
|
|
|
}
|
2016-08-05 13:52:05 +08:00
|
|
|
|
2016-08-14 02:45:26 +08:00
|
|
|
if (ws.get_frozen_panes().get_row() > 1)
|
|
|
|
{
|
2016-09-20 06:52:11 +08:00
|
|
|
serializer().attribute("ySplit", ws.get_frozen_panes().get_row() - 1);
|
2016-08-14 02:45:26 +08:00
|
|
|
active_pane = "bottomLeft";
|
|
|
|
}
|
2016-08-05 13:52:05 +08:00
|
|
|
|
2016-09-20 06:52:11 +08:00
|
|
|
/*
|
2016-08-14 02:45:26 +08:00
|
|
|
if (ws.get_frozen_panes().get_row() > 1 && ws.get_frozen_panes().get_column_index() > 1)
|
|
|
|
{
|
2016-09-20 06:52:11 +08:00
|
|
|
serializer().start_element(xmlns, "selection");
|
|
|
|
serializer().attribute("pane", "topRight");
|
2016-08-14 02:45:26 +08:00
|
|
|
auto bottom_left_node = sheet_view_node.append_child("selection");
|
2016-09-20 06:52:11 +08:00
|
|
|
serializer().attribute("pane", "bottomLeft");
|
2016-08-14 02:45:26 +08:00
|
|
|
active_pane = "bottomRight";
|
|
|
|
}
|
2016-09-20 06:52:11 +08:00
|
|
|
*/
|
2016-08-05 13:52:05 +08:00
|
|
|
|
2016-09-20 06:52:11 +08:00
|
|
|
serializer().attribute("topLeftCell", ws.get_frozen_panes().to_string());
|
|
|
|
serializer().attribute("activePane", active_pane);
|
|
|
|
serializer().attribute("state", "frozen");
|
2016-08-13 11:06:25 +08:00
|
|
|
|
2016-09-20 06:52:11 +08:00
|
|
|
serializer().start_element(xmlns, "selection");
|
2016-08-13 11:06:25 +08:00
|
|
|
|
2016-08-14 02:45:26 +08:00
|
|
|
if (ws.get_frozen_panes().get_row() > 1 && ws.get_frozen_panes().get_column_index() > 1)
|
|
|
|
{
|
2016-09-20 06:52:11 +08:00
|
|
|
serializer().attribute("pane", "bottomRight");
|
2016-08-14 02:45:26 +08:00
|
|
|
}
|
|
|
|
else if (ws.get_frozen_panes().get_row() > 1)
|
|
|
|
{
|
2016-09-20 06:52:11 +08:00
|
|
|
serializer().attribute("pane", "bottomLeft");
|
2016-08-14 02:45:26 +08:00
|
|
|
}
|
|
|
|
else if (ws.get_frozen_panes().get_column_index() > 1)
|
|
|
|
{
|
2016-09-20 06:52:11 +08:00
|
|
|
serializer().attribute("pane", "topRight");
|
2016-08-14 02:45:26 +08:00
|
|
|
}
|
2016-09-20 06:52:11 +08:00
|
|
|
|
|
|
|
serializer().end_element(xmlns, "selection");
|
|
|
|
serializer().end_element(xmlns, "pane");
|
2016-08-13 11:06:25 +08:00
|
|
|
}
|
2016-09-20 06:52:11 +08:00
|
|
|
|
|
|
|
serializer().end_element(xmlns, "sheetView");
|
|
|
|
serializer().end_element(xmlns, "sheetViews");
|
2016-08-13 11:06:25 +08:00
|
|
|
}
|
2016-08-05 13:52:05 +08:00
|
|
|
|
2016-08-14 02:45:26 +08:00
|
|
|
if (ws.has_format_properties())
|
|
|
|
{
|
2016-09-20 06:52:11 +08:00
|
|
|
serializer().start_element(xmlns, "sheetFormatPr");
|
|
|
|
serializer().attribute("baseColWidth", "10");
|
|
|
|
serializer().attribute("defaultRowHeight", "16");
|
2016-09-22 07:04:16 +08:00
|
|
|
if (ws.x14ac_enabled())
|
|
|
|
{
|
|
|
|
serializer().attribute(xmlns_x14ac, "dyDescent", "0.2");
|
|
|
|
}
|
2016-09-20 06:52:11 +08:00
|
|
|
serializer().end_element(xmlns, "sheetFormatPr");
|
2016-08-14 02:45:26 +08:00
|
|
|
}
|
2016-08-05 13:52:05 +08:00
|
|
|
|
|
|
|
bool has_column_properties = false;
|
|
|
|
|
|
|
|
for (auto column = ws.get_lowest_column(); column <= ws.get_highest_column(); column++)
|
|
|
|
{
|
|
|
|
if (ws.has_column_properties(column))
|
|
|
|
{
|
|
|
|
has_column_properties = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (has_column_properties)
|
|
|
|
{
|
2016-09-20 06:52:11 +08:00
|
|
|
serializer().start_element(xmlns, "cols");
|
2016-08-05 13:52:05 +08:00
|
|
|
|
|
|
|
for (auto column = ws.get_lowest_column(); column <= ws.get_highest_column(); column++)
|
|
|
|
{
|
2016-09-20 06:52:11 +08:00
|
|
|
if (!ws.has_column_properties(column)) continue;
|
2016-08-05 13:52:05 +08:00
|
|
|
|
|
|
|
const auto &props = ws.get_column_properties(column);
|
|
|
|
|
2016-10-14 08:11:02 +08:00
|
|
|
serializer().start_element(xmlns, "col");
|
2016-09-20 06:52:11 +08:00
|
|
|
serializer().attribute("min", column.index);
|
|
|
|
serializer().attribute("max", column.index);
|
|
|
|
serializer().attribute("width", props.width);
|
|
|
|
serializer().attribute("style", props.style);
|
|
|
|
serializer().attribute("customWidth", write_bool(props.custom));
|
2016-10-14 08:11:02 +08:00
|
|
|
serializer().end_element(xmlns, "col");
|
2016-08-05 13:52:05 +08:00
|
|
|
}
|
2016-09-20 06:52:11 +08:00
|
|
|
|
|
|
|
serializer().end_element(xmlns, "cols");
|
2016-08-05 13:52:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::unordered_map<std::string, std::string> hyperlink_references;
|
|
|
|
|
2016-09-18 23:32:59 +08:00
|
|
|
serializer().start_element(xmlns, "sheetData");
|
2016-08-05 13:52:05 +08:00
|
|
|
const auto &shared_strings = ws.get_workbook().get_shared_strings();
|
2016-09-20 06:52:11 +08:00
|
|
|
|
2016-08-05 13:52:05 +08:00
|
|
|
for (auto row : ws.rows())
|
|
|
|
{
|
|
|
|
auto min = static_cast<xlnt::row_t>(row.num_cells());
|
|
|
|
xlnt::row_t max = 0;
|
|
|
|
bool any_non_null = false;
|
|
|
|
|
|
|
|
for (auto cell : row)
|
|
|
|
{
|
|
|
|
min = std::min(min, cell.get_column().index);
|
|
|
|
max = std::max(max, cell.get_column().index);
|
|
|
|
|
|
|
|
if (!cell.garbage_collectible())
|
|
|
|
{
|
|
|
|
any_non_null = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!any_non_null)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-09-20 06:52:11 +08:00
|
|
|
serializer().start_element(xmlns, "row");
|
2016-08-05 13:52:05 +08:00
|
|
|
|
2016-09-20 06:52:11 +08:00
|
|
|
serializer().attribute("r", row.front().get_row());
|
|
|
|
serializer().attribute("spans", std::to_string(min) + ":" + std::to_string(max));
|
2016-08-05 13:52:05 +08:00
|
|
|
|
|
|
|
if (ws.has_row_properties(row.front().get_row()))
|
|
|
|
{
|
2016-09-20 06:52:11 +08:00
|
|
|
serializer().attribute("customHeight", "1");
|
2016-08-05 13:52:05 +08:00
|
|
|
auto height = ws.get_row_properties(row.front().get_row()).height;
|
|
|
|
|
|
|
|
if (height == std::floor(height))
|
|
|
|
{
|
2016-09-20 06:52:11 +08:00
|
|
|
serializer().attribute("ht", std::to_string(static_cast<long long int>(height)) + ".0");
|
2016-08-05 13:52:05 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-09-20 06:52:11 +08:00
|
|
|
serializer().attribute("ht", height);
|
2016-08-05 13:52:05 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-20 06:52:11 +08:00
|
|
|
if (!skip_unknown_elements)
|
|
|
|
{
|
2016-09-22 07:04:16 +08:00
|
|
|
serializer().attribute(xmlns_x14ac, "dyDescent", 0.25);
|
2016-09-20 06:52:11 +08:00
|
|
|
}
|
2016-08-05 13:52:05 +08:00
|
|
|
|
|
|
|
for (auto cell : row)
|
|
|
|
{
|
|
|
|
if (!cell.garbage_collectible())
|
|
|
|
{
|
2016-09-20 06:52:11 +08:00
|
|
|
serializer().start_element(xmlns, "c");
|
|
|
|
serializer().attribute("r", cell.get_reference().to_string());
|
|
|
|
|
|
|
|
if (cell.has_format())
|
|
|
|
{
|
|
|
|
serializer().attribute("s", cell.get_format().id());
|
|
|
|
}
|
2016-08-05 13:52:05 +08:00
|
|
|
|
|
|
|
if (cell.get_data_type() == cell::type::string)
|
|
|
|
{
|
|
|
|
if (cell.has_formula())
|
|
|
|
{
|
2016-09-20 06:52:11 +08:00
|
|
|
serializer().attribute("t", "str");
|
|
|
|
serializer().element(xmlns, "f", cell.get_formula());
|
|
|
|
serializer().element(xmlns, "v", cell.to_string());
|
|
|
|
serializer().end_element(xmlns, "c");
|
2016-08-05 13:52:05 +08:00
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
int match_index = -1;
|
|
|
|
|
|
|
|
for (std::size_t i = 0; i < shared_strings.size(); i++)
|
|
|
|
{
|
2016-10-29 22:23:04 +08:00
|
|
|
if (shared_strings[i] == cell.get_value<formatted_text>())
|
2016-08-05 13:52:05 +08:00
|
|
|
{
|
|
|
|
match_index = static_cast<int>(i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (match_index == -1)
|
|
|
|
{
|
|
|
|
if (cell.get_value<std::string>().empty())
|
|
|
|
{
|
2016-09-20 06:52:11 +08:00
|
|
|
serializer().attribute("t", "s");
|
2016-08-05 13:52:05 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-09-20 06:52:11 +08:00
|
|
|
serializer().attribute("t", "inlineStr");
|
|
|
|
serializer().start_element(xmlns, "is");
|
|
|
|
serializer().element(xmlns, "t", cell.get_value<std::string>());
|
|
|
|
serializer().end_element(xmlns, "is");
|
2016-08-05 13:52:05 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-09-20 06:52:11 +08:00
|
|
|
serializer().attribute("t", "s");
|
|
|
|
serializer().element(xmlns, "v", match_index);
|
2016-08-05 13:52:05 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (cell.get_data_type() != cell::type::null)
|
|
|
|
{
|
|
|
|
if (cell.get_data_type() == cell::type::boolean)
|
|
|
|
{
|
2016-09-20 06:52:11 +08:00
|
|
|
serializer().attribute("t", "b");
|
|
|
|
serializer().element(xmlns, "v", write_bool(cell.get_value<bool>()));
|
2016-08-05 13:52:05 +08:00
|
|
|
}
|
|
|
|
else if (cell.get_data_type() == cell::type::numeric)
|
|
|
|
{
|
|
|
|
if (cell.has_formula())
|
|
|
|
{
|
2016-09-20 06:52:11 +08:00
|
|
|
serializer().element(xmlns, "f", cell.get_formula());
|
|
|
|
serializer().element(xmlns, "v", cell.to_string());
|
|
|
|
serializer().end_element(xmlns, "c");
|
|
|
|
|
2016-08-05 13:52:05 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-09-20 06:52:11 +08:00
|
|
|
serializer().attribute("t", "n");
|
|
|
|
serializer().start_element(xmlns, "v");
|
2016-08-05 13:52:05 +08:00
|
|
|
|
|
|
|
if (is_integral(cell.get_value<long double>()))
|
|
|
|
{
|
2016-09-20 06:52:11 +08:00
|
|
|
serializer().characters(cell.get_value<long long>());
|
2016-08-05 13:52:05 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::stringstream ss;
|
|
|
|
ss.precision(20);
|
|
|
|
ss << cell.get_value<long double>();
|
|
|
|
ss.str();
|
2016-09-20 06:52:11 +08:00
|
|
|
serializer().characters(ss.str());
|
2016-08-05 13:52:05 +08:00
|
|
|
}
|
2016-09-20 06:52:11 +08:00
|
|
|
|
|
|
|
serializer().end_element(xmlns, "v");
|
2016-08-05 13:52:05 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (cell.has_formula())
|
|
|
|
{
|
2016-09-20 06:52:11 +08:00
|
|
|
serializer().element(xmlns, "f", cell.get_formula());
|
|
|
|
serializer().element(xmlns, "v", "");
|
|
|
|
serializer().end_element(xmlns, "c");
|
|
|
|
|
2016-08-05 13:52:05 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2016-09-20 06:52:11 +08:00
|
|
|
|
|
|
|
serializer().end_element(xmlns, "c");
|
2016-08-05 13:52:05 +08:00
|
|
|
}
|
|
|
|
}
|
2016-09-20 06:52:11 +08:00
|
|
|
|
|
|
|
serializer().end_element(xmlns, "row");
|
2016-08-05 13:52:05 +08:00
|
|
|
}
|
2016-09-20 06:52:11 +08:00
|
|
|
|
|
|
|
serializer().end_element(xmlns, "sheetData");
|
|
|
|
|
2016-08-05 13:52:05 +08:00
|
|
|
if (ws.has_auto_filter())
|
|
|
|
{
|
2016-09-20 06:52:11 +08:00
|
|
|
serializer().start_element(xmlns, "autoFilter");
|
|
|
|
serializer().attribute("ref", ws.get_auto_filter().to_string());
|
|
|
|
serializer().end_element(xmlns, "autoFilter");
|
2016-08-05 13:52:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!ws.get_merged_ranges().empty())
|
|
|
|
{
|
2016-09-20 06:52:11 +08:00
|
|
|
serializer().start_element(xmlns, "mergeCells");
|
|
|
|
serializer().attribute("count", ws.get_merged_ranges().size());
|
2016-08-05 13:52:05 +08:00
|
|
|
|
|
|
|
for (auto merged_range : ws.get_merged_ranges())
|
|
|
|
{
|
2016-09-20 06:52:11 +08:00
|
|
|
serializer().start_element(xmlns, "mergeCell");
|
|
|
|
serializer().attribute("ref", merged_range.to_string());
|
|
|
|
serializer().end_element(xmlns, "mergeCell");
|
2016-08-05 13:52:05 +08:00
|
|
|
}
|
2016-09-20 06:52:11 +08:00
|
|
|
|
|
|
|
serializer().end_element(xmlns, "mergeCells");
|
2016-08-05 13:52:05 +08:00
|
|
|
}
|
|
|
|
|
2016-08-14 02:45:26 +08:00
|
|
|
const auto sheet_rels = source_.get_manifest().get_relationships(rel.get_target().get_path());
|
|
|
|
|
|
|
|
if (!sheet_rels.empty())
|
2016-08-05 13:52:05 +08:00
|
|
|
{
|
2016-08-06 22:40:17 +08:00
|
|
|
std::vector<relationship> hyperlink_sheet_rels;
|
2016-08-05 13:52:05 +08:00
|
|
|
|
2016-08-06 22:40:17 +08:00
|
|
|
for (const auto &sheet_rel : sheet_rels)
|
2016-08-05 13:52:05 +08:00
|
|
|
{
|
2016-08-06 22:40:17 +08:00
|
|
|
if (sheet_rel.get_type() == relationship::type::hyperlink)
|
|
|
|
{
|
|
|
|
hyperlink_sheet_rels.push_back(sheet_rel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!hyperlink_sheet_rels.empty())
|
|
|
|
{
|
2016-09-20 06:52:11 +08:00
|
|
|
serializer().start_element(xmlns, "hyperlinks");
|
2016-08-06 22:40:17 +08:00
|
|
|
|
|
|
|
for (const auto &hyperlink_rel : hyperlink_sheet_rels)
|
|
|
|
{
|
2016-09-20 06:52:11 +08:00
|
|
|
serializer().start_element(xmlns, "hyperlink");
|
|
|
|
serializer().attribute("display", hyperlink_rel.get_target().get_path().string());
|
|
|
|
serializer().attribute("ref", hyperlink_references.at(hyperlink_rel.get_id()));
|
|
|
|
serializer().attribute(xmlns_r, "id", hyperlink_rel.get_id());
|
|
|
|
serializer().end_element(xmlns, "hyperlink");
|
2016-08-06 22:40:17 +08:00
|
|
|
}
|
2016-09-20 06:52:11 +08:00
|
|
|
|
|
|
|
serializer().end_element(xmlns, "hyperlinks");
|
2016-08-05 13:52:05 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-14 02:45:26 +08:00
|
|
|
if (ws.has_page_setup())
|
2016-08-05 13:52:05 +08:00
|
|
|
{
|
2016-09-20 06:52:11 +08:00
|
|
|
serializer().start_element(xmlns, "printOptions");
|
|
|
|
serializer().attribute("horizontalCentered", write_bool(ws.get_page_setup().get_horizontal_centered()));
|
|
|
|
serializer().attribute("verticalCentered", write_bool(ws.get_page_setup().get_vertical_centered()));
|
|
|
|
serializer().end_element(xmlns, "printOptions");
|
2016-08-05 13:52:05 +08:00
|
|
|
}
|
|
|
|
|
2016-08-14 02:45:26 +08:00
|
|
|
if (ws.has_page_margins())
|
2016-08-05 13:52:05 +08:00
|
|
|
{
|
2016-09-20 06:52:11 +08:00
|
|
|
serializer().start_element(xmlns, "pageMargins");
|
2016-08-14 02:45:26 +08:00
|
|
|
|
|
|
|
//TODO: there must be a better way to do this
|
|
|
|
auto remove_trailing_zeros = [](const std::string &n)
|
|
|
|
{
|
|
|
|
auto decimal = n.find('.');
|
2016-08-05 13:52:05 +08:00
|
|
|
|
2016-08-14 02:45:26 +08:00
|
|
|
if (decimal == std::string::npos) return n;
|
2016-08-05 13:52:05 +08:00
|
|
|
|
2016-08-14 02:45:26 +08:00
|
|
|
auto index = n.size() - 1;
|
2016-08-05 13:52:05 +08:00
|
|
|
|
2016-08-14 02:45:26 +08:00
|
|
|
while (index >= decimal && n[index] == '0')
|
|
|
|
{
|
|
|
|
index--;
|
|
|
|
}
|
2016-08-05 13:52:05 +08:00
|
|
|
|
2016-08-14 02:45:26 +08:00
|
|
|
if (index == decimal)
|
|
|
|
{
|
|
|
|
return n.substr(0, decimal);
|
|
|
|
}
|
2016-08-05 13:52:05 +08:00
|
|
|
|
2016-08-14 02:45:26 +08:00
|
|
|
return n.substr(0, index + 1);
|
|
|
|
};
|
2016-08-05 13:52:05 +08:00
|
|
|
|
2016-09-20 06:52:11 +08:00
|
|
|
serializer().attribute("left", remove_trailing_zeros(std::to_string(ws.get_page_margins().get_left())));
|
|
|
|
serializer().attribute("right", remove_trailing_zeros(std::to_string(ws.get_page_margins().get_right())));
|
|
|
|
serializer().attribute("top", remove_trailing_zeros(std::to_string(ws.get_page_margins().get_top())));
|
|
|
|
serializer().attribute("bottom", remove_trailing_zeros(std::to_string(ws.get_page_margins().get_bottom())));
|
|
|
|
serializer().attribute("header", remove_trailing_zeros(std::to_string(ws.get_page_margins().get_header())));
|
|
|
|
serializer().attribute("footer", remove_trailing_zeros(std::to_string(ws.get_page_margins().get_footer())));
|
|
|
|
|
|
|
|
serializer().end_element(xmlns, "pageMargins");
|
2016-08-14 02:45:26 +08:00
|
|
|
}
|
2016-08-05 13:52:05 +08:00
|
|
|
|
2016-08-14 02:45:26 +08:00
|
|
|
if (ws.has_page_setup())
|
2016-08-05 13:52:05 +08:00
|
|
|
{
|
2016-09-20 06:52:11 +08:00
|
|
|
serializer().start_element(xmlns, "pageSetup");
|
|
|
|
serializer().attribute("orientation",
|
|
|
|
ws.get_page_setup().get_orientation() == xlnt::orientation::landscape
|
|
|
|
? "landscape" : "portrait");
|
|
|
|
serializer().attribute("paperSize", static_cast<std::size_t>(ws.get_page_setup().get_paper_size()));
|
|
|
|
serializer().attribute("fitToHeight", write_bool(ws.get_page_setup().fit_to_height()));
|
|
|
|
serializer().attribute("fitToWidth", write_bool(ws.get_page_setup().fit_to_width()));
|
|
|
|
serializer().end_element(xmlns, "pageSetup");
|
2016-08-05 13:52:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!ws.get_header_footer().is_default())
|
|
|
|
{
|
2016-09-20 06:52:11 +08:00
|
|
|
// todo: this shouldn't be hardcoded
|
|
|
|
static const auto header_text =
|
2016-08-05 13:52:05 +08:00
|
|
|
"&L&\"Calibri,Regular\"&K000000Left Header Text&C&\"Arial,Regular\"&6&K445566Center Header "
|
2016-09-20 06:52:11 +08:00
|
|
|
"Text&R&\"Arial,Bold\"&8&K112233Right Header Text"s;
|
|
|
|
static const auto footer_text =
|
2016-08-05 13:52:05 +08:00
|
|
|
"&L&\"Times New Roman,Regular\"&10&K445566Left Footer Text_x000D_And &D and &T&C&\"Times New "
|
|
|
|
"Roman,Bold\"&12&K778899Center Footer Text &Z&F on &A&R&\"Times New Roman,Italic\"&14&KAABBCCRight Footer "
|
2016-09-20 06:52:11 +08:00
|
|
|
"Text &P of &N"s;
|
|
|
|
|
|
|
|
serializer().start_element(xmlns, "headerFooter");
|
|
|
|
serializer().element(xmlns, "oddHeader", header_text);
|
|
|
|
serializer().element(xmlns, "oddFooter", footer_text);
|
|
|
|
serializer().end_element(xmlns, "headerFooter");
|
2016-08-05 13:52:05 +08:00
|
|
|
}
|
2016-09-17 10:59:13 +08:00
|
|
|
|
2016-09-18 23:32:59 +08:00
|
|
|
serializer().end_element();
|
2016-08-05 13:52:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Sheet Relationship Target Parts
|
|
|
|
|
2016-09-18 23:32:59 +08:00
|
|
|
void xlsx_producer::write_comments(const relationship &rel)
|
2016-08-05 13:52:05 +08:00
|
|
|
{
|
2016-09-18 23:32:59 +08:00
|
|
|
serializer().start_element("comments");
|
2016-08-05 13:52:05 +08:00
|
|
|
}
|
|
|
|
|
2016-09-18 23:32:59 +08:00
|
|
|
void xlsx_producer::write_drawings(const relationship &rel)
|
2016-08-05 13:52:05 +08:00
|
|
|
{
|
2016-09-18 23:32:59 +08:00
|
|
|
serializer().start_element("wsDr");
|
2016-08-05 13:52:05 +08:00
|
|
|
}
|
|
|
|
|
2016-08-06 22:40:17 +08:00
|
|
|
// Other Parts
|
|
|
|
|
2016-09-18 23:32:59 +08:00
|
|
|
void xlsx_producer::write_custom_property()
|
2016-08-06 22:40:17 +08:00
|
|
|
{
|
|
|
|
}
|
2016-08-05 13:52:05 +08:00
|
|
|
|
2016-09-18 23:32:59 +08:00
|
|
|
void xlsx_producer::write_unknown_parts()
|
2016-08-05 13:52:05 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-09-18 23:32:59 +08:00
|
|
|
void xlsx_producer::write_unknown_relationships()
|
2016-08-05 13:52:05 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-08-12 12:22:14 +08:00
|
|
|
void xlsx_producer::write_thumbnail(const relationship &rel)
|
|
|
|
{
|
|
|
|
const auto &thumbnail = source_.get_thumbnail();
|
|
|
|
std::string thumbnail_string(thumbnail.begin(), thumbnail.end());
|
|
|
|
destination_.write_string(thumbnail_string, rel.get_target().get_path());
|
|
|
|
}
|
|
|
|
|
2016-09-18 23:32:59 +08:00
|
|
|
xml::serializer &xlsx_producer::serializer()
|
|
|
|
{
|
|
|
|
return *serializer_;
|
|
|
|
}
|
|
|
|
|
2016-08-18 19:34:18 +08:00
|
|
|
std::string xlsx_producer::write_bool(bool boolean) const
|
|
|
|
{
|
|
|
|
if (source_.d_->short_bools_)
|
|
|
|
{
|
|
|
|
return boolean ? "1" : "0";
|
|
|
|
}
|
|
|
|
|
|
|
|
return boolean ? "true" : "false";
|
|
|
|
}
|
|
|
|
|
2016-09-18 23:32:59 +08:00
|
|
|
|
|
|
|
void xlsx_producer::write_relationships(const std::vector<xlnt::relationship> &relationships, const path &part)
|
|
|
|
{
|
|
|
|
path parent = part.parent();
|
|
|
|
|
|
|
|
if (parent.is_absolute())
|
|
|
|
{
|
|
|
|
parent = path(parent.string().substr(1));
|
|
|
|
}
|
|
|
|
|
|
|
|
std::ostringstream rels_stream;
|
|
|
|
path rels_path(parent.append("_rels").append(part.filename() + ".rels").string());
|
|
|
|
xml::serializer rels_serializer(rels_stream, rels_path.string());
|
|
|
|
|
|
|
|
const auto xmlns = xlnt::constants::get_namespace("relationships");
|
|
|
|
|
|
|
|
rels_serializer.start_element(xmlns, "Relationships");
|
|
|
|
rels_serializer.namespace_decl(xmlns, "");
|
|
|
|
|
|
|
|
for (const auto &relationship : relationships)
|
|
|
|
{
|
|
|
|
rels_serializer.start_element(xmlns, "Relationship");
|
|
|
|
|
|
|
|
rels_serializer.attribute("Id", relationship.get_id());
|
|
|
|
rels_serializer.attribute("Type", relationship.get_type());
|
|
|
|
rels_serializer.attribute("Target", relationship.get_target().get_path().string());
|
|
|
|
|
|
|
|
if (relationship.get_target_mode() == xlnt::target_mode::external)
|
|
|
|
{
|
|
|
|
rels_serializer.attribute("TargetMode", "External");
|
|
|
|
}
|
|
|
|
|
|
|
|
rels_serializer.end_element(xmlns, "Relationship");
|
|
|
|
}
|
|
|
|
|
|
|
|
rels_serializer.end_element(xmlns, "Relationships");
|
|
|
|
destination_.write_string(rels_stream.str(), rels_path);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-19 09:49:37 +08:00
|
|
|
void xlsx_producer::write_color(const xlnt::color &color)
|
2016-09-18 23:32:59 +08:00
|
|
|
{
|
|
|
|
switch (color.get_type())
|
|
|
|
{
|
|
|
|
case xlnt::color::type::theme:
|
2016-09-19 09:49:37 +08:00
|
|
|
serializer().attribute("theme", color.get_theme().get_index());
|
2016-09-18 23:32:59 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case xlnt::color::type::indexed:
|
2016-09-19 09:49:37 +08:00
|
|
|
serializer().attribute("indexed", color.get_indexed().get_index());
|
2016-09-18 23:32:59 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case xlnt::color::type::rgb:
|
|
|
|
default:
|
|
|
|
serializer().attribute("rgb", color.get_rgb().get_hex_string());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-05 13:52:05 +08:00
|
|
|
} // namespace detail
|
|
|
|
} // namepsace xlnt
|