OpenXLSX 1.12.1
Modern C++ Excel Library (Fork of OpenXLSX by Kenneth Troldal Balslev)
Loading...
Searching...
No Matches
XLAutoFilter.hpp
Go to the documentation of this file.
1/*
2 * OpenXLSX-NX - Modern High-Performance C++ Excel Library
3 *
4 * Original work Copyright (c) 2018-2025, Kenneth Troldal Balslev and OpenXLSX contributors
5 * Modified work Copyright (c) 2026, Curry Tang and OpenXLSX-NX contributors
6 *
7 * Distributed under the BSD 3-Clause License.
8 * See LICENSE.md in the project root or https://opensource.org/licenses/BSD-3-Clause
9 */
10
11#pragma once
12
13#include "XLXmlParser.hpp"
14#include <cstdint>
15#include <string>
16
17namespace OpenXLSX
18{
19
23 enum class XLFilterLogic { And, Or };
24
30 {
31 public:
36 explicit XLFilterColumn(XMLNode node);
37
42 void addFilter(const std::string& value);
43
47 void clearFilters();
48
54 void setCustomFilter(const std::string& op, const std::string& val);
55
64 void setCustomFilter(const std::string& op1,
65 const std::string& val1,
66 XLFilterLogic logic,
67 const std::string& op2,
68 const std::string& val2);
69
76 void setTop10(double value, bool percent = false, bool top = true);
77
82 void setDynamicFilter(const std::string& type);
83
88 uint16_t colId() const;
89
90 private:
91 XMLNode m_node;
92 };
93
98 class XLCellRange;
99
101 {
102 public:
107 explicit XLAutoFilter(XMLNode node);
108
113 operator bool() const;
114
119 std::string ref() const;
120
125 XLAutoFilter& setRef(const std::string& ref);
126
131 XLAutoFilter& setRef(const XLCellRange& range);
132
138 XLFilterColumn filterColumn(uint16_t colId);
139
140 private:
141 XMLNode m_node;
142 };
143
144} // namespace OpenXLSX
XLFilterColumn filterColumn(uint16_t colId)
Get or create a filter column by its ID.
Definition XLAutoFilter.cpp:141
XLAutoFilter & setRef(const std::string &ref)
Set the reference range of the AutoFilter.
Definition XLAutoFilter.cpp:128
std::string ref() const
Get the reference range of the AutoFilter.
Definition XLAutoFilter.cpp:122
XLAutoFilter(XMLNode node)
Constructor.
Definition XLAutoFilter.cpp:118
Represents a rectangular area of cells within a worksheet.
Definition XLCellRange.hpp:40
The XLFilterColumn class encapsulates the <filterColumn> XML node. It allows setting different kinds ...
Definition XLAutoFilter.hpp:30
void clearFilters()
Clear all filters for this column.
Definition XLAutoFilter.cpp:41
void setCustomFilter(const std::string &op, const std::string &val)
Set a single custom filter criteria.
Definition XLAutoFilter.cpp:52
void setTop10(double value, bool percent=false, bool top=true)
Set a top-10 filter.
Definition XLAutoFilter.cpp:86
uint16_t colId() const
Get the column ID (0-based relative to the AutoFilter range).
Definition XLAutoFilter.cpp:110
XLFilterColumn(XMLNode node)
Constructor.
Definition XLAutoFilter.cpp:20
void setDynamicFilter(const std::string &type)
Set a dynamic filter (e.g. "aboveAverage", "today", "Q1").
Definition XLAutoFilter.cpp:100
void addFilter(const std::string &value)
Add a specific string value to filter by.
Definition XLAutoFilter.cpp:22
Definition IXLCellProvider.hpp:24
XLFilterLogic
Enum class defining the logical operator for custom filters.
Definition XLAutoFilter.hpp:23
@ Or
Definition XLAutoFilter.hpp:23
@ And
Definition XLAutoFilter.hpp:23
OpenXLSX_xml_node XMLNode
Definition XLXmlParser.hpp:64