14#ifndef OPENXLSX_XLWORKSHEET_HPP
15# define OPENXLSX_XLWORKSHEET_HPP
18# include "OpenXLSX-Exports.hpp"
22# include <string_view>
72 "conditionalFormatting",
152 [[nodiscard]] std::string
getCellFormula(uint32_t
row, uint16_t col)
const override;
153 [[nodiscard]]
bool hasCell(uint32_t
row, uint16_t col)
const override;
154 [[nodiscard]] std::string
sheetName()
const override;
166 XLStreamWriter streamWriter(
bool useSharedStrings =
false,
size_t maxUniqueStrings = 100000);
180 XLCellAssignable findCell(
const std::string& ref)
const;
181 XLCellAssignable findCell(
const XLCellReference& ref)
const;
182 XLCellAssignable findCell(uint32_t rowNumber, uint16_t columnNumber)
const;
184 std::optional<XLCell> peekCell(
const std::string& ref)
const;
185 std::optional<XLCell> peekCell(
const XLCellReference& ref)
const;
186 std::optional<XLCell> peekCell(uint32_t rowNumber, uint16_t columnNumber)
const;
191 XLCellRange range(std::string
const& topLeft, std::string
const& bottomRight)
const;
192 XLCellRange range(std::string
const& rangeReference)
const;
196 XLRowRange rows(uint32_t firstRow, uint32_t lastRow)
const;
198 XLRow row(uint32_t rowNumber)
const;
204 void appendRow(
const std::vector<XLCellValue>& values);
212 typename = std::enable_if_t<!std::is_same_v<T, std::vector<XLCellValue>> &&
213 std::is_base_of_v<std::bidirectional_iterator_tag,
214 typename std::iterator_traits<typename T::iterator>::iterator_category>,
219 XLColumn column(uint16_t columnNumber)
const;
220 XLColumn column(std::string
const& columnRef)
const;
225 void autoFitColumn(uint16_t columnNumber);
227 void groupRows(uint32_t rowFirst, uint32_t rowLast, uint8_t outlineLevel = 1,
bool collapsed =
false);
228 void groupColumns(uint16_t colFirst, uint16_t colLast, uint8_t outlineLevel = 1,
bool collapsed =
false);
231 void clearAutoFilter();
232 bool hasAutoFilter()
const;
233 std::string autoFilter()
const;
242 void addSortCondition(
const std::string& ref, uint16_t colId,
bool descending =
false);
249 void applyAutoFilter();
252 uint16_t columnCount() const noexcept;
253 uint32_t rowCount() const noexcept;
255 bool deleteRow(uint32_t rowNumber);
266 bool insertRow(uint32_t rowNumber, uint32_t count = 1);
276 bool deleteRow(uint32_t rowNumber, uint32_t count);
284 bool insertColumn(uint16_t colNumber, uint16_t count = 1);
292 bool deleteColumn(uint16_t colNumber, uint16_t count = 1);
293 void updateSheetName(const
std::
string& oldName, const
std::
string& newName);
294 void updateDimension();
300 void setStreamWriterOpen(
bool open) noexcept;
301 void setStreamExtents(uint32_t lastRow, uint16_t maxCol) noexcept;
302 void setStreamMaterialization(
std::
string filePath,
std::
string memoryPayload) noexcept;
303 bool isStreamedSheet() const noexcept;
320 XLCellRange mergeCells(const
std::
string& rangeReference,
bool emptyHiddenCells = false);
321 void unmergeCells(
XLCellRange const& rangeToMerge);
322 void unmergeCells(const
std::
string& rangeReference);
326 bool setColumnFormat(uint16_t column,
XLStyleIndex cellFormatIndex);
327 bool setColumnFormat(const
std::
string& column,
XLStyleIndex cellFormatIndex);
330 bool setRowFormat(uint32_t row,
XLStyleIndex cellFormatIndex);
333 void addConditionalFormatting(const
std::
string& sqref, const
XLCfRule& rule);
334 void addConditionalFormatting(const
std::
string& sqref, const
XLCfRule& rule, const
XLDxf& dxf);
338 void removeConditionalFormatting(const
std::
string& sqref);
339 void removeConditionalFormatting(const
XLCellRange& range);
340 void clearAllConditionalFormatting();
351 void setPrintArea(const
std::
string& sqref);
358 void setPrintTitleRows(uint32_t firstRow, uint32_t lastRow);
365 void setPrintTitleCols(uint16_t firstCol, uint16_t lastCol);
375 bool protectSheet(
bool set = true);
376 bool protectObjects(
bool set = true);
377 bool protectScenarios(
bool set = true);
379 bool allowInsertColumns(
bool set = true);
380 bool allowInsertRows(
bool set = true);
381 bool allowDeleteColumns(
bool set = true);
382 bool allowDeleteRows(
bool set = true);
383 bool allowFormatCells(
bool set = true);
384 bool allowFormatColumns(
bool set = true);
385 bool allowFormatRows(
bool set = true);
386 bool allowInsertHyperlinks(
bool set = true);
387 bool allowSort(
bool set = true);
388 bool allowAutoFilter(
bool set = true);
389 bool allowPivotTables(
bool set = true);
390 bool allowSelectLockedCells(
bool set = true);
391 bool allowSelectUnlockedCells(
bool set = true);
407 bool setPasswordHash(std::string hash);
408 bool setPassword(std::string password);
409 bool clearPassword();
410 bool clearSheetProtection();
412 bool sheetProtected()
const;
413 bool objectsProtected()
const;
414 bool scenariosProtected()
const;
416 bool insertColumnsAllowed()
const;
417 bool insertRowsAllowed()
const;
418 bool deleteColumnsAllowed()
const;
419 bool deleteRowsAllowed()
const;
420 bool formatCellsAllowed()
const;
421 bool formatColumnsAllowed()
const;
422 bool formatRowsAllowed()
const;
423 bool insertHyperlinksAllowed()
const;
424 bool sortAllowed()
const;
425 bool autoFilterAllowed()
const;
426 bool pivotTablesAllowed()
const;
427 bool selectLockedCellsAllowed()
const;
428 bool selectUnlockedCellsAllowed()
const;
430 std::string passwordHash()
const;
431 bool passwordIsSet()
const;
432 std::string sheetProtectionSummary()
const;
448 void addSparkline(
const std::string& location,
const std::string& dataRange,
const XLSparklineOptions& options);
450 bool hasRelationships()
const;
451 bool hasDrawing()
const;
452 bool hasVmlDrawing()
const;
453 bool hasComments()
const;
454 bool hasThreadedComments()
const;
455 bool hasTables()
const;
458 void addImage(
const std::string& name,
459 const std::string& data,
465 void addImage(
const std::string& name,
466 gsl::span<const uint8_t> data,
489 void addTableSlicer(std::string_view cellReference,
491 std::string_view columnName,
502 void addPivotSlicer(std::string_view cellReference,
504 std::string_view columnName,
533 void deleteSlicer(
const std::string& name);
535 void insertImage(
const std::string& cellReference,
const std::string& imagePath);
543 void insertImage(
const std::string& cellReference,
const std::string& imagePath,
const XLImageOptions& options);
544 void insertImage(
const std::string& cellReference, gsl::span<const uint8_t> imageData,
const XLImageOptions& options =
XLImageOptions{});
545 void addScaledImage(
const std::string& name,
const std::string& data, uint32_t row, uint32_t col,
double scalingFactor = 1.0);
546 std::vector<XLDrawingItem> images();
548 XLChart addChart(XLChartType type, std::string_view name, uint32_t row, uint32_t col, uint32_t width, uint32_t height);
549 XLChart addChart(XLChartType type,
const XLChartAnchor& anchor);
555 std::vector<XLPivotTable> pivotTables();
562 XLPivotTable addPivotTable(
const XLPivotTableOptions& options);
569 bool deletePivotTable(std::string_view name);
571 XLVmlDrawing& vmlDrawing();
572 XLComments& comments();
573 XLThreadedComments& threadedComments();
580 void addNote(std::string_view cellRef, std::string_view text, std::string_view author =
"");
586 void deleteComment(std::string_view cellRef);
592 void deleteNote(std::string_view cellRef);
600 XLThreadedComment addComment(std::string_view cellRef, std::string_view text, std::string_view author =
"");
608 XLThreadedComment addReply(
const std::string& parentId,
const std::string& text,
const std::string& author =
"");
610 XLTableCollection& tables();
612 void addHyperlink(std::string_view cellRef, std::string_view url, std::string_view tooltip =
"");
613 void addInternalHyperlink(std::string_view cellRef, std::string_view location, std::string_view tooltip =
"");
614 [[nodiscard]]
bool hasHyperlink(std::string_view cellRef)
const;
615 [[nodiscard]] std::string getHyperlink(std::string_view cellRef)
const;
616 void removeHyperlink(std::string_view cellRef);
618 [[nodiscard]]
bool hasPanes()
const;
619 void freezePanes(uint16_t column, uint32_t row);
626 void freezePanes(
const std::string& topLeftCell);
628 void splitPanes(
double xSplit,
double ySplit, std::string_view topLeftCell =
"", XLPane activePane = XLPane::BottomRight);
631 void setZoom(uint16_t scale);
632 [[nodiscard]] uint16_t zoom()
const;
634 void insertRowBreak(uint32_t row);
635 void insertColBreak(uint16_t col);
636 void removeRowBreak(uint32_t row);
637 void removeColBreak(uint16_t col);
639 void setSheetViewMode(std::string_view mode);
640 [[nodiscard]] std::string sheetViewMode()
const;
642 void setShowGridLines(
bool show);
643 [[nodiscard]]
bool showGridLines()
const;
645 void setShowRowColHeaders(
bool show);
646 [[nodiscard]]
bool showRowColHeaders()
const;
648 void fitToPages(uint32_t fitToWidth, uint32_t fitToHeight);
650 [[nodiscard]]
static std::string makeInternalLocation(std::string_view sheetName, std::string_view cellRef);
653 uint16_t sheetXmlNumber()
const;
654 XLRelationships& relationships();
656 XLColor getColor_impl()
const;
657 void setColor_impl(
const XLColor& color);
658 bool isSelected_impl()
const;
659 void setSelected_impl(
bool selected);
660 bool isActive_impl()
const;
661 bool setActive_impl();
663 XMLNode prepareSheetViewForPanes();
672 [[nodiscard]]
static std::string
673 shiftCellRef(std::string_view ref, int32_t rowDelta, int32_t colDelta, uint32_t fromRow, uint16_t fromCol);
676 [[nodiscard]]
static std::string
677 shiftFormulaRefs(std::string_view formula, int32_t rowDelta, int32_t colDelta, uint32_t fromRow, uint16_t fromCol);
680 void shiftSheetDataRows(int32_t delta, uint32_t fromRow);
683 void shiftSheetDataCols(int32_t delta, uint16_t fromCol);
686 void shiftColsNode(int32_t delta, uint16_t fromCol);
689 void shiftFormulas(int32_t rowDelta, int32_t colDelta, uint32_t fromRow, uint16_t fromCol);
692 void shiftDrawingAnchors(int32_t rowDelta, int32_t colDelta, uint32_t fromRow, uint16_t fromCol);
695 void shiftDataValidations(int32_t rowDelta, int32_t colDelta, uint32_t fromRow, uint16_t fromCol);
698 void shiftAutoFilter(int32_t rowDelta, int32_t colDelta, uint32_t fromRow, uint16_t fromCol);
701 std::unique_ptr<XLWorksheetImpl> m_impl;
702 inline static const std::vector<std::string_view>& m_nodeOrder = XLWorksheetNodeOrder;
705 mutable uint32_t m_hintRowNumber{0};
706 mutable XMLNode m_hintRowNode{};
707 mutable uint16_t m_hintColNumber{0};
708 mutable XMLNode m_hintCellNode{};
711 mutable uint16_t m_maxColumn{0};
712 mutable bool m_dimensionDirty{
true};
Abstract immutable interface for accessing cell values and formulas across spreadsheet grids.
Definition IXLCellProvider.hpp:32
Definition XLAutoFilter.hpp:101
Definition XLCell.hpp:234
Represents a rectangular area of cells within a worksheet.
Definition XLCellRange.hpp:40
Definition XLCellReference.hpp:44
Class encapsulating a cell value.
Definition XLCellValue.hpp:89
Definition XLConditionalFormatting.hpp:277
Definition XLColumn.hpp:35
Definition XLDataValidation.hpp:184
The XLDrawing class is the base class for worksheet drawings (images, charts, etc....
Definition XLDrawing.hpp:398
Definition XLStyles_Dxfs.hpp:36
Manages merged cell ranges in a worksheet.
Definition XLMergeCells.hpp:48
A class representing the page margins of a worksheet.
Definition XLPageSetup.hpp:30
Definition XLPageSetup.hpp:135
Definition XLPivotTable.hpp:74
Definition XLPivotTable.hpp:368
A class representing the print options of a worksheet.
Definition XLPageSetup.hpp:67
Definition XLRelationships.hpp:150
The XLRow class represent a row in an Excel spreadsheet. Using XLRow objects, various row formatting ...
Definition XLRow.hpp:34
XLSheetBase()
Definition XLSheetBase.hpp:69
Definition XLSlicerCollection.hpp:114
Definition XLSlicer.hpp:58
Definition XLStreamReader.hpp:170
Definition XLStreamWriter.hpp:240
The XLTableCollection class manages multiple tables within a worksheet.
Definition XLTables.hpp:52
The XLTable class represents a single Excel table (.xml file).
Definition XLTables.hpp:117
The XLVmlDrawing class is the base class for worksheet comments.
Definition XLDrawing.hpp:523
XLRow row(uint32_t rowNumber) const
Definition XLWorksheet.cpp:235
bool denyInsertColumns()
Definition XLWorksheet.hpp:393
bool denyFormatCells()
Definition XLWorksheet.hpp:397
XLCellRange range() const
Definition XLWorksheet.cpp:188
bool hasCell(uint32_t row, uint16_t col) const override
Check if cell exists and is populated.
Definition XLWorksheet.cpp:617
bool denySelectLockedCells()
Definition XLWorksheet.hpp:404
std::optional< XLCell > peekCell(XLRowIndex row, XLColIndex col) const
Definition XLWorksheet.hpp:187
bool allowDeleteRows(bool set=true)
Definition XLWorksheet_Protection.cpp:158
bool denyFormatColumns()
Definition XLWorksheet.hpp:398
void appendRow(const T &values)
Append a new row with the given container of values.
Definition XLWorksheet.hpp:216
bool allowSelectLockedCells(bool set=true)
Definition XLWorksheet_Protection.cpp:216
bool allowSort(bool set=true)
Definition XLWorksheet_Protection.cpp:198
XLCellValue getCellValue(uint32_t row, uint16_t col) const override
Get cell value at 1-based (row, column).
Definition XLWorksheet.cpp:623
bool allowInsertColumns(bool set=true)
Definition XLWorksheet_Protection.cpp:130
friend class XLTableCollection
Definition XLWorksheet.hpp:136
std::string sheetName() const override
Get sheet name.
Definition XLWorksheet.cpp:637
bool allowFormatColumns(bool set=true)
Definition XLWorksheet_Protection.cpp:170
XLWorksheet()
Definition XLWorksheet.cpp:46
friend class XLWorkbook
Definition XLWorksheet.hpp:135
bool denyDeleteColumns()
Definition XLWorksheet.hpp:395
std::string getCellFormula(uint32_t row, uint16_t col) const override
Get formula string at 1-based (row, column), or empty string if no formula.
Definition XLWorksheet.cpp:630
XLCellAssignable cell(XLRowIndex row, XLColIndex col) const
Definition XLWorksheet.hpp:160
bool denySort()
Definition XLWorksheet.hpp:401
bool allowSelectUnlockedCells(bool set=true)
Definition XLWorksheet_Protection.cpp:227
bool allowDeleteColumns(bool set=true)
Definition XLWorksheet_Protection.cpp:147
void fetchRangeValues(const XLCellRange &range, std::vector< XLCellValue > &out) const override
Batch fetch values for a rectangular range into an output vector.
Definition XLWorksheet.cpp:642
bool denyAutoFilter()
Definition XLWorksheet.hpp:402
bool denyInsertRows()
Definition XLWorksheet.hpp:394
bool denyPivotTables()
Definition XLWorksheet.hpp:403
uint32_t rowCount() const noexcept
Definition XLWorksheet.cpp:474
friend class XLCell
Definition XLWorksheet.hpp:133
bool allowPivotTables(bool set=true)
Definition XLWorksheet_Protection.cpp:210
bool denySelectUnlockedCells()
Definition XLWorksheet.hpp:405
bool denyInsertHyperlinks()
Definition XLWorksheet.hpp:400
XLCellAssignable cell(const std::string &ref) const
Definition XLWorksheet.cpp:168
bool allowInsertRows(bool set=true)
Definition XLWorksheet_Protection.cpp:141
bool allowFormatRows(bool set=true)
Definition XLWorksheet_Protection.cpp:181
XLWorksheet & operator=(const XLWorksheet &other)
Definition XLWorksheet.cpp:111
bool denyFormatRows()
Definition XLWorksheet.hpp:399
bool allowFormatCells(bool set=true)
Definition XLWorksheet_Protection.cpp:164
bool denyDeleteRows()
Definition XLWorksheet.hpp:396
bool allowInsertHyperlinks(bool set=true)
Definition XLWorksheet_Protection.cpp:187
friend class XLSlicerCollection
Definition XLWorksheet.hpp:137
friend class XLRow
Definition XLWorksheet.hpp:134
friend class XLRowDataProxy
Definition XLWorksheet.hpp:139
bool allowAutoFilter(bool set=true)
Definition XLWorksheet_Protection.cpp:204
The XLXmlData class encapsulates the properties and behaviour of the .xml files in an ....
Definition XLXmlData.hpp:79
std::string xmlData(XLXmlSavingDeclaration savingDeclaration=XLXmlSavingDeclaration{}) const
Method for getting the XML data represented by the object.
Definition XLXmlFile.cpp:49
Definition IXLCellProvider.hpp:24
XLSparklineType
The XLSparklineType enum represents the type of a sparkline.
Definition XLSparkline.hpp:23
@ Line
Definition XLSparkline.hpp:23
const std::vector< std::string_view > XLWorksheetNodeOrder
Definition XLWorksheet.hpp:55
const std::vector< std::string_view > XLSheetViewNodeOrder
Definition XLWorksheet.hpp:97
OpenXLSX_xml_node XMLNode
Definition XLXmlParser.hpp:64
size_t XLStyleIndex
Definition XLStyles_Common.hpp:36
Definition XLCellIterator.hpp:131
Definition XLConstants.hpp:29
uint16_t val
Definition XLConstants.hpp:30
Options for inserting an image into a worksheet.
Definition XLImageOptions.hpp:33
Definition XLConstants.hpp:22
A structure defining all granular sheet protection options.
Definition XLWorksheet.hpp:107
bool scenarios
Definition XLWorksheet.hpp:110
bool formatRows
Definition XLWorksheet.hpp:114
bool selectLockedCells
Definition XLWorksheet.hpp:124
bool sort
Definition XLWorksheet.hpp:120
bool pivotTables
Definition XLWorksheet.hpp:122
bool deleteColumns
Definition XLWorksheet.hpp:118
bool formatColumns
Definition XLWorksheet.hpp:113
bool objects
Definition XLWorksheet.hpp:109
bool insertRows
Definition XLWorksheet.hpp:116
bool selectUnlockedCells
Definition XLWorksheet.hpp:125
bool deleteRows
Definition XLWorksheet.hpp:119
bool sheet
Definition XLWorksheet.hpp:108
bool formatCells
Definition XLWorksheet.hpp:112
bool insertColumns
Definition XLWorksheet.hpp:115
bool insertHyperlinks
Definition XLWorksheet.hpp:117
bool autoFilter
Definition XLWorksheet.hpp:121
Definition XLTables.hpp:35
The XLSparklineOptions struct encapsulates configuration for a sparkline group.
Definition XLSparkline.hpp:29
Stream hyperlink (injected as <hyperlinks> on close; external uses sheet relationships).
Definition XLStreamWriter.hpp:152
Options for XLStreamReader construction.
Definition XLStreamReader.hpp:72
Minimal table definition for streaming AddTable (excelize-compatible constraints).
Definition XLStreamWriter.hpp:136
Options for XLStreamWriter construction.
Definition XLStreamWriter.hpp:62
Definition XLDrawing.hpp:325
Definition XLWorksheetImpl.hpp:24