2017-01-03 09:35:18 +08:00
|
|
|
// Copyright (c) 2014-2017 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
|
2017-04-21 02:03:03 +08:00
|
|
|
|
2014-05-22 05:48:51 +08:00
|
|
|
#include <algorithm>
|
2016-06-11 22:17:58 +08:00
|
|
|
#include <cmath>
|
2015-11-02 14:07:43 +08:00
|
|
|
#include <limits>
|
2014-05-22 05:48:51 +08:00
|
|
|
|
2017-04-21 02:03:03 +08:00
|
|
|
#include <detail/constants.hpp>
|
|
|
|
#include <detail/implementations/cell_impl.hpp>
|
|
|
|
#include <detail/implementations/workbook_impl.hpp>
|
|
|
|
#include <detail/implementations/worksheet_impl.hpp>
|
2014-08-14 06:56:34 +08:00
|
|
|
#include <xlnt/cell/cell.hpp>
|
2015-11-02 14:07:43 +08:00
|
|
|
#include <xlnt/cell/cell_reference.hpp>
|
2015-11-21 09:41:32 +08:00
|
|
|
#include <xlnt/cell/index_types.hpp>
|
2015-11-03 21:38:09 +08:00
|
|
|
#include <xlnt/packaging/relationship.hpp>
|
2015-11-20 11:54:54 +08:00
|
|
|
#include <xlnt/utils/date.hpp>
|
2015-11-03 21:38:09 +08:00
|
|
|
#include <xlnt/utils/datetime.hpp>
|
|
|
|
#include <xlnt/utils/exceptions.hpp>
|
2015-10-15 06:05:13 +08:00
|
|
|
#include <xlnt/workbook/named_range.hpp>
|
2014-08-14 06:56:34 +08:00
|
|
|
#include <xlnt/workbook/workbook.hpp>
|
2016-08-02 06:33:43 +08:00
|
|
|
#include <xlnt/workbook/worksheet_iterator.hpp>
|
2016-01-25 00:15:49 +08:00
|
|
|
#include <xlnt/worksheet/cell_iterator.hpp>
|
2016-12-24 23:04:57 +08:00
|
|
|
#include <xlnt/worksheet/header_footer.hpp>
|
2015-10-15 06:05:13 +08:00
|
|
|
#include <xlnt/worksheet/range.hpp>
|
2016-01-25 00:15:49 +08:00
|
|
|
#include <xlnt/worksheet/range_iterator.hpp>
|
2015-10-15 06:05:13 +08:00
|
|
|
#include <xlnt/worksheet/range_reference.hpp>
|
|
|
|
#include <xlnt/worksheet/worksheet.hpp>
|
2014-08-14 06:56:34 +08:00
|
|
|
|
2016-12-24 23:04:57 +08:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
int points_to_pixels(double points, double dpi)
|
|
|
|
{
|
|
|
|
return static_cast<int>(std::ceil(points * dpi / 72));
|
2017-03-21 07:23:44 +08:00
|
|
|
}
|
2016-12-24 23:04:57 +08:00
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2014-05-21 22:20:30 +08:00
|
|
|
namespace xlnt {
|
2014-05-22 05:48:51 +08:00
|
|
|
|
2016-12-24 23:04:57 +08:00
|
|
|
worksheet::worksheet()
|
|
|
|
: d_(nullptr)
|
2014-05-30 08:52:14 +08:00
|
|
|
{
|
|
|
|
}
|
2015-11-01 22:43:01 +08:00
|
|
|
|
2016-12-24 23:04:57 +08:00
|
|
|
worksheet::worksheet(detail::worksheet_impl *d)
|
|
|
|
: d_(d)
|
2014-05-21 22:20:30 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-12-24 23:04:57 +08:00
|
|
|
worksheet::worksheet(const worksheet &rhs)
|
|
|
|
: d_(rhs.d_)
|
2014-05-21 22:20:30 +08:00
|
|
|
{
|
|
|
|
}
|
2015-11-01 22:43:01 +08:00
|
|
|
|
2014-05-21 22:20:30 +08:00
|
|
|
bool worksheet::has_frozen_panes() const
|
|
|
|
{
|
2016-12-24 23:04:57 +08:00
|
|
|
return !d_->views_.empty() && d_->views_.front().has_pane()
|
2016-12-02 21:37:50 +08:00
|
|
|
&& (d_->views_.front().pane().state == pane_state::frozen
|
2016-12-24 23:04:57 +08:00
|
|
|
|| d_->views_.front().pane().state == pane_state::frozen_split);
|
2014-05-21 22:20:30 +08:00
|
|
|
}
|
|
|
|
|
2015-11-11 08:47:31 +08:00
|
|
|
void worksheet::create_named_range(const std::string &name, const std::string &reference_string)
|
|
|
|
{
|
|
|
|
create_named_range(name, range_reference(reference_string));
|
|
|
|
}
|
|
|
|
|
2015-11-11 07:58:54 +08:00
|
|
|
void worksheet::create_named_range(const std::string &name, const range_reference &reference)
|
2014-05-21 22:20:30 +08:00
|
|
|
{
|
2016-12-24 23:04:57 +08:00
|
|
|
try
|
|
|
|
{
|
|
|
|
auto temp = cell_reference::split_reference(name);
|
2016-07-30 05:50:33 +08:00
|
|
|
|
2016-12-24 23:04:57 +08:00
|
|
|
// name is a valid reference, make sure it's outside the allowed range
|
2016-08-16 12:23:49 +08:00
|
|
|
|
2016-12-24 23:04:57 +08:00
|
|
|
if (column_t(temp.first).index <= column_t("XFD").index && temp.second <= 1048576)
|
|
|
|
{
|
|
|
|
throw invalid_parameter(); //("named range name must be outside the range A1-XFD1048576");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (xlnt::invalid_cell_reference)
|
|
|
|
{
|
|
|
|
// name is not a valid reference, that's good
|
|
|
|
}
|
2016-08-16 12:23:49 +08:00
|
|
|
|
|
|
|
std::vector<named_range::target> targets;
|
2016-12-24 23:04:57 +08:00
|
|
|
targets.push_back({*this, reference});
|
2016-07-30 05:50:33 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
d_->named_ranges_[name] = xlnt::named_range(name, targets);
|
2014-05-21 22:20:30 +08:00
|
|
|
}
|
|
|
|
|
2014-05-22 05:48:51 +08:00
|
|
|
cell worksheet::operator[](const cell_reference &ref)
|
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
return cell(ref);
|
2014-05-22 05:48:51 +08:00
|
|
|
}
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
std::vector<range_reference> worksheet::merged_ranges() const
|
2014-05-21 22:20:30 +08:00
|
|
|
{
|
2014-05-30 08:52:14 +08:00
|
|
|
return d_->merged_cells_;
|
2014-05-21 22:20:30 +08:00
|
|
|
}
|
|
|
|
|
2016-08-14 02:45:26 +08:00
|
|
|
bool worksheet::has_page_margins() const
|
2015-10-31 06:54:04 +08:00
|
|
|
{
|
2016-12-24 23:04:57 +08:00
|
|
|
return d_->page_margins_.is_set();
|
2016-08-14 02:45:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool worksheet::has_page_setup() const
|
|
|
|
{
|
2016-12-24 23:04:57 +08:00
|
|
|
return d_->page_setup_.is_set();
|
2015-10-31 06:54:04 +08:00
|
|
|
}
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
page_margins worksheet::page_margins() const
|
2014-05-21 22:20:30 +08:00
|
|
|
{
|
2016-12-10 08:18:50 +08:00
|
|
|
return d_->page_margins_.get();
|
2014-05-21 22:20:30 +08:00
|
|
|
}
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
void worksheet::page_margins(const class page_margins &margins)
|
2016-08-14 02:45:26 +08:00
|
|
|
{
|
2016-12-24 23:04:57 +08:00
|
|
|
d_->page_margins_ = margins;
|
2016-08-14 02:45:26 +08:00
|
|
|
}
|
|
|
|
|
2015-11-11 08:47:31 +08:00
|
|
|
void worksheet::auto_filter(const std::string &reference_string)
|
|
|
|
{
|
|
|
|
auto_filter(range_reference(reference_string));
|
|
|
|
}
|
|
|
|
|
2014-06-05 06:42:17 +08:00
|
|
|
void worksheet::auto_filter(const range_reference &reference)
|
2014-05-21 22:20:30 +08:00
|
|
|
{
|
2014-05-30 08:52:14 +08:00
|
|
|
d_->auto_filter_ = reference;
|
2014-05-21 22:20:30 +08:00
|
|
|
}
|
|
|
|
|
2014-06-05 06:42:17 +08:00
|
|
|
void worksheet::auto_filter(const xlnt::range &range)
|
2014-05-21 22:20:30 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
auto_filter(range.reference());
|
2014-05-21 22:20:30 +08:00
|
|
|
}
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
range_reference worksheet::auto_filter() const
|
2014-05-21 22:20:30 +08:00
|
|
|
{
|
2016-12-10 08:18:50 +08:00
|
|
|
return d_->auto_filter_.get();
|
2014-05-21 22:20:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool worksheet::has_auto_filter() const
|
|
|
|
{
|
2016-12-10 08:18:50 +08:00
|
|
|
return d_->auto_filter_.is_set();
|
2014-05-21 22:20:30 +08:00
|
|
|
}
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
void worksheet::clear_auto_filter()
|
2014-05-21 22:20:30 +08:00
|
|
|
{
|
2016-12-10 08:18:50 +08:00
|
|
|
d_->auto_filter_.clear();
|
2014-05-21 22:20:30 +08:00
|
|
|
}
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
void worksheet::page_setup(const struct page_setup &setup)
|
2015-10-31 06:54:04 +08:00
|
|
|
{
|
2016-12-24 23:04:57 +08:00
|
|
|
d_->page_setup_ = setup;
|
2015-10-31 06:54:04 +08:00
|
|
|
}
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
page_setup worksheet::page_setup() const
|
2014-05-21 22:20:30 +08:00
|
|
|
{
|
2016-12-24 23:04:57 +08:00
|
|
|
if (!has_page_setup())
|
|
|
|
{
|
|
|
|
throw invalid_attribute();
|
|
|
|
}
|
2016-08-14 02:45:26 +08:00
|
|
|
|
2016-12-10 08:18:50 +08:00
|
|
|
return d_->page_setup_.get();
|
2014-05-21 22:20:30 +08:00
|
|
|
}
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
workbook &worksheet::workbook()
|
2014-05-21 22:20:30 +08:00
|
|
|
{
|
2014-05-30 08:52:14 +08:00
|
|
|
return *d_->parent_;
|
2014-05-21 22:20:30 +08:00
|
|
|
}
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
const workbook &worksheet::workbook() const
|
2016-05-12 07:24:53 +08:00
|
|
|
{
|
2016-12-24 23:04:57 +08:00
|
|
|
return *d_->parent_;
|
2016-05-12 07:24:53 +08:00
|
|
|
}
|
|
|
|
|
2014-05-21 22:20:30 +08:00
|
|
|
void worksheet::garbage_collect()
|
|
|
|
{
|
2014-05-30 08:52:14 +08:00
|
|
|
auto cell_map_iter = d_->cell_map_.begin();
|
2014-07-25 05:31:46 +08:00
|
|
|
|
2015-11-01 22:43:01 +08:00
|
|
|
while (cell_map_iter != d_->cell_map_.end())
|
2014-05-30 08:52:14 +08:00
|
|
|
{
|
|
|
|
auto cell_iter = cell_map_iter->second.begin();
|
2014-07-25 05:31:46 +08:00
|
|
|
|
2015-11-01 22:43:01 +08:00
|
|
|
while (cell_iter != cell_map_iter->second.end())
|
2014-05-30 08:52:14 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
class cell current_cell(&cell_iter->second);
|
2014-07-25 05:31:46 +08:00
|
|
|
|
2015-11-01 22:43:01 +08:00
|
|
|
if (current_cell.garbage_collectible())
|
2014-05-30 08:52:14 +08:00
|
|
|
{
|
|
|
|
cell_iter = cell_map_iter->second.erase(cell_iter);
|
|
|
|
continue;
|
|
|
|
}
|
2014-07-25 05:31:46 +08:00
|
|
|
|
2014-05-30 08:52:14 +08:00
|
|
|
cell_iter++;
|
|
|
|
}
|
2014-07-25 05:31:46 +08:00
|
|
|
|
2015-11-01 22:43:01 +08:00
|
|
|
if (cell_map_iter->second.empty())
|
2014-05-30 08:52:14 +08:00
|
|
|
{
|
|
|
|
cell_map_iter = d_->cell_map_.erase(cell_map_iter);
|
|
|
|
continue;
|
|
|
|
}
|
2014-07-25 05:31:46 +08:00
|
|
|
|
2014-05-30 08:52:14 +08:00
|
|
|
cell_map_iter++;
|
|
|
|
}
|
2014-05-21 22:20:30 +08:00
|
|
|
}
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
void worksheet::id(std::size_t id)
|
2016-07-27 08:13:09 +08:00
|
|
|
{
|
|
|
|
d_->id_ = id;
|
|
|
|
}
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
std::size_t worksheet::id() const
|
2016-07-27 08:13:09 +08:00
|
|
|
{
|
|
|
|
return d_->id_;
|
|
|
|
}
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
std::string worksheet::title() const
|
2014-05-21 22:20:30 +08:00
|
|
|
{
|
2014-05-30 08:52:14 +08:00
|
|
|
return d_->title_;
|
2014-05-21 22:20:30 +08:00
|
|
|
}
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
void worksheet::title(const std::string &title)
|
2014-05-21 22:20:30 +08:00
|
|
|
{
|
2016-12-24 23:04:57 +08:00
|
|
|
if (title.length() > 31)
|
|
|
|
{
|
|
|
|
throw invalid_sheet_title(title);
|
|
|
|
}
|
2016-08-02 06:33:43 +08:00
|
|
|
|
2016-12-24 23:04:57 +08:00
|
|
|
if (title.find_first_of("*:/\\?[]") != std::string::npos)
|
|
|
|
{
|
|
|
|
throw invalid_sheet_title(title);
|
|
|
|
}
|
2016-08-02 06:33:43 +08:00
|
|
|
|
2017-02-27 20:47:33 +08:00
|
|
|
auto same_title = std::find_if(workbook().begin(), workbook().end(),
|
|
|
|
[&](worksheet ws) { return ws.title() == title; });
|
2016-08-02 06:33:43 +08:00
|
|
|
|
2016-12-24 23:04:57 +08:00
|
|
|
if (same_title != workbook().end() && *same_title != *this)
|
|
|
|
{
|
|
|
|
throw invalid_sheet_title(title);
|
|
|
|
}
|
2016-08-02 06:33:43 +08:00
|
|
|
|
2016-12-24 23:04:57 +08:00
|
|
|
workbook().d_->sheet_title_rel_id_map_[title] = workbook().d_->sheet_title_rel_id_map_[d_->title_];
|
|
|
|
workbook().d_->sheet_title_rel_id_map_.erase(d_->title_);
|
|
|
|
d_->title_ = title;
|
2017-02-27 20:47:33 +08:00
|
|
|
|
|
|
|
workbook().update_sheet_properties();
|
2014-05-21 22:20:30 +08:00
|
|
|
}
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
cell_reference worksheet::frozen_panes() const
|
2014-05-21 22:20:30 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
if (!has_frozen_panes())
|
|
|
|
{
|
|
|
|
throw xlnt::invalid_attribute();
|
|
|
|
}
|
|
|
|
|
|
|
|
return d_->views_.front().pane().top_left_cell.get();
|
2014-05-21 22:20:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void worksheet::freeze_panes(xlnt::cell top_left_cell)
|
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
freeze_panes(top_left_cell.reference());
|
2014-05-21 22:20:30 +08:00
|
|
|
}
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
void worksheet::freeze_panes(const cell_reference &ref)
|
2014-05-21 22:20:30 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
if (!has_view())
|
|
|
|
{
|
|
|
|
d_->views_.push_back(sheet_view());
|
|
|
|
}
|
|
|
|
|
|
|
|
auto &primary_view = d_->views_.front();
|
|
|
|
|
|
|
|
if (!primary_view.has_pane())
|
|
|
|
{
|
|
|
|
primary_view.pane(pane());
|
|
|
|
}
|
|
|
|
|
|
|
|
primary_view.pane().top_left_cell = ref;
|
|
|
|
primary_view.pane().state = pane_state::frozen;
|
|
|
|
|
|
|
|
primary_view.clear_selections();
|
|
|
|
primary_view.add_selection(selection());
|
2016-12-24 23:04:57 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
if (ref == "A1")
|
2016-03-08 15:45:35 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
unfreeze_panes();
|
2016-03-08 15:45:35 +08:00
|
|
|
}
|
2016-12-02 21:37:50 +08:00
|
|
|
else if (ref.column() == "A")
|
2016-03-08 15:45:35 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
primary_view.add_selection(selection());
|
|
|
|
primary_view.selection(0).pane(pane_corner::bottom_left);
|
|
|
|
primary_view.selection(0).active_cell(ref.make_offset(0, -1)); // cell above
|
|
|
|
primary_view.selection(1).active_cell(ref);
|
|
|
|
primary_view.pane().active_pane = pane_corner::bottom_left;
|
|
|
|
primary_view.pane().y_split = ref.row() - 1;
|
2016-03-08 15:45:35 +08:00
|
|
|
}
|
2016-12-02 21:37:50 +08:00
|
|
|
else if (ref.row() == 1)
|
2016-03-08 15:45:35 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
primary_view.add_selection(selection());
|
|
|
|
primary_view.selection(0).pane(pane_corner::top_right);
|
|
|
|
primary_view.selection(0).active_cell(ref.make_offset(-1, 0)); // cell to the left
|
|
|
|
primary_view.selection(1).active_cell(ref);
|
|
|
|
primary_view.pane().active_pane = pane_corner::top_right;
|
|
|
|
primary_view.pane().x_split = ref.column_index() - 1;
|
2016-03-08 15:45:35 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
primary_view.add_selection(selection());
|
|
|
|
primary_view.add_selection(selection());
|
|
|
|
primary_view.selection(0).pane(pane_corner::top_right);
|
|
|
|
primary_view.selection(0).active_cell(ref.make_offset(0, -1)); // cell above
|
|
|
|
primary_view.selection(1).pane(pane_corner::bottom_left);
|
|
|
|
primary_view.selection(1).active_cell(ref.make_offset(-1, 0)); // cell to the left
|
|
|
|
primary_view.selection(2).pane(pane_corner::bottom_right);
|
|
|
|
primary_view.selection(2).active_cell(ref);
|
|
|
|
primary_view.pane().active_pane = pane_corner::bottom_right;
|
|
|
|
primary_view.pane().x_split = ref.column_index() - 1;
|
|
|
|
primary_view.pane().y_split = ref.row() - 1;
|
2016-03-08 15:45:35 +08:00
|
|
|
}
|
2014-05-21 22:20:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void worksheet::unfreeze_panes()
|
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
if (!has_view()) return;
|
|
|
|
|
|
|
|
auto &primary_view = d_->views_.front();
|
|
|
|
|
|
|
|
primary_view.clear_selections();
|
|
|
|
primary_view.clear_pane();
|
2014-05-21 22:20:30 +08:00
|
|
|
}
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
cell worksheet::cell(const cell_reference &reference)
|
2014-05-21 22:20:30 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
auto &row = d_->cell_map_[reference.row()];
|
2017-09-09 07:08:38 +08:00
|
|
|
auto match = row.find(reference.column_index());
|
2015-11-01 22:43:01 +08:00
|
|
|
|
2017-09-09 07:08:38 +08:00
|
|
|
if (match == row.end())
|
2014-05-30 08:52:14 +08:00
|
|
|
{
|
2017-09-09 07:08:38 +08:00
|
|
|
match = row.emplace(reference.column_index(), detail::cell_impl()).first;
|
|
|
|
auto &impl = match->second;
|
|
|
|
|
2016-12-24 23:04:57 +08:00
|
|
|
impl.parent_ = d_;
|
|
|
|
impl.column_ = reference.column_index();
|
|
|
|
impl.row_ = reference.row();
|
2014-05-30 08:52:14 +08:00
|
|
|
}
|
2015-11-01 22:43:01 +08:00
|
|
|
|
2017-09-09 07:08:38 +08:00
|
|
|
return xlnt::cell(&match->second);
|
2014-05-21 22:20:30 +08:00
|
|
|
}
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
const cell worksheet::cell(const cell_reference &reference) const
|
2014-05-22 05:48:51 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
return xlnt::cell(&d_->cell_map_.at(reference.row()).at(reference.column_index()));
|
2014-05-22 05:48:51 +08:00
|
|
|
}
|
|
|
|
|
2017-03-23 09:44:59 +08:00
|
|
|
cell worksheet::cell(xlnt::column_t column, row_t row)
|
|
|
|
{
|
|
|
|
return cell(cell_reference(column, row));
|
|
|
|
}
|
|
|
|
|
|
|
|
const cell worksheet::cell(xlnt::column_t column, row_t row) const
|
|
|
|
{
|
|
|
|
return cell(cell_reference(column, row));
|
|
|
|
}
|
|
|
|
|
2015-12-24 14:58:11 +08:00
|
|
|
bool worksheet::has_cell(const cell_reference &reference) const
|
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
const auto row = d_->cell_map_.find(reference.row());
|
2016-12-24 23:04:57 +08:00
|
|
|
if (row == d_->cell_map_.cend()) return false;
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
const auto col = row->second.find(reference.column_index());
|
2016-12-24 23:04:57 +08:00
|
|
|
if (col == row->second.cend()) return false;
|
|
|
|
|
2015-12-24 14:58:11 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-06-11 05:12:15 +08:00
|
|
|
bool worksheet::has_row_properties(row_t row) const
|
|
|
|
{
|
|
|
|
return d_->row_properties_.find(row) != d_->row_properties_.end();
|
|
|
|
}
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
range worksheet::named_range(const std::string &name)
|
2014-05-21 22:20:30 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
if (!workbook().has_named_range(name))
|
2016-03-08 15:45:35 +08:00
|
|
|
{
|
2016-07-30 06:55:49 +08:00
|
|
|
throw key_not_found();
|
2016-03-08 15:45:35 +08:00
|
|
|
}
|
2016-12-24 23:04:57 +08:00
|
|
|
|
2015-11-01 22:43:01 +08:00
|
|
|
if (!has_named_range(name))
|
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
|
|
|
}
|
2015-11-01 22:43:01 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
return range(d_->named_ranges_[name].targets()[0].second);
|
2014-05-30 08:52:14 +08:00
|
|
|
}
|
|
|
|
|
2017-03-21 08:17:09 +08:00
|
|
|
const range worksheet::named_range(const std::string &name) const
|
|
|
|
{
|
|
|
|
if (!workbook().has_named_range(name))
|
|
|
|
{
|
|
|
|
throw key_not_found();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!has_named_range(name))
|
|
|
|
{
|
|
|
|
throw key_not_found();
|
|
|
|
}
|
|
|
|
|
|
|
|
return range(d_->named_ranges_[name].targets()[0].second);
|
|
|
|
}
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
column_t worksheet::lowest_column() const
|
2014-05-30 08:52:14 +08:00
|
|
|
{
|
2015-11-01 22:43:01 +08:00
|
|
|
if (d_->cell_map_.empty())
|
2014-05-30 08:52:14 +08:00
|
|
|
{
|
2016-07-23 08:26:02 +08:00
|
|
|
return constants::min_column();
|
2014-05-30 08:52:14 +08:00
|
|
|
}
|
2015-11-01 22:43:01 +08:00
|
|
|
|
2016-07-23 08:26:02 +08:00
|
|
|
column_t lowest = constants::max_column();
|
2015-11-01 22:43:01 +08:00
|
|
|
|
|
|
|
for (auto &row : d_->cell_map_)
|
2014-05-30 08:52:14 +08:00
|
|
|
{
|
2015-11-01 22:43:01 +08:00
|
|
|
for (auto &c : row.second)
|
2014-05-30 08:52:14 +08:00
|
|
|
{
|
2015-11-04 03:53:48 +08:00
|
|
|
lowest = std::min(lowest, c.first);
|
2014-05-30 08:52:14 +08:00
|
|
|
}
|
|
|
|
}
|
2015-11-01 22:43:01 +08:00
|
|
|
|
2015-10-14 01:56:07 +08:00
|
|
|
return lowest;
|
2014-05-30 08:52:14 +08:00
|
|
|
}
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
row_t worksheet::lowest_row() const
|
2014-05-30 08:52:14 +08:00
|
|
|
{
|
2015-11-01 22:43:01 +08:00
|
|
|
if (d_->cell_map_.empty())
|
2014-05-30 08:52:14 +08:00
|
|
|
{
|
2016-07-23 08:26:02 +08:00
|
|
|
return constants::min_row();
|
2014-05-30 08:52:14 +08:00
|
|
|
}
|
2015-11-01 22:43:01 +08:00
|
|
|
|
2016-07-23 08:26:02 +08:00
|
|
|
row_t lowest = constants::max_row();
|
2015-11-01 22:43:01 +08:00
|
|
|
|
|
|
|
for (auto &row : d_->cell_map_)
|
2014-05-30 08:52:14 +08:00
|
|
|
{
|
2015-11-04 03:53:48 +08:00
|
|
|
lowest = std::min(lowest, row.first);
|
2014-05-30 08:52:14 +08:00
|
|
|
}
|
2015-11-01 22:43:01 +08:00
|
|
|
|
2015-10-14 01:56:07 +08:00
|
|
|
return lowest;
|
2014-05-21 22:20:30 +08:00
|
|
|
}
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
row_t worksheet::highest_row() const
|
2014-05-21 22:20:30 +08:00
|
|
|
{
|
2016-07-23 08:26:02 +08:00
|
|
|
row_t highest = constants::min_row();
|
2015-11-01 22:43:01 +08:00
|
|
|
|
|
|
|
for (auto &row : d_->cell_map_)
|
2014-05-30 08:52:14 +08:00
|
|
|
{
|
2015-11-04 03:53:48 +08:00
|
|
|
highest = std::max(highest, row.first);
|
2014-05-30 08:52:14 +08:00
|
|
|
}
|
2015-11-01 22:43:01 +08:00
|
|
|
|
2015-10-14 01:56:07 +08:00
|
|
|
return highest;
|
2014-05-21 22:20:30 +08:00
|
|
|
}
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
column_t worksheet::highest_column() const
|
2014-05-21 22:20:30 +08:00
|
|
|
{
|
2016-07-23 08:26:02 +08:00
|
|
|
column_t highest = constants::min_column();
|
2015-11-01 22:43:01 +08:00
|
|
|
|
|
|
|
for (auto &row : d_->cell_map_)
|
2014-05-30 08:52:14 +08:00
|
|
|
{
|
2015-11-01 22:43:01 +08:00
|
|
|
for (auto &c : row.second)
|
2014-05-30 08:52:14 +08:00
|
|
|
{
|
2015-11-04 03:53:48 +08:00
|
|
|
highest = std::max(highest, c.first);
|
2014-05-30 08:52:14 +08:00
|
|
|
}
|
|
|
|
}
|
2015-11-01 22:43:01 +08:00
|
|
|
|
2015-10-14 01:56:07 +08:00
|
|
|
return highest;
|
2014-05-21 22:20:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
range_reference worksheet::calculate_dimension() const
|
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
return range_reference(lowest_column(), lowest_row(), highest_column(), highest_row());
|
2014-05-21 22:20:30 +08:00
|
|
|
}
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
range worksheet::range(const std::string &reference_string)
|
2015-11-11 08:47:31 +08:00
|
|
|
{
|
2017-03-21 08:17:09 +08:00
|
|
|
if (has_named_range(reference_string))
|
|
|
|
{
|
|
|
|
return named_range(reference_string);
|
|
|
|
}
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
return range(range_reference(reference_string));
|
2015-11-11 08:47:31 +08:00
|
|
|
}
|
|
|
|
|
2017-03-21 08:17:09 +08:00
|
|
|
const range worksheet::range(const std::string &reference_string) const
|
2014-05-21 22:20:30 +08:00
|
|
|
{
|
2017-03-21 08:17:09 +08:00
|
|
|
if (has_named_range(reference_string))
|
|
|
|
{
|
|
|
|
return named_range(reference_string);
|
|
|
|
}
|
|
|
|
|
|
|
|
return range(range_reference(reference_string));
|
2014-05-30 08:52:14 +08:00
|
|
|
}
|
|
|
|
|
2017-03-21 08:17:09 +08:00
|
|
|
range worksheet::range(const range_reference &reference)
|
2015-11-11 08:47:31 +08:00
|
|
|
{
|
2017-03-21 08:17:09 +08:00
|
|
|
return xlnt::range(*this, reference);
|
2015-11-11 08:47:31 +08:00
|
|
|
}
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
const range worksheet::range(const range_reference &reference) const
|
2014-05-30 08:52:14 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
return xlnt::range(*this, reference);
|
2014-05-21 22:20:30 +08:00
|
|
|
}
|
|
|
|
|
2015-11-11 08:47:31 +08:00
|
|
|
void worksheet::merge_cells(const std::string &reference_string)
|
|
|
|
{
|
|
|
|
merge_cells(range_reference(reference_string));
|
|
|
|
}
|
|
|
|
|
|
|
|
void worksheet::unmerge_cells(const std::string &reference_string)
|
|
|
|
{
|
|
|
|
unmerge_cells(range_reference(reference_string));
|
|
|
|
}
|
|
|
|
|
2014-05-21 22:20:30 +08:00
|
|
|
void worksheet::merge_cells(const range_reference &reference)
|
|
|
|
{
|
2014-05-30 08:52:14 +08:00
|
|
|
d_->merged_cells_.push_back(reference);
|
|
|
|
bool first = true;
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
for (auto row : range(reference))
|
2014-05-30 08:52:14 +08:00
|
|
|
{
|
2015-11-01 22:43:01 +08:00
|
|
|
for (auto cell : row)
|
2014-05-30 08:52:14 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
cell.merged(true);
|
2014-07-26 04:39:25 +08:00
|
|
|
|
2015-11-01 22:43:01 +08:00
|
|
|
if (!first)
|
2014-05-30 08:52:14 +08:00
|
|
|
{
|
2017-05-10 20:44:25 +08:00
|
|
|
if (cell.data_type() == cell::type::shared_string)
|
2014-07-26 04:39:25 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
cell.value("");
|
2014-07-26 04:39:25 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-10-14 01:56:07 +08:00
|
|
|
cell.clear_value();
|
2014-07-26 04:39:25 +08:00
|
|
|
}
|
2014-05-30 08:52:14 +08:00
|
|
|
}
|
2014-07-26 04:39:25 +08:00
|
|
|
|
2014-05-30 08:52:14 +08:00
|
|
|
first = false;
|
|
|
|
}
|
|
|
|
}
|
2014-05-21 22:20:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void worksheet::unmerge_cells(const range_reference &reference)
|
|
|
|
{
|
2014-05-30 08:52:14 +08:00
|
|
|
auto match = std::find(d_->merged_cells_.begin(), d_->merged_cells_.end(), reference);
|
2015-11-01 22:43:01 +08:00
|
|
|
|
|
|
|
if (match == d_->merged_cells_.end())
|
2014-05-30 08:52:14 +08:00
|
|
|
{
|
2016-12-24 23:04:57 +08:00
|
|
|
throw invalid_parameter();
|
2014-05-30 08:52:14 +08:00
|
|
|
}
|
2015-11-01 22:43:01 +08:00
|
|
|
|
2014-05-30 08:52:14 +08:00
|
|
|
d_->merged_cells_.erase(match);
|
2015-11-01 22:43:01 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
for (auto row : range(reference))
|
2014-05-30 08:52:14 +08:00
|
|
|
{
|
2015-11-01 22:43:01 +08:00
|
|
|
for (auto cell : row)
|
2014-05-30 08:52:14 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
cell.merged(false);
|
2014-05-30 08:52:14 +08:00
|
|
|
}
|
|
|
|
}
|
2014-05-21 22:20:30 +08:00
|
|
|
}
|
2015-11-01 22:43:01 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
row_t worksheet::next_row() const
|
2015-10-14 04:35:22 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
auto row = highest_row() + 1;
|
2015-11-01 22:43:01 +08:00
|
|
|
|
|
|
|
if (row == 2 && d_->cell_map_.size() == 0)
|
2014-05-31 06:42:25 +08:00
|
|
|
{
|
2015-10-14 04:35:22 +08:00
|
|
|
row = 1;
|
2014-05-31 06:42:25 +08:00
|
|
|
}
|
2015-11-01 22:43:01 +08:00
|
|
|
|
2015-10-14 04:35:22 +08:00
|
|
|
return row;
|
2014-05-31 06:42:25 +08:00
|
|
|
}
|
|
|
|
|
2017-03-24 08:05:25 +08:00
|
|
|
xlnt::range worksheet::rows(bool skip_null)
|
2014-05-21 22:20:30 +08:00
|
|
|
{
|
2017-03-24 08:05:25 +08:00
|
|
|
return xlnt::range(*this, calculate_dimension(), major_order::row, skip_null);
|
|
|
|
}
|
|
|
|
|
|
|
|
const xlnt::range worksheet::rows(bool skip_null) const
|
|
|
|
{
|
|
|
|
return xlnt::range(*this, calculate_dimension(), major_order::row, skip_null);
|
|
|
|
}
|
|
|
|
|
|
|
|
xlnt::range worksheet::columns(bool skip_null)
|
|
|
|
{
|
|
|
|
return xlnt::range(*this, calculate_dimension(), major_order::column, skip_null);
|
|
|
|
}
|
|
|
|
|
|
|
|
const xlnt::range worksheet::columns(bool skip_null) const
|
|
|
|
{
|
|
|
|
return xlnt::range(*this, calculate_dimension(), major_order::column, skip_null);
|
2014-05-21 22:20:30 +08:00
|
|
|
}
|
|
|
|
|
2017-03-24 08:05:25 +08:00
|
|
|
/*
|
|
|
|
//TODO: finish implementing cell_iterator wrapping before uncommenting
|
|
|
|
|
|
|
|
cell_vector worksheet::cells(bool skip_null)
|
2014-07-20 04:59:05 +08:00
|
|
|
{
|
2017-03-24 08:05:25 +08:00
|
|
|
const auto dimension = calculate_dimension();
|
|
|
|
return cell_vector(*this, dimension.top_left(), dimension, major_order::row, skip_null, true);
|
2014-07-20 04:59:05 +08:00
|
|
|
}
|
|
|
|
|
2017-03-24 08:05:25 +08:00
|
|
|
const cell_vector worksheet::cells(bool skip_null) const
|
|
|
|
{
|
|
|
|
const auto dimension = calculate_dimension();
|
|
|
|
return cell_vector(*this, dimension.top_left(), dimension, major_order::row, skip_null, true);
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2014-05-21 22:20:30 +08:00
|
|
|
bool worksheet::operator==(const worksheet &other) const
|
|
|
|
{
|
2016-03-06 10:39:50 +08:00
|
|
|
return compare(other, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool worksheet::compare(const worksheet &other, bool reference) const
|
|
|
|
{
|
2016-12-24 23:04:57 +08:00
|
|
|
if (reference)
|
2016-03-06 10:39:50 +08:00
|
|
|
{
|
|
|
|
return d_ == other.d_;
|
|
|
|
}
|
2016-12-24 23:04:57 +08:00
|
|
|
|
|
|
|
if (d_->parent_ != other.d_->parent_) return false;
|
|
|
|
|
|
|
|
for (auto &row : d_->cell_map_)
|
2016-03-06 10:39:50 +08:00
|
|
|
{
|
2016-12-24 23:04:57 +08:00
|
|
|
if (other.d_->cell_map_.find(row.first) == other.d_->cell_map_.end())
|
2016-03-06 10:39:50 +08:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2016-12-24 23:04:57 +08:00
|
|
|
|
|
|
|
for (auto &cell : row.second)
|
2016-03-06 10:39:50 +08:00
|
|
|
{
|
2016-12-24 23:04:57 +08:00
|
|
|
if (other.d_->cell_map_[row.first].find(cell.first) == other.d_->cell_map_[row.first].end())
|
2016-03-06 10:39:50 +08:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2016-12-24 23:04:57 +08:00
|
|
|
|
2016-08-16 12:23:49 +08:00
|
|
|
xlnt::cell this_cell(&cell.second);
|
2016-12-24 23:04:57 +08:00
|
|
|
xlnt::cell other_cell(&other.d_->cell_map_[row.first][cell.first]);
|
2016-06-23 16:33:10 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
if (this_cell.data_type() != other_cell.data_type())
|
2016-06-23 16:33:10 +08:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-05-10 20:44:25 +08:00
|
|
|
if (this_cell.data_type() == xlnt::cell::type::number
|
2016-12-02 21:37:50 +08:00
|
|
|
&& std::fabs(this_cell.value<long double>() - other_cell.value<long double>()) > 0.L)
|
2016-03-06 10:39:50 +08:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-12-24 23:04:57 +08:00
|
|
|
|
2016-03-06 10:39:50 +08:00
|
|
|
// todo: missing some comparisons
|
2016-12-24 23:04:57 +08:00
|
|
|
|
|
|
|
if (d_->auto_filter_ == other.d_->auto_filter_ && d_->views_ == other.d_->views_
|
2016-12-10 08:18:50 +08:00
|
|
|
&& d_->merged_cells_ == other.d_->merged_cells_)
|
2016-03-06 10:39:50 +08:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2016-12-24 23:04:57 +08:00
|
|
|
|
2016-03-06 10:39:50 +08:00
|
|
|
return false;
|
2014-05-21 22:20:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool worksheet::operator!=(const worksheet &other) const
|
|
|
|
{
|
2016-03-06 10:39:50 +08:00
|
|
|
return !(*this == other);
|
2014-05-21 22:20:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool worksheet::operator==(std::nullptr_t) const
|
|
|
|
{
|
2014-05-30 08:52:14 +08:00
|
|
|
return d_ == nullptr;
|
2014-05-21 22:20:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool worksheet::operator!=(std::nullptr_t) const
|
|
|
|
{
|
2014-05-30 08:52:14 +08:00
|
|
|
return d_ != nullptr;
|
2014-05-21 22:20:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void worksheet::operator=(const worksheet &other)
|
|
|
|
{
|
2014-05-30 08:52:14 +08:00
|
|
|
d_ = other.d_;
|
2014-05-21 22:20:30 +08:00
|
|
|
}
|
|
|
|
|
2014-05-22 05:48:51 +08:00
|
|
|
const cell worksheet::operator[](const cell_reference &ref) const
|
2014-05-21 22:20:30 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
return cell(ref);
|
2014-05-21 22:20:30 +08:00
|
|
|
}
|
|
|
|
|
2017-03-21 08:17:09 +08:00
|
|
|
bool worksheet::has_named_range(const std::string &name) const
|
2014-05-21 22:20:30 +08:00
|
|
|
{
|
2014-05-30 08:52:14 +08:00
|
|
|
return d_->named_ranges_.find(name) != d_->named_ranges_.end();
|
2014-05-21 22:20:30 +08:00
|
|
|
}
|
2014-05-30 08:52:14 +08:00
|
|
|
|
2015-11-11 07:58:54 +08:00
|
|
|
void worksheet::remove_named_range(const std::string &name)
|
2014-05-21 22:20:30 +08:00
|
|
|
{
|
2015-11-01 22:43:01 +08:00
|
|
|
if (!has_named_range(name))
|
2014-05-30 08:52:14 +08:00
|
|
|
{
|
2016-12-24 23:04:57 +08:00
|
|
|
throw key_not_found();
|
2014-05-30 08:52:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
d_->named_ranges_.erase(name);
|
2014-05-21 22:20:30 +08:00
|
|
|
}
|
2014-05-22 05:48:51 +08:00
|
|
|
|
|
|
|
void worksheet::reserve(std::size_t n)
|
|
|
|
{
|
2014-05-30 08:52:14 +08:00
|
|
|
d_->cell_map_.reserve(n);
|
2014-05-22 05:48:51 +08:00
|
|
|
}
|
2015-11-01 22:43:01 +08:00
|
|
|
|
2016-12-10 08:18:50 +08:00
|
|
|
class header_footer worksheet::header_footer() const
|
2014-07-20 04:59:05 +08:00
|
|
|
{
|
2016-12-10 08:18:50 +08:00
|
|
|
return d_->header_footer_.get();
|
2014-07-20 04:59:05 +08:00
|
|
|
}
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
cell_reference worksheet::point_pos(int left, int top) const
|
2014-07-26 04:39:25 +08:00
|
|
|
{
|
2015-10-14 01:56:07 +08:00
|
|
|
column_t current_column = 1;
|
|
|
|
row_t current_row = 1;
|
2014-07-26 04:39:25 +08:00
|
|
|
|
2016-12-26 22:38:26 +08:00
|
|
|
double left_pos = 0;
|
|
|
|
double top_pos = 0;
|
2014-07-26 04:39:25 +08:00
|
|
|
|
2015-11-01 22:43:01 +08:00
|
|
|
while (left_pos <= left)
|
2014-07-26 04:39:25 +08:00
|
|
|
{
|
2016-12-24 23:04:57 +08:00
|
|
|
left_pos += column_width(current_column++);
|
2014-07-26 04:39:25 +08:00
|
|
|
}
|
|
|
|
|
2015-11-01 22:43:01 +08:00
|
|
|
while (top_pos <= top)
|
2014-07-26 04:39:25 +08:00
|
|
|
{
|
2016-12-24 23:04:57 +08:00
|
|
|
top_pos += row_height(current_row++);
|
2014-07-26 04:39:25 +08:00
|
|
|
}
|
|
|
|
|
2016-12-24 23:04:57 +08:00
|
|
|
return {current_column - 1, current_row - 1};
|
2014-07-26 04:39:25 +08:00
|
|
|
}
|
|
|
|
|
2016-12-03 17:46:11 +08:00
|
|
|
void worksheet::sheet_state(xlnt::sheet_state state)
|
2015-10-14 12:03:48 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
page_setup().sheet_state(state);
|
2015-10-14 12:03:48 +08:00
|
|
|
}
|
2016-07-30 05:50:33 +08:00
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
sheet_state worksheet::sheet_state() const
|
2016-07-30 05:50:33 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
return page_setup().sheet_state();
|
2016-07-30 05:50:33 +08:00
|
|
|
}
|
2014-07-26 04:39:25 +08:00
|
|
|
|
2015-10-29 03:08:54 +08:00
|
|
|
void worksheet::add_column_properties(column_t column, const xlnt::column_properties &props)
|
|
|
|
{
|
|
|
|
d_->column_properties_[column] = props;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool worksheet::has_column_properties(column_t column) const
|
|
|
|
{
|
|
|
|
return d_->column_properties_.find(column) != d_->column_properties_.end();
|
|
|
|
}
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
column_properties &worksheet::column_properties(column_t column)
|
2015-10-29 03:08:54 +08:00
|
|
|
{
|
|
|
|
return d_->column_properties_[column];
|
|
|
|
}
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
const column_properties &worksheet::column_properties(column_t column) const
|
2015-10-29 03:08:54 +08:00
|
|
|
{
|
|
|
|
return d_->column_properties_.at(column);
|
|
|
|
}
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
row_properties &worksheet::row_properties(row_t row)
|
2015-10-29 03:08:54 +08:00
|
|
|
{
|
|
|
|
return d_->row_properties_[row];
|
|
|
|
}
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
const row_properties &worksheet::row_properties(row_t row) const
|
2015-10-29 03:08:54 +08:00
|
|
|
{
|
|
|
|
return d_->row_properties_.at(row);
|
|
|
|
}
|
|
|
|
|
2017-01-03 07:36:33 +08:00
|
|
|
void worksheet::add_row_properties(row_t row, const xlnt::row_properties &props)
|
|
|
|
{
|
|
|
|
d_->row_properties_[row] = props;
|
|
|
|
}
|
|
|
|
|
2015-11-21 09:41:32 +08:00
|
|
|
worksheet::iterator worksheet::begin()
|
|
|
|
{
|
2017-03-24 08:05:25 +08:00
|
|
|
return rows().begin();
|
2015-11-21 09:41:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
worksheet::iterator worksheet::end()
|
|
|
|
{
|
2017-03-24 08:05:25 +08:00
|
|
|
return rows().end();
|
2015-11-21 09:41:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
worksheet::const_iterator worksheet::cbegin() const
|
|
|
|
{
|
2017-03-24 08:05:25 +08:00
|
|
|
return rows().cbegin();
|
2015-11-21 09:41:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
worksheet::const_iterator worksheet::cend() const
|
|
|
|
{
|
2017-03-24 08:05:25 +08:00
|
|
|
return rows().cend();
|
2015-11-21 09:41:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
worksheet::const_iterator worksheet::begin() const
|
|
|
|
{
|
|
|
|
return cbegin();
|
|
|
|
}
|
|
|
|
|
|
|
|
worksheet::const_iterator worksheet::end() const
|
|
|
|
{
|
|
|
|
return cend();
|
|
|
|
}
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
void worksheet::print_title_rows(row_t last_row)
|
2016-03-08 15:45:35 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
print_title_rows(1, last_row);
|
2016-03-08 15:45:35 +08:00
|
|
|
}
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
void worksheet::print_title_rows(row_t first_row, row_t last_row)
|
2016-03-08 15:45:35 +08:00
|
|
|
{
|
2016-11-01 08:48:43 +08:00
|
|
|
d_->print_title_rows_ = std::to_string(first_row) + ":" + std::to_string(last_row);
|
2016-03-08 15:45:35 +08:00
|
|
|
}
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
void worksheet::print_title_cols(column_t last_column)
|
2016-03-08 15:45:35 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
print_title_cols(1, last_column);
|
2016-03-08 15:45:35 +08:00
|
|
|
}
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
void worksheet::print_title_cols(column_t first_column, column_t last_column)
|
2016-03-08 15:45:35 +08:00
|
|
|
{
|
2016-11-01 08:48:43 +08:00
|
|
|
d_->print_title_cols_ = first_column.column_string() + ":" + last_column.column_string();
|
2016-03-08 15:45:35 +08:00
|
|
|
}
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
std::string worksheet::print_titles() const
|
2016-03-08 15:45:35 +08:00
|
|
|
{
|
|
|
|
if (!d_->print_title_rows_.empty() && !d_->print_title_cols_.empty())
|
|
|
|
{
|
|
|
|
return d_->title_ + "!" + d_->print_title_rows_ + "," + d_->title_ + "!" + d_->print_title_cols_;
|
|
|
|
}
|
|
|
|
else if (!d_->print_title_cols_.empty())
|
|
|
|
{
|
|
|
|
return d_->title_ + "!" + d_->print_title_cols_;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return d_->title_ + "!" + d_->print_title_rows_;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
void worksheet::print_area(const std::string &print_area)
|
2016-03-08 15:45:35 +08:00
|
|
|
{
|
|
|
|
d_->print_area_ = range_reference::make_absolute(range_reference(print_area));
|
|
|
|
}
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
range_reference worksheet::print_area() const
|
2016-03-08 15:45:35 +08:00
|
|
|
{
|
2016-12-10 08:18:50 +08:00
|
|
|
return d_->print_area_.get();
|
2016-03-08 15:45:35 +08:00
|
|
|
}
|
|
|
|
|
2016-08-14 02:45:26 +08:00
|
|
|
bool worksheet::has_view() const
|
|
|
|
{
|
2016-12-24 23:04:57 +08:00
|
|
|
return !d_->views_.empty();
|
2016-08-14 02:45:26 +08:00
|
|
|
}
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
sheet_view worksheet::view(std::size_t index) const
|
2016-08-14 02:45:26 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
return d_->views_.at(index);
|
2016-08-14 02:45:26 +08:00
|
|
|
}
|
|
|
|
|
2016-12-02 21:37:50 +08:00
|
|
|
void worksheet::add_view(const sheet_view &new_view)
|
2016-08-14 02:45:26 +08:00
|
|
|
{
|
2016-12-02 21:37:50 +08:00
|
|
|
d_->views_.push_back(new_view);
|
2016-08-14 02:45:26 +08:00
|
|
|
}
|
|
|
|
|
2016-10-30 04:31:30 +08:00
|
|
|
void worksheet::register_comments_in_manifest()
|
|
|
|
{
|
2017-01-16 08:08:57 +08:00
|
|
|
workbook().register_worksheet_part(*this, relationship_type::comments);
|
2016-10-30 04:31:30 +08:00
|
|
|
}
|
|
|
|
|
2017-02-18 13:11:06 +08:00
|
|
|
void worksheet::register_calc_chain_in_manifest()
|
|
|
|
{
|
|
|
|
workbook().register_workbook_part(relationship_type::calculation_chain);
|
|
|
|
}
|
|
|
|
|
2016-12-10 08:18:50 +08:00
|
|
|
bool worksheet::has_header_footer() const
|
|
|
|
{
|
|
|
|
return d_->header_footer_.is_set();
|
|
|
|
}
|
|
|
|
|
|
|
|
void worksheet::header_footer(const class header_footer &hf)
|
|
|
|
{
|
|
|
|
d_->header_footer_ = hf;
|
|
|
|
}
|
|
|
|
|
2017-08-19 08:58:44 +08:00
|
|
|
void worksheet::clear_page_breaks()
|
|
|
|
{
|
|
|
|
d_->row_breaks_.clear();
|
|
|
|
d_->column_breaks_.clear();
|
|
|
|
}
|
|
|
|
|
2016-12-24 23:04:57 +08:00
|
|
|
void worksheet::page_break_at_row(row_t row)
|
2016-12-23 07:57:22 +08:00
|
|
|
{
|
2016-12-24 23:04:57 +08:00
|
|
|
d_->row_breaks_.push_back(row);
|
2016-12-23 07:57:22 +08:00
|
|
|
}
|
|
|
|
|
2016-12-24 23:04:57 +08:00
|
|
|
const std::vector<row_t> &worksheet::page_break_rows() const
|
2016-12-23 07:57:22 +08:00
|
|
|
{
|
|
|
|
return d_->row_breaks_;
|
|
|
|
}
|
|
|
|
|
2016-12-24 23:04:57 +08:00
|
|
|
void worksheet::page_break_at_column(xlnt::column_t column)
|
2016-12-23 07:57:22 +08:00
|
|
|
{
|
2016-12-24 23:04:57 +08:00
|
|
|
d_->column_breaks_.push_back(column);
|
2016-12-23 07:57:22 +08:00
|
|
|
}
|
|
|
|
|
2016-12-24 23:04:57 +08:00
|
|
|
const std::vector<column_t> &worksheet::page_break_columns() const
|
2016-12-23 07:57:22 +08:00
|
|
|
{
|
|
|
|
return d_->column_breaks_;
|
|
|
|
}
|
|
|
|
|
2016-12-24 23:04:57 +08:00
|
|
|
double worksheet::column_width(column_t column) const
|
|
|
|
{
|
|
|
|
static const auto DefaultColumnWidth = 51.85;
|
|
|
|
|
|
|
|
if (has_column_properties(column))
|
|
|
|
{
|
|
|
|
return column_properties(column).width.get();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return points_to_pixels(DefaultColumnWidth, 96.0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
double worksheet::row_height(row_t row) const
|
|
|
|
{
|
|
|
|
static const auto DefaultRowHeight = 15.0;
|
|
|
|
|
|
|
|
if (has_row_properties(row))
|
|
|
|
{
|
|
|
|
return row_properties(row).height.get();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return points_to_pixels(DefaultRowHeight, 96.0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-03 08:12:23 +08:00
|
|
|
void worksheet::garbage_collect_formulae()
|
|
|
|
{
|
|
|
|
workbook().garbage_collect_formulae();
|
|
|
|
}
|
|
|
|
|
2017-03-21 08:17:09 +08:00
|
|
|
void worksheet::parent(xlnt::workbook &wb)
|
|
|
|
{
|
|
|
|
d_->parent_ = &wb;
|
|
|
|
}
|
|
|
|
|
2017-04-04 07:24:36 +08:00
|
|
|
conditional_format worksheet::conditional_format(const range_reference &ref, const condition &when)
|
|
|
|
{
|
|
|
|
return workbook().d_->stylesheet_.get().add_conditional_format_rule(d_, ref, when);
|
|
|
|
}
|
|
|
|
|
2014-05-21 22:20:30 +08:00
|
|
|
} // namespace xlnt
|