2015-12-25 06:10:02 +08:00
|
|
|
// Copyright (c) 2014-2016 Thomas Fussell
|
2015-12-25 04:51:11 +08:00
|
|
|
// Copyright (c) 2010-2015 openpyxl
|
|
|
|
//
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
// of this software and associated documentation files (the "Software"), to deal
|
|
|
|
// in the Software without restriction, including without limitation the rights
|
|
|
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
// copies of the Software, and to permit persons to whom the Software is
|
|
|
|
// furnished to do so, subject to the following conditions:
|
|
|
|
//
|
|
|
|
// The above copyright notice and this permission notice shall be included in
|
|
|
|
// all copies or substantial portions of the Software.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, WRISING FROM,
|
|
|
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
// THE SOFTWARE
|
|
|
|
//
|
|
|
|
// @license: http://www.opensource.org/licenses/mit-license.php
|
|
|
|
// @author: see AUTHORS file
|
2016-11-08 10:55:40 +08:00
|
|
|
|
2014-05-22 05:48:51 +08:00
|
|
|
#include <algorithm>
|
2014-06-11 05:12:15 +08:00
|
|
|
#include <array>
|
2014-06-05 06:42:17 +08:00
|
|
|
#include <fstream>
|
2016-06-11 01:40:50 +08:00
|
|
|
#include <functional>
|
2014-07-27 04:19:15 +08:00
|
|
|
#include <set>
|
2014-05-21 22:20:30 +08:00
|
|
|
|
2016-11-08 11:12:08 +08:00
|
|
|
#ifdef WIN32
|
|
|
|
#include <codecvt> // utf-8 -> utf-16 conversion
|
|
|
|
#endif
|
|
|
|
|
2016-07-23 08:26:02 +08:00
|
|
|
#include <detail/cell_impl.hpp>
|
|
|
|
#include <detail/constants.hpp>
|
2016-08-16 12:23:49 +08:00
|
|
|
#include <detail/excel_thumbnail.hpp>
|
2016-10-31 03:48:40 +08:00
|
|
|
#include <detail/vector_streambuf.hpp>
|
2016-07-23 08:26:02 +08:00
|
|
|
#include <detail/workbook_impl.hpp>
|
|
|
|
#include <detail/worksheet_impl.hpp>
|
2016-10-31 03:48:40 +08:00
|
|
|
#include <detail/xlsx_consumer.hpp>
|
|
|
|
#include <detail/xlsx_producer.hpp>
|
2016-08-16 12:23:49 +08:00
|
|
|
#include <xlnt/cell/cell.hpp>
|
2015-11-03 22:06:01 +08:00
|
|
|
#include <xlnt/packaging/manifest.hpp>
|
2015-11-03 21:38:09 +08:00
|
|
|
#include <xlnt/packaging/relationship.hpp>
|
2015-10-19 03:30:46 +08:00
|
|
|
#include <xlnt/styles/alignment.hpp>
|
2015-10-21 11:30:10 +08:00
|
|
|
#include <xlnt/styles/border.hpp>
|
2016-05-15 01:57:07 +08:00
|
|
|
#include <xlnt/styles/format.hpp>
|
2015-10-19 03:30:46 +08:00
|
|
|
#include <xlnt/styles/fill.hpp>
|
|
|
|
#include <xlnt/styles/font.hpp>
|
2016-05-15 01:57:07 +08:00
|
|
|
#include <xlnt/styles/style.hpp>
|
2015-10-19 03:30:46 +08:00
|
|
|
#include <xlnt/styles/number_format.hpp>
|
|
|
|
#include <xlnt/styles/protection.hpp>
|
2015-11-03 21:38:09 +08:00
|
|
|
#include <xlnt/utils/exceptions.hpp>
|
2016-08-03 12:12:18 +08:00
|
|
|
#include <xlnt/utils/path.hpp>
|
2016-01-25 00:15:49 +08:00
|
|
|
#include <xlnt/workbook/const_worksheet_iterator.hpp>
|
2015-10-15 06:05:13 +08:00
|
|
|
#include <xlnt/workbook/named_range.hpp>
|
2015-10-30 07:37:07 +08:00
|
|
|
#include <xlnt/workbook/theme.hpp>
|
2015-10-14 12:03:48 +08:00
|
|
|
#include <xlnt/workbook/workbook.hpp>
|
2016-08-14 02:45:26 +08:00
|
|
|
#include <xlnt/workbook/workbook_view.hpp>
|
2016-01-25 00:15:49 +08:00
|
|
|
#include <xlnt/workbook/worksheet_iterator.hpp>
|
2015-10-14 12:03:48 +08:00
|
|
|
#include <xlnt/worksheet/range.hpp>
|
|
|
|
#include <xlnt/worksheet/worksheet.hpp>
|
2014-08-14 06:56:34 +08:00
|
|
|
|
2016-11-08 10:11:30 +08:00
|
|
|
namespace {
|
|
|
|
|
2016-11-20 08:41:21 +08:00
|
|
|
#ifdef _MSC_VER
|
2016-11-08 10:11:30 +08:00
|
|
|
std::wstring utf8_to_utf16(const std::string &utf8_string)
|
|
|
|
{
|
2016-11-08 10:55:40 +08:00
|
|
|
std::wstring_convert<std::codecvt_utf8<wchar_t>> convert;
|
2016-11-08 10:11:30 +08:00
|
|
|
return convert.from_bytes(utf8_string);
|
|
|
|
}
|
|
|
|
|
|
|
|
void open_stream(std::ifstream &stream, const std::wstring &path)
|
|
|
|
{
|
|
|
|
stream.open(path, std::ios::binary);
|
|
|
|
}
|
|
|
|
|
|
|
|
void open_stream(std::ofstream &stream, const std::wstring &path)
|
|
|
|
{
|
|
|
|
stream.open(path, std::ios::binary);
|
|
|
|
}
|
|
|
|
|
|
|
|
void open_stream(std::ifstream &stream, const std::string &path)
|
|
|
|
{
|
|
|
|
open_stream(stream, utf8_to_utf16(path));
|
|
|
|
}
|
|
|
|
|
|
|
|
void open_stream(std::ofstream &stream, const std::string &path)
|
|
|
|
{
|
2016-11-08 10:55:40 +08:00
|
|
|
open_stream(stream, utf8_to_utf16(path));
|
2016-11-08 10:11:30 +08:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
void open_stream(std::ifstream &stream, const std::string &path)
|
|
|
|
{
|
|
|
|
stream.open(path, std::ios::binary);
|
|
|
|
}
|
|
|
|
|
|
|
|
void open_stream(std::ofstream &stream, const std::string &path)
|
|
|
|
{
|
|
|
|
stream.open(path, std::ios::binary);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2014-05-21 22:20:30 +08:00
|
|
|
namespace xlnt {
|
2014-07-25 05:31:46 +08:00
|
|
|
|
2016-08-03 12:12:18 +08:00
|
|
|
workbook workbook::minimal()
|
2014-05-21 22:20:30 +08:00
|
|
|
{
|
2016-08-03 12:12:18 +08:00
|
|
|
auto impl = new detail::workbook_impl();
|
|
|
|
workbook wb(impl);
|
|
|
|
|
2016-08-06 22:40:17 +08:00
|
|
|
wb.d_->manifest_.register_default_type("rels",
|
|
|
|
"application/vnd.openxmlformats-package.relationships+xml");
|
2016-08-03 19:41:42 +08:00
|
|
|
|
2016-09-06 10:17:36 +08:00
|
|
|
wb.d_->manifest_.register_override_type(path("/workbook.xml"),
|
2016-08-06 22:40:17 +08:00
|
|
|
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml");
|
2016-08-12 12:22:14 +08:00
|
|
|
wb.d_->manifest_.register_relationship(uri("/"), relationship::type::office_document,
|
|
|
|
uri("workbook.xml"), target_mode::internal);
|
2016-08-06 22:40:17 +08:00
|
|
|
|
2016-08-14 02:45:26 +08:00
|
|
|
std::string title("1");
|
2016-08-06 22:40:17 +08:00
|
|
|
wb.d_->worksheets_.push_back(detail::worksheet_impl(&wb, 1, title));
|
|
|
|
|
2016-09-06 10:17:36 +08:00
|
|
|
wb.d_->manifest_.register_override_type(path("/sheet1.xml"),
|
2016-08-06 22:40:17 +08:00
|
|
|
"application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml");
|
2016-08-12 12:22:14 +08:00
|
|
|
auto ws_rel = wb.d_->manifest_.register_relationship(uri("workbook.xml"),
|
|
|
|
relationship::type::worksheet, uri("sheet1.xml"), target_mode::internal);
|
2016-08-06 22:40:17 +08:00
|
|
|
wb.d_->sheet_title_rel_id_map_[title] = ws_rel;
|
2016-08-03 19:41:42 +08:00
|
|
|
|
2016-08-03 12:12:18 +08:00
|
|
|
return wb;
|
2014-05-30 08:52:14 +08:00
|
|
|
}
|
2014-07-25 05:31:46 +08:00
|
|
|
|
2016-08-03 12:12:18 +08:00
|
|
|
workbook workbook::empty_excel()
|
|
|
|
{
|
|
|
|
auto impl = new detail::workbook_impl();
|
2016-08-16 12:23:49 +08:00
|
|
|
workbook wb(impl);
|
2016-08-03 12:12:18 +08:00
|
|
|
|
2016-09-06 10:17:36 +08:00
|
|
|
wb.d_->manifest_.register_override_type(path("/xl/workbook.xml"),
|
2016-08-06 22:40:17 +08:00
|
|
|
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml");
|
2016-08-12 12:22:14 +08:00
|
|
|
wb.d_->manifest_.register_relationship(uri("/"), relationship::type::office_document,
|
|
|
|
uri("xl/workbook.xml"), target_mode::internal);
|
2016-08-06 22:40:17 +08:00
|
|
|
|
|
|
|
wb.d_->manifest_.register_default_type("rels",
|
|
|
|
"application/vnd.openxmlformats-package.relationships+xml");
|
|
|
|
wb.d_->manifest_.register_default_type("xml", "application/xml");
|
|
|
|
|
2016-08-16 12:23:49 +08:00
|
|
|
wb.set_thumbnail(excel_thumbnail(), "jpeg", "image/jpeg");
|
2016-08-06 22:40:17 +08:00
|
|
|
|
2016-09-06 10:17:36 +08:00
|
|
|
wb.d_->manifest_.register_override_type(path("/docProps/core.xml"),
|
|
|
|
"application/vnd.openxmlformats-package.core-properties+xml");
|
2016-08-12 12:22:14 +08:00
|
|
|
wb.d_->manifest_.register_relationship(uri("/"), relationship::type::core_properties,
|
|
|
|
uri("docProps/core.xml"), target_mode::internal);
|
2016-08-06 22:40:17 +08:00
|
|
|
|
2016-09-06 10:17:36 +08:00
|
|
|
wb.d_->manifest_.register_override_type(path("/docProps/app.xml"),
|
2016-08-06 22:40:17 +08:00
|
|
|
"application/vnd.openxmlformats-officedocument.extended-properties+xml");
|
2016-08-12 12:22:14 +08:00
|
|
|
wb.d_->manifest_.register_relationship(uri("/"), relationship::type::extended_properties,
|
|
|
|
uri("docProps/app.xml"), target_mode::internal);
|
2016-08-03 19:41:42 +08:00
|
|
|
|
2016-08-13 11:06:25 +08:00
|
|
|
wb.set_creator("Microsoft Office User");
|
|
|
|
wb.set_last_modified_by("Microsoft Office User");
|
|
|
|
wb.set_created(datetime(2016, 8, 12, 3, 16, 56));
|
|
|
|
wb.set_modified(datetime(2016, 8, 12, 3, 17, 16));
|
|
|
|
wb.set_application("Microsoft Macintosh Excel");
|
|
|
|
wb.set_app_version("15.0300");
|
2016-08-14 02:45:26 +08:00
|
|
|
wb.set_absolute_path(path("/Users/thomas/Development/xlnt/tests/data/xlsx/"));
|
|
|
|
wb.enable_x15();
|
|
|
|
|
|
|
|
wb.d_->has_file_version_ = true;
|
|
|
|
wb.d_->file_version_.app_name = "xl";
|
|
|
|
wb.d_->file_version_.last_edited = 6;
|
|
|
|
wb.d_->file_version_.lowest_edited = 6;
|
|
|
|
wb.d_->file_version_.rup_build = 26709;
|
|
|
|
|
|
|
|
wb.d_->has_properties_ = true;
|
|
|
|
wb.d_->has_view_ = true;
|
|
|
|
wb.d_->has_arch_id_ = true;
|
|
|
|
wb.d_->has_calculation_properties_ = true;
|
|
|
|
|
|
|
|
auto ws = wb.create_sheet();
|
|
|
|
|
|
|
|
ws.enable_x14ac();
|
2016-09-06 10:17:36 +08:00
|
|
|
page_margins margins;
|
|
|
|
margins.set_left(0.7);
|
|
|
|
margins.set_right(0.7);
|
|
|
|
margins.set_top(0.75);
|
|
|
|
margins.set_bottom(0.75);
|
|
|
|
margins.set_header(0.3);
|
|
|
|
margins.set_footer(0.3);
|
|
|
|
ws.set_page_margins(margins);
|
2016-08-14 02:45:26 +08:00
|
|
|
ws.d_->has_dimension_ = true;
|
|
|
|
ws.d_->has_format_properties_ = true;
|
|
|
|
ws.d_->has_view_ = true;
|
2016-08-13 11:06:25 +08:00
|
|
|
|
2016-08-18 19:34:18 +08:00
|
|
|
auto default_border = border().side(border_side::bottom, border::border_property())
|
|
|
|
.side(border_side::top, border::border_property())
|
|
|
|
.side(border_side::start, border::border_property())
|
|
|
|
.side(border_side::end, border::border_property())
|
|
|
|
.side(border_side::diagonal, border::border_property());
|
|
|
|
wb.d_->stylesheet_.borders.push_back(default_border);
|
|
|
|
|
2016-11-08 10:11:30 +08:00
|
|
|
auto default_fill = fill(pattern_fill().type(pattern_fill_type::none));
|
|
|
|
wb.d_->stylesheet_.fills.push_back(default_fill);
|
|
|
|
auto gray125_fill = pattern_fill().type(pattern_fill_type::gray125);
|
|
|
|
wb.d_->stylesheet_.fills.push_back(gray125_fill);
|
2016-08-18 19:34:18 +08:00
|
|
|
|
2016-11-08 10:11:30 +08:00
|
|
|
auto default_font = font()
|
|
|
|
.name("Calibri")
|
|
|
|
.size(12)
|
|
|
|
.scheme("minor")
|
|
|
|
.family(2)
|
|
|
|
.color(theme_color(1));
|
|
|
|
wb.d_->stylesheet_.fonts.push_back(default_font);
|
|
|
|
|
|
|
|
wb.create_style("Normal").builtin_id(0)
|
|
|
|
.border(default_border, false)
|
|
|
|
.fill(default_fill, false)
|
|
|
|
.font(default_font, false)
|
|
|
|
.number_format(xlnt::number_format::general(), false);
|
|
|
|
|
2016-11-10 08:52:18 +08:00
|
|
|
wb.create_format(true)
|
2016-11-08 10:11:30 +08:00
|
|
|
.border(default_border, false)
|
|
|
|
.fill(default_fill, false)
|
|
|
|
.font(default_font, false)
|
|
|
|
.number_format(xlnt::number_format::general(), false)
|
|
|
|
.style("Normal");
|
2016-08-18 19:34:18 +08:00
|
|
|
|
|
|
|
wb.set_theme(theme());
|
|
|
|
|
2016-08-03 12:12:18 +08:00
|
|
|
return wb;
|
|
|
|
}
|
|
|
|
|
|
|
|
workbook workbook::empty_libre_office()
|
2014-05-30 08:52:14 +08:00
|
|
|
{
|
2016-08-03 12:12:18 +08:00
|
|
|
auto impl = new detail::workbook_impl();
|
|
|
|
workbook wb(impl);
|
2016-07-06 09:27:35 +08:00
|
|
|
|
2016-08-16 12:23:49 +08:00
|
|
|
wb.d_->manifest_.register_override_type(path("xl/workbook.xml"),
|
|
|
|
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml");
|
|
|
|
wb.d_->manifest_.register_relationship(uri("/"), relationship::type::office_document,
|
|
|
|
uri("xl/workbook.xml"), target_mode::internal);
|
|
|
|
|
|
|
|
wb.d_->manifest_.register_override_type(path("docProps/core.xml"),
|
2016-09-06 10:17:36 +08:00
|
|
|
"application/vnd.openxmlformats-package.core-properties+xml");
|
2016-08-16 12:23:49 +08:00
|
|
|
wb.d_->manifest_.register_relationship(uri("/"), relationship::type::core_properties,
|
|
|
|
uri("docProps/core.xml"), target_mode::internal);
|
|
|
|
|
|
|
|
wb.d_->manifest_.register_override_type(path("docProps/app.xml"),
|
|
|
|
"application/vnd.openxmlformats-officedocument.extended-properties+xml");
|
|
|
|
wb.d_->manifest_.register_relationship(uri("/"), relationship::type::extended_properties,
|
|
|
|
uri("docProps/app.xml"), target_mode::internal);
|
|
|
|
|
|
|
|
wb.d_->manifest_.register_override_type(path("_rels/.rels"),
|
|
|
|
"application/vnd.openxmlformats-package.relationships+xml");
|
|
|
|
wb.d_->manifest_.register_override_type(path("xl/_rels/workbook.xml.rels"),
|
|
|
|
"application/vnd.openxmlformats-package.relationships+xml");
|
|
|
|
|
|
|
|
std::string title("Sheet1");
|
|
|
|
wb.d_->worksheets_.push_back(detail::worksheet_impl(&wb, 1, title));
|
|
|
|
|
|
|
|
wb.d_->manifest_.register_override_type(path("xl/worksheets/sheet1.xml"),
|
|
|
|
"application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml");
|
|
|
|
auto ws_rel = wb.d_->manifest_.register_relationship(uri("xl/workbook.xml"),
|
|
|
|
relationship::type::worksheet, uri("worksheets/sheet1.xml"), target_mode::internal);
|
|
|
|
wb.d_->sheet_title_rel_id_map_[title] = ws_rel;
|
|
|
|
|
2016-08-18 19:34:18 +08:00
|
|
|
auto ws = wb.get_sheet_by_index(0);
|
|
|
|
ws.d_->has_format_properties_ = true;
|
|
|
|
ws.d_->has_view_ = true;
|
|
|
|
ws.d_->has_dimension_ = true;
|
|
|
|
page_margins margins;
|
|
|
|
margins.set_left(0.7875);
|
|
|
|
margins.set_right(0.7875);
|
|
|
|
margins.set_top(1.05277777777778);
|
|
|
|
margins.set_bottom(1.05277777777778);
|
|
|
|
margins.set_header(0.7875);
|
|
|
|
margins.set_footer(0.7875);
|
|
|
|
ws.set_page_margins(margins);
|
|
|
|
ws.set_page_setup(page_setup());
|
|
|
|
ws.get_header_footer().get_center_header().set_font_name("&C&\"Times New Roman\"&12&A");
|
|
|
|
ws.get_header_footer().get_center_footer().set_font_name("&C&\"Times New Roman\"&12Page &B");
|
|
|
|
ws.add_column_properties(1, column_properties());
|
|
|
|
|
|
|
|
auto default_alignment = xlnt::alignment()
|
2016-08-16 12:23:49 +08:00
|
|
|
.horizontal(horizontal_alignment::general)
|
|
|
|
.vertical(vertical_alignment::bottom)
|
|
|
|
.rotation(0)
|
|
|
|
.wrap(false)
|
|
|
|
.indent(0)
|
|
|
|
.shrink(false);
|
2016-08-18 19:34:18 +08:00
|
|
|
wb.d_->stylesheet_.alignments.push_back(default_alignment);
|
2016-08-16 12:23:49 +08:00
|
|
|
|
2016-08-18 19:34:18 +08:00
|
|
|
auto default_border = border().side(border_side::bottom, border::border_property())
|
|
|
|
.side(border_side::top, border::border_property())
|
|
|
|
.side(border_side::start, border::border_property())
|
|
|
|
.side(border_side::end, border::border_property())
|
|
|
|
.side(border_side::diagonal, border::border_property())
|
|
|
|
.diagonal(diagonal_direction::neither);
|
|
|
|
wb.d_->stylesheet_.borders.push_back(default_border);
|
|
|
|
|
|
|
|
auto default_fill = xlnt::fill(xlnt::pattern_fill().type(pattern_fill_type::none));
|
|
|
|
wb.d_->stylesheet_.fills.push_back(default_fill);
|
|
|
|
|
|
|
|
auto gray125_fill = xlnt::fill(xlnt::pattern_fill().type(pattern_fill_type::gray125));
|
|
|
|
wb.d_->stylesheet_.fills.push_back(gray125_fill);
|
2016-08-16 12:23:49 +08:00
|
|
|
|
2016-08-18 19:34:18 +08:00
|
|
|
auto default_font = font().name("Arial").size(10).family(2);
|
|
|
|
wb.d_->stylesheet_.fonts.push_back(default_font);
|
2016-08-16 12:23:49 +08:00
|
|
|
|
2016-08-18 19:34:18 +08:00
|
|
|
auto second_font = font().name("Arial").size(10).family(0);
|
|
|
|
wb.d_->stylesheet_.fonts.push_back(second_font);
|
|
|
|
|
|
|
|
auto default_number_format = xlnt::number_format();
|
|
|
|
default_number_format.set_format_string("General");
|
|
|
|
default_number_format.set_id(164);
|
2016-11-03 10:04:51 +08:00
|
|
|
wb.d_->stylesheet_.number_formats.push_back(default_number_format);
|
2016-08-18 19:34:18 +08:00
|
|
|
|
|
|
|
auto default_protection = xlnt::protection()
|
|
|
|
.locked(true)
|
|
|
|
.hidden(false);
|
|
|
|
wb.d_->stylesheet_.protections.push_back(default_protection);
|
|
|
|
|
2016-11-08 10:11:30 +08:00
|
|
|
wb.create_style("Normal").builtin_id(0).custom(false)
|
|
|
|
.alignment(default_alignment, false)
|
|
|
|
.border(default_border, true)
|
|
|
|
.fill(default_fill, true)
|
|
|
|
.font(default_font, true)
|
|
|
|
.number_format(default_number_format, false)
|
|
|
|
.protection(default_protection, false);
|
|
|
|
|
|
|
|
wb.create_style("Comma").builtin_id(3).custom(false)
|
|
|
|
.alignment(default_alignment, false)
|
|
|
|
.border(default_border, true)
|
|
|
|
.fill(default_fill, true)
|
|
|
|
.font(second_font, true)
|
|
|
|
.number_format(number_format::from_builtin_id(43), false)
|
|
|
|
.protection(default_protection, false);
|
|
|
|
|
|
|
|
wb.create_style("Comma [0]").builtin_id(6).custom(false)
|
|
|
|
.alignment(default_alignment, false)
|
|
|
|
.border(default_border, true)
|
|
|
|
.fill(default_fill, true)
|
|
|
|
.font(second_font, true)
|
|
|
|
.number_format(number_format::from_builtin_id(41), false)
|
|
|
|
.protection(default_protection, false);
|
|
|
|
|
|
|
|
wb.create_style("Currency").builtin_id(4).custom(false)
|
|
|
|
.alignment(default_alignment, false)
|
|
|
|
.border(default_border, true)
|
|
|
|
.fill(default_fill, true)
|
|
|
|
.font(second_font, true)
|
|
|
|
.number_format(number_format::from_builtin_id(44), false)
|
|
|
|
.protection(default_protection, false);
|
|
|
|
|
|
|
|
wb.create_style("Currency [0]").builtin_id(7).custom(false)
|
|
|
|
.alignment(default_alignment, false)
|
|
|
|
.border(default_border, true)
|
|
|
|
.fill(default_fill, true)
|
|
|
|
.font(second_font, true)
|
|
|
|
.number_format(number_format::from_builtin_id(42), false)
|
|
|
|
.protection(default_protection, false);
|
|
|
|
|
|
|
|
wb.create_style("Percent").builtin_id(5).custom(false)
|
|
|
|
.alignment(default_alignment, false)
|
|
|
|
.border(default_border, true)
|
|
|
|
.fill(default_fill, false)
|
|
|
|
.font(second_font, true)
|
|
|
|
.number_format(number_format::percentage(), false)
|
|
|
|
.protection(default_protection, false);
|
|
|
|
|
|
|
|
wb.create_format()
|
|
|
|
.number_format(default_number_format, true)
|
|
|
|
.alignment(default_alignment, true)
|
|
|
|
.protection(default_protection, true)
|
|
|
|
.style("Normal");
|
2016-08-18 19:34:18 +08:00
|
|
|
|
|
|
|
wb.d_->has_file_version_ = true;
|
|
|
|
wb.d_->file_version_.app_name = "Calc";
|
|
|
|
wb.d_->has_properties_ = true;
|
|
|
|
wb.d_->has_view_ = true;
|
|
|
|
wb.d_->has_calculation_properties_ = true;
|
|
|
|
wb.d_->application_ = "LibreOffice/5.1.4.2$Windows_x86 LibreOffice_project/f99d75f39f1c57ebdd7ffc5f42867c12031db97a";
|
|
|
|
wb.d_->short_bools_ = false;
|
2016-08-16 12:23:49 +08:00
|
|
|
|
2016-08-03 12:12:18 +08:00
|
|
|
return wb;
|
|
|
|
}
|
|
|
|
|
|
|
|
workbook workbook::empty_numbers()
|
|
|
|
{
|
|
|
|
auto impl = new detail::workbook_impl();
|
|
|
|
workbook wb(impl);
|
|
|
|
|
|
|
|
return wb;
|
|
|
|
}
|
|
|
|
|
|
|
|
workbook::workbook()
|
|
|
|
{
|
2016-08-03 20:46:50 +08:00
|
|
|
auto wb_template = empty_excel();
|
|
|
|
swap(*this, wb_template);
|
2016-08-03 12:12:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
workbook::workbook(detail::workbook_impl *impl) : d_(impl)
|
|
|
|
{
|
2016-11-04 07:26:11 +08:00
|
|
|
if (impl != nullptr)
|
|
|
|
{
|
|
|
|
d_->stylesheet_.parent = this;
|
|
|
|
}
|
2014-05-21 22:20:30 +08:00
|
|
|
}
|
|
|
|
|
2016-08-16 12:23:49 +08:00
|
|
|
void workbook::register_app_properties_in_manifest()
|
|
|
|
{
|
|
|
|
auto wb_rel = get_manifest().get_relationship(path("/"), relationship_type::office_document);
|
|
|
|
|
|
|
|
if (!get_manifest().has_relationship(wb_rel.get_target().get_path(), relationship_type::extended_properties))
|
|
|
|
{
|
2016-09-08 06:02:46 +08:00
|
|
|
get_manifest().register_override_type(path("/docProps/app.xml"),
|
2016-08-16 12:23:49 +08:00
|
|
|
"application/vnd.openxmlformats-officedocument.extended-properties+xml");
|
|
|
|
get_manifest().register_relationship(uri("/"), relationship::type::extended_properties,
|
|
|
|
uri("docProps/app.xml"), target_mode::internal);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void workbook::register_core_properties_in_manifest()
|
|
|
|
{
|
|
|
|
auto wb_rel = get_manifest().get_relationship(path("/"), relationship_type::office_document);
|
|
|
|
|
|
|
|
if (!get_manifest().has_relationship(wb_rel.get_target().get_path(), relationship_type::core_properties))
|
|
|
|
{
|
2016-09-08 06:02:46 +08:00
|
|
|
get_manifest().register_override_type(path("/docProps/core.xml"),
|
2016-09-06 10:17:36 +08:00
|
|
|
"application/vnd.openxmlformats-package.core-properties+xml");
|
2016-08-16 12:23:49 +08:00
|
|
|
get_manifest().register_relationship(uri("/"), relationship::type::core_properties,
|
|
|
|
uri("docProps/core.xml"), target_mode::internal);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void workbook::register_shared_string_table_in_manifest()
|
|
|
|
{
|
|
|
|
auto wb_rel = get_manifest().get_relationship(path("/"), relationship_type::office_document);
|
|
|
|
|
|
|
|
if (!get_manifest().has_relationship(wb_rel.get_target().get_path(), relationship_type::shared_string_table))
|
|
|
|
{
|
|
|
|
get_manifest().register_override_type(constants::part_shared_strings(),
|
|
|
|
"application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml");
|
|
|
|
get_manifest().register_relationship(wb_rel.get_target(),
|
2016-09-08 06:02:46 +08:00
|
|
|
relationship::type::shared_string_table, uri("sharedStrings.xml"), target_mode::internal);
|
2016-08-16 12:23:49 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void workbook::register_stylesheet_in_manifest()
|
|
|
|
{
|
|
|
|
auto wb_rel = get_manifest().get_relationship(path("/"), relationship_type::office_document);
|
|
|
|
|
2016-11-20 05:42:16 +08:00
|
|
|
if (!get_manifest().has_relationship(wb_rel.get_target().get_path(), relationship_type::stylesheet))
|
2016-08-16 12:23:49 +08:00
|
|
|
{
|
|
|
|
get_manifest().register_override_type(constants::part_styles(),
|
|
|
|
"application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml");
|
|
|
|
get_manifest().register_relationship(wb_rel.get_target(),
|
2016-11-20 05:42:16 +08:00
|
|
|
relationship::type::stylesheet, uri("styles.xml"), target_mode::internal);
|
2016-08-16 12:23:49 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void workbook::register_theme_in_manifest()
|
|
|
|
{
|
|
|
|
auto wb_rel = get_manifest().get_relationship(path("/"), relationship_type::office_document);
|
|
|
|
|
|
|
|
if (!get_manifest().has_relationship(wb_rel.get_target().get_path(), relationship_type::theme))
|
|
|
|
{
|
|
|
|
get_manifest().register_override_type(constants::part_theme(),
|
|
|
|
"application/vnd.openxmlformats-officedocument.theme+xml");
|
|
|
|
get_manifest().register_relationship(wb_rel.get_target(),
|
|
|
|
relationship::type::theme, uri("theme/theme1.xml"), target_mode::internal);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-30 04:31:30 +08:00
|
|
|
void workbook::register_comments_in_manifest(worksheet ws)
|
|
|
|
{
|
|
|
|
auto wb_rel = get_manifest().get_relationship(path("/"), relationship_type::office_document);
|
|
|
|
auto ws_rel = get_manifest().get_relationship(wb_rel.get_target().get_path(),
|
|
|
|
d_->sheet_title_rel_id_map_.at(ws.get_title()));
|
|
|
|
path ws_path(ws_rel.get_source().get_path().parent().append(ws_rel.get_target().get_path()));
|
|
|
|
|
|
|
|
if (!get_manifest().has_relationship(ws_path, relationship_type::vml_drawing))
|
|
|
|
{
|
|
|
|
std::size_t file_number = 1;
|
|
|
|
path filename("vmlDrawing1.vml");
|
|
|
|
|
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
bool filename_exists = false;
|
|
|
|
|
|
|
|
for (auto current_ws_rel : get_manifest().get_relationships(wb_rel.get_target().get_path(), xlnt::relationship_type::worksheet))
|
|
|
|
{
|
|
|
|
path current_ws_path(current_ws_rel.get_source().get_path().parent().append(current_ws_rel.get_target().get_path()));
|
|
|
|
if (!get_manifest().has_relationship(current_ws_path, xlnt::relationship_type::vml_drawing)) break;
|
|
|
|
|
|
|
|
for (auto current_ws_child_rel : get_manifest().get_relationships(current_ws_path, xlnt::relationship_type::vml_drawing))
|
|
|
|
{
|
|
|
|
if (current_ws_child_rel.get_target().get_path() == path("../drawings").append(filename))
|
|
|
|
{
|
|
|
|
filename_exists = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (filename_exists)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!filename_exists) break;
|
|
|
|
|
|
|
|
file_number++;
|
|
|
|
filename = path("vmlDrawing" + std::to_string(file_number) + ".vml");
|
|
|
|
}
|
|
|
|
|
|
|
|
get_manifest().register_default_type("vml",
|
|
|
|
"application/vnd.openxmlformats-officedocument.vmlDrawing");
|
|
|
|
|
|
|
|
const path relative_path(path("../drawings").append(filename));
|
|
|
|
get_manifest().register_relationship(uri(ws_path.string()),
|
|
|
|
relationship::type::vml_drawing, uri(relative_path.string()), target_mode::internal);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!get_manifest().has_relationship(ws_path, relationship_type::comments))
|
|
|
|
{
|
|
|
|
std::size_t file_number = 1;
|
|
|
|
path filename("comments1.xml");
|
|
|
|
|
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
if (!get_manifest().has_override_type(constants::package_xl().append(filename))) break;
|
|
|
|
|
|
|
|
file_number++;
|
|
|
|
filename = path("comments" + std::to_string(file_number) + ".xml");
|
|
|
|
}
|
|
|
|
|
|
|
|
const path absolute_path(constants::package_xl().append(filename));
|
|
|
|
get_manifest().register_override_type(absolute_path,
|
|
|
|
"application/vnd.openxmlformats-officedocument.spreadsheetml.comments+xml");
|
|
|
|
|
|
|
|
const path relative_path(path("..").append(filename));
|
|
|
|
get_manifest().register_relationship(uri(ws_path.string()),
|
|
|
|
relationship::type::comments, uri(relative_path.string()), target_mode::internal);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-05 13:52:05 +08:00
|
|
|
const worksheet workbook::get_sheet_by_title(const std::string &title) const
|
2014-05-21 22:20:30 +08:00
|
|
|
{
|
2015-11-01 22:43:01 +08:00
|
|
|
for (auto &impl : d_->worksheets_)
|
2014-05-21 22:20:30 +08:00
|
|
|
{
|
2016-08-05 13:52:05 +08:00
|
|
|
if (impl.title_ == title)
|
2014-06-13 05:04:37 +08:00
|
|
|
{
|
|
|
|
return worksheet(&impl);
|
|
|
|
}
|
2014-05-21 22:20:30 +08:00
|
|
|
}
|
2014-05-30 08:52:14 +08:00
|
|
|
|
2016-07-30 06:55:49 +08:00
|
|
|
throw key_not_found();
|
2014-05-30 08:52:14 +08:00
|
|
|
}
|
|
|
|
|
2016-08-05 13:52:05 +08:00
|
|
|
worksheet workbook::get_sheet_by_title(const std::string &title)
|
2016-05-26 10:05:30 +08:00
|
|
|
{
|
2016-07-22 11:04:36 +08:00
|
|
|
for (auto &impl : d_->worksheets_)
|
|
|
|
{
|
2016-08-05 13:52:05 +08:00
|
|
|
if (impl.title_ == title)
|
2016-07-22 11:04:36 +08:00
|
|
|
{
|
|
|
|
return worksheet(&impl);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-30 06:55:49 +08:00
|
|
|
throw key_not_found();
|
2016-05-26 10:05:30 +08:00
|
|
|
}
|
|
|
|
|
2014-05-30 08:52:14 +08:00
|
|
|
worksheet workbook::get_sheet_by_index(std::size_t index)
|
|
|
|
{
|
2016-08-03 12:12:18 +08:00
|
|
|
auto iter = d_->worksheets_.begin();
|
|
|
|
|
|
|
|
for (std::size_t i = 0; i < index; ++i, ++iter)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
return worksheet(&*iter);
|
2014-05-30 08:52:14 +08:00
|
|
|
}
|
2015-11-01 22:43:01 +08:00
|
|
|
|
2014-05-30 08:52:14 +08:00
|
|
|
const worksheet workbook::get_sheet_by_index(std::size_t index) const
|
|
|
|
{
|
2016-08-03 12:12:18 +08:00
|
|
|
auto iter = d_->worksheets_.begin();
|
|
|
|
|
|
|
|
for (std::size_t i = 0; i < index; ++i, ++iter)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
return worksheet(&*iter);
|
2014-05-21 22:20:30 +08:00
|
|
|
}
|
|
|
|
|
2016-08-05 13:52:05 +08:00
|
|
|
worksheet workbook::get_sheet_by_id(std::size_t id)
|
|
|
|
{
|
|
|
|
for (auto &impl : d_->worksheets_)
|
|
|
|
{
|
|
|
|
if (impl.id_ == id)
|
|
|
|
{
|
|
|
|
return worksheet(&impl);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
throw key_not_found();
|
|
|
|
}
|
|
|
|
|
|
|
|
const worksheet workbook::get_sheet_by_id(std::size_t id) const
|
|
|
|
{
|
|
|
|
for (auto &impl : d_->worksheets_)
|
|
|
|
{
|
|
|
|
if (impl.id_ == id)
|
|
|
|
{
|
|
|
|
return worksheet(&impl);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
throw key_not_found();
|
|
|
|
}
|
|
|
|
|
2014-05-21 22:20:30 +08:00
|
|
|
worksheet workbook::get_active_sheet()
|
|
|
|
{
|
2016-08-03 12:12:18 +08:00
|
|
|
return get_sheet_by_index(d_->active_sheet_index_);
|
2014-05-21 22:20:30 +08:00
|
|
|
}
|
|
|
|
|
2015-11-11 07:58:54 +08:00
|
|
|
bool workbook::has_named_range(const std::string &name) const
|
2014-05-21 22:20:30 +08:00
|
|
|
{
|
2015-11-01 22:43:01 +08:00
|
|
|
for (auto worksheet : *this)
|
2014-05-21 22:20:30 +08:00
|
|
|
{
|
2015-11-01 22:43:01 +08:00
|
|
|
if (worksheet.has_named_range(name))
|
2014-05-21 22:20:30 +08:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
worksheet workbook::create_sheet()
|
2015-11-01 22:43:01 +08:00
|
|
|
{
|
2016-08-13 11:06:25 +08:00
|
|
|
std::string title = "Sheet1";
|
|
|
|
int index = 1;
|
2014-05-30 08:52:14 +08:00
|
|
|
|
2016-07-22 11:04:36 +08:00
|
|
|
while (contains(title))
|
2014-05-21 22:20:30 +08:00
|
|
|
{
|
2015-11-11 07:58:54 +08:00
|
|
|
title = "Sheet" + std::to_string(++index);
|
2014-05-21 22:20:30 +08:00
|
|
|
}
|
2014-06-10 12:29:49 +08:00
|
|
|
|
2016-07-27 08:13:09 +08:00
|
|
|
auto sheet_id = d_->worksheets_.size() + 1;
|
|
|
|
std::string sheet_filename = "sheet" + std::to_string(sheet_id) + ".xml";
|
|
|
|
|
|
|
|
d_->worksheets_.push_back(detail::worksheet_impl(this, sheet_id, title));
|
2016-08-05 13:52:05 +08:00
|
|
|
|
2016-08-12 12:22:14 +08:00
|
|
|
auto workbook_rel = d_->manifest_.get_relationship(path("/"), relationship::type::office_document);
|
2016-09-06 10:17:36 +08:00
|
|
|
uri relative_sheet_uri(path("worksheets").append(sheet_filename).string());
|
|
|
|
auto absolute_sheet_path = path("/xl").append(relative_sheet_uri.get_path());
|
|
|
|
d_->manifest_.register_override_type(absolute_sheet_path,
|
2016-08-06 22:40:17 +08:00
|
|
|
"application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml");
|
2016-08-12 12:22:14 +08:00
|
|
|
auto ws_rel = d_->manifest_.register_relationship(workbook_rel.get_target(),
|
2016-09-06 10:17:36 +08:00
|
|
|
relationship::type::worksheet, relative_sheet_uri, target_mode::internal);
|
2016-08-06 22:40:17 +08:00
|
|
|
d_->sheet_title_rel_id_map_[title] = ws_rel;
|
2015-11-01 22:43:01 +08:00
|
|
|
|
|
|
|
return worksheet(&d_->worksheets_.back());
|
2014-05-21 22:20:30 +08:00
|
|
|
}
|
|
|
|
|
2016-08-16 12:23:49 +08:00
|
|
|
void workbook::copy_sheet(worksheet to_copy)
|
2014-05-21 22:20:30 +08:00
|
|
|
{
|
2016-08-16 12:23:49 +08:00
|
|
|
if(to_copy.d_->parent_ != this) throw invalid_parameter();
|
2016-03-08 11:35:22 +08:00
|
|
|
|
2016-08-16 12:23:49 +08:00
|
|
|
detail::worksheet_impl impl(*to_copy.d_);
|
2016-07-18 02:59:11 +08:00
|
|
|
auto new_sheet = create_sheet();
|
|
|
|
impl.title_ = new_sheet.get_title();
|
|
|
|
*new_sheet.d_ = impl;
|
2014-05-21 22:20:30 +08:00
|
|
|
}
|
|
|
|
|
2016-08-16 12:23:49 +08:00
|
|
|
void workbook::copy_sheet(worksheet to_copy, std::size_t index)
|
2014-05-21 22:20:30 +08:00
|
|
|
{
|
2016-08-16 12:23:49 +08:00
|
|
|
copy_sheet(to_copy);
|
2016-07-22 10:14:00 +08:00
|
|
|
|
|
|
|
if (index != d_->worksheets_.size() - 1)
|
|
|
|
{
|
2016-08-03 12:12:18 +08:00
|
|
|
auto iter = d_->worksheets_.begin();
|
|
|
|
|
|
|
|
for (std::size_t i = 0; i < index; ++i, ++iter)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
d_->worksheets_.insert(iter, d_->worksheets_.back());
|
2016-07-22 10:14:00 +08:00
|
|
|
d_->worksheets_.pop_back();
|
|
|
|
}
|
2014-05-21 22:20:30 +08:00
|
|
|
}
|
|
|
|
|
2016-08-16 12:23:49 +08:00
|
|
|
std::size_t workbook::get_index(worksheet ws)
|
2014-05-21 22:20:30 +08:00
|
|
|
{
|
2016-08-16 12:23:49 +08:00
|
|
|
auto match = std::find(begin(), end(), ws);
|
2016-07-22 10:14:00 +08:00
|
|
|
|
|
|
|
if (match == end())
|
2014-05-21 22:20:30 +08:00
|
|
|
{
|
2016-08-16 12:23:49 +08:00
|
|
|
throw invalid_parameter();
|
2014-05-21 22:20:30 +08:00
|
|
|
}
|
2016-07-22 10:14:00 +08:00
|
|
|
|
2016-11-01 08:48:43 +08:00
|
|
|
return static_cast<std::size_t>(std::distance(begin(), match));
|
2014-05-21 22:20:30 +08:00
|
|
|
}
|
|
|
|
|
2015-11-11 08:47:31 +08:00
|
|
|
void workbook::create_named_range(const std::string &name, worksheet range_owner, const std::string &reference_string)
|
|
|
|
{
|
|
|
|
create_named_range(name, range_owner, range_reference(reference_string));
|
|
|
|
}
|
|
|
|
|
2015-11-11 07:58:54 +08:00
|
|
|
void workbook::create_named_range(const std::string &name, worksheet range_owner, const range_reference &reference)
|
2014-05-21 22:20:30 +08:00
|
|
|
{
|
2016-08-05 13:52:05 +08:00
|
|
|
get_sheet_by_title(range_owner.get_title()).create_named_range(name, reference);
|
2014-05-21 22:20:30 +08:00
|
|
|
}
|
|
|
|
|
2015-11-11 07:58:54 +08:00
|
|
|
void workbook::remove_named_range(const std::string &name)
|
2014-05-21 22:20:30 +08:00
|
|
|
{
|
2015-11-01 22:43:01 +08:00
|
|
|
for (auto ws : *this)
|
2014-05-21 22:20:30 +08:00
|
|
|
{
|
2015-11-01 22:43:01 +08:00
|
|
|
if (ws.has_named_range(name))
|
2014-05-21 22:20:30 +08:00
|
|
|
{
|
2014-05-30 08:52:14 +08:00
|
|
|
ws.remove_named_range(name);
|
2014-05-21 22:20:30 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2015-11-01 22:43:01 +08:00
|
|
|
|
2016-08-16 12:23:49 +08:00
|
|
|
throw key_not_found();
|
2014-05-21 22:20:30 +08:00
|
|
|
}
|
|
|
|
|
2015-11-11 07:58:54 +08:00
|
|
|
range workbook::get_named_range(const std::string &name)
|
2014-05-21 22:20:30 +08:00
|
|
|
{
|
2015-11-01 22:43:01 +08:00
|
|
|
for (auto ws : *this)
|
2014-05-21 22:20:30 +08:00
|
|
|
{
|
2015-11-01 22:43:01 +08:00
|
|
|
if (ws.has_named_range(name))
|
2014-05-21 22:20:30 +08:00
|
|
|
{
|
2014-05-30 08:52:14 +08:00
|
|
|
return ws.get_named_range(name);
|
2014-05-21 22:20:30 +08:00
|
|
|
}
|
|
|
|
}
|
2015-11-01 22:43:01 +08:00
|
|
|
|
2016-08-16 12:23:49 +08:00
|
|
|
throw key_not_found();
|
2014-05-21 22:20:30 +08:00
|
|
|
}
|
|
|
|
|
2016-08-05 13:52:05 +08:00
|
|
|
void workbook::load(std::istream &stream)
|
2014-06-13 05:04:37 +08:00
|
|
|
{
|
2016-08-14 02:45:26 +08:00
|
|
|
clear();
|
2016-08-05 13:52:05 +08:00
|
|
|
detail::xlsx_consumer consumer(*this);
|
|
|
|
consumer.read(stream);
|
2014-06-13 05:04:37 +08:00
|
|
|
}
|
2015-11-01 22:43:01 +08:00
|
|
|
|
2016-10-10 19:28:49 +08:00
|
|
|
void workbook::load(const std::vector<std::uint8_t> &data)
|
2014-06-05 06:42:17 +08:00
|
|
|
{
|
2016-10-31 03:48:40 +08:00
|
|
|
xlnt::detail::vector_istreambuf data_buffer(data);
|
|
|
|
std::istream data_stream(&data_buffer);
|
2016-10-31 09:17:51 +08:00
|
|
|
load(data_stream);
|
2014-06-05 06:42:17 +08:00
|
|
|
}
|
|
|
|
|
2016-08-05 13:52:05 +08:00
|
|
|
void workbook::load(const std::string &filename)
|
2014-05-21 22:20:30 +08:00
|
|
|
{
|
2016-08-03 12:12:18 +08:00
|
|
|
return load(path(filename));
|
|
|
|
}
|
2015-10-30 07:37:07 +08:00
|
|
|
|
2016-08-05 13:52:05 +08:00
|
|
|
void workbook::load(const path &filename)
|
2016-08-03 12:12:18 +08:00
|
|
|
{
|
2016-11-08 10:11:30 +08:00
|
|
|
std::ifstream file_stream;
|
|
|
|
open_stream(file_stream, filename.string());
|
2016-10-31 09:17:51 +08:00
|
|
|
load(file_stream);
|
2014-05-21 22:20:30 +08:00
|
|
|
}
|
2014-06-14 05:06:23 +08:00
|
|
|
|
2016-10-10 19:28:49 +08:00
|
|
|
void workbook::load(const std::string &filename, const std::string &password)
|
|
|
|
{
|
|
|
|
return load(path(filename), password);
|
|
|
|
}
|
|
|
|
|
|
|
|
void workbook::load(const path &filename, const std::string &password)
|
|
|
|
{
|
2016-11-08 10:11:30 +08:00
|
|
|
std::ifstream file_stream;
|
|
|
|
open_stream(file_stream, filename.string());
|
2016-10-10 19:28:49 +08:00
|
|
|
return load(file_stream, password);
|
|
|
|
}
|
|
|
|
|
|
|
|
void workbook::load(const std::vector<std::uint8_t> &data, const std::string &password)
|
|
|
|
{
|
2016-10-31 03:48:40 +08:00
|
|
|
xlnt::detail::vector_istreambuf data_buffer(data);
|
|
|
|
std::istream data_stream(&data_buffer);
|
2016-10-31 09:17:51 +08:00
|
|
|
load(data_stream, password);
|
2016-10-10 19:28:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void workbook::load(std::istream &stream, const std::string &password)
|
|
|
|
{
|
|
|
|
clear();
|
|
|
|
detail::xlsx_consumer consumer(*this);
|
|
|
|
consumer.read(stream, password);
|
|
|
|
}
|
|
|
|
|
|
|
|
void workbook::save(std::vector<std::uint8_t> &data) const
|
2014-07-25 05:31:46 +08:00
|
|
|
{
|
2016-10-31 03:48:40 +08:00
|
|
|
xlnt::detail::vector_ostreambuf data_buffer(data);
|
|
|
|
std::ostream data_stream(&data_buffer);
|
|
|
|
save(data_stream);
|
2014-07-25 05:31:46 +08:00
|
|
|
}
|
|
|
|
|
2016-08-06 22:40:17 +08:00
|
|
|
void workbook::save(const std::string &filename) const
|
2014-07-25 05:31:46 +08:00
|
|
|
{
|
2016-08-05 13:52:05 +08:00
|
|
|
return save(path(filename));
|
2014-07-25 05:31:46 +08:00
|
|
|
}
|
|
|
|
|
2016-08-06 22:40:17 +08:00
|
|
|
void workbook::save(const path &filename) const
|
2014-06-14 05:06:23 +08:00
|
|
|
{
|
2016-11-08 10:11:30 +08:00
|
|
|
std::ofstream file_stream;
|
|
|
|
open_stream(file_stream, filename.string());
|
2016-10-31 03:48:40 +08:00
|
|
|
save(file_stream);
|
2014-06-14 05:06:23 +08:00
|
|
|
}
|
|
|
|
|
2016-08-06 22:40:17 +08:00
|
|
|
void workbook::save(std::ostream &stream) const
|
2016-05-16 03:03:02 +08:00
|
|
|
{
|
2016-08-05 13:52:05 +08:00
|
|
|
detail::xlsx_producer producer(*this);
|
|
|
|
producer.write(stream);
|
2016-05-16 03:03:02 +08:00
|
|
|
}
|
|
|
|
|
2016-11-08 10:55:40 +08:00
|
|
|
void workbook::save(std::ostream &stream, const std::string &password)
|
|
|
|
{
|
|
|
|
detail::xlsx_producer producer(*this);
|
|
|
|
producer.write(stream, password);
|
|
|
|
}
|
|
|
|
|
2016-11-20 08:41:21 +08:00
|
|
|
#ifdef _MSC_VER
|
2016-10-31 09:17:51 +08:00
|
|
|
void workbook::save(const std::wstring &filename)
|
|
|
|
{
|
2016-11-08 10:11:30 +08:00
|
|
|
std::ofstream file_stream;
|
|
|
|
open_stream(file_stream, filename);
|
2016-10-31 09:17:51 +08:00
|
|
|
save(file_stream);
|
|
|
|
}
|
|
|
|
|
2016-11-08 10:11:30 +08:00
|
|
|
void workbook::save(const std::wstring &filename, const std::string &password)
|
|
|
|
{
|
|
|
|
std::ofstream file_stream;
|
|
|
|
open_stream(file_stream, filename);
|
|
|
|
save(file_stream, password);
|
|
|
|
}
|
|
|
|
|
2016-10-31 09:17:51 +08:00
|
|
|
void workbook::load(const std::wstring &filename)
|
|
|
|
{
|
2016-11-08 10:11:30 +08:00
|
|
|
std::ifstream file_stream;
|
|
|
|
open_stream(file_stream, filename);
|
|
|
|
load(file_stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
void workbook::load(const std::wstring &filename, const std::string &password)
|
|
|
|
{
|
|
|
|
std::ifstream file_stream;
|
|
|
|
open_stream(file_stream, filename);
|
2016-11-08 10:55:40 +08:00
|
|
|
load(file_stream, password);
|
2016-10-31 09:17:51 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-08-05 13:52:05 +08:00
|
|
|
void workbook::set_guess_types(bool guess)
|
2014-06-14 05:06:23 +08:00
|
|
|
{
|
2016-08-05 13:52:05 +08:00
|
|
|
d_->guess_types_ = guess;
|
|
|
|
}
|
2014-06-14 05:06:23 +08:00
|
|
|
|
2016-08-05 13:52:05 +08:00
|
|
|
bool workbook::get_guess_types() const
|
|
|
|
{
|
|
|
|
return d_->guess_types_;
|
2014-06-14 05:06:23 +08:00
|
|
|
}
|
2015-11-01 22:43:01 +08:00
|
|
|
|
2014-05-21 22:20:30 +08:00
|
|
|
void workbook::remove_sheet(worksheet ws)
|
|
|
|
{
|
2015-11-01 22:43:01 +08:00
|
|
|
auto match_iter = std::find_if(d_->worksheets_.begin(), d_->worksheets_.end(),
|
2016-10-23 01:53:44 +08:00
|
|
|
[=](detail::worksheet_impl &comp) { return &comp == ws.d_; });
|
2014-05-30 08:52:14 +08:00
|
|
|
|
2015-11-01 22:43:01 +08:00
|
|
|
if (match_iter == d_->worksheets_.end())
|
2014-05-21 22:20:30 +08:00
|
|
|
{
|
2016-08-16 12:23:49 +08:00
|
|
|
throw invalid_parameter();
|
2014-05-21 22:20:30 +08:00
|
|
|
}
|
2015-11-01 22:43:01 +08:00
|
|
|
|
2016-10-23 01:53:44 +08:00
|
|
|
auto ws_rel_id = d_->sheet_title_rel_id_map_.at(ws.get_title());
|
|
|
|
auto wb_rel = d_->manifest_.get_relationship(xlnt::path("/"), xlnt::relationship_type::office_document);
|
|
|
|
auto ws_rel = d_->manifest_.get_relationship(wb_rel.get_target().get_path(), ws_rel_id);
|
|
|
|
d_->manifest_.unregister_override_type(ws_rel.get_target().get_path());
|
|
|
|
d_->manifest_.unregister_relationship(wb_rel.get_target(), ws_rel_id);;
|
|
|
|
d_->sheet_title_rel_id_map_.erase(ws.get_title());
|
2014-05-30 08:52:14 +08:00
|
|
|
d_->worksheets_.erase(match_iter);
|
2014-05-21 22:20:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
worksheet workbook::create_sheet(std::size_t index)
|
|
|
|
{
|
2014-05-30 08:52:14 +08:00
|
|
|
create_sheet();
|
2015-11-01 22:43:01 +08:00
|
|
|
|
|
|
|
if (index != d_->worksheets_.size() - 1)
|
|
|
|
{
|
2016-08-03 12:12:18 +08:00
|
|
|
auto iter = d_->worksheets_.begin();
|
|
|
|
|
|
|
|
for (std::size_t i = 0; i < index; ++i, ++iter)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
d_->worksheets_.insert(iter, d_->worksheets_.back());
|
2016-07-18 03:20:20 +08:00
|
|
|
d_->worksheets_.pop_back();
|
2015-11-01 22:43:01 +08:00
|
|
|
}
|
|
|
|
|
2016-08-03 12:12:18 +08:00
|
|
|
return get_sheet_by_index(index);
|
2014-05-21 22:20:30 +08:00
|
|
|
}
|
|
|
|
|
2016-08-02 06:33:43 +08:00
|
|
|
worksheet workbook::create_sheet_with_rel(const std::string &title, const relationship &rel)
|
2016-07-27 08:13:09 +08:00
|
|
|
{
|
|
|
|
auto sheet_id = d_->worksheets_.size() + 1;
|
|
|
|
d_->worksheets_.push_back(detail::worksheet_impl(this, sheet_id, title));
|
|
|
|
|
2016-11-01 09:53:22 +08:00
|
|
|
auto workbook_rel = d_->manifest_.get_relationship(path("/"), relationship::type::office_document);
|
|
|
|
auto sheet_absoulute_path = workbook_rel.get_target().get_path().parent().append(rel.get_target().get_path());
|
|
|
|
d_->manifest_.register_override_type(sheet_absoulute_path,
|
|
|
|
"application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml");
|
|
|
|
auto ws_rel = d_->manifest_.register_relationship(workbook_rel.get_target(),
|
|
|
|
relationship::type::worksheet, rel.get_target(), target_mode::internal);
|
|
|
|
d_->sheet_title_rel_id_map_[title] = ws_rel;
|
|
|
|
|
2016-07-27 08:13:09 +08:00
|
|
|
return worksheet(&d_->worksheets_.back());
|
|
|
|
}
|
|
|
|
|
2014-05-30 08:52:14 +08:00
|
|
|
workbook::iterator workbook::begin()
|
2014-05-21 22:20:30 +08:00
|
|
|
{
|
2014-05-30 08:52:14 +08:00
|
|
|
return iterator(*this, 0);
|
2014-05-21 22:20:30 +08:00
|
|
|
}
|
|
|
|
|
2014-05-30 08:52:14 +08:00
|
|
|
workbook::iterator workbook::end()
|
2014-05-21 22:20:30 +08:00
|
|
|
{
|
2014-05-30 08:52:14 +08:00
|
|
|
return iterator(*this, d_->worksheets_.size());
|
|
|
|
}
|
|
|
|
|
2015-11-23 01:41:27 +08:00
|
|
|
workbook::const_iterator workbook::begin() const
|
|
|
|
{
|
|
|
|
return cbegin();
|
|
|
|
}
|
|
|
|
|
|
|
|
workbook::const_iterator workbook::end() const
|
|
|
|
{
|
|
|
|
return cend();
|
|
|
|
}
|
|
|
|
|
2014-05-30 08:52:14 +08:00
|
|
|
workbook::const_iterator workbook::cbegin() const
|
|
|
|
{
|
|
|
|
return const_iterator(*this, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
workbook::const_iterator workbook::cend() const
|
|
|
|
{
|
|
|
|
return const_iterator(*this, d_->worksheets_.size());
|
2014-05-21 22:20:30 +08:00
|
|
|
}
|
|
|
|
|
2016-08-02 06:33:43 +08:00
|
|
|
std::vector<std::string> workbook::get_sheet_titles() const
|
2014-05-21 22:20:30 +08:00
|
|
|
{
|
2015-11-11 07:58:54 +08:00
|
|
|
std::vector<std::string> names;
|
2015-11-01 22:43:01 +08:00
|
|
|
|
|
|
|
for (auto ws : *this)
|
2014-05-21 22:20:30 +08:00
|
|
|
{
|
|
|
|
names.push_back(ws.get_title());
|
|
|
|
}
|
2015-11-01 22:43:01 +08:00
|
|
|
|
2014-05-21 22:20:30 +08:00
|
|
|
return names;
|
|
|
|
}
|
|
|
|
|
2016-08-14 02:45:26 +08:00
|
|
|
std::size_t workbook::get_sheet_count() const
|
|
|
|
{
|
|
|
|
return d_->worksheets_.size();
|
|
|
|
}
|
|
|
|
|
2015-11-11 07:58:54 +08:00
|
|
|
worksheet workbook::operator[](const std::string &name)
|
2014-05-21 22:20:30 +08:00
|
|
|
{
|
2016-08-05 13:52:05 +08:00
|
|
|
return get_sheet_by_title(name);
|
2014-05-21 22:20:30 +08:00
|
|
|
}
|
|
|
|
|
2014-06-11 05:12:15 +08:00
|
|
|
worksheet workbook::operator[](std::size_t index)
|
2014-05-21 22:20:30 +08:00
|
|
|
{
|
2016-08-03 12:12:18 +08:00
|
|
|
return get_sheet_by_index(index);
|
2014-05-21 22:20:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void workbook::clear()
|
|
|
|
{
|
2016-08-14 02:45:26 +08:00
|
|
|
*d_ = detail::workbook_impl();
|
2016-09-10 22:05:06 +08:00
|
|
|
d_->stylesheet_.clear();
|
2014-05-21 22:20:30 +08:00
|
|
|
}
|
|
|
|
|
2016-07-22 10:14:00 +08:00
|
|
|
bool workbook::operator==(const workbook &rhs) const
|
2014-07-20 04:59:05 +08:00
|
|
|
{
|
2016-07-22 10:14:00 +08:00
|
|
|
return d_.get() == rhs.d_.get();
|
2014-07-20 04:59:05 +08:00
|
|
|
}
|
|
|
|
|
2016-07-22 10:14:00 +08:00
|
|
|
bool workbook::operator!=(const workbook &rhs) const
|
2014-05-21 22:20:30 +08:00
|
|
|
{
|
2016-07-22 10:14:00 +08:00
|
|
|
return d_.get() != rhs.d_.get();
|
2014-05-21 22:20:30 +08:00
|
|
|
}
|
2014-06-16 01:06:47 +08:00
|
|
|
|
2014-07-24 08:51:28 +08:00
|
|
|
void swap(workbook &left, workbook &right)
|
2014-07-20 04:59:05 +08:00
|
|
|
{
|
2014-07-24 08:51:28 +08:00
|
|
|
using std::swap;
|
|
|
|
swap(left.d_, right.d_);
|
2015-11-01 22:43:01 +08:00
|
|
|
|
2016-08-03 12:12:18 +08:00
|
|
|
if (left.d_ != nullptr)
|
|
|
|
{
|
|
|
|
for (auto ws : left)
|
|
|
|
{
|
|
|
|
ws.set_parent(left);
|
|
|
|
}
|
2016-11-04 07:26:11 +08:00
|
|
|
|
|
|
|
left.d_->stylesheet_.parent = &left;
|
2016-08-03 12:12:18 +08:00
|
|
|
}
|
2015-11-01 22:43:01 +08:00
|
|
|
|
2016-08-03 12:12:18 +08:00
|
|
|
if (right.d_ != nullptr)
|
|
|
|
{
|
|
|
|
for (auto ws : right)
|
|
|
|
{
|
|
|
|
ws.set_parent(right);
|
|
|
|
}
|
2016-11-04 07:26:11 +08:00
|
|
|
|
|
|
|
right.d_->stylesheet_.parent = &right;
|
2016-08-03 12:12:18 +08:00
|
|
|
}
|
2014-07-24 08:51:28 +08:00
|
|
|
}
|
2015-11-01 22:43:01 +08:00
|
|
|
|
2014-07-24 08:51:28 +08:00
|
|
|
workbook &workbook::operator=(workbook other)
|
|
|
|
{
|
|
|
|
swap(*this, other);
|
2016-11-04 07:26:11 +08:00
|
|
|
d_->stylesheet_.parent = this;
|
2014-07-24 08:51:28 +08:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2016-08-03 12:12:18 +08:00
|
|
|
workbook::workbook(workbook &&other) : workbook(nullptr)
|
2014-07-24 08:51:28 +08:00
|
|
|
{
|
|
|
|
swap(*this, other);
|
|
|
|
}
|
2015-11-01 22:43:01 +08:00
|
|
|
|
2014-07-24 08:51:28 +08:00
|
|
|
workbook::workbook(const workbook &other) : workbook()
|
|
|
|
{
|
|
|
|
*d_.get() = *other.d_.get();
|
2015-11-01 22:43:01 +08:00
|
|
|
|
|
|
|
for (auto ws : *this)
|
2014-07-24 08:51:28 +08:00
|
|
|
{
|
|
|
|
ws.set_parent(*this);
|
|
|
|
}
|
2016-11-04 07:26:11 +08:00
|
|
|
|
|
|
|
d_->stylesheet_.parent = this;
|
2014-07-20 04:59:05 +08:00
|
|
|
}
|
|
|
|
|
2016-05-04 03:37:34 +08:00
|
|
|
workbook::~workbook()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-07-25 05:31:46 +08:00
|
|
|
bool workbook::get_data_only() const
|
|
|
|
{
|
|
|
|
return d_->data_only_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void workbook::set_data_only(bool data_only)
|
|
|
|
{
|
|
|
|
d_->data_only_ = data_only;
|
|
|
|
}
|
2015-10-19 03:30:46 +08:00
|
|
|
|
2016-08-03 12:12:18 +08:00
|
|
|
bool workbook::has_theme() const
|
2015-10-19 03:30:46 +08:00
|
|
|
{
|
2016-08-03 12:12:18 +08:00
|
|
|
return d_->has_theme_;
|
2015-10-19 03:30:46 +08:00
|
|
|
}
|
|
|
|
|
2016-08-03 12:12:18 +08:00
|
|
|
const theme &workbook::get_theme() const
|
2015-10-19 03:30:46 +08:00
|
|
|
{
|
2015-10-30 07:37:07 +08:00
|
|
|
return d_->theme_;
|
2015-10-19 03:30:46 +08:00
|
|
|
}
|
|
|
|
|
2016-08-03 12:12:18 +08:00
|
|
|
void workbook::set_theme(const theme &value)
|
|
|
|
{
|
2016-08-16 12:23:49 +08:00
|
|
|
register_theme_in_manifest();
|
2016-08-03 12:12:18 +08:00
|
|
|
d_->has_theme_ = true;
|
|
|
|
d_->theme_ = value;
|
|
|
|
}
|
|
|
|
|
2015-10-19 03:30:46 +08:00
|
|
|
std::vector<named_range> workbook::get_named_ranges() const
|
|
|
|
{
|
|
|
|
std::vector<named_range> named_ranges;
|
2015-11-01 22:43:01 +08:00
|
|
|
|
|
|
|
for (auto ws : *this)
|
2015-10-14 01:56:07 +08:00
|
|
|
{
|
2015-11-01 22:43:01 +08:00
|
|
|
for (auto &ws_named_range : ws.d_->named_ranges_)
|
2015-10-19 03:30:46 +08:00
|
|
|
{
|
|
|
|
named_ranges.push_back(ws_named_range.second);
|
|
|
|
}
|
2015-10-14 01:56:07 +08:00
|
|
|
}
|
2015-11-01 22:43:01 +08:00
|
|
|
|
2015-10-19 03:30:46 +08:00
|
|
|
return named_ranges;
|
|
|
|
}
|
|
|
|
|
2016-11-10 08:52:18 +08:00
|
|
|
format workbook::create_format(bool default_format)
|
2016-06-11 01:40:50 +08:00
|
|
|
{
|
2016-11-03 10:04:51 +08:00
|
|
|
register_stylesheet_in_manifest();
|
2016-11-10 08:52:18 +08:00
|
|
|
return d_->stylesheet_.create_format(default_format);
|
2016-06-11 01:40:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool workbook::has_style(const std::string &name) const
|
|
|
|
{
|
2016-08-16 12:23:49 +08:00
|
|
|
return d_->stylesheet_.has_style(name);
|
2015-10-24 02:42:36 +08:00
|
|
|
}
|
2015-11-01 22:43:01 +08:00
|
|
|
|
2016-05-16 03:03:02 +08:00
|
|
|
void workbook::clear_styles()
|
|
|
|
{
|
2016-06-11 01:40:50 +08:00
|
|
|
apply_to_cells([](cell c) { c.clear_style(); });
|
2016-05-16 03:03:02 +08:00
|
|
|
}
|
|
|
|
|
2016-05-15 01:57:07 +08:00
|
|
|
void workbook::clear_formats()
|
2016-05-14 02:40:17 +08:00
|
|
|
{
|
2016-06-11 01:40:50 +08:00
|
|
|
apply_to_cells([](cell c) { c.clear_format(); });
|
|
|
|
}
|
|
|
|
|
|
|
|
void workbook::apply_to_cells(std::function<void(cell)> f)
|
|
|
|
{
|
|
|
|
for (auto ws : *this)
|
|
|
|
{
|
2016-11-08 10:11:30 +08:00
|
|
|
for (auto row = ws.get_lowest_row(); row <= ws.get_highest_row(); ++row)
|
2016-06-11 01:40:50 +08:00
|
|
|
{
|
2016-11-08 10:11:30 +08:00
|
|
|
for (auto column = ws.get_lowest_column(); column <= ws.get_highest_column(); ++column)
|
2016-06-11 01:40:50 +08:00
|
|
|
{
|
2016-11-08 10:11:30 +08:00
|
|
|
if (ws.has_cell(cell_reference(column, row)))
|
|
|
|
{
|
|
|
|
f.operator()(ws.get_cell(cell_reference(column, row)));
|
|
|
|
}
|
2016-06-11 01:40:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-05-14 02:40:17 +08:00
|
|
|
}
|
|
|
|
|
2016-11-08 10:11:30 +08:00
|
|
|
format workbook::get_format(std::size_t format_index)
|
2015-10-29 03:08:54 +08:00
|
|
|
{
|
2016-08-16 12:23:49 +08:00
|
|
|
return d_->stylesheet_.get_format(format_index);
|
2015-10-29 03:08:54 +08:00
|
|
|
}
|
|
|
|
|
2016-11-08 10:11:30 +08:00
|
|
|
const format workbook::get_format(std::size_t format_index) const
|
2015-10-29 03:08:54 +08:00
|
|
|
{
|
2016-08-16 12:23:49 +08:00
|
|
|
return d_->stylesheet_.get_format(format_index);
|
2015-10-29 03:08:54 +08:00
|
|
|
}
|
2015-10-30 01:46:56 +08:00
|
|
|
|
|
|
|
manifest &workbook::get_manifest()
|
|
|
|
{
|
|
|
|
return d_->manifest_;
|
|
|
|
}
|
2015-11-01 22:43:01 +08:00
|
|
|
|
2015-10-30 01:46:56 +08:00
|
|
|
const manifest &workbook::get_manifest() const
|
|
|
|
{
|
|
|
|
return d_->manifest_;
|
|
|
|
}
|
|
|
|
|
2016-10-29 22:23:04 +08:00
|
|
|
std::vector<formatted_text> &workbook::get_shared_strings()
|
2015-10-31 06:54:04 +08:00
|
|
|
{
|
|
|
|
return d_->shared_strings_;
|
|
|
|
}
|
|
|
|
|
2016-10-29 22:23:04 +08:00
|
|
|
const std::vector<formatted_text> &workbook::get_shared_strings() const
|
2015-10-31 06:54:04 +08:00
|
|
|
{
|
|
|
|
return d_->shared_strings_;
|
|
|
|
}
|
|
|
|
|
2016-10-29 22:23:04 +08:00
|
|
|
void workbook::add_shared_string(const formatted_text &shared, bool allow_duplicates)
|
2015-10-31 06:54:04 +08:00
|
|
|
{
|
2016-08-16 12:23:49 +08:00
|
|
|
register_shared_string_table_in_manifest();
|
2016-07-23 08:26:02 +08:00
|
|
|
|
2016-04-27 01:09:17 +08:00
|
|
|
if (!allow_duplicates)
|
|
|
|
{
|
|
|
|
//TODO: inefficient, use a set or something?
|
|
|
|
for (auto &s : d_->shared_strings_)
|
|
|
|
{
|
|
|
|
if (s == shared) return;
|
|
|
|
}
|
|
|
|
}
|
2015-11-02 12:52:19 +08:00
|
|
|
|
2015-10-31 06:54:04 +08:00
|
|
|
d_->shared_strings_.push_back(shared);
|
|
|
|
}
|
|
|
|
|
2016-03-06 10:39:50 +08:00
|
|
|
bool workbook::contains(const std::string &sheet_title) const
|
|
|
|
{
|
|
|
|
for(auto ws : *this)
|
|
|
|
{
|
|
|
|
if(ws.get_title() == sheet_title) return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-08-06 22:40:17 +08:00
|
|
|
void workbook::set_thumbnail(const std::vector<std::uint8_t> &thumbnail,
|
|
|
|
const std::string &extension, const std::string &content_type)
|
2016-03-10 17:12:51 +08:00
|
|
|
{
|
2016-08-12 12:22:14 +08:00
|
|
|
if (!d_->manifest_.has_relationship(path("/"), relationship::type::thumbnail))
|
|
|
|
{
|
|
|
|
d_->manifest_.register_default_type(extension, content_type);
|
|
|
|
d_->manifest_.register_relationship(uri("/"), relationship::type::thumbnail,
|
|
|
|
uri("docProps/thumbnail.jpeg"), target_mode::internal);
|
|
|
|
}
|
2016-08-06 22:40:17 +08:00
|
|
|
|
2016-03-10 17:12:51 +08:00
|
|
|
d_->thumbnail_.assign(thumbnail.begin(), thumbnail.end());
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::vector<std::uint8_t> &workbook::get_thumbnail() const
|
|
|
|
{
|
|
|
|
return d_->thumbnail_;
|
|
|
|
}
|
|
|
|
|
2016-11-08 10:11:30 +08:00
|
|
|
style workbook::create_style(const std::string &name)
|
2016-05-04 03:37:34 +08:00
|
|
|
{
|
2016-11-08 10:11:30 +08:00
|
|
|
return d_->stylesheet_.create_style(name);
|
2016-05-04 03:37:34 +08:00
|
|
|
}
|
|
|
|
|
2016-11-08 10:11:30 +08:00
|
|
|
style workbook::style(const std::string &name)
|
2016-05-15 23:51:32 +08:00
|
|
|
{
|
2016-11-08 10:11:30 +08:00
|
|
|
return d_->stylesheet_.style(name);
|
2016-05-15 23:51:32 +08:00
|
|
|
}
|
|
|
|
|
2016-11-08 10:11:30 +08:00
|
|
|
const style workbook::style(const std::string &name) const
|
2016-05-15 23:51:32 +08:00
|
|
|
{
|
2016-11-08 10:11:30 +08:00
|
|
|
return d_->stylesheet_.style(name);
|
2016-06-20 02:43:41 +08:00
|
|
|
}
|
|
|
|
|
2016-08-03 12:12:18 +08:00
|
|
|
std::string workbook::get_application() const
|
|
|
|
{
|
|
|
|
return d_->application_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void workbook::set_application(const std::string &application)
|
|
|
|
{
|
|
|
|
d_->write_app_properties_ = true;
|
|
|
|
d_->application_ = application;
|
|
|
|
}
|
|
|
|
|
|
|
|
calendar workbook::get_base_date() const
|
|
|
|
{
|
|
|
|
return d_->base_date_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void workbook::set_base_date(calendar base_date)
|
|
|
|
{
|
|
|
|
d_->base_date_ = base_date;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string workbook::get_creator() const
|
|
|
|
{
|
|
|
|
return d_->creator_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void workbook::set_creator(const std::string &creator)
|
|
|
|
{
|
|
|
|
d_->creator_ = creator;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string workbook::get_last_modified_by() const
|
|
|
|
{
|
|
|
|
return d_->last_modified_by_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void workbook::set_last_modified_by(const std::string &last_modified_by)
|
|
|
|
{
|
|
|
|
d_->last_modified_by_ = last_modified_by;
|
|
|
|
}
|
|
|
|
|
|
|
|
datetime workbook::get_created() const
|
|
|
|
{
|
|
|
|
return d_->created_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void workbook::set_created(const datetime &when)
|
|
|
|
{
|
|
|
|
d_->created_ = when;
|
|
|
|
}
|
|
|
|
|
|
|
|
datetime workbook::get_modified() const
|
|
|
|
{
|
|
|
|
return d_->modified_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void workbook::set_modified(const datetime &when)
|
|
|
|
{
|
|
|
|
d_->modified_ = when;
|
|
|
|
}
|
|
|
|
|
|
|
|
int workbook::get_doc_security() const
|
|
|
|
{
|
|
|
|
return d_->doc_security_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void workbook::set_doc_security(int doc_security)
|
|
|
|
{
|
|
|
|
d_->doc_security_ = doc_security;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool workbook::get_scale_crop() const
|
|
|
|
{
|
|
|
|
return d_->scale_crop_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void workbook::set_scale_crop(bool scale_crop)
|
|
|
|
{
|
|
|
|
d_->scale_crop_ = scale_crop;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string workbook::get_company() const
|
|
|
|
{
|
|
|
|
return d_->company_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void workbook::set_company(const std::string &company)
|
|
|
|
{
|
|
|
|
d_->company_ = company;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool workbook::links_up_to_date() const
|
|
|
|
{
|
|
|
|
return d_->links_up_to_date_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void workbook::set_links_up_to_date(bool links_up_to_date)
|
|
|
|
{
|
|
|
|
d_->links_up_to_date_ = links_up_to_date;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool workbook::is_shared_doc() const
|
|
|
|
{
|
|
|
|
return d_->shared_doc_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void workbook::set_shared_doc(bool shared_doc)
|
|
|
|
{
|
|
|
|
d_->shared_doc_ = shared_doc;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool workbook::hyperlinks_changed() const
|
|
|
|
{
|
|
|
|
return d_->hyperlinks_changed_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void workbook::set_hyperlinks_changed(bool hyperlinks_changed)
|
|
|
|
{
|
|
|
|
d_->hyperlinks_changed_ = hyperlinks_changed;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string workbook::get_app_version() const
|
|
|
|
{
|
|
|
|
return d_->app_version_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void workbook::set_app_version(const std::string &version)
|
|
|
|
{
|
|
|
|
d_->app_version_ = version;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string workbook::get_title() const
|
|
|
|
{
|
|
|
|
return d_->title_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void workbook::set_title(const std::string &title)
|
|
|
|
{
|
|
|
|
d_->title_ = title;
|
|
|
|
}
|
|
|
|
|
2016-08-05 13:52:05 +08:00
|
|
|
detail::workbook_impl &workbook::impl()
|
|
|
|
{
|
|
|
|
return *d_;
|
|
|
|
}
|
|
|
|
|
|
|
|
const detail::workbook_impl &workbook::impl() const
|
|
|
|
{
|
|
|
|
return *d_;
|
|
|
|
}
|
2016-08-03 12:12:18 +08:00
|
|
|
|
2016-08-14 02:45:26 +08:00
|
|
|
bool workbook::has_view() const
|
|
|
|
{
|
|
|
|
return d_->has_view_;
|
|
|
|
}
|
|
|
|
|
|
|
|
workbook_view workbook::get_view() const
|
|
|
|
{
|
|
|
|
if (!d_->has_view_)
|
|
|
|
{
|
|
|
|
throw invalid_attribute();
|
|
|
|
}
|
|
|
|
|
|
|
|
return d_->view_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void workbook::set_view(const workbook_view &view)
|
|
|
|
{
|
|
|
|
d_->has_view_ = true;
|
|
|
|
d_->view_ = view;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool workbook::has_code_name() const
|
|
|
|
{
|
|
|
|
return d_->has_code_name_;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string workbook::get_code_name() const
|
|
|
|
{
|
|
|
|
if (!d_->has_code_name_)
|
|
|
|
{
|
|
|
|
throw invalid_attribute();
|
|
|
|
}
|
|
|
|
|
|
|
|
return d_->code_name_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void workbook::set_code_name(const std::string &code_name)
|
|
|
|
{
|
|
|
|
d_->code_name_ = code_name;
|
|
|
|
d_->has_code_name_ = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool workbook::x15_enabled() const
|
|
|
|
{
|
|
|
|
return d_->x15_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void workbook::enable_x15()
|
|
|
|
{
|
|
|
|
d_->x15_ = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void workbook::disable_x15()
|
|
|
|
{
|
|
|
|
d_->x15_ = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool workbook::has_absolute_path() const
|
|
|
|
{
|
|
|
|
return d_->has_absolute_path_;
|
|
|
|
}
|
|
|
|
|
|
|
|
path workbook::get_absolute_path() const
|
|
|
|
{
|
|
|
|
return d_->absolute_path_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void workbook::set_absolute_path(const path &absolute_path)
|
|
|
|
{
|
|
|
|
d_->absolute_path_ = absolute_path;
|
|
|
|
d_->has_absolute_path_ = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void workbook::clear_absolute_path()
|
|
|
|
{
|
|
|
|
d_->absolute_path_ = path();
|
|
|
|
d_->has_absolute_path_ = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool workbook::has_properties() const
|
|
|
|
{
|
|
|
|
return d_->has_properties_;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool workbook::has_file_version() const
|
|
|
|
{
|
|
|
|
return d_->has_file_version_;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string workbook::get_app_name() const
|
|
|
|
{
|
|
|
|
return d_->file_version_.app_name;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::size_t workbook::get_last_edited() const
|
|
|
|
{
|
|
|
|
return d_->file_version_.last_edited;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::size_t workbook::get_lowest_edited() const
|
|
|
|
{
|
|
|
|
return d_->file_version_.lowest_edited;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::size_t workbook::get_rup_build() const
|
|
|
|
{
|
|
|
|
return d_->file_version_.rup_build;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool workbook::has_calculation_properties() const
|
|
|
|
{
|
|
|
|
return d_->has_calculation_properties_;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool workbook::has_arch_id() const
|
|
|
|
{
|
|
|
|
return d_->has_arch_id_;
|
|
|
|
}
|
|
|
|
|
2015-10-19 03:30:46 +08:00
|
|
|
} // namespace xlnt
|