diff --git a/include/xlnt/packaging/app_properties.hpp b/include/xlnt/packaging/app_properties.hpp deleted file mode 100644 index c2c1d225..00000000 --- a/include/xlnt/packaging/app_properties.hpp +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright (c) 2014-2016 Thomas Fussell -// Copyright (c) 2010-2015 openpyxl -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, WRISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE -// -// @license: http://www.opensource.org/licenses/mit-license.php -// @author: see AUTHORS file -#pragma once - -#include - -#include - -namespace xlnt { - -/// -/// High-level properties of the OOXML document regarding the app that created it. -/// -class XLNT_CLASS app_properties -{ -public: - -}; - -} // namespace xlnt diff --git a/include/xlnt/packaging/document_properties.hpp b/include/xlnt/packaging/document_properties.hpp deleted file mode 100644 index ad8a3fcf..00000000 --- a/include/xlnt/packaging/document_properties.hpp +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright (c) 2014-2016 Thomas Fussell -// Copyright (c) 2010-2015 openpyxl -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, WRISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE -// -// @license: http://www.opensource.org/licenses/mit-license.php -// @author: see AUTHORS file -#pragma once - -#include - -#include -#include - -namespace xlnt { - -/// -/// High-level properties of the OOXML document. -/// -class XLNT_CLASS document_properties -{ -public: - document_properties(); - - -}; - -} // namespace xlnt diff --git a/source/detail/xlsx_writer.cpp b/source/detail/xlsx_writer.cpp index 353a4bb7..6309bde7 100644 --- a/source/detail/xlsx_writer.cpp +++ b/source/detail/xlsx_writer.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -46,17 +47,19 @@ void write_content_types(const xlnt::workbook &target, xlnt::zip_file &archive) auto types_node = document.append_child("Types"); types_node.append_attribute("xmlns").set_value("http://schemas.openxmlformats.org/package/2006/content-types"); - auto default_node = types_node.append_child("Default"); - default_node.append_attribute("Extension").set_value("rels"); - default_node.append_attribute("ContentType").set_value("application/vnd.openxmlformats-package.relationships+xml"); + for (const auto &default_type : target.get_manifest().get_default_types()) + { + auto default_node = types_node.append_child("Default"); + default_node.append_attribute("Extension").set_value(default_type.second.get_extension().c_str()); + default_node.append_attribute("ContentType").set_value(default_type.second.get_content_type().c_str()); + } - auto workbook_override_node = types_node.append_child("Override"); - workbook_override_node.append_attribute("PartName").set_value("/workbook.xml"); - workbook_override_node.append_attribute("ContentType").set_value("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml"); - - auto sheet_override_node = types_node.append_child("Default"); - sheet_override_node.append_attribute("PartName").set_value("/sheet1.xml"); - sheet_override_node.append_attribute("ContentType").set_value("application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"); + for (const auto &override_type : target.get_manifest().get_override_types()) + { + auto override_node = types_node.append_child("Override"); + override_node.append_attribute("PartName").set_value(override_type.second.get_part().to_string('/').c_str()); + override_node.append_attribute("ContentType").set_value(override_type.second.get_content_type().c_str()); + } write_document_to_archive(document, xlnt::constants::part_content_types(), archive); } diff --git a/source/packaging/document_properties.cpp b/source/packaging/document_properties.cpp deleted file mode 100644 index be5aaa42..00000000 --- a/source/packaging/document_properties.cpp +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright (c) 2014-2016 Thomas Fussell -// Copyright (c) 2010-2015 openpyxl -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, WRISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE -// -// @license: http://www.opensource.org/licenses/mit-license.php -// @author: see AUTHORS file -#include - -namespace xlnt { - -document_properties::document_properties() - : created(1900, 1, 1), - modified(1900, 1, 1), - excel_base_date(calendar::windows_1900) -{ -} - -} // namespace xlnt diff --git a/source/packaging/zip_file.cpp b/source/packaging/zip_file.cpp index 30e5a0fd..f13fef1e 100644 --- a/source/packaging/zip_file.cpp +++ b/source/packaging/zip_file.cpp @@ -21,6 +21,7 @@ // // @license: http://www.opensource.org/licenses/mit-license.php // @author: see AUTHORS file + #include #include #include @@ -28,38 +29,11 @@ #include #include -#ifdef _WIN32 -#include -#else -#include -#include -#include -#endif - -#include #include #include namespace { -void mkdir_recursive(const xlnt::path &path) -{ - if (path.exists()) return; - - auto parent = path.parent(); - - if (!parent.is_root()) - { - mkdir_recursive(parent); - } - -#ifdef _WIN32 - _mkdir(path.to_string().c_str()); -#else - mkdir(path.c_str(), 0755); -#endif -} - uint32_t crc32buf(const char *buf, std::size_t len) { uint32_t oldcrc32 = 0xFFFFFFFF; diff --git a/source/workbook/workbook.cpp b/source/workbook/workbook.cpp index ee3f5c7f..ccf958fc 100644 --- a/source/workbook/workbook.cpp +++ b/source/workbook/workbook.cpp @@ -64,6 +64,10 @@ workbook workbook::minimal() auto impl = new detail::workbook_impl(); workbook wb(impl); + wb.create_sheet(); + + wb.d_->root_relationships_.push_back(relationship(relationship::type::office_document, "rId1", constants::part_workbook().to_string())); + return wb; } @@ -72,6 +76,10 @@ workbook workbook::empty_excel() auto impl = new detail::workbook_impl(); xlnt::workbook wb(impl); + wb.d_->root_relationships_.push_back(relationship(relationship::type::core_properties, "rId1", constants::part_core().to_string())); + wb.d_->root_relationships_.push_back(relationship(relationship::type::extended_properties, "rId2", constants::part_app().to_string())); + wb.d_->root_relationships_.push_back(relationship(relationship::type::office_document, "rId3", constants::part_workbook().to_string())); + wb.set_application("Microsoft Excel"); wb.create_sheet(); wb.add_format(format()); @@ -711,16 +719,6 @@ const manifest &workbook::get_manifest() const const std::vector &workbook::get_root_relationships() const { - if (d_->root_relationships_.empty()) - { - d_->root_relationships_.push_back( - relationship(relationship::type::core_properties, "rId1", constants::part_core().to_string())); - d_->root_relationships_.push_back( - relationship(relationship::type::extended_properties, "rId2", constants::part_app().to_string())); - d_->root_relationships_.push_back( - relationship(relationship::type::office_document, "rId3", constants::part_workbook().to_string())); - } - return d_->root_relationships_; }