mirror of
https://github.com/tfussell/xlnt.git
synced 2024-03-22 13:11:17 +08:00
improve pane freezing, add print area and print title rows/cols, sync worksheet tests
This commit is contained in:
parent
ad69dcb335
commit
e7b062bb4c
|
@ -24,14 +24,41 @@
|
|||
#pragma once
|
||||
|
||||
#include <xlnt/xlnt_config.hpp>
|
||||
#include <xlnt/cell/cell_reference.hpp>
|
||||
|
||||
namespace xlnt {
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
enum class XLNT_CLASS pane_state
|
||||
{
|
||||
frozen,
|
||||
normal
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
enum class XLNT_CLASS pane_corner
|
||||
{
|
||||
top_left,
|
||||
top_right,
|
||||
bottom_left,
|
||||
bottom_right
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// A fixed portion of a worksheet.
|
||||
/// </summary>
|
||||
class XLNT_CLASS pane
|
||||
{
|
||||
public:
|
||||
cell_reference top_left_cell;
|
||||
pane_state state;
|
||||
pane_corner active_pane;
|
||||
int y_split;
|
||||
int x_split;
|
||||
};
|
||||
|
||||
} // namespace xlnt
|
||||
|
|
|
@ -23,6 +23,9 @@
|
|||
#pragma once
|
||||
|
||||
#include <xlnt/xlnt_config.hpp>
|
||||
#include <xlnt/cell/cell_reference.hpp>
|
||||
#include <xlnt/worksheet/pane.hpp>
|
||||
#include <xlnt/worksheet/range_reference.hpp>
|
||||
|
||||
namespace xlnt {
|
||||
|
||||
|
@ -31,6 +34,16 @@ namespace xlnt {
|
|||
/// </summary>
|
||||
class XLNT_CLASS selection
|
||||
{
|
||||
public:
|
||||
cell_reference get_active_cell() const { return active_cell_; }
|
||||
range_reference get_sqref() const { return sqref_; }
|
||||
pane_corner get_pane() const { return pane_; }
|
||||
void set_pane(pane_corner corner) { pane_ = corner; }
|
||||
|
||||
private:
|
||||
cell_reference active_cell_;
|
||||
range_reference sqref_;
|
||||
pane_corner pane_;
|
||||
};
|
||||
|
||||
} // namespace xlnt
|
||||
|
|
|
@ -24,6 +24,8 @@
|
|||
#pragma once
|
||||
|
||||
#include <xlnt/xlnt_config.hpp>
|
||||
#include <xlnt/worksheet/pane.hpp>
|
||||
#include <xlnt/worksheet/selection.hpp>
|
||||
|
||||
namespace xlnt {
|
||||
|
||||
|
@ -33,6 +35,15 @@ namespace xlnt {
|
|||
/// </summary>
|
||||
class XLNT_CLASS sheet_view
|
||||
{
|
||||
public:
|
||||
pane &get_pane() { return pane_; }
|
||||
const pane &get_pane() const { return pane_; }
|
||||
std::vector<selection> &get_selections() { return selections_; }
|
||||
const std::vector<selection> &get_selections() const { return selections_; }
|
||||
|
||||
private:
|
||||
pane pane_;
|
||||
std::vector<selection> selections_;
|
||||
};
|
||||
|
||||
} // namespace xlnt
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
#include <xlnt/worksheet/header_footer.hpp>
|
||||
#include <xlnt/worksheet/page_margins.hpp>
|
||||
#include <xlnt/worksheet/page_setup.hpp>
|
||||
#include <xlnt/worksheet/sheet_view.hpp>
|
||||
|
||||
namespace xlnt {
|
||||
|
||||
|
@ -218,6 +219,17 @@ public:
|
|||
const_iterator cend() const;
|
||||
|
||||
range iter_cells(bool skip_null);
|
||||
|
||||
void add_print_title(int i);
|
||||
void add_print_title(int i, const std::string &rows_or_cols);
|
||||
void set_print_title_rows(const std::string &rows);
|
||||
void set_print_title_cols(const std::string &rows);
|
||||
std::string get_print_titles() const;
|
||||
|
||||
void set_print_area(const std::string &print_area);
|
||||
range_reference get_print_area() const;
|
||||
|
||||
sheet_view get_sheet_view() const;
|
||||
|
||||
private:
|
||||
friend class workbook;
|
||||
|
|
|
@ -69,7 +69,12 @@ cell_reference::cell_reference(const std::string &column, row_t row)
|
|||
cell_reference::cell_reference(column_t column_index, row_t row)
|
||||
: column_(column_index), row_(row), absolute_row_(false), absolute_column_(false)
|
||||
{
|
||||
if (row_ == 0 || !(row_ <= constants::MaxRow()) || column_ == 0 || !(column_ <= constants::MaxColumn()))
|
||||
if (row_ == 0 || column_ == 0)
|
||||
{
|
||||
throw value_error();
|
||||
}
|
||||
|
||||
if (!(row_ <= constants::MaxRow()) || !(column_ <= constants::MaxColumn()))
|
||||
{
|
||||
throw cell_coordinates_exception(column_, row_);
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ namespace detail {
|
|||
struct worksheet_impl
|
||||
{
|
||||
worksheet_impl(workbook *parent_workbook, const std::string &title)
|
||||
: parent_(parent_workbook), title_(title), freeze_panes_("A1"), comment_count_(0)
|
||||
: parent_(parent_workbook), title_(title), comment_count_(0)
|
||||
{
|
||||
page_margins_.set_left(0.75);
|
||||
page_margins_.set_right(0.75);
|
||||
|
@ -59,7 +59,6 @@ struct worksheet_impl
|
|||
column_properties_ = other.column_properties_;
|
||||
row_properties_ = other.row_properties_;
|
||||
title_ = other.title_;
|
||||
freeze_panes_ = other.freeze_panes_;
|
||||
cell_map_ = other.cell_map_;
|
||||
for (auto &row : cell_map_)
|
||||
{
|
||||
|
@ -76,13 +75,16 @@ struct worksheet_impl
|
|||
named_ranges_ = other.named_ranges_;
|
||||
comment_count_ = other.comment_count_;
|
||||
header_footer_ = other.header_footer_;
|
||||
print_title_cols_ = other.print_title_cols_;
|
||||
print_title_rows_ = other.print_title_rows_;
|
||||
print_area_ = other.print_area_;
|
||||
view_ = other.view_;
|
||||
}
|
||||
|
||||
workbook *parent_;
|
||||
std::unordered_map<column_t, column_properties> column_properties_;
|
||||
std::unordered_map<row_t, row_properties> row_properties_;
|
||||
std::string title_;
|
||||
cell_reference freeze_panes_;
|
||||
std::unordered_map<row_t, std::unordered_map<column_t, cell_impl>> cell_map_;
|
||||
std::vector<relationship> relationships_;
|
||||
page_setup page_setup_;
|
||||
|
@ -92,6 +94,10 @@ struct worksheet_impl
|
|||
std::unordered_map<std::string, named_range> named_ranges_;
|
||||
std::size_t comment_count_;
|
||||
header_footer header_footer_;
|
||||
std::string print_title_cols_;
|
||||
std::string print_title_rows_;
|
||||
range_reference print_area_;
|
||||
sheet_view view_;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -216,22 +216,59 @@ void worksheet::set_title(const std::string &title)
|
|||
|
||||
cell_reference worksheet::get_frozen_panes() const
|
||||
{
|
||||
return d_->freeze_panes_;
|
||||
return d_->view_.get_pane().top_left_cell;
|
||||
}
|
||||
|
||||
void worksheet::freeze_panes(xlnt::cell top_left_cell)
|
||||
{
|
||||
d_->freeze_panes_ = top_left_cell.get_reference();
|
||||
freeze_panes(top_left_cell.get_reference().to_string());
|
||||
}
|
||||
|
||||
void worksheet::freeze_panes(const std::string &top_left_coordinate)
|
||||
{
|
||||
d_->freeze_panes_ = cell_reference(top_left_coordinate);
|
||||
auto ref = cell_reference(top_left_coordinate);
|
||||
d_->view_.get_pane().top_left_cell = ref;
|
||||
d_->view_.get_pane().state = pane_state::frozen;
|
||||
|
||||
d_->view_.get_selections().clear();
|
||||
d_->view_.get_selections().push_back(selection());
|
||||
|
||||
if (ref.get_column_index() == 1
|
||||
&& ref.get_row() == 1)
|
||||
{
|
||||
d_->view_.get_selections().back().set_pane(pane_corner::top_left);
|
||||
d_->view_.get_pane().active_pane = pane_corner::top_left;
|
||||
d_->view_.get_pane().state = pane_state::normal;
|
||||
}
|
||||
else if (ref.get_column_index() == 1)
|
||||
{
|
||||
d_->view_.get_selections().back().set_pane(pane_corner::bottom_left);
|
||||
d_->view_.get_pane().active_pane = pane_corner::bottom_left;
|
||||
d_->view_.get_pane().y_split = ref.get_row() - 1;
|
||||
}
|
||||
else if (ref.get_row() == 1)
|
||||
{
|
||||
d_->view_.get_selections().back().set_pane(pane_corner::top_right);
|
||||
d_->view_.get_pane().active_pane = pane_corner::top_right;
|
||||
d_->view_.get_pane().x_split = ref.get_column_index().index - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
d_->view_.get_selections().push_back(selection());
|
||||
d_->view_.get_selections().push_back(selection());
|
||||
d_->view_.get_selections()[0].set_pane(pane_corner::top_right);
|
||||
d_->view_.get_selections()[1].set_pane(pane_corner::bottom_left);
|
||||
d_->view_.get_selections()[2].set_pane(pane_corner::bottom_right);
|
||||
d_->view_.get_pane().active_pane = pane_corner::bottom_right;
|
||||
d_->view_.get_pane().x_split = ref.get_column_index().index - 1;
|
||||
d_->view_.get_pane().y_split = ref.get_row() - 1;
|
||||
}
|
||||
}
|
||||
|
||||
void worksheet::unfreeze_panes()
|
||||
{
|
||||
d_->freeze_panes_ = cell_reference("A1");
|
||||
d_->view_.get_pane().top_left_cell = cell_reference("A1");
|
||||
d_->view_.get_pane().state = pane_state::normal;
|
||||
}
|
||||
|
||||
cell worksheet::get_cell(const cell_reference &reference)
|
||||
|
@ -276,6 +313,11 @@ bool worksheet::has_row_properties(row_t row) const
|
|||
|
||||
range worksheet::get_named_range(const std::string &name)
|
||||
{
|
||||
if (!get_parent().has_named_range(name))
|
||||
{
|
||||
throw key_error();
|
||||
}
|
||||
|
||||
if (!has_named_range(name))
|
||||
{
|
||||
throw named_range_exception();
|
||||
|
@ -623,7 +665,7 @@ bool worksheet::compare(const worksheet &other, bool reference) const
|
|||
|
||||
if(d_->auto_filter_ == other.d_->auto_filter_
|
||||
&& d_->comment_count_ == other.d_->comment_count_
|
||||
&& d_->freeze_panes_ == other.d_->freeze_panes_
|
||||
&& d_->view_.get_pane().top_left_cell == other.d_->view_.get_pane().top_left_cell
|
||||
&& d_->merged_cells_ == other.d_->merged_cells_
|
||||
&& d_->relationships_ == other.d_->relationships_)
|
||||
{
|
||||
|
@ -890,4 +932,62 @@ range worksheet::iter_cells(bool skip_null)
|
|||
return range(*this, calculate_dimension(), major_order::row, skip_null);
|
||||
}
|
||||
|
||||
void worksheet::add_print_title(int i)
|
||||
{
|
||||
add_print_title(i, "rows");
|
||||
}
|
||||
|
||||
void worksheet::add_print_title(int i, const std::string &rows_or_cols)
|
||||
{
|
||||
if(rows_or_cols == "cols")
|
||||
{
|
||||
set_print_title_cols("A:" + column_t::column_string_from_index(i));
|
||||
}
|
||||
else
|
||||
{
|
||||
set_print_title_rows("1:" + std::to_string(i));
|
||||
}
|
||||
}
|
||||
|
||||
void worksheet::set_print_title_rows(const std::string &rows)
|
||||
{
|
||||
d_->print_title_rows_ = rows;
|
||||
}
|
||||
|
||||
void worksheet::set_print_title_cols(const std::string &cols)
|
||||
{
|
||||
d_->print_title_cols_ = cols;
|
||||
}
|
||||
|
||||
std::string worksheet::get_print_titles() const
|
||||
{
|
||||
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_;
|
||||
}
|
||||
}
|
||||
|
||||
void worksheet::set_print_area(const std::string &print_area)
|
||||
{
|
||||
d_->print_area_ = range_reference::make_absolute(range_reference(print_area));
|
||||
}
|
||||
|
||||
range_reference worksheet::get_print_area() const
|
||||
{
|
||||
return d_->print_area_;
|
||||
}
|
||||
|
||||
sheet_view worksheet::get_sheet_view() const
|
||||
{
|
||||
return d_->view_;
|
||||
}
|
||||
|
||||
} // namespace xlnt
|
||||
|
|
Loading…
Reference in New Issue
Block a user