OpenXLSX 1.12.1
Modern C++ Excel Library (Fork of OpenXLSX by Kenneth Troldal Balslev)
Loading...
Searching...
No Matches
IXLCellProvider.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#ifndef OPENXLSX_IXLCELLPROVIDER_HPP
12#define OPENXLSX_IXLCELLPROVIDER_HPP
13
14#include "OpenXLSX-Exports.hpp"
15#include "XLCellValue.hpp"
16#include "XLCellRange.hpp"
17
18#include <cstdint>
19#include <string>
20#include <string_view>
21#include <vector>
22
23namespace OpenXLSX
24{
31 class OPENXLSX_EXPORT IXLCellProvider
32 {
33 public:
34 virtual ~IXLCellProvider() = default;
35
39 [[nodiscard]] virtual XLCellValue getCellValue(uint32_t row, uint16_t col) const = 0;
40
44 [[nodiscard]] virtual std::string getCellFormula(uint32_t row, uint16_t col) const = 0;
45
49 [[nodiscard]] virtual bool hasCell(uint32_t row, uint16_t col) const = 0;
50
54 [[nodiscard]] virtual std::string sheetName() const = 0;
55
61 virtual void fetchRangeValues(const XLCellRange& range, std::vector<XLCellValue>& out) const
62 {
63 uint32_t r1 = range.topLeft().row();
64 uint32_t r2 = range.bottomRight().row();
65 uint16_t c1 = range.topLeft().column();
66 uint16_t c2 = range.bottomRight().column();
67
68 size_t count = static_cast<size_t>(r2 - r1 + 1) * static_cast<size_t>(c2 - c1 + 1);
69 out.reserve(out.size() + count);
70
71 for (uint32_t r = r1; r <= r2; ++r) {
72 for (uint16_t c = c1; c <= c2; ++c) {
73 out.emplace_back(getCellValue(r, c));
74 }
75 }
76 }
77 };
78} // namespace OpenXLSX
79
80#endif // OPENXLSX_IXLCELLPROVIDER_HPP
Abstract immutable interface for accessing cell values and formulas across spreadsheet grids.
Definition IXLCellProvider.hpp:32
virtual std::string sheetName() const =0
Get sheet name.
virtual ~IXLCellProvider()=default
virtual std::string getCellFormula(uint32_t row, uint16_t col) const =0
Get formula string at 1-based (row, column), or empty string if no formula.
virtual XLCellValue getCellValue(uint32_t row, uint16_t col) const =0
Get cell value at 1-based (row, column).
virtual void fetchRangeValues(const XLCellRange &range, std::vector< XLCellValue > &out) const
Batch fetch values for a rectangular range into an output vector.
Definition IXLCellProvider.hpp:61
virtual bool hasCell(uint32_t row, uint16_t col) const =0
Check if cell exists and is populated.
Represents a rectangular area of cells within a worksheet.
Definition XLCellRange.hpp:40
XLCellReference topLeft() const
Definition XLCellRange.cpp:90
XLCellReference bottomRight() const
Definition XLCellRange.cpp:95
uint32_t row() const noexcept
Get the row number of the XLCellReference.
Definition XLCellReference.cpp:157
uint16_t column() const noexcept
Get the column number of the XLCellReference.
Definition XLCellReference.cpp:175
Class encapsulating a cell value.
Definition XLCellValue.hpp:89
Definition IXLCellProvider.hpp:24