2015-12-25 06:10:02 +08:00
|
|
|
// Copyright (c) 2014-2016 Thomas Fussell
|
2015-12-25 04:51:11 +08:00
|
|
|
// Copyright (c) 2010-2015 openpyxl
|
|
|
|
//
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
// of this software and associated documentation files (the "Software"), to deal
|
|
|
|
// in the Software without restriction, including without limitation the rights
|
|
|
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
// copies of the Software, and to permit persons to whom the Software is
|
|
|
|
// furnished to do so, subject to the following conditions:
|
|
|
|
//
|
|
|
|
// The above copyright notice and this permission notice shall be included in
|
|
|
|
// all copies or substantial portions of the Software.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, WRISING FROM,
|
|
|
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
// THE SOFTWARE
|
|
|
|
//
|
|
|
|
// @license: http://www.opensource.org/licenses/mit-license.php
|
|
|
|
// @author: see AUTHORS file
|
2015-10-31 18:56:54 +08:00
|
|
|
#include <algorithm>
|
|
|
|
|
2016-03-09 11:32:32 +08:00
|
|
|
#include <xlnt/packaging/app_properties.hpp>
|
2015-11-03 22:06:01 +08:00
|
|
|
#include <xlnt/packaging/document_properties.hpp>
|
|
|
|
#include <xlnt/packaging/manifest.hpp>
|
2015-11-03 21:38:09 +08:00
|
|
|
#include <xlnt/packaging/relationship.hpp>
|
2015-11-02 01:31:29 +08:00
|
|
|
#include <xlnt/serialization/workbook_serializer.hpp>
|
|
|
|
#include <xlnt/serialization/xml_document.hpp>
|
|
|
|
#include <xlnt/serialization/xml_node.hpp>
|
2015-11-03 21:38:09 +08:00
|
|
|
#include <xlnt/utils/datetime.hpp>
|
|
|
|
#include <xlnt/utils/exceptions.hpp>
|
2015-10-30 07:37:07 +08:00
|
|
|
#include <xlnt/workbook/named_range.hpp>
|
2015-10-14 12:03:48 +08:00
|
|
|
#include <xlnt/workbook/workbook.hpp>
|
2016-01-25 00:15:49 +08:00
|
|
|
#include <xlnt/workbook/worksheet_iterator.hpp>
|
2015-10-30 07:37:07 +08:00
|
|
|
#include <xlnt/worksheet/range_reference.hpp>
|
|
|
|
#include <xlnt/worksheet/worksheet.hpp>
|
2015-10-14 12:03:48 +08:00
|
|
|
|
2015-11-03 21:38:09 +08:00
|
|
|
#include <detail/constants.hpp>
|
2015-10-14 12:03:48 +08:00
|
|
|
|
|
|
|
namespace {
|
2015-11-01 22:43:01 +08:00
|
|
|
|
2015-11-11 07:58:54 +08:00
|
|
|
xlnt::datetime w3cdtf_to_datetime(const std::string &string)
|
2015-10-30 01:46:56 +08:00
|
|
|
{
|
|
|
|
xlnt::datetime result(1900, 1, 1);
|
|
|
|
auto separator_index = string.find('-');
|
2015-11-11 07:58:54 +08:00
|
|
|
result.year = std::stoi(string.substr(0, separator_index));
|
|
|
|
result.month = std::stoi(string.substr(separator_index + 1, string.find('-', separator_index + 1)));
|
2015-10-30 01:46:56 +08:00
|
|
|
separator_index = string.find('-', separator_index + 1);
|
2015-11-11 07:58:54 +08:00
|
|
|
result.day = std::stoi(string.substr(separator_index + 1, string.find('T', separator_index + 1)));
|
2015-10-30 01:46:56 +08:00
|
|
|
separator_index = string.find('T', separator_index + 1);
|
2015-11-11 07:58:54 +08:00
|
|
|
result.hour = std::stoi(string.substr(separator_index + 1, string.find(':', separator_index + 1)));
|
2015-10-30 01:46:56 +08:00
|
|
|
separator_index = string.find(':', separator_index + 1);
|
2015-11-11 07:58:54 +08:00
|
|
|
result.minute = std::stoi(string.substr(separator_index + 1, string.find(':', separator_index + 1)));
|
2015-10-30 01:46:56 +08:00
|
|
|
separator_index = string.find(':', separator_index + 1);
|
2015-11-11 07:58:54 +08:00
|
|
|
result.second = std::stoi(string.substr(separator_index + 1, string.find('Z', separator_index + 1)));
|
2015-10-30 01:46:56 +08:00
|
|
|
return result;
|
|
|
|
}
|
2015-11-01 22:43:01 +08:00
|
|
|
|
2015-11-11 07:58:54 +08:00
|
|
|
std::string fill(const std::string &string, std::size_t length = 2)
|
2015-10-15 06:05:13 +08:00
|
|
|
{
|
2015-11-11 07:58:54 +08:00
|
|
|
if (string.size() >= length)
|
2015-10-15 06:05:13 +08:00
|
|
|
{
|
2015-11-11 07:58:54 +08:00
|
|
|
return string;
|
2015-10-15 06:05:13 +08:00
|
|
|
}
|
2015-11-01 22:43:01 +08:00
|
|
|
|
2015-11-11 07:58:54 +08:00
|
|
|
return std::string(length - string.size(), '0') + string;
|
2015-10-15 06:05:13 +08:00
|
|
|
}
|
2015-10-14 12:03:48 +08:00
|
|
|
|
2015-11-11 07:58:54 +08:00
|
|
|
std::string datetime_to_w3cdtf(const xlnt::datetime &dt)
|
2015-10-14 12:03:48 +08:00
|
|
|
{
|
2015-11-11 07:58:54 +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";
|
2015-10-14 12:03:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
namespace xlnt {
|
2015-10-31 06:54:04 +08:00
|
|
|
|
|
|
|
workbook_serializer::workbook_serializer(workbook &wb) : workbook_(wb)
|
|
|
|
{
|
|
|
|
}
|
2015-11-01 22:43:01 +08:00
|
|
|
|
2015-10-30 01:46:56 +08:00
|
|
|
void workbook_serializer::read_properties_core(const xml_document &xml)
|
|
|
|
{
|
2015-10-31 06:54:04 +08:00
|
|
|
auto &props = workbook_.get_properties();
|
2015-11-02 12:52:19 +08:00
|
|
|
auto root_node = xml.get_child("cp:coreProperties");
|
2015-11-01 22:43:01 +08:00
|
|
|
|
2015-10-30 01:46:56 +08:00
|
|
|
props.excel_base_date = calendar::windows_1900;
|
2015-11-01 22:43:01 +08:00
|
|
|
|
|
|
|
if (root_node.has_child("dc:creator"))
|
2015-10-30 01:46:56 +08:00
|
|
|
{
|
|
|
|
props.creator = root_node.get_child("dc:creator").get_text();
|
|
|
|
}
|
2015-11-01 22:43:01 +08:00
|
|
|
if (root_node.has_child("cp:lastModifiedBy"))
|
2015-10-30 01:46:56 +08:00
|
|
|
{
|
|
|
|
props.last_modified_by = root_node.get_child("cp:lastModifiedBy").get_text();
|
|
|
|
}
|
2015-11-01 22:43:01 +08:00
|
|
|
if (root_node.has_child("dcterms:created"))
|
2015-10-30 01:46:56 +08:00
|
|
|
{
|
2015-11-11 07:58:54 +08:00
|
|
|
std::string created_string = root_node.get_child("dcterms:created").get_text();
|
2015-10-30 01:46:56 +08:00
|
|
|
props.created = w3cdtf_to_datetime(created_string);
|
|
|
|
}
|
2015-11-01 22:43:01 +08:00
|
|
|
if (root_node.has_child("dcterms:modified"))
|
2015-10-30 01:46:56 +08:00
|
|
|
{
|
2015-11-11 07:58:54 +08:00
|
|
|
std::string modified_string = root_node.get_child("dcterms:modified").get_text();
|
2015-10-30 01:46:56 +08:00
|
|
|
props.modified = w3cdtf_to_datetime(modified_string);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-09 11:32:32 +08:00
|
|
|
void workbook_serializer::read_properties_app(const xml_document &xml)
|
|
|
|
{
|
|
|
|
auto &props = workbook_.get_app_properties();
|
|
|
|
auto root_node = xml.get_child("Properties");
|
|
|
|
|
|
|
|
if(root_node.has_child("Application"))
|
|
|
|
{
|
|
|
|
props.application = root_node.get_child("Application").get_text();
|
|
|
|
}
|
|
|
|
|
|
|
|
if(root_node.has_child("DocSecurity"))
|
|
|
|
{
|
|
|
|
props.doc_security = std::stoi(root_node.get_child("DocSecurity").get_text());
|
|
|
|
}
|
|
|
|
|
|
|
|
if(root_node.has_child("ScaleCrop"))
|
|
|
|
{
|
|
|
|
props.scale_crop = root_node.get_child("ScaleCrop").get_text() == "true";
|
|
|
|
}
|
|
|
|
|
|
|
|
if(root_node.has_child("Company"))
|
|
|
|
{
|
|
|
|
props.company = root_node.get_child("Company").get_text();
|
|
|
|
}
|
|
|
|
|
|
|
|
if(root_node.has_child("ScaleCrop"))
|
|
|
|
{
|
|
|
|
props.links_up_to_date = root_node.get_child("ScaleCrop").get_text() == "true";
|
|
|
|
}
|
|
|
|
|
|
|
|
if(root_node.has_child("SharedDoc"))
|
|
|
|
{
|
|
|
|
props.shared_doc = root_node.get_child("SharedDoc").get_text() == "true";
|
|
|
|
}
|
|
|
|
|
|
|
|
if(root_node.has_child("HyperlinksChanged"))
|
|
|
|
{
|
|
|
|
props.hyperlinks_changed = root_node.get_child("HyperlinksChanged").get_text() == "true";
|
|
|
|
}
|
|
|
|
|
|
|
|
if(root_node.has_child("AppVersion"))
|
|
|
|
{
|
|
|
|
props.app_version = root_node.get_child("AppVersion").get_text();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-30 07:37:07 +08:00
|
|
|
xml_document workbook_serializer::write_properties_core() const
|
2015-10-15 06:05:13 +08:00
|
|
|
{
|
2015-10-31 06:54:04 +08:00
|
|
|
auto &props = workbook_.get_properties();
|
2015-11-01 22:43:01 +08:00
|
|
|
|
2015-10-30 07:37:07 +08:00
|
|
|
xml_document xml;
|
2015-11-01 22:43:01 +08:00
|
|
|
|
2015-10-31 06:54:04 +08:00
|
|
|
auto root_node = xml.add_child("cp:coreProperties");
|
2015-11-01 22:43:01 +08:00
|
|
|
|
2015-10-30 07:37:07 +08:00
|
|
|
xml.add_namespace("cp", "http://schemas.openxmlformats.org/package/2006/metadata/core-properties");
|
|
|
|
xml.add_namespace("dc", "http://purl.org/dc/elements/1.1/");
|
|
|
|
xml.add_namespace("dcmitype", "http://purl.org/dc/dcmitype/");
|
|
|
|
xml.add_namespace("dcterms", "http://purl.org/dc/terms/");
|
|
|
|
xml.add_namespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
|
2015-11-01 22:43:01 +08:00
|
|
|
|
2015-10-30 07:37:07 +08:00
|
|
|
root_node.add_child("dc:creator").set_text(props.creator);
|
|
|
|
root_node.add_child("cp:lastModifiedBy").set_text(props.last_modified_by);
|
|
|
|
root_node.add_child("dcterms:created").set_text(datetime_to_w3cdtf(props.created));
|
|
|
|
root_node.get_child("dcterms:created").add_attribute("xsi:type", "dcterms:W3CDTF");
|
|
|
|
root_node.add_child("dcterms:modified").set_text(datetime_to_w3cdtf(props.modified));
|
|
|
|
root_node.get_child("dcterms:modified").add_attribute("xsi:type", "dcterms:W3CDTF");
|
|
|
|
root_node.add_child("dc:title").set_text(props.title);
|
|
|
|
root_node.add_child("dc:description");
|
|
|
|
root_node.add_child("dc:subject");
|
|
|
|
root_node.add_child("cp:keywords");
|
|
|
|
root_node.add_child("cp:category");
|
2015-11-01 22:43:01 +08:00
|
|
|
|
2015-10-30 07:37:07 +08:00
|
|
|
return xml;
|
2015-10-15 06:05:13 +08:00
|
|
|
}
|
2015-11-01 22:43:01 +08:00
|
|
|
|
2015-10-30 07:37:07 +08:00
|
|
|
xml_document workbook_serializer::write_properties_app() const
|
2015-10-14 12:03:48 +08:00
|
|
|
{
|
2015-10-30 07:37:07 +08:00
|
|
|
xml_document xml;
|
2015-11-01 22:43:01 +08:00
|
|
|
|
2015-10-31 06:54:04 +08:00
|
|
|
auto root_node = xml.add_child("Properties");
|
2015-11-01 22:43:01 +08:00
|
|
|
|
2015-10-31 06:54:04 +08:00
|
|
|
xml.add_namespace("", "http://schemas.openxmlformats.org/officeDocument/2006/extended-properties");
|
|
|
|
xml.add_namespace("vt", "http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes");
|
2016-03-09 11:32:32 +08:00
|
|
|
|
|
|
|
auto &properties = workbook_.get_app_properties();
|
|
|
|
|
|
|
|
root_node.add_child("Application").set_text(properties.application);
|
|
|
|
root_node.add_child("DocSecurity").set_text(std::to_string(properties.doc_security));
|
|
|
|
root_node.add_child("ScaleCrop").set_text(properties.scale_crop ? "true" : "false");
|
|
|
|
|
|
|
|
auto company_node = root_node.add_child("Company");
|
|
|
|
|
|
|
|
if (!properties.company.empty())
|
|
|
|
{
|
|
|
|
company_node.set_text(properties.company);
|
|
|
|
}
|
|
|
|
|
|
|
|
root_node.add_child("LinksUpToDate").set_text(properties.links_up_to_date ? "true" : "false");
|
|
|
|
root_node.add_child("SharedDoc").set_text(properties.shared_doc ? "true" : "false");
|
|
|
|
root_node.add_child("HyperlinksChanged").set_text(properties.hyperlinks_changed ? "true" : "false");
|
|
|
|
root_node.add_child("AppVersion").set_text(properties.app_version);
|
|
|
|
|
|
|
|
// TODO what is this stuff?
|
|
|
|
|
2015-10-30 07:37:07 +08:00
|
|
|
auto heading_pairs_node = root_node.add_child("HeadingPairs");
|
|
|
|
auto heading_pairs_vector_node = heading_pairs_node.add_child("vt:vector");
|
|
|
|
heading_pairs_vector_node.add_attribute("baseType", "variant");
|
|
|
|
heading_pairs_vector_node.add_attribute("size", "2");
|
|
|
|
heading_pairs_vector_node.add_child("vt:variant").add_child("vt:lpstr").set_text("Worksheets");
|
2015-11-01 22:43:01 +08:00
|
|
|
heading_pairs_vector_node.add_child("vt:variant")
|
|
|
|
.add_child("vt:i4")
|
2015-11-11 07:58:54 +08:00
|
|
|
.set_text(std::to_string(workbook_.get_sheet_names().size()));
|
2015-11-01 22:43:01 +08:00
|
|
|
|
2015-10-30 07:37:07 +08:00
|
|
|
auto titles_of_parts_node = root_node.add_child("TitlesOfParts");
|
|
|
|
auto titles_of_parts_vector_node = titles_of_parts_node.add_child("vt:vector");
|
|
|
|
titles_of_parts_vector_node.add_attribute("baseType", "lpstr");
|
2015-11-11 07:58:54 +08:00
|
|
|
titles_of_parts_vector_node.add_attribute("size", std::to_string(workbook_.get_sheet_names().size()));
|
2015-11-01 22:43:01 +08:00
|
|
|
|
|
|
|
for (auto ws : workbook_)
|
2015-10-14 12:03:48 +08:00
|
|
|
{
|
2015-10-30 07:37:07 +08:00
|
|
|
titles_of_parts_vector_node.add_child("vt:lpstr").set_text(ws.get_title());
|
2015-10-14 12:03:48 +08:00
|
|
|
}
|
|
|
|
|
2015-10-30 07:37:07 +08:00
|
|
|
return xml;
|
2015-10-14 12:03:48 +08:00
|
|
|
}
|
|
|
|
|
2015-10-30 07:37:07 +08:00
|
|
|
xml_document workbook_serializer::write_workbook() const
|
2015-10-14 12:03:48 +08:00
|
|
|
{
|
|
|
|
std::size_t num_visible = 0;
|
2015-11-01 22:43:01 +08:00
|
|
|
|
|
|
|
for (auto ws : workbook_)
|
2015-10-14 12:03:48 +08:00
|
|
|
{
|
2015-11-20 11:54:54 +08:00
|
|
|
if (ws.get_page_setup().get_sheet_state() == sheet_state::visible)
|
2015-10-14 12:03:48 +08:00
|
|
|
{
|
|
|
|
num_visible++;
|
|
|
|
}
|
|
|
|
}
|
2015-11-01 22:43:01 +08:00
|
|
|
|
|
|
|
if (num_visible == 0)
|
2015-10-14 12:03:48 +08:00
|
|
|
{
|
2015-10-30 07:37:07 +08:00
|
|
|
throw xlnt::value_error();
|
2015-10-14 12:03:48 +08:00
|
|
|
}
|
2015-11-01 22:43:01 +08:00
|
|
|
|
2015-10-30 07:37:07 +08:00
|
|
|
xml_document xml;
|
2015-11-01 22:43:01 +08:00
|
|
|
|
2015-10-31 06:54:04 +08:00
|
|
|
auto root_node = xml.add_child("workbook");
|
2015-11-01 22:43:01 +08:00
|
|
|
|
2015-10-31 06:54:04 +08:00
|
|
|
xml.add_namespace("", "http://schemas.openxmlformats.org/spreadsheetml/2006/main");
|
|
|
|
xml.add_namespace("r", "http://schemas.openxmlformats.org/officeDocument/2006/relationships");
|
2015-11-01 22:43:01 +08:00
|
|
|
|
2015-10-31 06:54:04 +08:00
|
|
|
auto file_version_node = root_node.add_child("fileVersion");
|
2015-10-30 07:37:07 +08:00
|
|
|
file_version_node.add_attribute("appName", "xl");
|
|
|
|
file_version_node.add_attribute("lastEdited", "4");
|
|
|
|
file_version_node.add_attribute("lowestEdited", "4");
|
|
|
|
file_version_node.add_attribute("rupBuild", "4505");
|
2015-11-01 22:43:01 +08:00
|
|
|
|
2015-10-31 06:54:04 +08:00
|
|
|
auto workbook_pr_node = root_node.add_child("workbookPr");
|
2015-10-30 07:37:07 +08:00
|
|
|
workbook_pr_node.add_attribute("codeName", "ThisWorkbook");
|
|
|
|
workbook_pr_node.add_attribute("defaultThemeVersion", "124226");
|
2015-11-01 22:43:01 +08:00
|
|
|
workbook_pr_node.add_attribute("date1904",
|
|
|
|
workbook_.get_properties().excel_base_date == calendar::mac_1904 ? "1" : "0");
|
|
|
|
|
2015-10-30 07:37:07 +08:00
|
|
|
auto book_views_node = root_node.add_child("bookViews");
|
|
|
|
auto workbook_view_node = book_views_node.add_child("workbookView");
|
|
|
|
workbook_view_node.add_attribute("activeTab", "0");
|
|
|
|
workbook_view_node.add_attribute("autoFilterDateGrouping", "1");
|
|
|
|
workbook_view_node.add_attribute("firstSheet", "0");
|
|
|
|
workbook_view_node.add_attribute("minimized", "0");
|
|
|
|
workbook_view_node.add_attribute("showHorizontalScroll", "1");
|
|
|
|
workbook_view_node.add_attribute("showSheetTabs", "1");
|
|
|
|
workbook_view_node.add_attribute("showVerticalScroll", "1");
|
|
|
|
workbook_view_node.add_attribute("tabRatio", "600");
|
|
|
|
workbook_view_node.add_attribute("visibility", "visible");
|
2015-11-01 22:43:01 +08:00
|
|
|
|
2015-10-30 07:37:07 +08:00
|
|
|
auto sheets_node = root_node.add_child("sheets");
|
|
|
|
auto defined_names_node = root_node.add_child("definedNames");
|
2015-11-01 22:43:01 +08:00
|
|
|
|
|
|
|
for (const auto &relationship : workbook_.get_relationships())
|
2015-10-14 12:03:48 +08:00
|
|
|
{
|
2015-11-01 22:43:01 +08:00
|
|
|
if (relationship.get_type() == relationship::type::worksheet)
|
2015-10-14 12:03:48 +08:00
|
|
|
{
|
2015-11-01 22:43:01 +08:00
|
|
|
// TODO: this is ugly
|
2015-11-11 07:58:54 +08:00
|
|
|
std::string sheet_index_string = relationship.get_target_uri();
|
2015-10-14 12:03:48 +08:00
|
|
|
sheet_index_string = sheet_index_string.substr(0, sheet_index_string.find('.'));
|
|
|
|
sheet_index_string = sheet_index_string.substr(sheet_index_string.find_last_of('/'));
|
|
|
|
auto iter = sheet_index_string.end();
|
2015-11-11 07:58:54 +08:00
|
|
|
iter--;
|
2015-11-08 07:37:23 +08:00
|
|
|
while (isdigit(*iter))
|
2015-11-11 07:58:54 +08:00
|
|
|
iter--;
|
2015-10-14 12:03:48 +08:00
|
|
|
auto first_digit = iter - sheet_index_string.begin();
|
2015-11-11 07:58:54 +08:00
|
|
|
sheet_index_string = sheet_index_string.substr(static_cast<std::string::size_type>(first_digit + 1));
|
|
|
|
std::size_t sheet_index = static_cast<std::size_t>(std::stoll(sheet_index_string) - 1);
|
2015-11-01 22:43:01 +08:00
|
|
|
|
2015-10-31 06:54:04 +08:00
|
|
|
auto ws = workbook_.get_sheet_by_index(sheet_index);
|
2015-11-01 22:43:01 +08:00
|
|
|
|
2015-10-30 07:37:07 +08:00
|
|
|
auto sheet_node = sheets_node.add_child("sheet");
|
|
|
|
sheet_node.add_attribute("name", ws.get_title());
|
2015-11-11 07:58:54 +08:00
|
|
|
sheet_node.add_attribute("sheetId", std::to_string(sheet_index + 1));
|
2015-10-31 06:54:04 +08:00
|
|
|
sheet_node.add_attribute("r:id", relationship.get_id());
|
2015-11-01 22:43:01 +08:00
|
|
|
|
|
|
|
if (ws.has_auto_filter())
|
2015-10-14 12:03:48 +08:00
|
|
|
{
|
2015-10-31 06:54:04 +08:00
|
|
|
auto defined_name_node = defined_names_node.add_child("definedName");
|
2015-10-30 07:37:07 +08:00
|
|
|
defined_name_node.add_attribute("name", "_xlnm._FilterDatabase");
|
|
|
|
defined_name_node.add_attribute("hidden", "1");
|
|
|
|
defined_name_node.add_attribute("localSheetId", "0");
|
2015-11-11 07:58:54 +08:00
|
|
|
std::string name =
|
2015-11-01 22:43:01 +08:00
|
|
|
"'" + ws.get_title() + "'!" + range_reference::make_absolute(ws.get_auto_filter()).to_string();
|
2015-10-30 07:37:07 +08:00
|
|
|
defined_name_node.set_text(name);
|
2015-10-14 12:03:48 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-11-01 22:43:01 +08:00
|
|
|
|
2015-10-30 07:37:07 +08:00
|
|
|
auto calc_pr_node = root_node.add_child("calcPr");
|
|
|
|
calc_pr_node.add_attribute("calcId", "124519");
|
|
|
|
calc_pr_node.add_attribute("calcMode", "auto");
|
|
|
|
calc_pr_node.add_attribute("fullCalcOnLoad", "1");
|
2015-11-01 22:43:01 +08:00
|
|
|
|
2015-10-30 07:37:07 +08:00
|
|
|
return xml;
|
2015-10-14 12:03:48 +08:00
|
|
|
}
|
2015-11-01 22:43:01 +08:00
|
|
|
|
2015-10-31 06:54:04 +08:00
|
|
|
xml_node workbook_serializer::write_named_ranges() const
|
2015-10-14 12:03:48 +08:00
|
|
|
{
|
2015-10-31 06:54:04 +08:00
|
|
|
xlnt::xml_node named_ranges_node;
|
2015-11-01 22:43:01 +08:00
|
|
|
|
|
|
|
for (auto &named_range : workbook_.get_named_ranges())
|
2015-10-15 06:05:13 +08:00
|
|
|
{
|
2015-10-30 07:37:07 +08:00
|
|
|
named_ranges_node.add_child(named_range.get_name());
|
2015-10-15 06:05:13 +08:00
|
|
|
}
|
2015-10-30 07:37:07 +08:00
|
|
|
|
2015-10-31 06:54:04 +08:00
|
|
|
return named_ranges_node;
|
2015-10-14 12:03:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace xlnt
|