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-10-31 03:48:40 +08:00
|
|
|
|
2016-08-05 13:52:05 +08:00
|
|
|
#include <cctype>
|
2016-10-29 22:23:04 +08:00
|
|
|
#include <numeric> // for std::accumulate
|
2016-08-05 13:52:05 +08:00
|
|
|
|
|
|
|
#include <detail/constants.hpp>
|
2016-09-18 23:32:59 +08:00
|
|
|
#include <detail/custom_value_traits.hpp>
|
2016-12-02 21:37:50 +08:00
|
|
|
#include <detail/vector_streambuf.hpp>
|
2016-08-05 13:52:05 +08:00
|
|
|
#include <detail/workbook_impl.hpp>
|
2016-11-20 06:19:38 +08:00
|
|
|
#include <detail/xlsx_consumer.hpp>
|
2016-10-31 03:48:40 +08:00
|
|
|
#include <detail/zip.hpp>
|
2016-08-18 19:34:18 +08:00
|
|
|
#include <xlnt/cell/cell.hpp>
|
2016-08-05 13:52:05 +08:00
|
|
|
#include <xlnt/packaging/manifest.hpp>
|
2016-11-20 06:19:38 +08:00
|
|
|
#include <xlnt/utils/path.hpp>
|
2016-08-05 13:52:05 +08:00
|
|
|
#include <xlnt/workbook/const_worksheet_iterator.hpp>
|
|
|
|
#include <xlnt/workbook/workbook.hpp>
|
|
|
|
#include <xlnt/worksheet/worksheet.hpp>
|
|
|
|
|
2016-11-20 05:42:16 +08:00
|
|
|
namespace std {
|
|
|
|
|
2016-11-25 21:13:55 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Allows xml::qname to be used as a key in a std::unordered_map.
|
|
|
|
/// </summary>
|
2016-11-20 05:42:16 +08:00
|
|
|
template <>
|
|
|
|
struct hash<xml::qname>
|
|
|
|
{
|
2016-11-20 06:19:38 +08:00
|
|
|
std::size_t operator()(const xml::qname &k) const
|
2016-11-20 05:42:16 +08:00
|
|
|
{
|
|
|
|
static std::hash<std::string> hasher;
|
|
|
|
return hasher(k.string());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace std
|
|
|
|
|
2016-08-05 13:52:05 +08:00
|
|
|
namespace {
|
|
|
|
|
2016-11-30 07:31:06 +08:00
|
|
|
#ifndef NDEBUG
|
2016-11-25 21:13:55 +08:00
|
|
|
#define THROW_ON_INVALID_XML
|
2016-11-30 07:31:06 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef THROW_ON_INVALID_XML
|
|
|
|
#define unexpected_element(element) throw xlnt::exception(element.string());
|
|
|
|
#else
|
|
|
|
#define unexpected_element(element) skip_remaining_content(element);
|
|
|
|
#endif
|
2016-11-25 21:13:55 +08:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Returns true if bool_string represents a true xsd:boolean.
|
|
|
|
/// </summary>
|
2016-08-05 13:52:05 +08:00
|
|
|
bool is_true(const std::string &bool_string)
|
|
|
|
{
|
2016-11-25 21:13:55 +08:00
|
|
|
if (bool_string == "1" || bool_string == "true")
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef THROW_ON_INVALID_XML
|
|
|
|
if (bool_string == "0" || bool_string == "false")
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
throw xlnt::exception("xsd:boolean should be one of: 0, 1, true, or false, found " + bool_string);
|
|
|
|
#else
|
2016-08-05 13:52:05 +08:00
|
|
|
|
2016-11-30 07:31:06 +08:00
|
|
|
return false;
|
2016-08-05 13:52:05 +08:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2016-11-30 07:31:06 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Helper template function that returns true if element is in container.
|
|
|
|
/// </summary>
|
2016-11-25 21:13:55 +08:00
|
|
|
template<typename T>
|
2016-11-30 07:31:06 +08:00
|
|
|
bool contains(const std::vector<T> &container, const T &element)
|
2016-11-25 21:13:55 +08:00
|
|
|
{
|
2016-11-30 07:31:06 +08:00
|
|
|
return std::find(container.begin(), container.end(), element) != container.end();
|
2016-11-25 21:13:55 +08:00
|
|
|
}
|
|
|
|
|
2016-08-05 13:52:05 +08:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
namespace xlnt {
|
|
|
|
namespace detail {
|
|
|
|
|
2016-11-20 06:19:38 +08:00
|
|
|
xlsx_consumer::xlsx_consumer(workbook &target)
|
|
|
|
: target_(target),
|
|
|
|
parser_(nullptr)
|
2016-08-05 13:52:05 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void xlsx_consumer::read(std::istream &source)
|
|
|
|
{
|
2016-11-20 06:19:38 +08:00
|
|
|
archive_.reset(new ZipFileReader(source));
|
|
|
|
populate_workbook();
|
2016-08-05 13:52:05 +08:00
|
|
|
}
|
|
|
|
|
2016-10-12 11:16:14 +08:00
|
|
|
xml::parser &xlsx_consumer::parser()
|
|
|
|
{
|
2016-11-20 06:19:38 +08:00
|
|
|
return *parser_;
|
2016-10-12 11:16:14 +08:00
|
|
|
}
|
2016-08-05 13:52:05 +08:00
|
|
|
|
2016-11-25 21:13:55 +08:00
|
|
|
std::vector<relationship> xlsx_consumer::read_relationships(const path &part)
|
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
auto part_rels_path = part.parent()
|
|
|
|
.append("_rels")
|
|
|
|
.append(part.filename() + ".rels")
|
|
|
|
.relative_to(path("/"));
|
|
|
|
|
2016-11-25 21:13:55 +08:00
|
|
|
std::vector<xlnt::relationship> relationships;
|
2016-12-02 21:37:50 +08:00
|
|
|
if (!archive_->has_file(part_rels_path.string())) return relationships;
|
2016-11-25 21:13:55 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
auto &rels_stream = archive_->open(part_rels_path.string());
|
|
|
|
xml::parser parser(rels_stream, part_rels_path.string());
|
2016-11-25 21:13:55 +08:00
|
|
|
parser_ = &parser;
|
|
|
|
|
|
|
|
xlnt::uri source(part.string());
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
static const auto &xmlns = xlnt::constants::namespace_("relationships");
|
2016-11-25 21:13:55 +08:00
|
|
|
|
|
|
|
expect_start_element(xml::qname(xmlns, "Relationships"), xml::content::complex);
|
|
|
|
|
|
|
|
while (in_element(xml::qname(xmlns, "Relationships")))
|
|
|
|
{
|
|
|
|
expect_start_element(xml::qname(xmlns, "Relationship"), xml::content::simple);
|
2016-11-30 08:05:47 +08:00
|
|
|
|
2016-12-04 04:39:03 +08:00
|
|
|
auto target_mode = xlnt::target_mode::internal;
|
2016-12-02 21:37:50 +08:00
|
|
|
|
|
|
|
if (parser.attribute_present("TargetMode"))
|
|
|
|
{
|
|
|
|
target_mode = parser.attribute<xlnt::target_mode>("TargetMode");
|
|
|
|
}
|
|
|
|
|
2016-11-25 21:13:55 +08:00
|
|
|
relationships.emplace_back(parser.attribute("Id"),
|
2016-12-02 21:37:50 +08:00
|
|
|
parser.attribute<xlnt::relationship_type>("Type"), source,
|
2016-11-25 21:13:55 +08:00
|
|
|
xlnt::uri(parser.attribute("Target")),
|
2016-12-02 21:37:50 +08:00
|
|
|
target_mode);
|
2016-11-30 08:05:47 +08:00
|
|
|
|
2016-11-25 21:13:55 +08:00
|
|
|
expect_end_element(xml::qname(xmlns, "Relationship"));
|
|
|
|
}
|
|
|
|
|
|
|
|
expect_end_element(xml::qname(xmlns, "Relationships"));
|
|
|
|
|
|
|
|
parser_ = nullptr;
|
|
|
|
|
|
|
|
return relationships;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-11-20 05:42:16 +08:00
|
|
|
void xlsx_consumer::read_part(const std::vector<relationship> &rel_chain)
|
2016-08-05 13:52:05 +08:00
|
|
|
{
|
2016-11-20 06:19:38 +08:00
|
|
|
// ignore namespace declarations except in parts of these types
|
2016-12-02 21:37:50 +08:00
|
|
|
const auto using_namespaces = std::vector<relationship_type>
|
2016-11-20 05:42:16 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
relationship_type::office_document,
|
|
|
|
relationship_type::stylesheet,
|
|
|
|
relationship_type::chartsheet,
|
|
|
|
relationship_type::dialogsheet,
|
|
|
|
relationship_type::worksheet
|
2016-11-20 05:42:16 +08:00
|
|
|
};
|
2016-11-20 06:19:38 +08:00
|
|
|
|
2016-11-20 05:42:16 +08:00
|
|
|
auto receive = xml::parser::receive_default;
|
2016-11-20 06:19:38 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
if (contains(using_namespaces, rel_chain.back().type()))
|
2016-11-20 05:42:16 +08:00
|
|
|
{
|
|
|
|
receive |= xml::parser::receive_namespace_decls;
|
|
|
|
}
|
2016-08-05 13:52:05 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
const auto &manifest = target_.manifest();
|
2016-11-20 05:42:16 +08:00
|
|
|
auto part_path = manifest.canonicalize(rel_chain);
|
|
|
|
auto &stream = archive_->open(part_path.string());
|
|
|
|
xml::parser parser(stream, part_path.string(), receive);
|
|
|
|
parser_ = &parser;
|
2016-11-20 06:19:38 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
switch (rel_chain.back().type())
|
2016-11-20 05:42:16 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
case relationship_type::core_properties:
|
|
|
|
read_properties(part_path, xml::qname(constants::namespace_("core-properties"), "coreProperties"));
|
2016-11-20 06:19:38 +08:00
|
|
|
break;
|
2016-10-12 11:16:14 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
case relationship_type::extended_properties:
|
|
|
|
read_properties(part_path, xml::qname(constants::namespace_("extended-properties"), "Properties"));
|
2016-11-20 06:19:38 +08:00
|
|
|
break;
|
2016-10-12 11:16:14 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
case relationship_type::custom_properties:
|
|
|
|
read_properties(part_path, xml::qname(constants::namespace_("custom-properties"), "Properties"));
|
2016-11-20 06:19:38 +08:00
|
|
|
break;
|
2016-10-12 11:16:14 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
case relationship_type::office_document:
|
|
|
|
read_office_document(manifest.content_type(part_path));
|
2016-11-20 06:19:38 +08:00
|
|
|
break;
|
2016-10-12 11:16:14 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
case relationship_type::connections:
|
2016-11-20 06:19:38 +08:00
|
|
|
read_connections();
|
|
|
|
break;
|
2016-10-12 11:16:14 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
case relationship_type::custom_xml_mappings:
|
2016-11-20 06:19:38 +08:00
|
|
|
read_custom_xml_mappings();
|
|
|
|
break;
|
2016-10-12 11:16:14 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
case relationship_type::external_workbook_references:
|
2016-11-20 06:19:38 +08:00
|
|
|
read_external_workbook_references();
|
|
|
|
break;
|
2016-10-12 11:16:14 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
case relationship_type::metadata:
|
2016-11-20 06:19:38 +08:00
|
|
|
read_metadata();
|
|
|
|
break;
|
2016-10-12 11:16:14 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
case relationship_type::pivot_table:
|
2016-11-20 06:19:38 +08:00
|
|
|
read_pivot_table();
|
|
|
|
break;
|
2016-10-12 11:16:14 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
case relationship_type::shared_workbook_revision_headers:
|
2016-11-20 06:19:38 +08:00
|
|
|
read_shared_workbook_revision_headers();
|
|
|
|
break;
|
2016-10-12 11:16:14 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
case relationship_type::volatile_dependencies:
|
2016-11-20 06:19:38 +08:00
|
|
|
read_volatile_dependencies();
|
|
|
|
break;
|
2016-10-12 11:16:14 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
case relationship_type::shared_string_table:
|
2016-11-20 06:19:38 +08:00
|
|
|
read_shared_string_table();
|
|
|
|
break;
|
2016-10-12 11:16:14 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
case relationship_type::stylesheet:
|
2016-11-20 06:19:38 +08:00
|
|
|
read_stylesheet();
|
|
|
|
break;
|
2016-10-12 11:16:14 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
case relationship_type::theme:
|
2016-11-20 06:19:38 +08:00
|
|
|
read_theme();
|
|
|
|
break;
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
case relationship_type::chartsheet:
|
|
|
|
read_chartsheet(rel_chain.back().id());
|
2016-11-20 06:19:38 +08:00
|
|
|
break;
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
case relationship_type::dialogsheet:
|
|
|
|
read_dialogsheet(rel_chain.back().id());
|
2016-11-20 06:19:38 +08:00
|
|
|
break;
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
case relationship_type::worksheet:
|
|
|
|
read_worksheet(rel_chain.back().id());
|
2016-11-20 06:19:38 +08:00
|
|
|
break;
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
case relationship_type::thumbnail:
|
|
|
|
read_image(part_path);
|
2016-11-20 06:19:38 +08:00
|
|
|
break;
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
case relationship_type::calculation_chain:
|
2016-11-20 06:19:38 +08:00
|
|
|
read_calculation_chain();
|
|
|
|
break;
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
case relationship_type::hyperlink:
|
2016-11-20 06:19:38 +08:00
|
|
|
break;
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
case relationship_type::comments:
|
2016-11-20 06:19:38 +08:00
|
|
|
break;
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
case relationship_type::vml_drawing:
|
2016-11-20 06:19:38 +08:00
|
|
|
break;
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
case relationship_type::unknown:
|
2016-11-20 06:19:38 +08:00
|
|
|
break;
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
case relationship_type::printer_settings:
|
2016-11-20 06:19:38 +08:00
|
|
|
break;
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
case relationship_type::custom_property:
|
2016-11-20 06:19:38 +08:00
|
|
|
break;
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
case relationship_type::drawings:
|
2016-11-20 06:19:38 +08:00
|
|
|
break;
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
case relationship_type::pivot_table_cache_definition:
|
2016-11-20 06:19:38 +08:00
|
|
|
break;
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
case relationship_type::pivot_table_cache_records:
|
2016-11-20 06:19:38 +08:00
|
|
|
break;
|
2016-10-12 11:16:14 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
case relationship_type::query_table:
|
2016-11-20 06:19:38 +08:00
|
|
|
break;
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
case relationship_type::shared_workbook:
|
2016-11-20 06:19:38 +08:00
|
|
|
break;
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
case relationship_type::revision_log:
|
2016-11-20 06:19:38 +08:00
|
|
|
break;
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
case relationship_type::shared_workbook_user_data:
|
2016-11-20 06:19:38 +08:00
|
|
|
break;
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
case relationship_type::single_cell_table_definitions:
|
2016-11-20 06:19:38 +08:00
|
|
|
break;
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
case relationship_type::table_definition:
|
2016-11-20 06:19:38 +08:00
|
|
|
break;
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
case relationship_type::image:
|
|
|
|
read_image(part_path);
|
2016-11-20 06:19:38 +08:00
|
|
|
break;
|
2016-11-20 05:42:16 +08:00
|
|
|
}
|
2016-11-20 06:19:38 +08:00
|
|
|
|
2016-11-20 05:42:16 +08:00
|
|
|
parser_ = nullptr;
|
|
|
|
}
|
2016-10-12 11:16:14 +08:00
|
|
|
|
2016-11-20 05:42:16 +08:00
|
|
|
void xlsx_consumer::populate_workbook()
|
|
|
|
{
|
2016-11-20 06:19:38 +08:00
|
|
|
target_.clear();
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
read_content_types();
|
|
|
|
const auto root_path = path("/");
|
2016-11-20 05:42:16 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
for (const auto &package_rel : read_relationships(root_path))
|
2016-11-20 05:42:16 +08:00
|
|
|
{
|
2016-12-04 20:29:10 +08:00
|
|
|
manifest().register_relationship(package_rel);
|
2016-11-20 06:19:38 +08:00
|
|
|
}
|
2016-08-05 13:52:05 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
for (auto package_rel : manifest().relationships(root_path))
|
2016-11-20 05:42:16 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
if (package_rel.type() == relationship_type::office_document)
|
2016-11-20 05:42:16 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
// Read the workbook after all the other package parts
|
|
|
|
continue;
|
2016-11-20 05:42:16 +08:00
|
|
|
}
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
read_part({package_rel});
|
|
|
|
}
|
2016-11-20 05:42:16 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
for (const auto &relationship_source_string : archive_->files())
|
2016-11-20 05:42:16 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
for (const auto &part_rel : read_relationships(path(relationship_source_string)))
|
2016-11-20 05:42:16 +08:00
|
|
|
{
|
2016-12-04 20:29:10 +08:00
|
|
|
manifest().register_relationship(part_rel);
|
2016-11-20 05:42:16 +08:00
|
|
|
}
|
|
|
|
}
|
2016-12-02 21:37:50 +08:00
|
|
|
|
|
|
|
const auto workbook_rel = manifest().relationship(root_path, relationship_type::office_document);
|
|
|
|
read_part({workbook_rel});
|
2016-08-05 13:52:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Package Parts
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
void xlsx_consumer::read_content_types()
|
2016-08-05 13:52:05 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
auto &manifest = target_.manifest();
|
2016-10-12 11:16:14 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
static const auto &xmlns = constants::namespace_("content-types");
|
2016-09-22 07:04:16 +08:00
|
|
|
|
2016-11-01 08:48:43 +08:00
|
|
|
xml::parser parser(archive_->open("[Content_Types].xml"), "[Content_Types].xml");
|
2016-11-25 21:13:55 +08:00
|
|
|
parser_ = &parser;
|
|
|
|
|
2016-11-30 07:31:06 +08:00
|
|
|
expect_start_element(xml::qname(xmlns, "Types"), xml::content::complex);
|
2016-08-05 13:52:05 +08:00
|
|
|
|
2016-11-25 21:13:55 +08:00
|
|
|
while (in_element(xml::qname(xmlns, "Types")))
|
2016-11-20 06:19:38 +08:00
|
|
|
{
|
2016-11-25 21:13:55 +08:00
|
|
|
auto current_element = expect_start_element(xml::content::complex);
|
2016-11-20 06:19:38 +08:00
|
|
|
|
2016-11-25 21:13:55 +08:00
|
|
|
if (current_element == xml::qname(xmlns, "Default"))
|
2016-09-17 10:59:13 +08:00
|
|
|
{
|
2016-11-20 06:19:38 +08:00
|
|
|
auto extension = parser.attribute("Extension");
|
|
|
|
auto content_type = parser.attribute("ContentType");
|
|
|
|
manifest.register_default_type(extension, content_type);
|
2016-09-17 10:59:13 +08:00
|
|
|
}
|
2016-11-25 21:13:55 +08:00
|
|
|
else if (current_element == xml::qname(xmlns, "Override"))
|
2016-09-17 10:59:13 +08:00
|
|
|
{
|
2016-11-20 06:19:38 +08:00
|
|
|
auto part_name = parser.attribute("PartName");
|
|
|
|
auto content_type = parser.attribute("ContentType");
|
|
|
|
manifest.register_override_type(path(part_name), content_type);
|
2016-09-17 10:59:13 +08:00
|
|
|
}
|
2016-11-25 21:13:55 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
unexpected_element(current_element);
|
|
|
|
}
|
|
|
|
|
|
|
|
expect_end_element(current_element);
|
2016-11-20 06:19:38 +08:00
|
|
|
}
|
|
|
|
|
2016-11-25 21:13:55 +08:00
|
|
|
expect_end_element(xml::qname(xmlns, "Types"));
|
2016-08-05 13:52:05 +08:00
|
|
|
}
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
void xlsx_consumer::read_properties(const path &part, const xml::qname &root)
|
2016-08-05 13:52:05 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
auto content_type = manifest().content_type(part);
|
2016-09-22 07:04:16 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
std::unordered_map<std::string, std::string> properties;
|
|
|
|
expect_start_element(root, xml::content::complex);
|
2016-11-20 06:19:38 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
while (in_element(root))
|
2016-11-20 05:42:16 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
auto property_element = expect_start_element(xml::content::mixed);
|
2016-11-25 21:13:55 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
if (property_element.name() != "Property")
|
2016-11-20 05:42:16 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
properties[property_element.name()] = read_text();
|
2016-09-22 07:04:16 +08:00
|
|
|
}
|
2016-11-20 06:19:38 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
skip_remaining_content(property_element);
|
2016-11-25 21:13:55 +08:00
|
|
|
expect_end_element(property_element);
|
2016-11-20 06:19:38 +08:00
|
|
|
}
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
expect_end_element(root);
|
2016-08-05 13:52:05 +08:00
|
|
|
}
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
void xlsx_consumer::read_office_document(const std::string &content_type)
|
2016-08-05 13:52:05 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
static const auto &xmlns = constants::namespace_("workbook");
|
|
|
|
static const auto &xmlns_mc = constants::namespace_("mc");
|
|
|
|
static const auto &xmlns_r = constants::namespace_("r");
|
|
|
|
static const auto &xmlns_s = constants::namespace_("spreadsheetml");
|
2016-11-20 06:19:38 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
if (content_type != "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml" &&
|
|
|
|
content_type != "application/vnd.openxmlformats-officedocument.spreadsheetml.template.main+xml")
|
2016-11-20 06:19:38 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
throw xlnt::invalid_file(content_type);
|
2016-11-20 06:19:38 +08:00
|
|
|
}
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
expect_start_element(xml::qname(xmlns, "workbook"), xml::content::complex);
|
|
|
|
skip_attribute(xml::qname(xmlns_mc, "Ignorable"));
|
|
|
|
read_namespaces();
|
2016-08-14 07:44:45 +08:00
|
|
|
|
2016-11-25 21:13:55 +08:00
|
|
|
while (in_element(xml::qname(xmlns, "workbook")))
|
2016-09-22 07:04:16 +08:00
|
|
|
{
|
2016-11-25 21:13:55 +08:00
|
|
|
auto current_workbook_element = expect_start_element(xml::content::complex);
|
2016-08-05 13:52:05 +08:00
|
|
|
|
2016-11-25 21:13:55 +08:00
|
|
|
if (current_workbook_element == xml::qname(xmlns, "fileVersion"))
|
2016-09-22 07:04:16 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
detail::workbook_impl::file_version_t file_version;
|
|
|
|
|
|
|
|
if (parser().attribute_present("appName"))
|
|
|
|
{
|
|
|
|
file_version.app_name = parser().attribute("appName");
|
|
|
|
}
|
2016-11-20 06:19:38 +08:00
|
|
|
|
2016-10-25 10:09:15 +08:00
|
|
|
if (parser().attribute_present("lastEdited"))
|
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
file_version.last_edited = parser().attribute<std::size_t>("lastEdited");
|
2016-10-25 10:09:15 +08:00
|
|
|
}
|
2016-11-25 21:13:55 +08:00
|
|
|
|
2016-10-25 10:09:15 +08:00
|
|
|
if (parser().attribute_present("lowestEdited"))
|
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
file_version.lowest_edited = parser().attribute<std::size_t>("lowestEdited");
|
2016-10-25 10:09:15 +08:00
|
|
|
}
|
2016-11-25 21:13:55 +08:00
|
|
|
|
2016-10-25 10:09:15 +08:00
|
|
|
if (parser().attribute_present("lowestEdited"))
|
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
file_version.rup_build = parser().attribute<std::size_t>("rupBuild");
|
2016-10-25 10:09:15 +08:00
|
|
|
}
|
2016-12-02 21:37:50 +08:00
|
|
|
|
|
|
|
skip_attribute("codeName");
|
|
|
|
|
|
|
|
target_.d_->file_version_ = file_version;
|
2016-09-22 07:04:16 +08:00
|
|
|
}
|
2016-11-25 21:13:55 +08:00
|
|
|
else if (current_workbook_element == xml::qname(xmlns_mc, "AlternateContent"))
|
2016-09-22 07:04:16 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
skip_remaining_content(xml::qname(xmlns_mc, "AlternateContent"));
|
2016-09-22 07:04:16 +08:00
|
|
|
}
|
2016-11-25 21:13:55 +08:00
|
|
|
else if (current_workbook_element == xml::qname(xmlns, "bookViews"))
|
2016-09-22 07:04:16 +08:00
|
|
|
{
|
2016-11-25 21:13:55 +08:00
|
|
|
while (in_element(xml::qname(xmlns, "bookViews")))
|
2016-09-22 07:04:16 +08:00
|
|
|
{
|
2016-11-25 21:13:55 +08:00
|
|
|
expect_start_element(xml::qname(xmlns, "workbookView"), xml::content::simple);
|
|
|
|
|
|
|
|
skip_attributes({"activeTab", "firstSheet", "showHorizontalScroll",
|
|
|
|
"showSheetTabs", "showVerticalScroll"});
|
2016-09-22 07:04:16 +08:00
|
|
|
|
|
|
|
workbook_view view;
|
2016-11-30 07:31:06 +08:00
|
|
|
view.x_window = parser().attribute<std::size_t>("xWindow");
|
|
|
|
view.y_window = parser().attribute<std::size_t>("yWindow");
|
|
|
|
view.window_width = parser().attribute<std::size_t>("windowWidth");
|
|
|
|
view.window_height = parser().attribute<std::size_t>("windowHeight");
|
2016-11-20 06:19:38 +08:00
|
|
|
|
|
|
|
if (parser().attribute_present("tabRatio"))
|
|
|
|
{
|
2016-11-30 07:31:06 +08:00
|
|
|
view.tab_ratio = parser().attribute<std::size_t>("tabRatio");
|
2016-11-20 06:19:38 +08:00
|
|
|
}
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
skip_attributes();
|
|
|
|
|
2016-11-25 21:13:55 +08:00
|
|
|
expect_end_element(xml::qname(xmlns, "workbookView"));
|
2016-11-20 06:19:38 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
target_.view(view);
|
2016-09-22 07:04:16 +08:00
|
|
|
}
|
|
|
|
}
|
2016-11-25 21:13:55 +08:00
|
|
|
else if (current_workbook_element == xml::qname(xmlns, "workbookPr"))
|
2016-09-22 07:04:16 +08:00
|
|
|
{
|
2016-10-12 11:16:14 +08:00
|
|
|
if (parser().attribute_present("date1904"))
|
2016-09-22 07:04:16 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
target_.base_date(is_true(parser().attribute("date1904"))
|
2016-11-25 21:13:55 +08:00
|
|
|
? calendar::mac_1904 : calendar::windows_1900);
|
2016-09-22 07:04:16 +08:00
|
|
|
}
|
2016-10-19 07:29:04 +08:00
|
|
|
|
2016-11-25 21:13:55 +08:00
|
|
|
skip_attributes({"codeName", "defaultThemeVersion",
|
|
|
|
"backupFile", "showObjects", "filterPrivacy", "dateCompatibility"});
|
2016-09-22 07:04:16 +08:00
|
|
|
}
|
2016-11-25 21:13:55 +08:00
|
|
|
else if (current_workbook_element == xml::qname(xmlns, "sheets"))
|
2016-09-22 07:04:16 +08:00
|
|
|
{
|
|
|
|
std::size_t index = 0;
|
2016-11-20 06:19:38 +08:00
|
|
|
|
2016-11-25 21:13:55 +08:00
|
|
|
while (in_element(xml::qname(xmlns, "sheets")))
|
2016-09-22 07:04:16 +08:00
|
|
|
{
|
2016-11-25 21:13:55 +08:00
|
|
|
expect_start_element(xml::qname(xmlns_s, "sheet"), xml::content::simple);
|
2016-09-22 07:04:16 +08:00
|
|
|
|
2016-11-25 21:13:55 +08:00
|
|
|
auto title = parser().attribute("name");
|
2016-12-02 21:37:50 +08:00
|
|
|
skip_attribute("state");
|
2016-09-22 07:04:16 +08:00
|
|
|
|
|
|
|
sheet_title_index_map_[title] = index++;
|
2016-11-30 07:31:06 +08:00
|
|
|
sheet_title_id_map_[title] = parser().attribute<std::size_t>("sheetId");
|
2016-11-25 21:13:55 +08:00
|
|
|
target_.d_->sheet_title_rel_id_map_[title] = parser().attribute(xml::qname(xmlns_r, "id"));
|
2016-11-20 06:19:38 +08:00
|
|
|
|
2016-11-25 21:13:55 +08:00
|
|
|
expect_end_element(xml::qname(xmlns_s, "sheet"));
|
2016-09-22 07:04:16 +08:00
|
|
|
}
|
|
|
|
}
|
2016-11-25 21:13:55 +08:00
|
|
|
else if (current_workbook_element == xml::qname(xmlns, "calcPr"))
|
2016-09-22 07:04:16 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
skip_remaining_content(current_workbook_element);
|
2016-09-22 07:04:16 +08:00
|
|
|
}
|
2016-11-25 21:13:55 +08:00
|
|
|
else if (current_workbook_element == xml::qname(xmlns, "extLst"))
|
2016-09-22 07:04:16 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
skip_remaining_content(current_workbook_element);
|
2016-09-22 07:04:16 +08:00
|
|
|
}
|
2016-11-25 21:13:55 +08:00
|
|
|
else if (current_workbook_element == xml::qname(xmlns, "workbookProtection"))
|
2016-10-25 10:09:15 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
skip_remaining_content(current_workbook_element);
|
2016-11-25 21:13:55 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
unexpected_element(current_workbook_element);
|
2016-10-25 10:09:15 +08:00
|
|
|
}
|
2016-11-25 21:13:55 +08:00
|
|
|
|
|
|
|
expect_end_element(current_workbook_element);
|
2016-09-22 07:04:16 +08:00
|
|
|
}
|
2016-11-20 05:42:16 +08:00
|
|
|
|
2016-11-25 21:13:55 +08:00
|
|
|
expect_end_element(xml::qname(xmlns, "workbook"));
|
2016-12-02 21:37:50 +08:00
|
|
|
|
|
|
|
auto workbook_rel = manifest().relationship(path("/"), relationship_type::office_document);
|
|
|
|
auto workbook_path = workbook_rel.target().path();
|
|
|
|
|
|
|
|
if (manifest().has_relationship(workbook_path, relationship_type::shared_string_table))
|
|
|
|
{
|
|
|
|
read_part({workbook_rel, manifest().relationship(workbook_path, relationship_type::shared_string_table)});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (manifest().has_relationship(workbook_path, relationship_type::stylesheet))
|
|
|
|
{
|
|
|
|
read_part({workbook_rel, manifest().relationship(workbook_path, relationship_type::stylesheet)});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (manifest().has_relationship(workbook_path, relationship_type::theme))
|
|
|
|
{
|
|
|
|
read_part({workbook_rel, manifest().relationship(workbook_path, relationship_type::theme)});
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto worksheet_rel : manifest().relationships(workbook_path, relationship_type::worksheet))
|
|
|
|
{
|
|
|
|
read_part({workbook_rel, worksheet_rel});
|
|
|
|
}
|
2016-08-05 13:52:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Write Workbook Relationship Target Parts
|
|
|
|
|
2016-10-12 11:16:14 +08:00
|
|
|
void xlsx_consumer::read_calculation_chain()
|
2016-08-05 13:52:05 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-11-20 06:19:38 +08:00
|
|
|
void xlsx_consumer::read_chartsheet(const std::string & /*title*/)
|
2016-08-05 13:52:05 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-10-12 11:16:14 +08:00
|
|
|
void xlsx_consumer::read_connections()
|
2016-08-05 13:52:05 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-10-12 11:16:14 +08:00
|
|
|
void xlsx_consumer::read_custom_property()
|
2016-08-05 13:52:05 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-10-12 11:16:14 +08:00
|
|
|
void xlsx_consumer::read_custom_xml_mappings()
|
2016-08-05 13:52:05 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-11-20 06:19:38 +08:00
|
|
|
void xlsx_consumer::read_dialogsheet(const std::string & /*title*/)
|
2016-08-05 13:52:05 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-10-12 11:16:14 +08:00
|
|
|
void xlsx_consumer::read_external_workbook_references()
|
2016-08-05 13:52:05 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-10-12 11:16:14 +08:00
|
|
|
void xlsx_consumer::read_metadata()
|
2016-08-05 13:52:05 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-10-12 11:16:14 +08:00
|
|
|
void xlsx_consumer::read_pivot_table()
|
2016-08-05 13:52:05 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-10-12 11:16:14 +08:00
|
|
|
void xlsx_consumer::read_shared_string_table()
|
2016-08-05 13:52:05 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
static const auto &xmlns = constants::namespace_("spreadsheetml");
|
2016-11-20 06:19:38 +08:00
|
|
|
|
2016-11-30 07:31:06 +08:00
|
|
|
expect_start_element(xml::qname(xmlns, "sst"), xml::content::complex);
|
2016-11-25 21:13:55 +08:00
|
|
|
skip_attributes({"count"});
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
bool has_unique_count = false;
|
2016-11-20 06:19:38 +08:00
|
|
|
std::size_t unique_count = 0;
|
2016-08-05 13:52:05 +08:00
|
|
|
|
2016-11-20 06:19:38 +08:00
|
|
|
if (parser().attribute_present("uniqueCount"))
|
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
has_unique_count = true;
|
2016-11-30 07:31:06 +08:00
|
|
|
unique_count = parser().attribute<std::size_t>("uniqueCount");
|
2016-11-20 06:19:38 +08:00
|
|
|
}
|
2016-08-05 13:52:05 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
auto &strings = target_.shared_strings();
|
2016-08-05 13:52:05 +08:00
|
|
|
|
2016-11-25 21:13:55 +08:00
|
|
|
while (in_element(xml::qname(xmlns, "sst")))
|
2016-09-22 07:04:16 +08:00
|
|
|
{
|
2016-11-25 21:13:55 +08:00
|
|
|
expect_start_element(xml::qname(xmlns, "si"), xml::content::complex);
|
2016-12-02 21:37:50 +08:00
|
|
|
strings.push_back(read_formatted_text(xml::qname(xmlns, "si")));
|
2016-11-25 21:13:55 +08:00
|
|
|
expect_end_element(xml::qname(xmlns, "si"));
|
2016-11-20 06:19:38 +08:00
|
|
|
}
|
2016-08-05 13:52:05 +08:00
|
|
|
|
2016-11-25 21:13:55 +08:00
|
|
|
expect_end_element(xml::qname(xmlns, "sst"));
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
if (has_unique_count && unique_count != strings.size())
|
2016-11-20 06:19:38 +08:00
|
|
|
{
|
|
|
|
throw invalid_file("sizes don't match");
|
|
|
|
}
|
2016-08-05 13:52:05 +08:00
|
|
|
}
|
|
|
|
|
2016-10-12 11:16:14 +08:00
|
|
|
void xlsx_consumer::read_shared_workbook_revision_headers()
|
2016-08-05 13:52:05 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-10-12 11:16:14 +08:00
|
|
|
void xlsx_consumer::read_shared_workbook()
|
2016-08-05 13:52:05 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-10-12 11:16:14 +08:00
|
|
|
void xlsx_consumer::read_shared_workbook_user_data()
|
2016-08-05 13:52:05 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-10-12 11:16:14 +08:00
|
|
|
void xlsx_consumer::read_stylesheet()
|
2016-08-05 13:52:05 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
static const auto &xmlns = constants::namespace_("spreadsheetml");
|
|
|
|
static const auto &xmlns_mc = constants::namespace_("mc");
|
|
|
|
static const auto &xmlns_x14ac = constants::namespace_("x14ac");
|
2016-11-20 06:19:38 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
target_.impl().stylesheet_ = detail::stylesheet();
|
|
|
|
auto &stylesheet = target_.impl().stylesheet_.get();
|
2016-11-25 21:13:55 +08:00
|
|
|
|
|
|
|
//todo: should this really be defined here?
|
|
|
|
//todo: maybe xlnt::style and xlnt::format can be used here instead now
|
2016-09-22 07:04:16 +08:00
|
|
|
struct formatting_record
|
|
|
|
{
|
2016-11-20 06:19:38 +08:00
|
|
|
std::pair<class alignment, bool> alignment = {{}, 0};
|
|
|
|
std::pair<std::size_t, bool> border_id = {0, false};
|
|
|
|
std::pair<std::size_t, bool> fill_id = {0, false};
|
|
|
|
std::pair<std::size_t, bool> font_id = {0, false};
|
|
|
|
std::pair<std::size_t, bool> number_format_id = {0, false};
|
|
|
|
std::pair<class protection, bool> protection = {{}, false};
|
|
|
|
std::pair<std::size_t, bool> style_id = {0, false};
|
2016-09-22 07:04:16 +08:00
|
|
|
};
|
2016-11-20 06:19:38 +08:00
|
|
|
|
2016-09-22 07:04:16 +08:00
|
|
|
struct style_data
|
|
|
|
{
|
|
|
|
std::string name;
|
|
|
|
std::size_t record_id;
|
2016-11-15 21:09:17 +08:00
|
|
|
std::pair<std::size_t, bool> builtin_id;
|
|
|
|
std::pair<std::size_t, bool> i_level;
|
|
|
|
std::pair<bool, bool> hidden;
|
2016-10-25 10:09:15 +08:00
|
|
|
bool custom_builtin;
|
2016-09-22 07:04:16 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
std::vector<style_data> style_datas;
|
|
|
|
std::vector<formatting_record> style_records;
|
|
|
|
std::vector<formatting_record> format_records;
|
|
|
|
|
2016-11-30 07:31:06 +08:00
|
|
|
expect_start_element(xml::qname(xmlns, "styleSheet"), xml::content::complex);
|
2016-11-25 21:13:55 +08:00
|
|
|
skip_attributes({xml::qname(xmlns_mc, "Ignorable")});
|
2016-12-02 21:37:50 +08:00
|
|
|
read_namespaces();
|
2016-09-22 07:04:16 +08:00
|
|
|
|
2016-11-25 21:13:55 +08:00
|
|
|
while (in_element(xml::qname(xmlns, "styleSheet")))
|
|
|
|
{
|
|
|
|
auto current_style_element = expect_start_element(xml::content::complex);
|
2016-09-22 07:04:16 +08:00
|
|
|
|
2016-11-25 21:13:55 +08:00
|
|
|
if (current_style_element == xml::qname(xmlns, "borders"))
|
2016-09-22 07:04:16 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
auto &borders = stylesheet.borders;
|
2016-10-12 11:16:14 +08:00
|
|
|
auto count = parser().attribute<std::size_t>("count");
|
2016-11-20 06:19:38 +08:00
|
|
|
|
2016-11-25 21:13:55 +08:00
|
|
|
while (in_element(xml::qname(xmlns, "borders")))
|
2016-09-10 22:05:06 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
borders.push_back(xlnt::border());
|
|
|
|
auto &border = borders.back();
|
2016-11-20 06:19:38 +08:00
|
|
|
|
2016-11-25 21:13:55 +08:00
|
|
|
expect_start_element(xml::qname(xmlns, "border"), xml::content::complex);
|
2016-10-12 11:16:14 +08:00
|
|
|
|
2016-10-25 10:09:15 +08:00
|
|
|
auto diagonal = diagonal_direction::neither;
|
2016-11-20 06:19:38 +08:00
|
|
|
|
2016-10-25 10:09:15 +08:00
|
|
|
if (parser().attribute_present("diagonalDown") && parser().attribute("diagonalDown") == "1")
|
|
|
|
{
|
|
|
|
diagonal = diagonal_direction::down;
|
|
|
|
}
|
2016-11-20 06:19:38 +08:00
|
|
|
|
2016-10-25 10:09:15 +08:00
|
|
|
if (parser().attribute_present("diagonalUp") && parser().attribute("diagonalUp") == "1")
|
|
|
|
{
|
|
|
|
diagonal = diagonal == diagonal_direction::down ? diagonal_direction::both : diagonal_direction::up;
|
|
|
|
}
|
2016-11-20 06:19:38 +08:00
|
|
|
|
2016-10-25 10:09:15 +08:00
|
|
|
if (diagonal != diagonal_direction::neither)
|
|
|
|
{
|
|
|
|
border.diagonal(diagonal);
|
|
|
|
}
|
2016-10-12 11:16:14 +08:00
|
|
|
|
2016-11-25 21:13:55 +08:00
|
|
|
while (in_element(xml::qname(xmlns, "border")))
|
2016-11-20 06:19:38 +08:00
|
|
|
{
|
2016-11-25 21:13:55 +08:00
|
|
|
auto current_side_element = expect_start_element(xml::content::complex);
|
2016-10-25 10:09:15 +08:00
|
|
|
|
2016-11-20 06:19:38 +08:00
|
|
|
xlnt::border::border_property side;
|
2016-10-12 11:16:14 +08:00
|
|
|
|
2016-11-20 06:19:38 +08:00
|
|
|
if (parser().attribute_present("style"))
|
|
|
|
{
|
|
|
|
side.style(parser().attribute<xlnt::border_style>("style"));
|
|
|
|
}
|
2016-10-12 11:16:14 +08:00
|
|
|
|
2016-11-25 21:13:55 +08:00
|
|
|
if (in_element(current_side_element))
|
2016-11-20 06:19:38 +08:00
|
|
|
{
|
2016-11-25 21:13:55 +08:00
|
|
|
expect_start_element(xml::qname(xmlns, "color"), xml::content::complex);
|
2016-11-30 07:31:06 +08:00
|
|
|
side.color(read_color());
|
2016-11-25 21:13:55 +08:00
|
|
|
expect_end_element(xml::qname(xmlns, "color"));
|
2016-11-20 06:19:38 +08:00
|
|
|
}
|
2016-10-12 11:16:14 +08:00
|
|
|
|
2016-11-25 21:13:55 +08:00
|
|
|
expect_end_element(current_side_element);
|
|
|
|
|
|
|
|
auto side_type = xml::value_traits<xlnt::border_side>::parse(current_side_element.name(), parser());
|
2016-11-20 06:19:38 +08:00
|
|
|
border.side(side_type, side);
|
|
|
|
}
|
2016-10-12 11:16:14 +08:00
|
|
|
|
2016-11-25 21:13:55 +08:00
|
|
|
expect_end_element(xml::qname(xmlns, "border"));
|
2016-09-22 07:04:16 +08:00
|
|
|
}
|
2016-11-20 06:19:38 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
if (count != borders.size())
|
2016-09-22 07:04:16 +08:00
|
|
|
{
|
2016-11-25 21:13:55 +08:00
|
|
|
throw xlnt::exception("border counts don't match");
|
2016-09-10 22:05:06 +08:00
|
|
|
}
|
|
|
|
}
|
2016-11-25 21:13:55 +08:00
|
|
|
else if (current_style_element == xml::qname(xmlns, "fills"))
|
2016-09-10 22:05:06 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
auto &fills = stylesheet.fills;
|
2016-10-12 11:16:14 +08:00
|
|
|
auto count = parser().attribute<std::size_t>("count");
|
2016-09-22 07:04:16 +08:00
|
|
|
|
2016-11-25 21:13:55 +08:00
|
|
|
while (in_element(xml::qname(xmlns, "fills")))
|
2016-09-22 07:04:16 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
fills.push_back(xlnt::fill());
|
|
|
|
auto &new_fill = fills.back();
|
2016-11-20 06:19:38 +08:00
|
|
|
|
2016-11-30 07:31:06 +08:00
|
|
|
expect_start_element(xml::qname(xmlns, "fill"), xml::content::complex);
|
|
|
|
auto fill_element = expect_start_element(xml::content::complex);
|
2016-11-20 06:19:38 +08:00
|
|
|
|
2016-11-30 07:31:06 +08:00
|
|
|
if (fill_element == xml::qname(xmlns, "patternFill"))
|
2016-11-20 06:19:38 +08:00
|
|
|
{
|
|
|
|
xlnt::pattern_fill pattern;
|
|
|
|
|
|
|
|
if (parser().attribute_present("patternType"))
|
|
|
|
{
|
|
|
|
pattern.type(parser().attribute<xlnt::pattern_fill_type>("patternType"));
|
|
|
|
|
2016-11-30 07:31:06 +08:00
|
|
|
while (in_element(xml::qname(xmlns, "patternFill")))
|
2016-11-20 06:19:38 +08:00
|
|
|
{
|
2016-11-30 07:31:06 +08:00
|
|
|
auto pattern_type_element = expect_start_element(xml::content::complex);
|
2016-11-20 06:19:38 +08:00
|
|
|
|
2016-11-30 07:31:06 +08:00
|
|
|
if (pattern_type_element == xml::qname(xmlns, "fgColor"))
|
2016-11-20 06:19:38 +08:00
|
|
|
{
|
2016-11-30 07:31:06 +08:00
|
|
|
pattern.foreground(read_color());
|
2016-11-20 06:19:38 +08:00
|
|
|
}
|
2016-11-30 07:31:06 +08:00
|
|
|
else if (pattern_type_element == xml::qname(xmlns, "bgColor"))
|
2016-11-20 06:19:38 +08:00
|
|
|
{
|
2016-11-30 07:31:06 +08:00
|
|
|
pattern.background(read_color());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
unexpected_element(pattern_type_element);
|
2016-11-20 06:19:38 +08:00
|
|
|
}
|
|
|
|
|
2016-11-30 07:31:06 +08:00
|
|
|
expect_end_element(pattern_type_element);
|
2016-11-20 06:19:38 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
new_fill = pattern;
|
|
|
|
}
|
2016-11-30 07:31:06 +08:00
|
|
|
else if (fill_element == xml::qname(xmlns, "gradientFill"))
|
2016-11-20 06:19:38 +08:00
|
|
|
{
|
|
|
|
xlnt::gradient_fill gradient;
|
|
|
|
|
|
|
|
if (parser().attribute_present("type"))
|
|
|
|
{
|
|
|
|
gradient.type(parser().attribute<xlnt::gradient_fill_type>("type"));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gradient.type(xlnt::gradient_fill_type::linear);
|
|
|
|
}
|
|
|
|
|
2016-11-25 21:13:55 +08:00
|
|
|
while (in_element(xml::qname(xmlns, "gradientFill")))
|
2016-11-20 06:19:38 +08:00
|
|
|
{
|
2016-11-30 07:31:06 +08:00
|
|
|
expect_start_element(xml::qname(xmlns, "stop"), xml::content::complex);
|
2016-11-20 06:19:38 +08:00
|
|
|
auto position = parser().attribute<double>("position");
|
2016-11-30 07:31:06 +08:00
|
|
|
expect_start_element(xml::qname(xmlns, "color"), xml::content::complex);
|
|
|
|
auto color = read_color();
|
|
|
|
expect_end_element(xml::qname(xmlns, "color"));
|
|
|
|
expect_end_element(xml::qname(xmlns, "stop"));
|
2016-11-20 06:19:38 +08:00
|
|
|
|
|
|
|
gradient.add_stop(position, color);
|
|
|
|
}
|
|
|
|
|
|
|
|
new_fill = gradient;
|
|
|
|
}
|
2016-11-30 07:31:06 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
unexpected_element(fill_element);
|
|
|
|
}
|
2016-11-20 06:19:38 +08:00
|
|
|
|
2016-11-30 07:31:06 +08:00
|
|
|
expect_end_element(fill_element);
|
|
|
|
expect_end_element(xml::qname(xmlns, "fill"));
|
2016-09-22 07:04:16 +08:00
|
|
|
}
|
2016-11-20 06:19:38 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
if (count != fills.size())
|
2016-09-22 07:04:16 +08:00
|
|
|
{
|
|
|
|
throw xlnt::exception("counts don't match");
|
|
|
|
}
|
2016-09-10 22:05:06 +08:00
|
|
|
}
|
2016-11-25 21:13:55 +08:00
|
|
|
else if (current_style_element == xml::qname(xmlns, "fonts"))
|
2016-09-22 07:04:16 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
auto &fonts = stylesheet.fonts;
|
2016-10-12 11:16:14 +08:00
|
|
|
auto count = parser().attribute<std::size_t>("count");
|
2016-11-25 21:13:55 +08:00
|
|
|
skip_attributes({xml::qname(xmlns_x14ac, "knownFonts")});
|
2016-11-20 06:19:38 +08:00
|
|
|
|
2016-11-25 21:13:55 +08:00
|
|
|
while (in_element(xml::qname(xmlns, "fonts")))
|
2016-09-22 07:04:16 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
fonts.push_back(xlnt::font());
|
2016-11-20 06:19:38 +08:00
|
|
|
auto &new_font = stylesheet.fonts.back();
|
|
|
|
|
2016-11-30 07:31:06 +08:00
|
|
|
expect_start_element(xml::qname(xmlns, "font"), xml::content::complex);
|
2016-11-20 06:19:38 +08:00
|
|
|
|
2016-11-25 21:13:55 +08:00
|
|
|
while (in_element(xml::qname(xmlns, "font")))
|
2016-11-20 06:19:38 +08:00
|
|
|
{
|
2016-11-30 07:31:06 +08:00
|
|
|
auto font_property_element = expect_start_element(xml::content::simple);
|
2016-11-20 06:19:38 +08:00
|
|
|
|
2016-11-30 07:31:06 +08:00
|
|
|
if (font_property_element == xml::qname(xmlns, "sz"))
|
2016-11-20 06:19:38 +08:00
|
|
|
{
|
2016-11-30 07:31:06 +08:00
|
|
|
new_font.size(parser().attribute<std::size_t>("val"));
|
2016-11-20 06:19:38 +08:00
|
|
|
}
|
2016-11-30 07:31:06 +08:00
|
|
|
else if (font_property_element == xml::qname(xmlns, "name"))
|
2016-11-20 06:19:38 +08:00
|
|
|
{
|
|
|
|
new_font.name(parser().attribute("val"));
|
|
|
|
}
|
2016-11-30 07:31:06 +08:00
|
|
|
else if (font_property_element == xml::qname(xmlns, "color"))
|
2016-11-20 06:19:38 +08:00
|
|
|
{
|
2016-11-30 07:31:06 +08:00
|
|
|
new_font.color(read_color());
|
2016-11-20 06:19:38 +08:00
|
|
|
}
|
2016-11-30 07:31:06 +08:00
|
|
|
else if (font_property_element == xml::qname(xmlns, "family"))
|
2016-11-20 06:19:38 +08:00
|
|
|
{
|
2016-11-30 07:31:06 +08:00
|
|
|
new_font.family(parser().attribute<std::size_t>("val"));
|
2016-11-20 06:19:38 +08:00
|
|
|
}
|
2016-11-30 07:31:06 +08:00
|
|
|
else if (font_property_element == xml::qname(xmlns, "scheme"))
|
2016-11-20 06:19:38 +08:00
|
|
|
{
|
|
|
|
new_font.scheme(parser().attribute("val"));
|
|
|
|
}
|
2016-11-30 07:31:06 +08:00
|
|
|
else if (font_property_element == xml::qname(xmlns, "b"))
|
2016-11-20 06:19:38 +08:00
|
|
|
{
|
|
|
|
if (parser().attribute_present("val"))
|
|
|
|
{
|
|
|
|
new_font.bold(is_true(parser().attribute("val")));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
new_font.bold(true);
|
|
|
|
}
|
|
|
|
}
|
2016-11-30 07:31:06 +08:00
|
|
|
else if (font_property_element == xml::qname(xmlns, "vertAlign"))
|
2016-11-20 06:19:38 +08:00
|
|
|
{
|
|
|
|
new_font.superscript(parser().attribute("val") == "superscript");
|
|
|
|
}
|
2016-11-30 07:31:06 +08:00
|
|
|
else if (font_property_element == xml::qname(xmlns, "strike"))
|
2016-11-20 06:19:38 +08:00
|
|
|
{
|
|
|
|
if (parser().attribute_present("val"))
|
|
|
|
{
|
|
|
|
new_font.strikethrough(is_true(parser().attribute("val")));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
new_font.strikethrough(true);
|
|
|
|
}
|
|
|
|
}
|
2016-11-30 07:31:06 +08:00
|
|
|
else if (font_property_element == xml::qname(xmlns, "i"))
|
2016-11-20 06:19:38 +08:00
|
|
|
{
|
|
|
|
if (parser().attribute_present("val"))
|
|
|
|
{
|
|
|
|
new_font.italic(is_true(parser().attribute("val")));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
new_font.italic(true);
|
|
|
|
}
|
|
|
|
}
|
2016-11-30 07:31:06 +08:00
|
|
|
else if (font_property_element == xml::qname(xmlns, "u"))
|
2016-11-20 06:19:38 +08:00
|
|
|
{
|
|
|
|
if (parser().attribute_present("val"))
|
|
|
|
{
|
|
|
|
new_font.underline(parser().attribute<xlnt::font::underline_style>("val"));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
new_font.underline(xlnt::font::underline_style::single);
|
|
|
|
}
|
|
|
|
}
|
2016-11-30 07:31:06 +08:00
|
|
|
else if (font_property_element == xml::qname(xmlns, "charset"))
|
2016-11-20 06:19:38 +08:00
|
|
|
{
|
|
|
|
if (parser().attribute_present("val"))
|
|
|
|
{
|
|
|
|
parser().attribute("val");
|
|
|
|
}
|
|
|
|
}
|
2016-11-30 07:31:06 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
unexpected_element(font_property_element);
|
|
|
|
}
|
2016-10-12 11:16:14 +08:00
|
|
|
|
2016-11-30 07:31:06 +08:00
|
|
|
expect_end_element(font_property_element);
|
2016-11-20 06:19:38 +08:00
|
|
|
}
|
2016-10-12 11:16:14 +08:00
|
|
|
|
2016-11-30 07:31:06 +08:00
|
|
|
expect_end_element(xml::qname(xmlns, "font"));
|
2016-09-22 07:04:16 +08:00
|
|
|
}
|
2016-11-20 06:19:38 +08:00
|
|
|
|
2016-09-22 07:04:16 +08:00
|
|
|
if (count != stylesheet.fonts.size())
|
|
|
|
{
|
|
|
|
throw xlnt::exception("counts don't match");
|
|
|
|
}
|
|
|
|
}
|
2016-11-25 21:13:55 +08:00
|
|
|
else if (current_style_element == xml::qname(xmlns, "numFmts"))
|
2016-09-22 07:04:16 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
auto &number_formats = stylesheet.number_formats;
|
2016-10-25 10:09:15 +08:00
|
|
|
auto count = parser().attribute<std::size_t>("count");
|
2016-09-22 07:04:16 +08:00
|
|
|
|
2016-11-25 21:13:55 +08:00
|
|
|
while (in_element(xml::qname(xmlns, "numFmts")))
|
2016-09-22 07:04:16 +08:00
|
|
|
{
|
2016-11-30 07:31:06 +08:00
|
|
|
expect_start_element(xml::qname(xmlns, "numFmt"), xml::content::simple);
|
2016-10-25 10:09:15 +08:00
|
|
|
|
2016-10-12 11:16:14 +08:00
|
|
|
auto format_string = parser().attribute("formatCode");
|
2016-09-22 07:04:16 +08:00
|
|
|
|
|
|
|
if (format_string == "GENERAL")
|
|
|
|
{
|
|
|
|
format_string = "General";
|
|
|
|
}
|
|
|
|
|
|
|
|
xlnt::number_format nf;
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
nf.format_string(format_string);
|
|
|
|
nf.id(parser().attribute<std::size_t>("numFmtId"));
|
2016-11-30 07:31:06 +08:00
|
|
|
|
|
|
|
expect_end_element(xml::qname(xmlns, "numFmt"));
|
2016-09-22 07:04:16 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
number_formats.push_back(nf);
|
2016-10-25 10:09:15 +08:00
|
|
|
}
|
2016-11-20 06:19:38 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
if (count != number_formats.size())
|
2016-10-25 10:09:15 +08:00
|
|
|
{
|
|
|
|
throw xlnt::exception("counts don't match");
|
2016-09-22 07:04:16 +08:00
|
|
|
}
|
|
|
|
}
|
2016-11-25 21:13:55 +08:00
|
|
|
else if (current_style_element == xml::qname(xmlns, "cellStyles"))
|
2016-09-22 07:04:16 +08:00
|
|
|
{
|
2016-10-12 11:16:14 +08:00
|
|
|
auto count = parser().attribute<std::size_t>("count");
|
2016-11-20 06:19:38 +08:00
|
|
|
|
2016-11-25 21:13:55 +08:00
|
|
|
while (in_element(xml::qname(xmlns, "cellStyles")))
|
2016-09-22 07:04:16 +08:00
|
|
|
{
|
|
|
|
auto &data = *style_datas.emplace(style_datas.end());
|
2016-11-20 06:19:38 +08:00
|
|
|
|
2016-11-30 07:31:06 +08:00
|
|
|
expect_start_element(xml::qname(xmlns, "cellStyle"), xml::content::simple);
|
2016-11-08 10:11:30 +08:00
|
|
|
|
2016-10-12 11:16:14 +08:00
|
|
|
data.name = parser().attribute("name");
|
|
|
|
data.record_id = parser().attribute<std::size_t>("xfId");
|
2016-11-20 06:19:38 +08:00
|
|
|
|
2016-11-15 21:09:17 +08:00
|
|
|
if (parser().attribute_present("builtinId"))
|
|
|
|
{
|
|
|
|
data.builtin_id = {parser().attribute<std::size_t>("builtinId"), true};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parser().attribute_present("iLevel"))
|
|
|
|
{
|
|
|
|
data.i_level = {parser().attribute<std::size_t>("iLevel"), true};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parser().attribute_present("hidden"))
|
|
|
|
{
|
|
|
|
data.hidden = {is_true(parser().attribute("hidden")), true};
|
|
|
|
}
|
2016-11-08 10:11:30 +08:00
|
|
|
|
2016-10-25 10:09:15 +08:00
|
|
|
if (parser().attribute_present("customBuiltin"))
|
|
|
|
{
|
2016-11-08 10:11:30 +08:00
|
|
|
data.custom_builtin = is_true(parser().attribute("customBuiltin"));
|
2016-10-25 10:09:15 +08:00
|
|
|
}
|
2016-11-08 10:11:30 +08:00
|
|
|
|
2016-11-30 07:31:06 +08:00
|
|
|
expect_end_element(xml::qname(xmlns, "cellStyle"));
|
2016-09-22 07:04:16 +08:00
|
|
|
}
|
2016-11-20 06:19:38 +08:00
|
|
|
|
2016-09-22 07:04:16 +08:00
|
|
|
if (count != style_datas.size())
|
|
|
|
{
|
|
|
|
throw xlnt::exception("counts don't match");
|
|
|
|
}
|
|
|
|
}
|
2016-11-25 21:13:55 +08:00
|
|
|
else if (current_style_element == xml::qname(xmlns, "cellStyleXfs") ||
|
|
|
|
current_style_element == xml::qname(xmlns, "cellXfs"))
|
2016-09-22 07:04:16 +08:00
|
|
|
{
|
2016-11-25 21:13:55 +08:00
|
|
|
auto in_style_records = current_style_element.name() == "cellStyleXfs";
|
2016-10-12 11:16:14 +08:00
|
|
|
auto count = parser().attribute<std::size_t>("count");
|
2016-11-20 06:19:38 +08:00
|
|
|
|
2016-11-25 21:13:55 +08:00
|
|
|
while (in_element(current_style_element))
|
2016-09-22 07:04:16 +08:00
|
|
|
{
|
2016-11-30 07:31:06 +08:00
|
|
|
expect_start_element(xml::qname(xmlns, "xf"), xml::content::complex);
|
2016-09-22 07:04:16 +08:00
|
|
|
|
|
|
|
auto &record = *(!in_style_records
|
|
|
|
? format_records.emplace(format_records.end())
|
|
|
|
: style_records.emplace(style_records.end()));
|
|
|
|
|
2016-10-12 11:16:14 +08:00
|
|
|
auto apply_alignment_present = parser().attribute_present("applyAlignment");
|
2016-11-25 21:13:55 +08:00
|
|
|
auto alignment_applied = apply_alignment_present
|
|
|
|
&& is_true(parser().attribute("applyAlignment"));
|
2016-09-22 07:04:16 +08:00
|
|
|
record.alignment.second = alignment_applied;
|
|
|
|
|
2016-10-12 11:16:14 +08:00
|
|
|
auto border_applied = parser().attribute_present("applyBorder")
|
|
|
|
&& is_true(parser().attribute("applyBorder"));
|
|
|
|
auto border_index = parser().attribute_present("borderId")
|
2016-11-30 07:31:06 +08:00
|
|
|
? parser().attribute<std::size_t>("borderId") : 0;
|
2016-11-20 06:19:38 +08:00
|
|
|
record.border_id = {border_index, border_applied};
|
|
|
|
|
2016-10-12 11:16:14 +08:00
|
|
|
auto fill_applied = parser().attribute_present("applyFill")
|
|
|
|
&& is_true(parser().attribute("applyFill"));
|
|
|
|
auto fill_index = parser().attribute_present("fillId")
|
2016-11-30 07:31:06 +08:00
|
|
|
? parser().attribute<std::size_t>("fillId") : 0;
|
2016-11-20 06:19:38 +08:00
|
|
|
record.fill_id = {fill_index, fill_applied};
|
2016-09-22 07:04:16 +08:00
|
|
|
|
2016-10-12 11:16:14 +08:00
|
|
|
auto font_applied = parser().attribute_present("applyFont")
|
|
|
|
&& is_true(parser().attribute("applyFont"));
|
|
|
|
auto font_index = parser().attribute_present("fontId")
|
2016-11-30 07:31:06 +08:00
|
|
|
? parser().attribute<std::size_t>("fontId") : 0;
|
2016-11-20 06:19:38 +08:00
|
|
|
record.font_id = {font_index, font_applied};
|
2016-09-22 07:04:16 +08:00
|
|
|
|
2016-10-12 11:16:14 +08:00
|
|
|
auto number_format_applied = parser().attribute_present("applyNumberFormat")
|
|
|
|
&& is_true(parser().attribute("applyNumberFormat"));
|
|
|
|
auto number_format_id = parser().attribute_present("numFmtId")
|
2016-11-30 07:31:06 +08:00
|
|
|
? parser().attribute<std::size_t>("numFmtId") : 0;
|
2016-11-20 06:19:38 +08:00
|
|
|
record.number_format_id = {number_format_id, number_format_applied};
|
2016-09-22 07:04:16 +08:00
|
|
|
|
2016-10-12 11:16:14 +08:00
|
|
|
auto apply_protection_present = parser().attribute_present("applyProtection");
|
2016-09-22 07:04:16 +08:00
|
|
|
auto protection_applied = apply_protection_present
|
2016-10-12 11:16:14 +08:00
|
|
|
&& is_true(parser().attribute("applyProtection"));
|
2016-09-22 07:04:16 +08:00
|
|
|
record.protection.second = protection_applied;
|
|
|
|
|
2016-10-12 11:16:14 +08:00
|
|
|
if (parser().attribute_present("xfId") && parser().name() == "cellXfs")
|
2016-09-22 07:04:16 +08:00
|
|
|
{
|
2016-11-20 06:19:38 +08:00
|
|
|
record.style_id = {parser().attribute<std::size_t>("xfId"), true};
|
2016-09-22 07:04:16 +08:00
|
|
|
}
|
2016-11-20 06:19:38 +08:00
|
|
|
|
2016-11-25 21:13:55 +08:00
|
|
|
while (in_element(xml::qname(xmlns, "xf")))
|
2016-09-22 07:04:16 +08:00
|
|
|
{
|
2016-11-30 07:31:06 +08:00
|
|
|
auto xf_child_element = expect_start_element(xml::content::simple);
|
2016-11-20 06:19:38 +08:00
|
|
|
|
2016-11-30 07:31:06 +08:00
|
|
|
if (xf_child_element == xml::qname(xmlns, "alignment"))
|
2016-09-22 07:04:16 +08:00
|
|
|
{
|
2016-11-20 06:19:38 +08:00
|
|
|
if (parser().attribute_present("wrapText"))
|
|
|
|
{
|
|
|
|
auto value = is_true(parser().attribute("wrapText"));
|
|
|
|
record.alignment.first.wrap(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parser().attribute_present("shrinkToFit"))
|
|
|
|
{
|
|
|
|
auto value = is_true(parser().attribute("shrinkToFit"));
|
|
|
|
record.alignment.first.shrink(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parser().attribute_present("indent"))
|
|
|
|
{
|
|
|
|
auto value = parser().attribute<int>("indent");
|
|
|
|
record.alignment.first.indent(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parser().attribute_present("textRotation"))
|
|
|
|
{
|
|
|
|
auto value = parser().attribute<int>("textRotation");
|
|
|
|
record.alignment.first.rotation(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parser().attribute_present("vertical"))
|
|
|
|
{
|
|
|
|
auto value = parser().attribute<xlnt::vertical_alignment>("vertical");
|
|
|
|
record.alignment.first.vertical(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parser().attribute_present("horizontal"))
|
|
|
|
{
|
|
|
|
auto value = parser().attribute<xlnt::horizontal_alignment>("horizontal");
|
|
|
|
record.alignment.first.horizontal(value);
|
|
|
|
}
|
2016-10-12 11:16:14 +08:00
|
|
|
|
2016-09-22 07:04:16 +08:00
|
|
|
record.alignment.second = !apply_alignment_present || alignment_applied;
|
|
|
|
}
|
2016-11-30 07:31:06 +08:00
|
|
|
else if (xf_child_element == xml::qname(xmlns, "protection"))
|
2016-09-22 07:04:16 +08:00
|
|
|
{
|
2016-11-20 06:19:38 +08:00
|
|
|
record.protection.first.locked(is_true(parser().attribute("locked")));
|
|
|
|
record.protection.first.hidden(is_true(parser().attribute("hidden")));
|
2016-09-22 07:04:16 +08:00
|
|
|
record.protection.second = !apply_protection_present || protection_applied;
|
|
|
|
}
|
2016-11-30 07:31:06 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
unexpected_element(xf_child_element);
|
|
|
|
}
|
2016-11-20 06:19:38 +08:00
|
|
|
|
2016-11-30 07:31:06 +08:00
|
|
|
expect_end_element(xf_child_element);
|
2016-09-22 07:04:16 +08:00
|
|
|
}
|
2016-11-20 06:19:38 +08:00
|
|
|
|
2016-11-30 07:31:06 +08:00
|
|
|
expect_end_element(xml::qname(xmlns, "xf"));
|
2016-09-22 07:04:16 +08:00
|
|
|
}
|
2016-11-20 06:19:38 +08:00
|
|
|
|
|
|
|
if ((in_style_records && count != style_records.size()) ||
|
|
|
|
(!in_style_records && count != format_records.size()))
|
2016-09-22 07:04:16 +08:00
|
|
|
{
|
|
|
|
throw xlnt::exception("counts don't match");
|
|
|
|
}
|
|
|
|
}
|
2016-11-25 21:13:55 +08:00
|
|
|
else if (current_style_element == xml::qname(xmlns, "dxfs"))
|
2016-09-22 07:04:16 +08:00
|
|
|
{
|
2016-10-12 11:16:14 +08:00
|
|
|
auto count = parser().attribute<std::size_t>("count");
|
2016-09-22 07:04:16 +08:00
|
|
|
std::size_t processed = 0;
|
2016-11-20 06:19:38 +08:00
|
|
|
|
2016-11-25 21:13:55 +08:00
|
|
|
while (in_element(xml::qname(xmlns, "dxfs")))
|
2016-09-22 07:04:16 +08:00
|
|
|
{
|
2016-11-25 21:13:55 +08:00
|
|
|
auto current_element = expect_start_element(xml::content::complex);
|
|
|
|
skip_remaining_content(current_element);
|
|
|
|
|
|
|
|
++processed;
|
2016-09-22 07:04:16 +08:00
|
|
|
}
|
2016-11-20 06:19:38 +08:00
|
|
|
|
2016-09-22 07:04:16 +08:00
|
|
|
if (count != processed)
|
|
|
|
{
|
|
|
|
throw xlnt::exception("counts don't match");
|
|
|
|
}
|
|
|
|
}
|
2016-11-25 21:13:55 +08:00
|
|
|
else if (current_style_element == xml::qname(xmlns, "tableStyles"))
|
2016-09-22 07:04:16 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
skip_attribute("defaultTableStyle");
|
|
|
|
skip_attribute("defaultPivotStyle");
|
2016-11-25 21:13:55 +08:00
|
|
|
|
2016-10-12 11:16:14 +08:00
|
|
|
auto count = parser().attribute<std::size_t>("count");
|
2016-09-22 07:04:16 +08:00
|
|
|
std::size_t processed = 0;
|
2016-11-20 06:19:38 +08:00
|
|
|
|
2016-11-25 21:13:55 +08:00
|
|
|
while (in_element(xml::qname(xmlns, "tableStyles")))
|
2016-09-22 07:04:16 +08:00
|
|
|
{
|
2016-11-25 21:13:55 +08:00
|
|
|
auto current_element = expect_start_element(xml::content::complex);
|
|
|
|
skip_remaining_content(current_element);
|
|
|
|
|
|
|
|
++processed;
|
2016-09-22 07:04:16 +08:00
|
|
|
}
|
2016-11-20 06:19:38 +08:00
|
|
|
|
2016-09-22 07:04:16 +08:00
|
|
|
if (count != processed)
|
|
|
|
{
|
|
|
|
throw xlnt::exception("counts don't match");
|
|
|
|
}
|
|
|
|
}
|
2016-11-25 21:13:55 +08:00
|
|
|
else if (current_style_element == xml::qname(xmlns, "extLst"))
|
2016-09-22 07:04:16 +08:00
|
|
|
{
|
2016-11-30 07:31:06 +08:00
|
|
|
skip_remaining_content(current_style_element);
|
2016-09-22 07:04:16 +08:00
|
|
|
}
|
2016-12-02 21:37:50 +08:00
|
|
|
else if (current_style_element == xml::qname(xmlns, "colors")) // CT_Colors 0-1
|
2016-11-25 21:13:55 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
while (in_element(xml::qname(xmlns, "colors")))
|
|
|
|
{
|
|
|
|
auto colors_child_element = expect_start_element(xml::content::complex);
|
|
|
|
|
|
|
|
if (colors_child_element == xml::qname(xmlns, "indexedColors")) // CT_IndexedColors 0-1
|
|
|
|
{
|
|
|
|
while (in_element(colors_child_element))
|
|
|
|
{
|
|
|
|
expect_start_element(xml::qname(xmlns, "rgbColor"), xml::content::simple);
|
|
|
|
stylesheet.colors.push_back(read_color());
|
|
|
|
expect_end_element(xml::qname(xmlns, "rgbColor"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (colors_child_element == xml::qname(xmlns, "mruColors")) // CT_MRUColors
|
|
|
|
{
|
|
|
|
skip_remaining_content(colors_child_element);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
unexpected_element(colors_child_element);
|
|
|
|
}
|
|
|
|
|
|
|
|
expect_end_element(colors_child_element);
|
|
|
|
}
|
2016-11-25 21:13:55 +08:00
|
|
|
}
|
|
|
|
else
|
2016-10-25 10:09:15 +08:00
|
|
|
{
|
2016-11-25 21:13:55 +08:00
|
|
|
unexpected_element(current_style_element);
|
2016-10-25 10:09:15 +08:00
|
|
|
}
|
2016-11-20 06:19:38 +08:00
|
|
|
|
2016-11-25 21:13:55 +08:00
|
|
|
expect_end_element(current_style_element);
|
2016-09-22 07:04:16 +08:00
|
|
|
}
|
2016-11-20 06:19:38 +08:00
|
|
|
|
2016-11-25 21:13:55 +08:00
|
|
|
expect_end_element(xml::qname(xmlns, "styleSheet"));
|
2016-11-20 06:19:38 +08:00
|
|
|
|
2016-09-22 07:04:16 +08:00
|
|
|
auto lookup_number_format = [&](std::size_t number_format_id)
|
|
|
|
{
|
|
|
|
auto result = number_format::general();
|
2016-09-10 22:05:06 +08:00
|
|
|
bool is_custom_number_format = false;
|
2016-11-20 06:19:38 +08:00
|
|
|
|
2016-09-10 22:05:06 +08:00
|
|
|
for (const auto &nf : stylesheet.number_formats)
|
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
if (nf.id() == number_format_id)
|
2016-09-10 22:05:06 +08:00
|
|
|
{
|
2016-11-03 10:04:51 +08:00
|
|
|
result = nf;
|
2016-09-10 22:05:06 +08:00
|
|
|
is_custom_number_format = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-09-22 07:04:16 +08:00
|
|
|
|
2016-09-10 22:05:06 +08:00
|
|
|
if (number_format_id < 164 && !is_custom_number_format)
|
|
|
|
{
|
2016-09-22 07:04:16 +08:00
|
|
|
result = number_format::from_builtin_id(number_format_id);
|
2016-09-10 22:05:06 +08:00
|
|
|
}
|
2016-11-20 06:19:38 +08:00
|
|
|
|
2016-09-22 07:04:16 +08:00
|
|
|
return result;
|
|
|
|
};
|
2016-11-20 06:19:38 +08:00
|
|
|
|
2016-10-25 10:09:15 +08:00
|
|
|
std::size_t xf_id = 0;
|
2016-11-20 06:19:38 +08:00
|
|
|
|
2016-09-22 07:04:16 +08:00
|
|
|
for (const auto &record : style_records)
|
|
|
|
{
|
2016-10-25 10:09:15 +08:00
|
|
|
auto style_data_iter = std::find_if(style_datas.begin(), style_datas.end(),
|
|
|
|
[&xf_id](const style_data &s) { return s.record_id == xf_id; });
|
|
|
|
++xf_id;
|
2016-11-20 06:19:38 +08:00
|
|
|
|
2016-10-25 10:09:15 +08:00
|
|
|
if (style_data_iter == style_datas.end()) continue;
|
2016-09-22 07:04:16 +08:00
|
|
|
|
2016-11-08 10:11:30 +08:00
|
|
|
auto new_style = stylesheet.create_style(style_data_iter->name);
|
2016-11-20 06:19:38 +08:00
|
|
|
|
2016-11-15 21:09:17 +08:00
|
|
|
if (style_data_iter->builtin_id.second)
|
|
|
|
{
|
|
|
|
new_style.builtin_id(style_data_iter->builtin_id.first);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (style_data_iter->hidden.second)
|
|
|
|
{
|
|
|
|
new_style.hidden(style_data_iter->hidden.first);
|
|
|
|
}
|
2016-09-22 07:04:16 +08:00
|
|
|
|
|
|
|
new_style.alignment(record.alignment.first, record.alignment.second);
|
|
|
|
new_style.border(stylesheet.borders.at(record.border_id.first), record.border_id.second);
|
|
|
|
new_style.fill(stylesheet.fills.at(record.fill_id.first), record.fill_id.second);
|
|
|
|
new_style.font(stylesheet.fonts.at(record.font_id.first), record.font_id.second);
|
|
|
|
new_style.number_format(lookup_number_format(record.number_format_id.first), record.number_format_id.second);
|
|
|
|
new_style.protection(record.protection.first, record.protection.second);
|
|
|
|
}
|
2016-11-20 06:19:38 +08:00
|
|
|
|
2016-11-08 10:11:30 +08:00
|
|
|
std::size_t record_index = 0;
|
|
|
|
|
2016-09-22 07:04:16 +08:00
|
|
|
for (const auto &record : format_records)
|
|
|
|
{
|
2016-11-08 10:11:30 +08:00
|
|
|
stylesheet.format_impls.push_back(format_impl());
|
|
|
|
auto &new_format = stylesheet.format_impls.back();
|
2016-11-20 06:19:38 +08:00
|
|
|
|
2016-11-08 10:11:30 +08:00
|
|
|
new_format.id = record_index++;
|
|
|
|
new_format.parent = &stylesheet;
|
2016-11-10 08:52:18 +08:00
|
|
|
|
|
|
|
++new_format.references;
|
|
|
|
|
2016-11-08 10:11:30 +08:00
|
|
|
if (record.style_id.second)
|
|
|
|
{
|
|
|
|
new_format.style = stylesheet.style_names[record.style_id.first];
|
|
|
|
}
|
|
|
|
|
|
|
|
new_format.alignment_id = stylesheet.find_or_add(stylesheet.alignments, record.alignment.first);
|
|
|
|
new_format.alignment_applied = record.alignment.second;
|
|
|
|
new_format.border_id = record.border_id.first;
|
|
|
|
new_format.border_applied = record.border_id.second;
|
|
|
|
new_format.fill_id = record.fill_id.first;
|
|
|
|
new_format.fill_applied = record.fill_id.second;
|
|
|
|
new_format.font_id = record.font_id.first;
|
|
|
|
new_format.font_applied = record.font_id.second;
|
|
|
|
new_format.number_format_id = record.number_format_id.first;
|
|
|
|
new_format.number_format_applied = record.number_format_id.second;
|
|
|
|
new_format.protection_id = stylesheet.find_or_add(stylesheet.protections, record.protection.first);
|
|
|
|
new_format.protection_applied = record.protection.second;
|
2016-09-22 07:04:16 +08:00
|
|
|
}
|
2016-08-05 13:52:05 +08:00
|
|
|
}
|
|
|
|
|
2016-10-12 11:16:14 +08:00
|
|
|
void xlsx_consumer::read_theme()
|
2016-08-05 13:52:05 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
auto workbook_rel = manifest().relationship(path("/"), relationship_type::office_document);
|
|
|
|
auto theme_rel = manifest().relationship(workbook_rel.target().path(), relationship_type::theme);
|
|
|
|
auto theme_path = manifest().canonicalize({workbook_rel, theme_rel});
|
|
|
|
|
|
|
|
target_.theme(theme());
|
|
|
|
|
|
|
|
if (manifest().has_relationship(theme_path, relationship_type::image))
|
|
|
|
{
|
|
|
|
read_part({workbook_rel, theme_rel, manifest().relationship(theme_path, relationship_type::image)});
|
|
|
|
}
|
2016-08-05 13:52:05 +08:00
|
|
|
}
|
|
|
|
|
2016-10-12 11:16:14 +08:00
|
|
|
void xlsx_consumer::read_volatile_dependencies()
|
2016-08-05 13:52:05 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-11-25 21:13:55 +08:00
|
|
|
// CT_Worksheet
|
2016-10-12 11:16:14 +08:00
|
|
|
void xlsx_consumer::read_worksheet(const std::string &rel_id)
|
2016-08-05 13:52:05 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
static const auto &xmlns = constants::namespace_("spreadsheetml");
|
|
|
|
static const auto &xmlns_mc = constants::namespace_("mc");
|
|
|
|
static const auto &xmlns_x14ac = constants::namespace_("x14ac");
|
|
|
|
static const auto &xmlns_r = constants::namespace_("r");
|
2016-09-22 07:04:16 +08:00
|
|
|
|
2016-11-20 06:19:38 +08:00
|
|
|
auto title = std::find_if(target_.d_->sheet_title_rel_id_map_.begin(),
|
|
|
|
target_.d_->sheet_title_rel_id_map_.end(),
|
|
|
|
[&](const std::pair<std::string, std::string> &p) { return p.second == rel_id; })->first;
|
2016-08-06 22:40:17 +08:00
|
|
|
|
2016-11-20 06:19:38 +08:00
|
|
|
auto id = sheet_title_id_map_[title];
|
|
|
|
auto index = sheet_title_index_map_[title];
|
2016-08-06 22:40:17 +08:00
|
|
|
|
2016-11-20 06:19:38 +08:00
|
|
|
auto insertion_iter = target_.d_->worksheets_.begin();
|
|
|
|
while (insertion_iter != target_.d_->worksheets_.end()
|
|
|
|
&& sheet_title_index_map_[insertion_iter->title_] < index)
|
|
|
|
{
|
|
|
|
++insertion_iter;
|
|
|
|
}
|
2016-08-05 13:52:05 +08:00
|
|
|
|
2016-11-20 06:19:38 +08:00
|
|
|
target_.d_->worksheets_.emplace(insertion_iter, &target_, id, title);
|
2016-08-05 13:52:05 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
auto ws = target_.sheet_by_id(id);
|
2016-08-05 13:52:05 +08:00
|
|
|
|
2016-11-30 07:31:06 +08:00
|
|
|
expect_start_element(xml::qname(xmlns, "worksheet"), xml::content::complex); // CT_Worksheet
|
2016-11-25 21:13:55 +08:00
|
|
|
skip_attributes({xml::qname(xmlns_mc, "Ignorable")});
|
2016-12-02 21:37:50 +08:00
|
|
|
read_namespaces();
|
2016-08-05 13:52:05 +08:00
|
|
|
|
2016-11-20 06:19:38 +08:00
|
|
|
xlnt::range_reference full_range;
|
2016-11-30 08:05:47 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
const auto &shared_strings = target_.shared_strings();
|
|
|
|
auto &manifest = target_.manifest();
|
2016-11-30 08:05:47 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
const auto workbook_rel = manifest.relationship(path("/"), relationship_type::office_document);
|
|
|
|
const auto sheet_rel = manifest.relationship(workbook_rel.target().path(), rel_id);
|
|
|
|
path sheet_path(sheet_rel.source().path().parent().append(sheet_rel.target().path()));
|
|
|
|
auto hyperlinks = manifest.relationships(sheet_path, xlnt::relationship_type::hyperlink);
|
2016-08-05 13:52:05 +08:00
|
|
|
|
2016-11-25 21:13:55 +08:00
|
|
|
while (in_element(xml::qname(xmlns, "worksheet")))
|
2016-09-22 07:04:16 +08:00
|
|
|
{
|
2016-11-25 21:13:55 +08:00
|
|
|
auto current_worksheet_element = expect_start_element(xml::content::complex);
|
2016-11-20 06:19:38 +08:00
|
|
|
|
2016-11-25 21:13:55 +08:00
|
|
|
if (current_worksheet_element == xml::qname(xmlns, "sheetPr")) // CT_SheetPr 0-1
|
|
|
|
{
|
|
|
|
skip_remaining_content(current_worksheet_element);
|
|
|
|
}
|
|
|
|
else if (current_worksheet_element == xml::qname(xmlns, "dimension")) // CT_SheetDimension 0-1
|
2016-09-22 07:04:16 +08:00
|
|
|
{
|
2016-10-12 11:16:14 +08:00
|
|
|
full_range = xlnt::range_reference(parser().attribute("ref"));
|
2016-09-22 07:04:16 +08:00
|
|
|
ws.d_->has_dimension_ = true;
|
|
|
|
}
|
2016-11-25 21:13:55 +08:00
|
|
|
else if (current_worksheet_element == xml::qname(xmlns, "sheetViews")) // CT_SheetViews 0-1
|
2016-09-22 07:04:16 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
while (in_element(current_worksheet_element))
|
|
|
|
{
|
|
|
|
expect_start_element(xml::qname(xmlns, "sheetView"), xml::content::complex); // CT_SheetView 1+
|
|
|
|
|
|
|
|
sheet_view new_view;
|
|
|
|
new_view.id(parser().attribute<std::size_t>("workbookViewId"));
|
|
|
|
|
|
|
|
if (parser().attribute_present("showGridLines")) // default="true"
|
|
|
|
{
|
|
|
|
new_view.show_grid_lines(is_true(parser().attribute("showGridLines")));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parser().attribute_present("defaultGridColor")) // default="true"
|
|
|
|
{
|
|
|
|
new_view.default_grid_color(is_true(parser().attribute("defaultGridColor")));
|
|
|
|
}
|
|
|
|
|
|
|
|
skip_attributes({"windowProtection", "showFormulas", "showRowColHeaders", "showZeros",
|
|
|
|
"rightToLeft", "tabSelected", "showRuler", "showOutlineSymbols", "showWhiteSpace", "view",
|
|
|
|
"topLeftCell", "colorId", "zoomScale", "zoomScaleNormal", "zoomScaleSheetLayoutView",
|
|
|
|
"zoomScalePageLayoutView"});
|
|
|
|
|
|
|
|
while (in_element(xml::qname(xmlns, "sheetView")))
|
|
|
|
{
|
|
|
|
auto sheet_view_child_element = expect_start_element(xml::content::simple);
|
|
|
|
|
|
|
|
if (sheet_view_child_element == xml::qname(xmlns, "pane")) // CT_Pane 0-1
|
|
|
|
{
|
|
|
|
pane new_pane;
|
|
|
|
|
|
|
|
if (parser().attribute_present("topLeftCell"))
|
|
|
|
{
|
|
|
|
new_pane.top_left_cell = cell_reference(parser().attribute("topLeftCell"));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parser().attribute_present("xSplit"))
|
|
|
|
{
|
|
|
|
new_pane.x_split = parser().attribute<column_t::index_t>("xSplit");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parser().attribute_present("ySplit"))
|
|
|
|
{
|
|
|
|
new_pane.y_split = parser().attribute<row_t>("ySplit");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parser().attribute_present("activePane"))
|
|
|
|
{
|
|
|
|
new_pane.active_pane = parser().attribute<pane_corner>("activePane");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parser().attribute_present("state"))
|
|
|
|
{
|
|
|
|
new_pane.state = parser().attribute<pane_state>("state");
|
|
|
|
}
|
|
|
|
|
|
|
|
new_view.pane(new_pane);
|
|
|
|
}
|
|
|
|
else if (sheet_view_child_element == xml::qname(xmlns, "selection")) // CT_Selection 0-4
|
|
|
|
{
|
|
|
|
skip_remaining_content(sheet_view_child_element);
|
|
|
|
}
|
|
|
|
else if (sheet_view_child_element == xml::qname(xmlns, "pivotSelection")) // CT_PivotSelection 0-4
|
|
|
|
{
|
|
|
|
skip_remaining_content(sheet_view_child_element);
|
|
|
|
}
|
|
|
|
else if (sheet_view_child_element == xml::qname(xmlns, "extLst")) // CT_ExtensionList 0-1
|
|
|
|
{
|
|
|
|
skip_remaining_content(sheet_view_child_element);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
unexpected_element(sheet_view_child_element);
|
|
|
|
}
|
|
|
|
|
|
|
|
expect_end_element(sheet_view_child_element);
|
|
|
|
}
|
|
|
|
|
|
|
|
expect_end_element(xml::qname(xmlns, "sheetView"));
|
|
|
|
|
|
|
|
ws.d_->views_.push_back(new_view);
|
|
|
|
}
|
2016-09-22 07:04:16 +08:00
|
|
|
}
|
2016-11-25 21:13:55 +08:00
|
|
|
else if (current_worksheet_element == xml::qname(xmlns, "sheetFormatPr")) // CT_SheetFormatPr 0-1
|
2016-09-22 07:04:16 +08:00
|
|
|
{
|
|
|
|
ws.d_->has_format_properties_ = true;
|
2016-11-25 21:13:55 +08:00
|
|
|
skip_remaining_content(current_worksheet_element);
|
2016-09-22 07:04:16 +08:00
|
|
|
}
|
2016-11-25 21:13:55 +08:00
|
|
|
else if (current_worksheet_element == xml::qname(xmlns, "cols")) // CT_Cols 0+
|
2016-09-22 07:04:16 +08:00
|
|
|
{
|
2016-11-25 21:13:55 +08:00
|
|
|
while (in_element(xml::qname(xmlns, "cols")))
|
2016-09-22 07:04:16 +08:00
|
|
|
{
|
2016-11-30 07:31:06 +08:00
|
|
|
expect_start_element(xml::qname(xmlns, "col"), xml::content::simple);
|
2016-08-05 13:52:05 +08:00
|
|
|
|
2016-11-25 21:13:55 +08:00
|
|
|
skip_attributes({"bestFit", "collapsed", "hidden", "outlineLevel"});
|
2016-08-14 07:44:45 +08:00
|
|
|
|
2016-11-25 21:13:55 +08:00
|
|
|
auto min = static_cast<column_t::index_t>(std::stoull(parser().attribute("min")));
|
|
|
|
auto max = static_cast<column_t::index_t>(std::stoull(parser().attribute("max")));
|
2016-08-14 07:44:45 +08:00
|
|
|
|
2016-11-25 21:13:55 +08:00
|
|
|
auto width = std::stold(parser().attribute("width"));
|
|
|
|
auto column_style = parser().attribute_present("style")
|
|
|
|
? parser().attribute<std::size_t>("style") : static_cast<std::size_t>(0);
|
|
|
|
auto custom = parser().attribute_present("customWidth")
|
|
|
|
? is_true(parser().attribute("customWidth")) : false;
|
|
|
|
|
2016-11-30 07:31:06 +08:00
|
|
|
expect_end_element(xml::qname(xmlns, "col"));
|
2016-11-25 21:13:55 +08:00
|
|
|
|
|
|
|
for (auto column = min; column <= max; column++)
|
|
|
|
{
|
|
|
|
column_properties props;
|
|
|
|
|
|
|
|
props.width = width;
|
|
|
|
props.style = column_style;
|
|
|
|
props.custom = custom;
|
2016-11-20 06:19:38 +08:00
|
|
|
|
2016-11-25 21:13:55 +08:00
|
|
|
ws.add_column_properties(column, props);
|
|
|
|
}
|
|
|
|
}
|
2016-09-22 07:04:16 +08:00
|
|
|
}
|
2016-11-25 21:13:55 +08:00
|
|
|
else if (current_worksheet_element == xml::qname(xmlns, "sheetData")) // CT_SheetData 1
|
2016-09-22 07:04:16 +08:00
|
|
|
{
|
2016-11-25 21:13:55 +08:00
|
|
|
while (in_element(xml::qname(xmlns, "sheetData")))
|
2016-09-22 07:04:16 +08:00
|
|
|
{
|
2016-11-30 07:31:06 +08:00
|
|
|
expect_start_element(xml::qname(xmlns, "row"), xml::content::complex); // CT_Row
|
2016-12-02 21:37:50 +08:00
|
|
|
auto row_index = parser().attribute<row_t>("r");
|
2016-09-22 07:04:16 +08:00
|
|
|
|
2016-10-12 11:16:14 +08:00
|
|
|
if (parser().attribute_present("ht"))
|
2016-09-22 07:04:16 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
ws.row_properties(row_index).height = parser().attribute<long double>("ht");
|
2016-09-22 07:04:16 +08:00
|
|
|
}
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
skip_attribute("customHeight");
|
2016-10-14 08:11:02 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
auto min_column = full_range.top_left().column_index();
|
|
|
|
auto max_column = full_range.bottom_right().column_index();
|
2016-09-22 07:04:16 +08:00
|
|
|
|
2016-10-25 10:09:15 +08:00
|
|
|
if (parser().attribute_present("spans"))
|
2016-09-22 07:04:16 +08:00
|
|
|
{
|
2016-10-25 10:09:15 +08:00
|
|
|
std::string span_string = parser().attribute("spans");
|
|
|
|
auto colon_index = span_string.find(':');
|
|
|
|
|
|
|
|
if (colon_index != std::string::npos)
|
|
|
|
{
|
|
|
|
min_column = static_cast<column_t::index_t>(std::stoll(span_string.substr(0, colon_index)));
|
|
|
|
max_column = static_cast<column_t::index_t>(std::stoll(span_string.substr(colon_index + 1)));
|
|
|
|
}
|
2016-09-22 07:04:16 +08:00
|
|
|
}
|
|
|
|
|
2016-11-25 21:13:55 +08:00
|
|
|
skip_attributes({xml::qname(xmlns_x14ac, "dyDescent")});
|
|
|
|
skip_attributes({"customFormat", "s", "customFont", "hidden",
|
|
|
|
"outlineLevel", "collapsed", "thickTop", "thickBot", "ph"});
|
2016-11-20 06:19:38 +08:00
|
|
|
|
2016-11-25 21:13:55 +08:00
|
|
|
while (in_element(xml::qname(xmlns, "row")))
|
2016-11-20 06:19:38 +08:00
|
|
|
{
|
2016-11-30 07:31:06 +08:00
|
|
|
expect_start_element(xml::qname(xmlns, "c"), xml::content::complex);
|
2016-12-02 21:37:50 +08:00
|
|
|
auto cell = ws.cell(cell_reference(parser().attribute("r")));
|
2016-11-20 06:19:38 +08:00
|
|
|
|
2016-10-12 11:16:14 +08:00
|
|
|
auto has_type = parser().attribute_present("t");
|
|
|
|
auto type = has_type ? parser().attribute("t") : "";
|
2016-09-22 07:04:16 +08:00
|
|
|
|
2016-10-12 11:16:14 +08:00
|
|
|
auto has_format = parser().attribute_present("s");
|
|
|
|
auto format_id = static_cast<std::size_t>(has_format ? std::stoull(parser().attribute("s")) : 0LL);
|
2016-11-20 06:19:38 +08:00
|
|
|
|
2016-09-22 07:04:16 +08:00
|
|
|
auto has_value = false;
|
|
|
|
auto value_string = std::string();
|
2016-11-20 06:19:38 +08:00
|
|
|
|
2016-09-22 07:04:16 +08:00
|
|
|
auto has_formula = false;
|
|
|
|
auto has_shared_formula = false;
|
|
|
|
auto formula_value_string = std::string();
|
2016-11-20 06:19:38 +08:00
|
|
|
|
2016-11-25 21:13:55 +08:00
|
|
|
while (in_element(xml::qname(xmlns, "c")))
|
2016-09-22 07:04:16 +08:00
|
|
|
{
|
2016-11-25 21:13:55 +08:00
|
|
|
auto current_element = expect_start_element(xml::content::mixed);
|
|
|
|
|
2016-11-27 16:41:03 +08:00
|
|
|
if (current_element == xml::qname(xmlns, "v")) // s:ST_Xstring
|
2016-09-22 07:04:16 +08:00
|
|
|
{
|
|
|
|
has_value = true;
|
2016-11-21 08:38:58 +08:00
|
|
|
value_string = read_text();
|
2016-09-22 07:04:16 +08:00
|
|
|
}
|
2016-11-27 16:41:03 +08:00
|
|
|
else if (current_element == xml::qname(xmlns, "f")) // CT_CellFormula
|
2016-09-22 07:04:16 +08:00
|
|
|
{
|
|
|
|
has_formula = true;
|
2016-11-27 16:41:03 +08:00
|
|
|
|
|
|
|
if (parser().attribute_present("t"))
|
|
|
|
{
|
|
|
|
has_shared_formula = parser().attribute("t") == "shared";
|
|
|
|
}
|
|
|
|
|
|
|
|
skip_attributes({"aca", "ref", "dt2D", "dtr", "del1", "del2", "r1", "r2", "ca", "si", "bx"});
|
|
|
|
|
2016-11-21 08:38:58 +08:00
|
|
|
formula_value_string = read_text();
|
2016-09-22 07:04:16 +08:00
|
|
|
}
|
2016-11-27 16:41:03 +08:00
|
|
|
else if (current_element == xml::qname(xmlns, "is")) // CT_Rst
|
2016-09-22 07:04:16 +08:00
|
|
|
{
|
2016-11-30 07:31:06 +08:00
|
|
|
expect_start_element(xml::qname(xmlns, "t"), xml::content::simple);
|
2016-11-21 08:38:58 +08:00
|
|
|
value_string = read_text();
|
2016-11-30 07:31:06 +08:00
|
|
|
expect_end_element(xml::qname(xmlns, "t"));
|
2016-09-22 07:04:16 +08:00
|
|
|
}
|
2016-11-25 21:13:55 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
unexpected_element(current_element);
|
|
|
|
}
|
2016-11-20 06:19:38 +08:00
|
|
|
|
2016-11-30 07:31:06 +08:00
|
|
|
expect_end_element(current_element);
|
2016-09-22 07:04:16 +08:00
|
|
|
}
|
|
|
|
|
2016-11-30 07:31:06 +08:00
|
|
|
expect_end_element(xml::qname(xmlns, "c"));
|
2016-11-25 21:13:55 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
if (has_formula && !has_shared_formula)
|
2016-09-22 07:04:16 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
cell.formula(formula_value_string);
|
2016-09-22 07:04:16 +08:00
|
|
|
}
|
|
|
|
|
2016-11-20 06:19:38 +08:00
|
|
|
if (has_type && (type == "inlineStr" || type == "str"))
|
2016-09-22 07:04:16 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
cell.value(value_string);
|
2016-09-22 07:04:16 +08:00
|
|
|
}
|
|
|
|
else if (has_type && type == "s" && !has_formula)
|
|
|
|
{
|
|
|
|
auto shared_string_index = static_cast<std::size_t>(std::stoull(value_string));
|
|
|
|
auto shared_string = shared_strings.at(shared_string_index);
|
2016-12-02 21:37:50 +08:00
|
|
|
cell.value(shared_string);
|
2016-09-22 07:04:16 +08:00
|
|
|
}
|
|
|
|
else if (has_type && type == "b") // boolean
|
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
cell.value(value_string != "0");
|
2016-09-22 07:04:16 +08:00
|
|
|
}
|
|
|
|
else if (has_value && !value_string.empty())
|
|
|
|
{
|
|
|
|
if (!value_string.empty() && value_string[0] == '#')
|
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
cell.error(value_string);
|
2016-09-22 07:04:16 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
cell.value(std::stold(value_string));
|
2016-09-22 07:04:16 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (has_format)
|
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
cell.format(target_.format(format_id));
|
2016-09-22 07:04:16 +08:00
|
|
|
}
|
|
|
|
}
|
2016-10-14 08:11:02 +08:00
|
|
|
|
2016-11-25 21:13:55 +08:00
|
|
|
expect_end_element(xml::qname(xmlns, "row"));
|
2016-09-22 07:04:16 +08:00
|
|
|
}
|
|
|
|
}
|
2016-11-25 21:13:55 +08:00
|
|
|
else if (current_worksheet_element == xml::qname(xmlns, "sheetCalcPr")) // CT_SheetCalcPr 0-1
|
2016-09-22 07:04:16 +08:00
|
|
|
{
|
2016-11-25 21:13:55 +08:00
|
|
|
skip_remaining_content(current_worksheet_element);
|
|
|
|
}
|
|
|
|
else if (current_worksheet_element == xml::qname(xmlns, "sheetProtection")) // CT_SheetProtection 0-1
|
|
|
|
{
|
|
|
|
skip_remaining_content(current_worksheet_element);
|
|
|
|
}
|
|
|
|
else if (current_worksheet_element == xml::qname(xmlns, "protectedRanges")) // CT_ProtectedRanges 0-1
|
|
|
|
{
|
|
|
|
skip_remaining_content(current_worksheet_element);
|
|
|
|
}
|
|
|
|
else if (current_worksheet_element == xml::qname(xmlns, "scenarios")) // CT_Scenarios 0-1
|
|
|
|
{
|
|
|
|
skip_remaining_content(current_worksheet_element);
|
|
|
|
}
|
|
|
|
else if (current_worksheet_element == xml::qname(xmlns, "autoFilter")) // CT_AutoFilter 0-1
|
|
|
|
{
|
|
|
|
ws.auto_filter(xlnt::range_reference(parser().attribute("ref")));
|
|
|
|
}
|
|
|
|
else if (current_worksheet_element == xml::qname(xmlns, "sortState")) // CT_SortState 0-1
|
|
|
|
{
|
|
|
|
skip_remaining_content(current_worksheet_element);
|
|
|
|
}
|
|
|
|
else if (current_worksheet_element == xml::qname(xmlns, "dataConsolidate")) // CT_DataConsolidate 0-1
|
|
|
|
{
|
|
|
|
skip_remaining_content(current_worksheet_element);
|
|
|
|
}
|
|
|
|
else if (current_worksheet_element == xml::qname(xmlns, "customSheetViews")) // CT_CustomSheetViews 0-1
|
|
|
|
{
|
|
|
|
skip_remaining_content(current_worksheet_element);
|
|
|
|
}
|
|
|
|
else if (current_worksheet_element == xml::qname(xmlns, "mergeCells")) // CT_MergeCells 0-1
|
|
|
|
{
|
|
|
|
auto count = std::stoull(parser().attribute("count"));
|
2016-11-20 06:19:38 +08:00
|
|
|
|
2016-11-25 21:13:55 +08:00
|
|
|
while (in_element(xml::qname(xmlns, "mergeCells")))
|
|
|
|
{
|
2016-11-30 07:31:06 +08:00
|
|
|
expect_start_element(xml::qname(xmlns, "mergeCell"), xml::content::simple);
|
2016-11-25 21:13:55 +08:00
|
|
|
ws.merge_cells(range_reference(parser().attribute("ref")));
|
2016-11-30 07:31:06 +08:00
|
|
|
expect_end_element(xml::qname(xmlns, "mergeCell"));
|
2016-11-20 06:19:38 +08:00
|
|
|
|
2016-11-25 21:13:55 +08:00
|
|
|
count--;
|
2016-09-22 07:04:16 +08:00
|
|
|
}
|
2016-11-20 06:19:38 +08:00
|
|
|
|
2016-11-25 21:13:55 +08:00
|
|
|
if (count != 0)
|
|
|
|
{
|
|
|
|
throw invalid_file("sizes don't match");
|
|
|
|
}
|
2016-09-22 07:04:16 +08:00
|
|
|
}
|
2016-11-25 21:13:55 +08:00
|
|
|
else if (current_worksheet_element == xml::qname(xmlns, "phoneticPr")) // CT_PhoneticPr 0-1
|
2016-09-22 07:04:16 +08:00
|
|
|
{
|
2016-11-25 21:13:55 +08:00
|
|
|
skip_remaining_content(current_worksheet_element);
|
|
|
|
}
|
|
|
|
else if (current_worksheet_element == xml::qname(xmlns, "conditionalFormatting")) // CT_ConditionalFormatting 0+
|
|
|
|
{
|
|
|
|
skip_remaining_content(current_worksheet_element);
|
2016-09-22 07:04:16 +08:00
|
|
|
}
|
2016-11-25 21:13:55 +08:00
|
|
|
else if (current_worksheet_element == xml::qname(xmlns, "dataValidations")) // CT_DataValidations 0-1
|
|
|
|
{
|
|
|
|
skip_remaining_content(current_worksheet_element);
|
|
|
|
}
|
|
|
|
else if (current_worksheet_element == xml::qname(xmlns, "hyperlinks")) // CT_Hyperlinks 0-1
|
|
|
|
{
|
2016-11-30 08:05:47 +08:00
|
|
|
while (in_element(xml::qname(xmlns, "hyperlinks")))
|
|
|
|
{
|
|
|
|
expect_start_element(xml::qname(xmlns, "hyperlink"), xml::content::simple);
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
auto cell = ws.cell(parser().attribute("ref"));
|
2016-11-30 08:05:47 +08:00
|
|
|
auto hyperlink_rel_id = parser().attribute(xml::qname(xmlns_r, "id"));
|
|
|
|
auto hyperlink_rel = std::find_if(hyperlinks.begin(), hyperlinks.end(),
|
2016-12-02 21:37:50 +08:00
|
|
|
[&](const relationship &r) { return r.id() == hyperlink_rel_id; });
|
2016-11-30 08:05:47 +08:00
|
|
|
|
|
|
|
if (hyperlink_rel != hyperlinks.end())
|
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
cell.hyperlink(hyperlink_rel->target().path().string());
|
2016-11-30 08:05:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
expect_end_element(xml::qname(xmlns, "hyperlink"));
|
|
|
|
}
|
2016-11-25 21:13:55 +08:00
|
|
|
}
|
|
|
|
else if (current_worksheet_element == xml::qname(xmlns, "printOptions")) // CT_PrintOptions 0-1
|
|
|
|
{
|
|
|
|
skip_remaining_content(current_worksheet_element);
|
|
|
|
}
|
|
|
|
else if (current_worksheet_element == xml::qname(xmlns, "pageMargins")) // CT_PageMargins 0-1
|
2016-09-22 07:04:16 +08:00
|
|
|
{
|
|
|
|
page_margins margins;
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
margins.top(parser().attribute<double>("top"));
|
|
|
|
margins.bottom(parser().attribute<double>("bottom"));
|
|
|
|
margins.left(parser().attribute<double>("left"));
|
|
|
|
margins.right(parser().attribute<double>("right"));
|
|
|
|
margins.header(parser().attribute<double>("header"));
|
|
|
|
margins.footer(parser().attribute<double>("footer"));
|
2016-09-22 07:04:16 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
ws.page_margins(margins);
|
2016-09-22 07:04:16 +08:00
|
|
|
}
|
2016-11-25 21:13:55 +08:00
|
|
|
else if (current_worksheet_element == xml::qname(xmlns, "pageSetup")) // CT_PageSetup 0-1
|
2016-10-25 10:09:15 +08:00
|
|
|
{
|
2016-11-25 21:13:55 +08:00
|
|
|
skip_remaining_content(current_worksheet_element);
|
2016-10-25 10:09:15 +08:00
|
|
|
}
|
2016-11-25 21:13:55 +08:00
|
|
|
else if (current_worksheet_element == xml::qname(xmlns, "headerFooter")) // CT_HeaderFooter 0-1
|
2016-10-25 10:09:15 +08:00
|
|
|
{
|
2016-11-25 21:13:55 +08:00
|
|
|
skip_remaining_content(current_worksheet_element);
|
2016-10-25 10:09:15 +08:00
|
|
|
}
|
2016-11-25 21:13:55 +08:00
|
|
|
else if (current_worksheet_element == xml::qname(xmlns, "rowBreaks")) // CT_PageBreak 0-1
|
2016-10-25 10:09:15 +08:00
|
|
|
{
|
2016-11-25 21:13:55 +08:00
|
|
|
skip_remaining_content(current_worksheet_element);
|
2016-10-25 10:09:15 +08:00
|
|
|
}
|
2016-11-25 21:13:55 +08:00
|
|
|
else if (current_worksheet_element == xml::qname(xmlns, "colBreaks")) // CT_PageBreak 0-1
|
2016-10-25 10:09:15 +08:00
|
|
|
{
|
2016-11-25 21:13:55 +08:00
|
|
|
skip_remaining_content(current_worksheet_element);
|
2016-10-25 10:09:15 +08:00
|
|
|
}
|
2016-11-25 21:13:55 +08:00
|
|
|
else if (current_worksheet_element == xml::qname(xmlns, "customProperties")) // CT_CustomProperties 0-1
|
2016-10-25 10:09:15 +08:00
|
|
|
{
|
2016-11-25 21:13:55 +08:00
|
|
|
skip_remaining_content(current_worksheet_element);
|
2016-10-25 10:09:15 +08:00
|
|
|
}
|
2016-11-25 21:13:55 +08:00
|
|
|
else if (current_worksheet_element == xml::qname(xmlns, "cellWatches")) // CT_CellWatches 0-1
|
2016-10-29 22:23:04 +08:00
|
|
|
{
|
2016-11-25 21:13:55 +08:00
|
|
|
skip_remaining_content(current_worksheet_element);
|
2016-11-15 21:09:17 +08:00
|
|
|
}
|
2016-11-25 21:13:55 +08:00
|
|
|
else if (current_worksheet_element == xml::qname(xmlns, "ignoredErrors")) // CT_IgnoredErrors 0-1
|
2016-11-15 21:09:17 +08:00
|
|
|
{
|
2016-11-25 21:13:55 +08:00
|
|
|
skip_remaining_content(current_worksheet_element);
|
2016-11-21 14:45:38 +08:00
|
|
|
}
|
2016-11-25 21:13:55 +08:00
|
|
|
else if (current_worksheet_element == xml::qname(xmlns, "smartTags")) // CT_SmartTags 0-1
|
2016-11-21 14:45:38 +08:00
|
|
|
{
|
2016-11-25 21:13:55 +08:00
|
|
|
skip_remaining_content(current_worksheet_element);
|
|
|
|
}
|
|
|
|
else if (current_worksheet_element == xml::qname(xmlns, "drawing")) // CT_Drawing 0-1
|
|
|
|
{
|
|
|
|
skip_remaining_content(current_worksheet_element);
|
2016-11-15 21:09:17 +08:00
|
|
|
}
|
2016-11-25 21:13:55 +08:00
|
|
|
else if (current_worksheet_element == xml::qname(xmlns, "legacyDrawing"))
|
|
|
|
{
|
|
|
|
skip_remaining_content(current_worksheet_element);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
unexpected_element(current_worksheet_element);
|
|
|
|
}
|
|
|
|
|
2016-11-30 07:31:06 +08:00
|
|
|
expect_end_element(current_worksheet_element);
|
2016-09-22 07:04:16 +08:00
|
|
|
}
|
2016-11-20 06:19:38 +08:00
|
|
|
|
2016-11-30 07:31:06 +08:00
|
|
|
expect_end_element(xml::qname(xmlns, "worksheet"));
|
2016-10-29 22:23:04 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
if (manifest.has_relationship(sheet_path, xlnt::relationship_type::comments))
|
2016-10-29 22:23:04 +08:00
|
|
|
{
|
2016-11-20 06:19:38 +08:00
|
|
|
auto comments_part = manifest.canonicalize(
|
2016-12-02 21:37:50 +08:00
|
|
|
{workbook_rel, sheet_rel, manifest.relationship(sheet_path, xlnt::relationship_type::comments)});
|
2016-10-31 03:48:40 +08:00
|
|
|
|
2016-10-29 22:23:04 +08:00
|
|
|
auto receive = xml::parser::receive_default;
|
2016-11-14 00:52:39 +08:00
|
|
|
xml::parser parser(archive_->open(comments_part.string()), comments_part.string(), receive);
|
2016-10-29 22:23:04 +08:00
|
|
|
parser_ = &parser;
|
2016-11-20 06:19:38 +08:00
|
|
|
|
2016-11-14 00:52:39 +08:00
|
|
|
read_comments(ws);
|
2016-11-20 06:19:38 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
if (manifest.has_relationship(sheet_path, xlnt::relationship_type::vml_drawing))
|
2016-10-29 22:23:04 +08:00
|
|
|
{
|
2016-11-14 00:52:39 +08:00
|
|
|
auto vml_drawings_part = manifest.canonicalize({workbook_rel, sheet_rel,
|
2016-12-02 21:37:50 +08:00
|
|
|
manifest.relationship(sheet_path, xlnt::relationship_type::vml_drawing)});
|
2016-10-29 22:23:04 +08:00
|
|
|
|
2016-11-21 00:06:52 +08:00
|
|
|
xml::parser vml_parser(archive_->open(vml_drawings_part.string()), vml_drawings_part.string(), receive);
|
|
|
|
parser_ = &vml_parser;
|
2016-11-20 06:19:38 +08:00
|
|
|
|
2016-11-14 00:52:39 +08:00
|
|
|
read_vml_drawings(ws);
|
|
|
|
}
|
2016-10-29 22:23:04 +08:00
|
|
|
}
|
2016-08-05 13:52:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Sheet Relationship Target Parts
|
|
|
|
|
2016-11-21 00:06:52 +08:00
|
|
|
void xlsx_consumer::read_vml_drawings(worksheet/*ws*/)
|
2016-11-14 00:52:39 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-10-29 22:23:04 +08:00
|
|
|
void xlsx_consumer::read_comments(worksheet ws)
|
2016-08-05 13:52:05 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
static const auto &xmlns = xlnt::constants::namespace_("spreadsheetml");
|
2016-11-20 06:19:38 +08:00
|
|
|
|
2016-10-29 22:23:04 +08:00
|
|
|
std::vector<std::string> authors;
|
2016-11-20 06:19:38 +08:00
|
|
|
|
2016-11-27 16:35:21 +08:00
|
|
|
expect_start_element(xml::qname(xmlns, "comments"), xml::content::complex);
|
|
|
|
expect_start_element(xml::qname(xmlns, "authors"), xml::content::complex);
|
2016-11-20 06:19:38 +08:00
|
|
|
|
2016-11-25 21:13:55 +08:00
|
|
|
while (in_element(xml::qname(xmlns, "authors")))
|
2016-10-29 22:23:04 +08:00
|
|
|
{
|
2016-11-27 16:35:21 +08:00
|
|
|
expect_start_element(xml::qname(xmlns, "author"), xml::content::simple);
|
2016-11-25 21:13:55 +08:00
|
|
|
authors.push_back(read_text());
|
2016-11-27 16:35:21 +08:00
|
|
|
expect_end_element(xml::qname(xmlns, "author"));
|
2016-10-29 22:23:04 +08:00
|
|
|
}
|
2016-11-20 06:19:38 +08:00
|
|
|
|
2016-11-27 16:35:21 +08:00
|
|
|
expect_end_element(xml::qname(xmlns, "authors"));
|
|
|
|
expect_start_element(xml::qname(xmlns, "commentList"), xml::content::complex);
|
2016-11-20 06:19:38 +08:00
|
|
|
|
2016-11-25 21:13:55 +08:00
|
|
|
while (in_element(xml::qname(xmlns, "commentList")))
|
2016-10-29 22:23:04 +08:00
|
|
|
{
|
2016-11-27 16:35:21 +08:00
|
|
|
expect_start_element(xml::qname(xmlns, "comment"), xml::content::complex);
|
2016-10-29 22:23:04 +08:00
|
|
|
|
|
|
|
auto cell_ref = parser().attribute("ref");
|
|
|
|
auto author_id = parser().attribute<std::size_t>("authorId");
|
2016-11-20 06:19:38 +08:00
|
|
|
|
2016-11-27 16:35:21 +08:00
|
|
|
expect_start_element(xml::qname(xmlns, "text"), xml::content::complex);
|
2016-10-29 22:23:04 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
ws.cell(cell_ref).comment(comment(read_formatted_text(xml::qname(xmlns, "text")), authors.at(author_id)));
|
2016-10-30 04:31:30 +08:00
|
|
|
|
2016-11-27 16:35:21 +08:00
|
|
|
expect_end_element(xml::qname(xmlns, "text"));
|
|
|
|
expect_end_element(xml::qname(xmlns, "comment"));
|
2016-10-29 22:23:04 +08:00
|
|
|
}
|
2016-11-20 06:19:38 +08:00
|
|
|
|
2016-11-27 16:35:21 +08:00
|
|
|
expect_end_element(xml::qname(xmlns, "commentList"));
|
|
|
|
expect_end_element(xml::qname(xmlns, "comments"));
|
2016-08-05 13:52:05 +08:00
|
|
|
}
|
|
|
|
|
2016-10-12 11:16:14 +08:00
|
|
|
void xlsx_consumer::read_drawings()
|
2016-08-05 13:52:05 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// Unknown Parts
|
|
|
|
|
2016-10-12 11:16:14 +08:00
|
|
|
void xlsx_consumer::read_unknown_parts()
|
2016-08-05 13:52:05 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-10-12 11:16:14 +08:00
|
|
|
void xlsx_consumer::read_unknown_relationships()
|
2016-08-05 13:52:05 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
void xlsx_consumer::read_image(const xlnt::path &image_path)
|
|
|
|
{
|
|
|
|
auto &in_stream = archive_->open(image_path.string());
|
|
|
|
vector_ostreambuf buffer(target_.d_->images_[image_path.string()]);
|
|
|
|
std::ostream out_stream(&buffer);
|
|
|
|
out_stream << in_stream.rdbuf();
|
|
|
|
}
|
|
|
|
|
2016-11-20 05:42:16 +08:00
|
|
|
std::string xlsx_consumer::read_text()
|
|
|
|
{
|
|
|
|
auto text = std::string();
|
|
|
|
|
|
|
|
while (parser().peek() == xml::parser::event_type::characters)
|
|
|
|
{
|
|
|
|
parser().next_expect(xml::parser::event_type::characters);
|
|
|
|
text.append(parser().value());
|
|
|
|
}
|
|
|
|
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
|
2016-11-25 21:13:55 +08:00
|
|
|
void xlsx_consumer::skip_attributes(const std::vector<std::string> &names)
|
2016-11-20 05:42:16 +08:00
|
|
|
{
|
2016-11-25 21:13:55 +08:00
|
|
|
for (const auto &name : names)
|
2016-11-20 05:42:16 +08:00
|
|
|
{
|
2016-11-25 21:13:55 +08:00
|
|
|
if (parser().attribute_present(name))
|
|
|
|
{
|
|
|
|
parser().attribute(name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-11-20 05:42:16 +08:00
|
|
|
|
2016-11-25 21:13:55 +08:00
|
|
|
void xlsx_consumer::skip_attributes(const std::vector<xml::qname> &names)
|
|
|
|
{
|
|
|
|
for (const auto &name : names)
|
|
|
|
{
|
|
|
|
if (parser().attribute_present(name))
|
2016-11-20 05:42:16 +08:00
|
|
|
{
|
2016-11-25 21:13:55 +08:00
|
|
|
parser().attribute(name);
|
2016-11-20 05:42:16 +08:00
|
|
|
}
|
2016-11-25 21:13:55 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void xlsx_consumer::skip_attributes()
|
|
|
|
{
|
|
|
|
parser().attribute_map();
|
|
|
|
}
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
void xlsx_consumer::skip_attribute(const xml::qname &name)
|
|
|
|
{
|
|
|
|
if (parser().attribute_present(name))
|
|
|
|
{
|
|
|
|
parser().attribute(name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void xlsx_consumer::skip_attribute(const std::string &name)
|
|
|
|
{
|
|
|
|
if (parser().attribute_present(name))
|
|
|
|
{
|
|
|
|
parser().attribute(name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-25 21:13:55 +08:00
|
|
|
void xlsx_consumer::skip_remaining_content(const xml::qname &name)
|
|
|
|
{
|
|
|
|
// start by assuming we've already parsed the opening tag
|
|
|
|
|
|
|
|
skip_attributes();
|
2016-11-30 07:31:06 +08:00
|
|
|
read_namespaces();
|
2016-11-25 21:13:55 +08:00
|
|
|
read_text();
|
|
|
|
|
|
|
|
// continue until the closing tag is reached
|
|
|
|
while (in_element(name))
|
|
|
|
{
|
2016-11-30 07:31:06 +08:00
|
|
|
auto child_element = expect_start_element(xml::content::mixed);
|
|
|
|
skip_remaining_content(child_element);
|
|
|
|
expect_end_element(child_element);
|
|
|
|
read_text(); // trailing character content (usually whitespace)
|
2016-11-25 21:13:55 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<std::string> xlsx_consumer::read_namespaces()
|
|
|
|
{
|
|
|
|
std::vector<std::string> namespaces;
|
|
|
|
|
|
|
|
while (parser().peek() == xml::parser::event_type::start_namespace_decl)
|
|
|
|
{
|
|
|
|
parser().next_expect(xml::parser::event_type::start_namespace_decl);
|
2016-11-30 07:31:06 +08:00
|
|
|
namespaces.push_back(parser().namespace_());
|
|
|
|
|
|
|
|
if (parser().peek() == xml::parser::event_type::end_namespace_decl)
|
|
|
|
{
|
|
|
|
parser().next_expect(xml::parser::event_type::end_namespace_decl);
|
|
|
|
}
|
2016-11-25 21:13:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return namespaces;
|
|
|
|
}
|
2016-11-20 05:42:16 +08:00
|
|
|
|
2016-11-30 07:31:06 +08:00
|
|
|
bool xlsx_consumer::in_element(const xml::qname &name)
|
2016-11-25 21:13:55 +08:00
|
|
|
{
|
2016-11-30 07:31:06 +08:00
|
|
|
if (parser().peek() == xml::parser::event_type::end_element || stack_.back() != name)
|
2016-11-25 21:13:55 +08:00
|
|
|
{
|
|
|
|
return false;
|
2016-11-20 05:42:16 +08:00
|
|
|
}
|
|
|
|
|
2016-11-25 21:13:55 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
xml::qname xlsx_consumer::expect_start_element(xml::content content)
|
|
|
|
{
|
|
|
|
parser().next_expect(xml::parser::event_type::start_element);
|
|
|
|
parser().content(content);
|
2016-11-30 07:31:06 +08:00
|
|
|
stack_.push_back(parser().qname());
|
2016-11-25 21:13:55 +08:00
|
|
|
|
2016-11-30 07:31:06 +08:00
|
|
|
return stack_.back();
|
2016-11-25 21:13:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void xlsx_consumer::expect_start_element(const xml::qname &name, xml::content content)
|
|
|
|
{
|
|
|
|
parser().next_expect(xml::parser::event_type::start_element, name);
|
|
|
|
parser().content(content);
|
2016-11-30 07:31:06 +08:00
|
|
|
stack_.push_back(name);
|
2016-11-20 05:42:16 +08:00
|
|
|
}
|
|
|
|
|
2016-11-25 21:13:55 +08:00
|
|
|
void xlsx_consumer::expect_end_element(const xml::qname &name)
|
2016-11-21 07:36:52 +08:00
|
|
|
{
|
2016-11-25 21:13:55 +08:00
|
|
|
parser().next_expect(xml::parser::event_type::end_element, name);
|
|
|
|
|
|
|
|
while (parser().peek() == xml::parser::event_type::end_namespace_decl)
|
|
|
|
{
|
|
|
|
parser().next_expect(xml::parser::event_type::end_namespace_decl);
|
|
|
|
}
|
2016-11-30 07:31:06 +08:00
|
|
|
|
|
|
|
stack_.pop_back();
|
2016-11-25 21:13:55 +08:00
|
|
|
}
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
formatted_text xlsx_consumer::read_formatted_text(const xml::qname &parent)
|
2016-11-25 21:13:55 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
const auto &xmlns = parent.namespace_();
|
2016-11-25 21:13:55 +08:00
|
|
|
formatted_text t;
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
while (in_element(parent))
|
2016-11-25 21:13:55 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
auto text_element = expect_start_element(xml::content::mixed);
|
|
|
|
skip_attributes();
|
|
|
|
auto text = read_text();
|
2016-11-25 21:13:55 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
if (text_element == xml::qname(xmlns, "t"))
|
2016-11-25 21:13:55 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
t.plain_text(text);
|
|
|
|
}
|
|
|
|
else if (text_element == xml::qname(xmlns, "r"))
|
|
|
|
{
|
|
|
|
text_run run;
|
2016-11-25 21:13:55 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
while (in_element(xml::qname(xmlns, "r")))
|
|
|
|
{
|
|
|
|
auto run_element = expect_start_element(xml::content::mixed);
|
|
|
|
auto run_text = read_text();
|
|
|
|
|
|
|
|
if (run_element == xml::qname(xmlns, "rPr"))
|
2016-11-25 21:13:55 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
while (in_element(xml::qname(xmlns, "rPr")))
|
2016-11-30 07:31:06 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
auto current_run_property_element = expect_start_element(xml::content::simple);
|
2016-11-25 21:13:55 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
if (current_run_property_element == xml::qname(xmlns, "sz"))
|
|
|
|
{
|
|
|
|
run.size(parser().attribute<std::size_t>("val"));
|
|
|
|
}
|
|
|
|
else if (current_run_property_element == xml::qname(xmlns, "rFont"))
|
|
|
|
{
|
|
|
|
run.font(parser().attribute("val"));
|
|
|
|
}
|
|
|
|
else if (current_run_property_element == xml::qname(xmlns, "color"))
|
|
|
|
{
|
|
|
|
run.color(read_color());
|
|
|
|
}
|
|
|
|
else if (current_run_property_element == xml::qname(xmlns, "family"))
|
|
|
|
{
|
|
|
|
run.family(parser().attribute<std::size_t>("val"));
|
|
|
|
}
|
|
|
|
else if (current_run_property_element == xml::qname(xmlns, "scheme"))
|
|
|
|
{
|
|
|
|
run.scheme(parser().attribute("val"));
|
|
|
|
}
|
|
|
|
else if (current_run_property_element == xml::qname(xmlns, "b"))
|
|
|
|
{
|
|
|
|
run.bold(parser().attribute_present("val") ? is_true(parser().attribute("val")) : true);
|
|
|
|
}
|
|
|
|
else if (current_run_property_element == xml::qname(xmlns, "u"))
|
|
|
|
{
|
|
|
|
if (parser().attribute_present("val"))
|
|
|
|
{
|
|
|
|
run.underline(parser().attribute<font::underline_style>("val"));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
run.underline(font::underline_style::single);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
unexpected_element(current_run_property_element);
|
|
|
|
}
|
|
|
|
|
|
|
|
expect_end_element(current_run_property_element);
|
|
|
|
read_text();
|
|
|
|
}
|
2016-11-25 21:13:55 +08:00
|
|
|
}
|
2016-12-02 21:37:50 +08:00
|
|
|
else if (run_element == xml::qname(xmlns, "t"))
|
|
|
|
{
|
|
|
|
run.string(run_text);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
unexpected_element(run_element);
|
|
|
|
}
|
|
|
|
|
|
|
|
read_text();
|
|
|
|
expect_end_element(run_element);
|
|
|
|
read_text();
|
2016-11-30 07:31:06 +08:00
|
|
|
}
|
2016-11-25 21:13:55 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
t.add_run(run);
|
|
|
|
}
|
|
|
|
else if (text_element == xml::qname(xmlns, "rPh"))
|
|
|
|
{
|
|
|
|
skip_remaining_content(text_element);
|
|
|
|
}
|
|
|
|
else if (text_element == xml::qname(xmlns, "phoneticPr"))
|
|
|
|
{
|
|
|
|
skip_remaining_content(text_element);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
unexpected_element(text_element);
|
2016-11-25 21:13:55 +08:00
|
|
|
}
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
read_text();
|
|
|
|
expect_end_element(text_element);
|
|
|
|
}
|
2016-11-25 21:13:55 +08:00
|
|
|
|
|
|
|
return t;
|
2016-11-21 07:36:52 +08:00
|
|
|
}
|
|
|
|
|
2016-11-30 07:31:06 +08:00
|
|
|
|
|
|
|
xlnt::color xlsx_consumer::read_color()
|
|
|
|
{
|
|
|
|
xlnt::color result;
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
if (parser().attribute_present("auto") && is_true(parser().attribute("auto")))
|
2016-11-30 07:31:06 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
result.auto_(true);
|
2016-11-30 07:31:06 +08:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parser().attribute_present("rgb"))
|
|
|
|
{
|
|
|
|
result = xlnt::rgb_color(parser().attribute("rgb"));
|
|
|
|
}
|
|
|
|
else if (parser().attribute_present("theme"))
|
|
|
|
{
|
|
|
|
result = xlnt::theme_color(parser().attribute<std::size_t>("theme"));
|
|
|
|
}
|
|
|
|
else if (parser().attribute_present("indexed"))
|
|
|
|
{
|
|
|
|
result = xlnt::indexed_color(parser().attribute<std::size_t>("indexed"));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parser().attribute_present("tint"))
|
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
result.tint(parser().attribute("tint", 0.0));
|
2016-11-30 07:31:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
manifest &xlsx_consumer::manifest()
|
2016-11-30 07:31:06 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
return target_.manifest();
|
2016-11-30 07:31:06 +08:00
|
|
|
}
|
|
|
|
|
2016-08-05 13:52:05 +08:00
|
|
|
} // namespace detail
|
|
|
|
} // namepsace xlnt
|