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
|
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
|
|
|
#include <sstream>
|
|
|
|
|
2016-07-23 08:26:02 +08:00
|
|
|
#include <detail/cell_impl.hpp>
|
|
|
|
#include <detail/constants.hpp>
|
|
|
|
#include <detail/excel_serializer.hpp>
|
|
|
|
#include <detail/include_windows.hpp>
|
|
|
|
#include <detail/workbook_impl.hpp>
|
|
|
|
#include <detail/worksheet_impl.hpp>
|
2016-03-09 11:32:32 +08:00
|
|
|
#include <xlnt/packaging/app_properties.hpp>
|
2015-11-03 22:06:01 +08:00
|
|
|
#include <xlnt/packaging/document_properties.hpp>
|
|
|
|
#include <xlnt/packaging/manifest.hpp>
|
2015-11-03 21:38:09 +08:00
|
|
|
#include <xlnt/packaging/relationship.hpp>
|
|
|
|
#include <xlnt/packaging/zip_file.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-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-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
|
|
|
|
2014-05-21 22:20:30 +08:00
|
|
|
namespace xlnt {
|
2014-05-31 06:42:25 +08:00
|
|
|
namespace detail {
|
2014-07-25 05:31:46 +08:00
|
|
|
|
2015-11-01 22:43:01 +08:00
|
|
|
workbook_impl::workbook_impl()
|
2016-06-11 01:40:50 +08:00
|
|
|
: active_sheet_index_(0),
|
|
|
|
guess_types_(false),
|
|
|
|
data_only_(false),
|
|
|
|
read_only_(false)
|
2014-05-21 22:20:30 +08:00
|
|
|
{
|
2014-05-30 08:52:14 +08:00
|
|
|
}
|
2014-07-25 05:31:46 +08:00
|
|
|
|
2014-05-31 06:42:25 +08:00
|
|
|
} // namespace detail
|
2015-11-01 22:43:01 +08:00
|
|
|
|
2014-06-16 01:06:47 +08:00
|
|
|
workbook::workbook() : d_(new detail::workbook_impl())
|
2014-05-30 08:52:14 +08:00
|
|
|
{
|
2014-06-16 01:06:47 +08:00
|
|
|
create_sheet("Sheet");
|
2015-11-02 12:52:19 +08:00
|
|
|
|
2016-05-16 03:03:02 +08:00
|
|
|
create_relationship("rId2", "styles.xml", relationship::type::styles);
|
|
|
|
create_relationship("rId3", "theme/theme1.xml", relationship::type::theme);
|
2015-11-02 12:52:19 +08:00
|
|
|
|
|
|
|
d_->manifest_.add_default_type("rels", "application/vnd.openxmlformats-package.relationships+xml");
|
|
|
|
d_->manifest_.add_default_type("xml", "application/xml");
|
|
|
|
|
2016-07-23 08:26:02 +08:00
|
|
|
d_->manifest_.add_override_type("/" + constants::part_workbook(), "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml");
|
|
|
|
d_->manifest_.add_override_type("/" + constants::part_theme(), "application/vnd.openxmlformats-officedocument.theme+xml");
|
|
|
|
d_->manifest_.add_override_type("/" + constants::part_styles(), "application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml");
|
|
|
|
d_->manifest_.add_override_type("/" + constants::part_core(), "application/vnd.openxmlformats-package.core-properties+xml");
|
|
|
|
d_->manifest_.add_override_type("/" + constants::part_app(), "application/vnd.openxmlformats-officedocument.extended-properties+xml");
|
2016-05-04 03:37:34 +08:00
|
|
|
|
2016-05-15 01:57:07 +08:00
|
|
|
add_format(format());
|
2016-05-16 03:03:02 +08:00
|
|
|
create_style("Normal");
|
2016-06-11 01:40:50 +08:00
|
|
|
d_->stylesheet_.format_styles.front() = "Normal";
|
2016-07-06 09:27:35 +08:00
|
|
|
|
2016-07-15 10:09:57 +08:00
|
|
|
xlnt::fill gray125 = xlnt::fill::pattern(xlnt::pattern_fill::type::gray125);
|
2016-07-06 09:27:35 +08:00
|
|
|
d_->stylesheet_.fills.push_back(gray125);
|
2014-05-21 22:20:30 +08:00
|
|
|
}
|
|
|
|
|
2016-05-26 10:05:30 +08:00
|
|
|
const worksheet workbook::get_sheet_by_name(const std::string &name) 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
|
|
|
{
|
2015-11-01 22:43:01 +08:00
|
|
|
if (impl.title_ == name)
|
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-22 11:04:36 +08:00
|
|
|
throw key_error();
|
2014-05-30 08:52:14 +08:00
|
|
|
}
|
|
|
|
|
2016-05-26 10:05:30 +08:00
|
|
|
worksheet workbook::get_sheet_by_name(const std::string &name)
|
|
|
|
{
|
2016-07-22 11:04:36 +08:00
|
|
|
for (auto &impl : d_->worksheets_)
|
|
|
|
{
|
|
|
|
if (impl.title_ == name)
|
|
|
|
{
|
|
|
|
return worksheet(&impl);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
throw key_error();
|
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)
|
|
|
|
{
|
|
|
|
return worksheet(&d_->worksheets_[index]);
|
|
|
|
}
|
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
|
|
|
|
{
|
|
|
|
return worksheet(&d_->worksheets_.at(index));
|
2014-05-21 22:20:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
worksheet workbook::get_active_sheet()
|
|
|
|
{
|
2014-05-30 08:52:14 +08:00
|
|
|
return worksheet(&d_->worksheets_[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-07-22 11:04:36 +08:00
|
|
|
if(get_read_only()) throw xlnt::read_only_workbook_error();
|
2016-03-06 10:39:50 +08:00
|
|
|
|
|
|
|
std::string title = "Sheet";
|
|
|
|
int index = 0;
|
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
|
|
|
}
|
2015-11-02 12:52:19 +08:00
|
|
|
|
2015-11-11 07:58:54 +08:00
|
|
|
std::string sheet_filename = "worksheets/sheet" + std::to_string(d_->worksheets_.size() + 1) + ".xml";
|
2014-06-10 12:29:49 +08:00
|
|
|
|
2014-06-14 03:05:24 +08:00
|
|
|
d_->worksheets_.push_back(detail::worksheet_impl(this, title));
|
2015-11-11 07:58:54 +08:00
|
|
|
create_relationship("rId" + std::to_string(d_->relationships_.size() + 1),
|
2015-11-02 12:52:19 +08:00
|
|
|
sheet_filename,
|
2015-11-01 22:43:01 +08:00
|
|
|
relationship::type::worksheet);
|
2015-11-02 12:52:19 +08:00
|
|
|
|
|
|
|
d_->manifest_.add_override_type("/xl/" + sheet_filename, "application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml");
|
2015-11-01 22:43:01 +08:00
|
|
|
|
|
|
|
return worksheet(&d_->worksheets_.back());
|
2014-05-21 22:20:30 +08:00
|
|
|
}
|
|
|
|
|
2016-07-22 10:14:00 +08:00
|
|
|
void workbook::copy_sheet(xlnt::worksheet worksheet)
|
2014-05-21 22:20:30 +08:00
|
|
|
{
|
2016-03-06 10:39:50 +08:00
|
|
|
if(worksheet.d_->parent_ != this) throw xlnt::value_error();
|
2016-03-08 11:35:22 +08:00
|
|
|
|
|
|
|
xlnt::detail::worksheet_impl impl(*worksheet.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-07-22 10:14:00 +08:00
|
|
|
void workbook::copy_sheet(xlnt::worksheet worksheet, std::size_t index)
|
2014-05-21 22:20:30 +08:00
|
|
|
{
|
2016-07-22 10:14:00 +08:00
|
|
|
copy_sheet(worksheet);
|
|
|
|
|
|
|
|
if (index != d_->worksheets_.size() - 1)
|
|
|
|
{
|
|
|
|
d_->worksheets_.insert(d_->worksheets_.begin() + index, d_->worksheets_.back());
|
|
|
|
d_->worksheets_.pop_back();
|
|
|
|
}
|
2014-05-21 22:20:30 +08:00
|
|
|
}
|
|
|
|
|
2016-07-22 10:14:00 +08:00
|
|
|
std::size_t workbook::get_index(xlnt::worksheet worksheet)
|
2014-05-21 22:20:30 +08:00
|
|
|
{
|
2016-07-22 10:14:00 +08:00
|
|
|
auto match = std::find(begin(), end(), worksheet);
|
|
|
|
|
|
|
|
if (match == end())
|
2014-05-21 22:20:30 +08:00
|
|
|
{
|
2016-07-22 10:14:00 +08:00
|
|
|
throw std::runtime_error("worksheet isn't owned by this workbook");
|
2014-05-21 22:20:30 +08:00
|
|
|
}
|
2016-07-22 10:14:00 +08:00
|
|
|
|
|
|
|
return 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
|
|
|
{
|
2014-05-30 08:52:14 +08:00
|
|
|
auto match = get_sheet_by_name(range_owner.get_title());
|
2015-11-01 22:43:01 +08:00
|
|
|
if (match != nullptr)
|
2014-05-21 22:20:30 +08:00
|
|
|
{
|
2014-05-30 08:52:14 +08:00
|
|
|
match.create_named_range(name, reference);
|
|
|
|
return;
|
2014-05-21 22:20:30 +08:00
|
|
|
}
|
|
|
|
throw std::runtime_error("worksheet isn't owned by this workbook");
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2014-05-30 08:52:14 +08:00
|
|
|
throw std::runtime_error("named range 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
|
|
|
|
2014-05-30 08:52:14 +08:00
|
|
|
throw std::runtime_error("named range not found");
|
2014-05-21 22:20:30 +08:00
|
|
|
}
|
|
|
|
|
2015-10-24 02:42:36 +08:00
|
|
|
bool workbook::load(std::istream &stream)
|
2014-06-13 05:04:37 +08:00
|
|
|
{
|
2015-10-30 07:37:07 +08:00
|
|
|
excel_serializer serializer_(*this);
|
|
|
|
serializer_.load_stream_workbook(stream);
|
2015-11-01 22:43:01 +08:00
|
|
|
|
2014-06-13 05:04:37 +08:00
|
|
|
return true;
|
|
|
|
}
|
2015-11-01 22:43:01 +08:00
|
|
|
|
2014-06-05 06:42:17 +08:00
|
|
|
bool workbook::load(const std::vector<unsigned char> &data)
|
|
|
|
{
|
2015-10-30 07:37:07 +08:00
|
|
|
excel_serializer serializer_(*this);
|
|
|
|
serializer_.load_virtual_workbook(data);
|
2015-11-01 22:43:01 +08:00
|
|
|
|
2015-10-24 02:42:36 +08:00
|
|
|
return true;
|
2014-06-05 06:42:17 +08:00
|
|
|
}
|
|
|
|
|
2015-11-11 07:58:54 +08:00
|
|
|
bool workbook::load(const std::string &filename)
|
2014-05-21 22:20:30 +08:00
|
|
|
{
|
2015-10-30 07:37:07 +08:00
|
|
|
excel_serializer serializer_(*this);
|
|
|
|
serializer_.load_workbook(filename);
|
|
|
|
|
2014-06-05 06:42:17 +08:00
|
|
|
return true;
|
2014-05-21 22:20:30 +08:00
|
|
|
}
|
2014-06-14 05:06:23 +08:00
|
|
|
|
2014-07-25 05:31:46 +08:00
|
|
|
void workbook::set_guess_types(bool guess)
|
|
|
|
{
|
|
|
|
d_->guess_types_ = guess;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool workbook::get_guess_types() const
|
|
|
|
{
|
|
|
|
return d_->guess_types_;
|
|
|
|
}
|
|
|
|
|
2015-11-11 07:58:54 +08:00
|
|
|
void workbook::create_relationship(const std::string &id, const std::string &target, relationship::type type)
|
2014-06-14 05:06:23 +08:00
|
|
|
{
|
|
|
|
d_->relationships_.push_back(relationship(type, id, target));
|
|
|
|
}
|
|
|
|
|
2016-05-16 03:03:02 +08:00
|
|
|
void workbook::create_root_relationship(const std::string &id, const std::string &target, relationship::type type)
|
|
|
|
{
|
|
|
|
d_->root_relationships_.push_back(relationship(type, id, target));
|
|
|
|
}
|
|
|
|
|
2015-11-11 07:58:54 +08:00
|
|
|
relationship workbook::get_relationship(const std::string &id) const
|
2014-06-14 05:06:23 +08:00
|
|
|
{
|
2015-11-01 22:43:01 +08:00
|
|
|
for (auto &rel : d_->relationships_)
|
2014-06-14 05:06:23 +08:00
|
|
|
{
|
2015-11-01 22:43:01 +08:00
|
|
|
if (rel.get_id() == id)
|
2014-06-14 05:06:23 +08:00
|
|
|
{
|
|
|
|
return rel;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
throw std::runtime_error("");
|
|
|
|
}
|
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(),
|
|
|
|
[=](detail::worksheet_impl &comp) { return worksheet(&comp) == ws; });
|
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
|
|
|
{
|
|
|
|
throw std::runtime_error("worksheet not owned by this workbook");
|
|
|
|
}
|
2015-11-01 22:43:01 +08:00
|
|
|
|
2015-11-11 07:58:54 +08:00
|
|
|
auto sheet_filename = "worksheets/sheet" + std::to_string(d_->worksheets_.size()) + ".xml";
|
2015-11-01 22:43:01 +08:00
|
|
|
auto rel_iter = std::find_if(d_->relationships_.begin(), d_->relationships_.end(),
|
|
|
|
[=](relationship &r) { return r.get_target_uri() == sheet_filename; });
|
|
|
|
|
2015-10-27 11:06:00 +08:00
|
|
|
d_->relationships_.erase(rel_iter);
|
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-07-18 03:20:20 +08:00
|
|
|
d_->worksheets_.insert(d_->worksheets_.begin() + index, d_->worksheets_.back());
|
|
|
|
d_->worksheets_.pop_back();
|
2015-11-01 22:43:01 +08:00
|
|
|
}
|
|
|
|
|
2014-05-30 08:52:14 +08:00
|
|
|
return worksheet(&d_->worksheets_[index]);
|
2014-05-21 22:20:30 +08:00
|
|
|
}
|
|
|
|
|
2015-11-01 22:43:01 +08:00
|
|
|
// TODO: There should be a better way to do this...
|
2015-11-11 07:58:54 +08:00
|
|
|
std::size_t workbook::index_from_ws_filename(const std::string &ws_filename)
|
2015-10-15 06:05:13 +08:00
|
|
|
{
|
2015-11-11 07:58:54 +08:00
|
|
|
std::string sheet_index_string(ws_filename);
|
2015-10-15 06:05:13 +08:00
|
|
|
sheet_index_string = sheet_index_string.substr(0, sheet_index_string.find('.'));
|
|
|
|
sheet_index_string = sheet_index_string.substr(sheet_index_string.find_last_of('/'));
|
|
|
|
auto iter = sheet_index_string.end();
|
2015-11-11 07:58:54 +08:00
|
|
|
iter--;
|
|
|
|
while (isdigit(*iter))
|
|
|
|
iter--;
|
2015-10-15 06:05:13 +08:00
|
|
|
auto first_digit = static_cast<std::size_t>(iter - sheet_index_string.begin());
|
|
|
|
sheet_index_string = sheet_index_string.substr(first_digit + 1);
|
2015-11-11 07:58:54 +08:00
|
|
|
auto sheet_index = static_cast<std::size_t>(std::stoll(sheet_index_string) - 1);
|
2015-10-15 06:05:13 +08:00
|
|
|
return sheet_index;
|
|
|
|
}
|
2015-11-01 22:43:01 +08:00
|
|
|
|
2015-11-11 07:58:54 +08:00
|
|
|
worksheet workbook::create_sheet(const std::string &title, const relationship &rel)
|
2015-10-06 22:32:52 +08:00
|
|
|
{
|
2015-11-01 22:43:01 +08:00
|
|
|
d_->worksheets_.push_back(detail::worksheet_impl(this, title));
|
2015-10-06 22:32:52 +08:00
|
|
|
|
2015-11-01 22:43:01 +08:00
|
|
|
auto index = index_from_ws_filename(rel.get_target_uri());
|
|
|
|
if (index != d_->worksheets_.size() - 1)
|
|
|
|
{
|
|
|
|
std::swap(d_->worksheets_.back(), d_->worksheets_[index]);
|
|
|
|
d_->worksheets_.pop_back();
|
|
|
|
}
|
2015-10-06 22:32:52 +08:00
|
|
|
|
2015-11-01 22:43:01 +08:00
|
|
|
return worksheet(&d_->worksheets_[index]);
|
2015-10-06 22:32:52 +08:00
|
|
|
}
|
|
|
|
|
2015-11-11 07:58:54 +08:00
|
|
|
worksheet workbook::create_sheet(std::size_t index, const std::string &title)
|
2014-05-21 22:20:30 +08:00
|
|
|
{
|
|
|
|
auto ws = create_sheet(index);
|
|
|
|
ws.set_title(title);
|
2015-11-01 22:43:01 +08:00
|
|
|
|
2014-05-21 22:20:30 +08:00
|
|
|
return ws;
|
|
|
|
}
|
|
|
|
|
2015-11-11 07:58:54 +08:00
|
|
|
worksheet workbook::create_sheet(const std::string &title)
|
2014-05-21 22:20:30 +08:00
|
|
|
{
|
2015-11-01 22:43:01 +08:00
|
|
|
if (title.length() > 31)
|
2014-05-21 22:20:30 +08:00
|
|
|
{
|
2016-07-22 11:04:36 +08:00
|
|
|
throw sheet_title_error(title);
|
2014-05-21 22:20:30 +08:00
|
|
|
}
|
2015-11-01 22:43:01 +08:00
|
|
|
|
2015-11-11 07:58:54 +08:00
|
|
|
if (std::find_if(title.begin(), title.end(), [](char c) {
|
2015-11-01 22:43:01 +08:00
|
|
|
return c == '*' || c == ':' || c == '/' || c == '\\' || c == '?' || c == '[' || c == ']';
|
2015-11-11 07:58:54 +08:00
|
|
|
}) != title.end())
|
2014-05-21 22:20:30 +08:00
|
|
|
{
|
2016-07-22 11:04:36 +08:00
|
|
|
throw sheet_title_error(title);
|
2014-05-21 22:20:30 +08:00
|
|
|
}
|
2015-11-01 22:43:01 +08:00
|
|
|
|
2015-11-11 07:58:54 +08:00
|
|
|
std::string unique_title = title;
|
2015-11-01 22:43:01 +08:00
|
|
|
|
|
|
|
if (std::find_if(d_->worksheets_.begin(), d_->worksheets_.end(), [&](detail::worksheet_impl &ws) {
|
|
|
|
return worksheet(&ws).get_title() == unique_title;
|
|
|
|
}) != d_->worksheets_.end())
|
2014-05-21 22:20:30 +08:00
|
|
|
{
|
2014-07-20 04:59:05 +08:00
|
|
|
std::size_t suffix = 1;
|
2015-11-01 22:43:01 +08:00
|
|
|
|
|
|
|
while (std::find_if(d_->worksheets_.begin(), d_->worksheets_.end(), [&](detail::worksheet_impl &ws) {
|
|
|
|
return worksheet(&ws).get_title() == unique_title;
|
|
|
|
}) != d_->worksheets_.end())
|
2014-07-20 04:59:05 +08:00
|
|
|
{
|
2015-11-11 07:58:54 +08:00
|
|
|
unique_title = title + std::to_string(suffix);
|
2014-07-20 04:59:05 +08:00
|
|
|
suffix++;
|
|
|
|
}
|
2014-05-21 22:20:30 +08:00
|
|
|
}
|
2015-11-01 22:43:01 +08:00
|
|
|
|
2014-05-30 08:52:14 +08:00
|
|
|
auto ws = create_sheet();
|
2014-07-20 04:59:05 +08:00
|
|
|
ws.set_title(unique_title);
|
2014-05-30 08:52:14 +08:00
|
|
|
|
|
|
|
return ws;
|
2014-05-21 22:20:30 +08:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2015-11-11 07:58:54 +08:00
|
|
|
std::vector<std::string> workbook::get_sheet_names() 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;
|
|
|
|
}
|
|
|
|
|
2015-11-11 07:58:54 +08:00
|
|
|
worksheet workbook::operator[](const std::string &name)
|
2014-05-21 22:20:30 +08:00
|
|
|
{
|
2014-05-30 08:52:14 +08:00
|
|
|
return get_sheet_by_name(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-07-22 11:04:36 +08:00
|
|
|
if (index > d_->worksheets_.size())
|
|
|
|
{
|
|
|
|
throw key_error();
|
|
|
|
}
|
|
|
|
|
2014-05-30 08:52:14 +08:00
|
|
|
return worksheet(&d_->worksheets_[index]);
|
2014-05-21 22:20:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void workbook::clear()
|
|
|
|
{
|
2014-05-30 08:52:14 +08:00
|
|
|
d_->worksheets_.clear();
|
2014-07-20 02:43:48 +08:00
|
|
|
d_->relationships_.clear();
|
|
|
|
d_->active_sheet_index_ = 0;
|
2014-07-20 04:59:05 +08:00
|
|
|
d_->properties_ = document_properties();
|
2016-07-18 02:59:11 +08:00
|
|
|
clear_styles();
|
|
|
|
clear_formats();
|
2014-05-21 22:20:30 +08:00
|
|
|
}
|
|
|
|
|
2014-06-05 06:42:17 +08:00
|
|
|
bool workbook::save(std::vector<unsigned char> &data)
|
|
|
|
{
|
2015-10-30 07:37:07 +08:00
|
|
|
excel_serializer serializer(*this);
|
|
|
|
serializer.save_virtual_workbook(data);
|
|
|
|
|
2014-06-11 05:12:15 +08:00
|
|
|
return true;
|
2014-06-05 06:42:17 +08:00
|
|
|
}
|
|
|
|
|
2015-11-11 07:58:54 +08:00
|
|
|
bool workbook::save(const std::string &filename)
|
2014-05-21 22:20:30 +08:00
|
|
|
{
|
2015-10-30 07:37:07 +08:00
|
|
|
excel_serializer serializer(*this);
|
|
|
|
serializer.save_workbook(filename);
|
2015-11-01 22:43:01 +08:00
|
|
|
|
2015-10-30 07:37:07 +08:00
|
|
|
return true;
|
2014-05-21 22:20:30 +08:00
|
|
|
}
|
2014-07-20 04:59:05 +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
|
|
|
|
2015-10-30 07:37:07 +08:00
|
|
|
const std::vector<relationship> &xlnt::workbook::get_relationships() const
|
2014-06-16 01:06:47 +08:00
|
|
|
{
|
2015-11-01 22:43:01 +08:00
|
|
|
return d_->relationships_;
|
2014-06-16 01:06:47 +08:00
|
|
|
}
|
|
|
|
|
2014-07-20 04:59:05 +08:00
|
|
|
document_properties &workbook::get_properties()
|
|
|
|
{
|
|
|
|
return d_->properties_;
|
|
|
|
}
|
|
|
|
|
|
|
|
const document_properties &workbook::get_properties() const
|
|
|
|
{
|
|
|
|
return d_->properties_;
|
|
|
|
}
|
|
|
|
|
2016-03-09 11:32:32 +08:00
|
|
|
app_properties &workbook::get_app_properties()
|
|
|
|
{
|
|
|
|
return d_->app_properties_;
|
|
|
|
}
|
|
|
|
|
|
|
|
const app_properties &workbook::get_app_properties() const
|
|
|
|
{
|
|
|
|
return d_->app_properties_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
for (auto ws : left)
|
2014-07-24 08:51:28 +08:00
|
|
|
{
|
|
|
|
ws.set_parent(left);
|
|
|
|
}
|
2015-11-01 22:43:01 +08:00
|
|
|
|
|
|
|
for (auto ws : right)
|
2014-07-24 08:51:28 +08:00
|
|
|
{
|
|
|
|
ws.set_parent(right);
|
|
|
|
}
|
|
|
|
}
|
2015-11-01 22:43:01 +08:00
|
|
|
|
2014-07-24 08:51:28 +08:00
|
|
|
workbook &workbook::operator=(workbook other)
|
|
|
|
{
|
|
|
|
swap(*this, other);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
workbook::workbook(workbook &&other) : workbook()
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
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-03-06 10:39:50 +08:00
|
|
|
bool workbook::get_read_only() const
|
|
|
|
{
|
|
|
|
return d_->read_only_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void workbook::set_read_only(bool read_only)
|
|
|
|
{
|
|
|
|
d_->read_only_ = read_only;
|
|
|
|
}
|
|
|
|
|
2015-11-11 07:58:54 +08:00
|
|
|
void workbook::set_code_name(const std::string & /*code_name*/)
|
2015-10-19 03:30:46 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-10-30 07:37:07 +08:00
|
|
|
bool workbook::has_loaded_theme() const
|
2015-10-19 03:30:46 +08:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-10-30 07:37:07 +08:00
|
|
|
const theme &workbook::get_loaded_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
|
|
|
}
|
|
|
|
|
|
|
|
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-06-11 01:40:50 +08:00
|
|
|
std::size_t workbook::add_format(const format &to_add)
|
2015-10-24 02:42:36 +08:00
|
|
|
{
|
2016-06-11 01:40:50 +08:00
|
|
|
return d_->stylesheet_.add_format(to_add);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::size_t workbook::add_style(const style &to_add)
|
|
|
|
{
|
|
|
|
return d_->stylesheet_.add_style(to_add);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool workbook::has_style(const std::string &name) const
|
|
|
|
{
|
|
|
|
return std::find_if(d_->stylesheet_.styles.begin(), d_->stylesheet_.styles.end(),
|
|
|
|
[&](const style &s) { return s.get_name() == name; }) != d_->stylesheet_.styles.end();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::size_t workbook::get_style_id(const std::string &name) const
|
|
|
|
{
|
|
|
|
return std::distance(d_->stylesheet_.styles.begin(),
|
|
|
|
std::find_if(d_->stylesheet_.styles.begin(), d_->stylesheet_.styles.end(),
|
|
|
|
[&](const style &s) { return s.get_name() == 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
|
|
|
d_->stylesheet_.styles.clear();
|
|
|
|
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
|
|
|
d_->stylesheet_.formats.clear();
|
|
|
|
apply_to_cells([](cell c) { c.clear_format(); });
|
|
|
|
}
|
|
|
|
|
|
|
|
void workbook::apply_to_cells(std::function<void(cell)> f)
|
|
|
|
{
|
|
|
|
for (auto ws : *this)
|
|
|
|
{
|
|
|
|
for (auto r : ws.iter_cells(true))
|
|
|
|
{
|
|
|
|
for (auto c : r)
|
|
|
|
{
|
|
|
|
f.operator()(c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-05-14 02:40:17 +08:00
|
|
|
}
|
|
|
|
|
2016-05-15 01:57:07 +08:00
|
|
|
format &workbook::get_format(std::size_t format_index)
|
2015-10-29 03:08:54 +08:00
|
|
|
{
|
2016-06-11 01:40:50 +08:00
|
|
|
return d_->stylesheet_.formats.at(format_index);
|
2015-10-29 03:08:54 +08:00
|
|
|
}
|
|
|
|
|
2016-05-15 01:57:07 +08:00
|
|
|
const format &workbook::get_format(std::size_t format_index) const
|
2015-10-29 03:08:54 +08:00
|
|
|
{
|
2016-06-11 01:40:50 +08:00
|
|
|
return d_->stylesheet_.formats.at(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_;
|
|
|
|
}
|
|
|
|
|
2015-10-30 07:37:07 +08:00
|
|
|
const std::vector<relationship> &workbook::get_root_relationships() const
|
|
|
|
{
|
2015-11-01 22:43:01 +08:00
|
|
|
if (d_->root_relationships_.empty())
|
2015-10-30 07:37:07 +08:00
|
|
|
{
|
2015-11-01 22:43:01 +08:00
|
|
|
d_->root_relationships_.push_back(
|
2016-07-23 08:26:02 +08:00
|
|
|
relationship(relationship::type::core_properties, "rId1", constants::part_core()));
|
2015-11-01 22:43:01 +08:00
|
|
|
d_->root_relationships_.push_back(
|
2016-07-23 08:26:02 +08:00
|
|
|
relationship(relationship::type::extended_properties, "rId2", constants::part_app()));
|
|
|
|
d_->root_relationships_.push_back(
|
|
|
|
relationship(relationship::type::office_document, "rId3", constants::part_workbook()));
|
2015-10-30 07:37:07 +08:00
|
|
|
}
|
2015-11-01 22:43:01 +08:00
|
|
|
|
2015-10-30 07:37:07 +08:00
|
|
|
return d_->root_relationships_;
|
|
|
|
}
|
|
|
|
|
2016-05-15 03:19:08 +08:00
|
|
|
std::vector<text> &workbook::get_shared_strings()
|
2015-10-31 06:54:04 +08:00
|
|
|
{
|
|
|
|
return d_->shared_strings_;
|
|
|
|
}
|
|
|
|
|
2016-05-15 03:19:08 +08:00
|
|
|
const std::vector<text> &workbook::get_shared_strings() const
|
2015-10-31 06:54:04 +08:00
|
|
|
{
|
|
|
|
return d_->shared_strings_;
|
|
|
|
}
|
|
|
|
|
2016-05-15 03:19:08 +08:00
|
|
|
void workbook::add_shared_string(const text &shared, bool allow_duplicates)
|
2015-10-31 06:54:04 +08:00
|
|
|
{
|
2016-05-16 03:03:02 +08:00
|
|
|
if (d_->shared_strings_.empty())
|
|
|
|
{
|
|
|
|
create_relationship(next_relationship_id(), "sharedStrings.xml", relationship::type::shared_strings);
|
2016-07-23 08:26:02 +08:00
|
|
|
d_->manifest_.add_override_type("/" + constants::part_shared_strings(), "application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml");
|
2016-05-16 03:03:02 +08:00
|
|
|
}
|
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-03-10 17:12:51 +08:00
|
|
|
void workbook::set_thumbnail(const std::vector<std::uint8_t> &thumbnail)
|
|
|
|
{
|
|
|
|
d_->thumbnail_.assign(thumbnail.begin(), thumbnail.end());
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::vector<std::uint8_t> &workbook::get_thumbnail() const
|
|
|
|
{
|
|
|
|
return d_->thumbnail_;
|
|
|
|
}
|
|
|
|
|
2016-05-15 01:57:07 +08:00
|
|
|
style &workbook::create_style(const std::string &name)
|
2016-05-04 03:37:34 +08:00
|
|
|
{
|
2016-05-15 01:57:07 +08:00
|
|
|
style style;
|
2016-05-04 03:37:34 +08:00
|
|
|
style.set_name(name);
|
|
|
|
|
2016-06-11 01:40:50 +08:00
|
|
|
d_->stylesheet_.styles.push_back(style);
|
2016-05-04 03:37:34 +08:00
|
|
|
|
2016-06-11 01:40:50 +08:00
|
|
|
return d_->stylesheet_.styles.back();
|
2016-05-04 03:37:34 +08:00
|
|
|
}
|
|
|
|
|
2016-05-15 01:57:07 +08:00
|
|
|
std::vector<format> &workbook::get_formats()
|
2016-05-15 00:42:34 +08:00
|
|
|
{
|
2016-06-11 01:40:50 +08:00
|
|
|
return d_->stylesheet_.formats;
|
2016-05-15 00:42:34 +08:00
|
|
|
}
|
|
|
|
|
2016-05-15 01:57:07 +08:00
|
|
|
const std::vector<format> &workbook::get_formats() const
|
2016-05-15 00:42:34 +08:00
|
|
|
{
|
2016-06-11 01:40:50 +08:00
|
|
|
return d_->stylesheet_.formats;
|
2016-05-15 00:42:34 +08:00
|
|
|
}
|
|
|
|
|
2016-05-15 23:51:32 +08:00
|
|
|
style &workbook::get_style(const std::string &name)
|
|
|
|
{
|
2016-06-11 01:40:50 +08:00
|
|
|
return *std::find_if(d_->stylesheet_.styles.begin(), d_->stylesheet_.styles.end(),
|
2016-05-15 23:51:32 +08:00
|
|
|
[&name](const style &s) { return s.get_name() == name; });
|
|
|
|
}
|
|
|
|
|
|
|
|
const style &workbook::get_style(const std::string &name) const
|
|
|
|
{
|
2016-06-11 01:40:50 +08:00
|
|
|
return *std::find_if(d_->stylesheet_.styles.begin(), d_->stylesheet_.styles.end(),
|
2016-05-15 23:51:32 +08:00
|
|
|
[&name](const style &s) { return s.get_name() == name; });
|
|
|
|
}
|
|
|
|
|
2016-06-20 02:43:41 +08:00
|
|
|
style &workbook::get_style_by_id(std::size_t style_id)
|
|
|
|
{
|
|
|
|
return d_->stylesheet_.styles.at(style_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
const style &workbook::get_style_by_id(std::size_t style_id) const
|
|
|
|
{
|
|
|
|
return d_->stylesheet_.styles.at(style_id);
|
|
|
|
}
|
|
|
|
|
2016-05-16 03:03:02 +08:00
|
|
|
std::string workbook::next_relationship_id() const
|
|
|
|
{
|
|
|
|
std::size_t i = 1;
|
|
|
|
|
|
|
|
while (std::find_if(d_->relationships_.begin(), d_->relationships_.end(),
|
|
|
|
[i](const relationship &r) { return r.get_id() == "rId" + std::to_string(i); }) != d_->relationships_.end())
|
|
|
|
{
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return "rId" + std::to_string(i);
|
|
|
|
}
|
|
|
|
|
2015-10-19 03:30:46 +08:00
|
|
|
} // namespace xlnt
|