mirror of
https://github.com/tfussell/xlnt.git
synced 2024-03-22 13:11:17 +08:00
implement sheet view serialization
This commit is contained in:
parent
0f0d3de75f
commit
2426215801
|
@ -74,6 +74,8 @@ public:
|
|||
range_reference(column_t column_index_start, row_t row_index_start,
|
||||
column_t column_index_end, row_t row_index_end);
|
||||
|
||||
range_reference(const range_reference &ref);
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if the range has a width and height of 1 cell.
|
||||
/// </summary>
|
||||
|
@ -154,6 +156,11 @@ public:
|
|||
/// </summary>
|
||||
bool operator!=(const char *reference_string) const;
|
||||
|
||||
/// <summary>
|
||||
/// Assigns the extents of the provided range to this range.
|
||||
/// </summary>
|
||||
range_reference &operator=(const range_reference &ref);
|
||||
|
||||
private:
|
||||
/// <summary>
|
||||
/// The top left cell in the range
|
||||
|
|
|
@ -60,12 +60,36 @@ public:
|
|||
active_cell_ = ref;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if this selection has a defined sqref.
|
||||
/// </summary>
|
||||
bool has_sqref() const
|
||||
{
|
||||
return sqref_.is_set();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the range encompassed by this selection.
|
||||
/// </summary>
|
||||
range_reference sqref() const
|
||||
{
|
||||
return sqref_;
|
||||
return sqref_.get();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the range encompassed by this selection.
|
||||
/// </summary>
|
||||
void sqref(const range_reference &ref)
|
||||
{
|
||||
sqref_ = ref;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the range encompassed by this selection.
|
||||
/// </summary>
|
||||
void sqref(const std::string &ref)
|
||||
{
|
||||
sqref(range_reference(ref));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -104,7 +128,7 @@ private:
|
|||
/// <summary>
|
||||
/// The range
|
||||
/// </summary>
|
||||
range_reference sqref_;
|
||||
optional<range_reference> sqref_;
|
||||
|
||||
/// <summary>
|
||||
/// The quadrant
|
||||
|
|
|
@ -654,7 +654,7 @@ public:
|
|||
/// <summary>
|
||||
/// Returns the view at the given index.
|
||||
/// </summary>
|
||||
sheet_view view(std::size_t index = 0) const;
|
||||
sheet_view &view(std::size_t index = 0) const;
|
||||
|
||||
/// <summary>
|
||||
/// Adds new_view to the set of available views for this sheet.
|
||||
|
|
|
@ -441,9 +441,9 @@ std::string xlsx_consumer::read_worksheet_begin(const std::string &rel_id)
|
|||
: sheet_view_type::page_layout);
|
||||
}
|
||||
|
||||
skip_attributes({ "windowProtection", "showFormulas", "showRowColHeaders", "showZeros", "rightToLeft",
|
||||
"tabSelected", "showRuler", "showOutlineSymbols", "showWhiteSpace", "view", "topLeftCell",
|
||||
"colorId", "zoomScale", "zoomScaleNormal", "zoomScaleSheetLayoutView", "zoomScalePageLayoutView" });
|
||||
skip_attributes({ "windowProtection", "showFormulas", "showRowColHeaders", "showZeros", "rightToLeft", "tabSelected", "showRuler", "showOutlineSymbols", "showWhiteSpace",
|
||||
"view", "topLeftCell", "colorId", "zoomScale", "zoomScaleNormal", "zoomScaleSheetLayoutView",
|
||||
"zoomScalePageLayoutView" });
|
||||
|
||||
while (in_element(qn("spreadsheetml", "sheetView")))
|
||||
{
|
||||
|
@ -489,6 +489,12 @@ std::string xlsx_consumer::read_worksheet_begin(const std::string &rel_id)
|
|||
current_selection.active_cell(parser().attribute("activeCell"));
|
||||
}
|
||||
|
||||
if (parser().attribute_present("sqref"))
|
||||
{
|
||||
const auto sqref = range_reference(parser().attribute("sqref"));
|
||||
current_selection.sqref(sqref);
|
||||
}
|
||||
|
||||
current_selection.pane(pane_corner::top_left);
|
||||
|
||||
new_view.add_selection(current_selection);
|
||||
|
|
|
@ -2093,14 +2093,13 @@ void xlsx_producer::write_worksheet(const relationship &rel)
|
|||
if (current_selection.has_active_cell())
|
||||
{
|
||||
write_attribute("activeCell", current_selection.active_cell().to_string());
|
||||
write_attribute("sqref", current_selection.active_cell().to_string());
|
||||
}
|
||||
/*
|
||||
if (current_selection.sqref() != "A1:A1")
|
||||
|
||||
if (current_selection.has_sqref())
|
||||
{
|
||||
write_attribute("sqref", current_selection.sqref().to_string());
|
||||
}
|
||||
*/
|
||||
|
||||
if (current_selection.pane() != pane_corner::top_left)
|
||||
{
|
||||
write_attribute("pane", current_selection.pane());
|
||||
|
|
|
@ -46,6 +46,12 @@ range_reference::range_reference(const char *range_string)
|
|||
{
|
||||
}
|
||||
|
||||
range_reference::range_reference(const range_reference &ref)
|
||||
{
|
||||
top_left_ = ref.top_left_;
|
||||
bottom_right_ = ref.bottom_right_;
|
||||
}
|
||||
|
||||
range_reference::range_reference(const std::string &range_string)
|
||||
: top_left_("A1"), bottom_right_("A1")
|
||||
{
|
||||
|
@ -178,4 +184,11 @@ XLNT_API bool operator!=(const char *reference_string, const range_reference &re
|
|||
return ref != reference_string;
|
||||
}
|
||||
|
||||
range_reference &range_reference::operator=(const range_reference &ref)
|
||||
{
|
||||
top_left_ = ref.top_left_;
|
||||
bottom_right_ = ref.bottom_right_;
|
||||
return *this;
|
||||
}
|
||||
|
||||
} // namespace xlnt
|
||||
|
|
|
@ -1011,7 +1011,7 @@ bool worksheet::has_view() const
|
|||
return !d_->views_.empty();
|
||||
}
|
||||
|
||||
sheet_view worksheet::view(std::size_t index) const
|
||||
sheet_view &worksheet::view(std::size_t index) const
|
||||
{
|
||||
return d_->views_.at(index);
|
||||
}
|
||||
|
|
|
@ -189,6 +189,12 @@ public:
|
|||
auto sheet1 = wb.active_sheet();
|
||||
sheet1.format_properties(format_properties);
|
||||
|
||||
auto &view = sheet1.view();
|
||||
auto selection = xlnt::selection();
|
||||
selection.active_cell("C1");
|
||||
selection.sqref("C1");
|
||||
view.add_selection(selection);
|
||||
|
||||
auto comment_font = xlnt::font()
|
||||
.bold(true)
|
||||
.size(10)
|
||||
|
|
Loading…
Reference in New Issue
Block a user