OpenXLSX 1.12.1
Modern C++ Excel Library (Fork of OpenXLSX by Kenneth Troldal Balslev)
Loading...
Searching...
No Matches
OpenXLSX::XLWorksheet Class Referencefinal

A class encapsulating an Excel worksheet. Access to XLWorksheet objects should be via the workbook object. More...

#include <XLWorksheet.hpp>

Inheritance diagram for OpenXLSX::XLWorksheet:
OpenXLSX::XLSheetBase< XLWorksheet > OpenXLSX::IXLCellProvider OpenXLSX::XLXmlFile

Public Member Functions

 XLWorksheet ()
 XLWorksheet (XLXmlData *xmlData)
 ~XLWorksheet ()
 XLWorksheet (const XLWorksheet &other)
 XLWorksheet (XLWorksheet &&other) noexcept
XLWorksheet & operator= (const XLWorksheet &other)
XLWorksheet & operator= (XLWorksheet &&other)
XLCellValue getCellValue (uint32_t row, uint16_t col) const override
 Get cell value at 1-based (row, column).
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.
bool hasCell (uint32_t row, uint16_t col) const override
 Check if cell exists and is populated.
std::string sheetName () const override
 Get sheet name.
void fetchRangeValues (const XLCellRange &range, std::vector< XLCellValue > &out) const override
 Batch fetch values for a rectangular range into an output vector.
XLCellAssignable cell (const std::string &ref) const
XLCellAssignable cell (const XLCellReference &ref) const
XLCellAssignable cell (uint32_t rowNumber, uint16_t columnNumber) const
XLCellAssignable cell (XLRowIndex row, XLColIndex col) const
XLStreamWriter streamWriter (bool useSharedStrings=false, size_t maxUniqueStrings=100000)
 Starts a high-performance, low-memory stream writer for this worksheet.
XLStreamWriter streamWriter (const XLStreamWriteOptions &options)
 Stream writer with full options (open mode, spill threshold, shared strings, …).
XLStreamReader streamReader (const XLStreamReadOptions &options={}) const
 Create a stream reader for memory efficient reading of large documents.
XLCellAssignable findCell (const std::string &ref) const
XLCellAssignable findCell (const XLCellReference &ref) const
XLCellAssignable findCell (uint32_t rowNumber, uint16_t columnNumber) const
std::optional< XLCell > peekCell (const std::string &ref) const
std::optional< XLCell > peekCell (const XLCellReference &ref) const
std::optional< XLCell > peekCell (uint32_t rowNumber, uint16_t columnNumber) const
std::optional< XLCell > peekCell (XLRowIndex row, XLColIndex col) const
XLCellRange range () const
XLCellRange range (const XLCellReference &topLeft, const XLCellReference &bottomRight) const
XLCellRange range (std::string const &topLeft, std::string const &bottomRight) const
XLCellRange range (std::string const &rangeReference) const
XLRowRange rows () const
XLRowRange rows (uint32_t rowCount) const
XLRowRange rows (uint32_t firstRow, uint32_t lastRow) const
XLRow row (uint32_t rowNumber) const
void appendRow (const std::vector< XLCellValue > &values)
 Append a new row with the given values.
template<typename T, typename = std::enable_if_t<!std::is_same_v<T, std::vector<XLCellValue>> && std::is_base_of_v<std::bidirectional_iterator_tag, typename std::iterator_traits<typename T::iterator>::iterator_category>, T>>
void appendRow (const T &values)
 Append a new row with the given container of values.
XLColumn column (uint16_t columnNumber) const
XLColumn column (std::string const &columnRef) const
void autoFitColumn (uint16_t columnNumber)
 Automatically adjusts the column width based on the content of its cells.
void groupRows (uint32_t rowFirst, uint32_t rowLast, uint8_t outlineLevel=1, bool collapsed=false)
void groupColumns (uint16_t colFirst, uint16_t colLast, uint8_t outlineLevel=1, bool collapsed=false)
void setAutoFilter (const XLCellRange &range)
void clearAutoFilter ()
bool hasAutoFilter () const
std::string autoFilter () const
XLAutoFilter autofilterObject () const
void addSortCondition (const std::string &ref, uint16_t colId, bool descending=false)
 Set the sort state for the worksheet.
void applyAutoFilter ()
 Evaluates the current autoFilter conditions and hides rows that do not match the criteria. Note: Only basic text/value matching and some simple custom filters are evaluated. Complex dynamic filters might not be supported.
XLCellReference lastCell () const noexcept
uint16_t columnCount () const noexcept
uint32_t rowCount () const noexcept
bool deleteRow (uint32_t rowNumber)
bool insertRow (uint32_t rowNumber, uint32_t count=1)
 Insert one or more empty rows before the given row number.
bool deleteRow (uint32_t rowNumber, uint32_t count)
 Delete one or more rows and shift subsequent rows up.
bool insertColumn (uint16_t colNumber, uint16_t count=1)
 Insert one or more empty columns before the given column number.
bool deleteColumn (uint16_t colNumber, uint16_t count=1)
 Delete one or more columns and shift subsequent columns left.
void updateSheetName (const std::string &oldName, const std::string &newName)
void updateDimension ()
void setStreamWriterOpen (bool open) noexcept
 Internal: mark whether an XLStreamWriter for this sheet is still open (save guard).
void setStreamExtents (uint32_t lastRow, uint16_t maxCol) noexcept
void setStreamMaterialization (std::string filePath, std::string memoryPayload) noexcept
bool isStreamedSheet () const noexcept
std::string registerStreamTable (const XLStreamTableOptions &table)
 Register a table part for stream-written sheets; returns tableParts XML fragment.
std::string registerStreamHyperlinks (const std::vector< XLStreamHyperlink > &links)
 Register stream hyperlinks: adds external relationships and returns <hyperlinks> XML.
XLMergeCells & merges ()
XLDataValidations & dataValidations ()
XLCellRange mergeCells (XLCellRange const &rangeToMerge, bool emptyHiddenCells=false)
XLCellRange mergeCells (const std::string &rangeReference, bool emptyHiddenCells=false)
void unmergeCells (XLCellRange const &rangeToMerge)
void unmergeCells (const std::string &rangeReference)
XLStyleIndex getColumnFormat (uint16_t column) const
XLStyleIndex getColumnFormat (const std::string &column) const
bool setColumnFormat (uint16_t column, XLStyleIndex cellFormatIndex)
bool setColumnFormat (const std::string &column, XLStyleIndex cellFormatIndex)
XLStyleIndex getRowFormat (uint16_t row) const
bool setRowFormat (uint32_t row, XLStyleIndex cellFormatIndex)
XLConditionalFormats conditionalFormats () const
void addConditionalFormatting (const std::string &sqref, const XLCfRule &rule)
void addConditionalFormatting (const std::string &sqref, const XLCfRule &rule, const XLDxf &dxf)
void addConditionalFormatting (const XLCellRange &range, const XLCfRule &rule)
void addConditionalFormatting (const XLCellRange &range, const XLCfRule &rule, const XLDxf &dxf)
void removeConditionalFormatting (const std::string &sqref)
void removeConditionalFormatting (const XLCellRange &range)
void clearAllConditionalFormatting ()
XLPageMargins pageMargins () const
XLPrintOptions printOptions () const
XLPageSetup pageSetup () const
XLHeaderFooter headerFooter () const
void setPrintArea (const std::string &sqref)
 Set the print area for this worksheet.
void setPrintTitleRows (uint32_t firstRow, uint32_t lastRow)
 Set rows to repeat at the top of each printed page.
void setPrintTitleCols (uint16_t firstCol, uint16_t lastCol)
 Set columns to repeat at the left of each printed page.
bool protect (const XLSheetProtectionOptions &options, std::string_view password="")
 Protect the worksheet with granular options.
bool protectSheet (bool set=true)
bool protectObjects (bool set=true)
bool protectScenarios (bool set=true)
bool allowInsertColumns (bool set=true)
bool allowInsertRows (bool set=true)
bool allowDeleteColumns (bool set=true)
bool allowDeleteRows (bool set=true)
bool allowFormatCells (bool set=true)
bool allowFormatColumns (bool set=true)
bool allowFormatRows (bool set=true)
bool allowInsertHyperlinks (bool set=true)
bool allowSort (bool set=true)
bool allowAutoFilter (bool set=true)
bool allowPivotTables (bool set=true)
bool allowSelectLockedCells (bool set=true)
bool allowSelectUnlockedCells (bool set=true)
bool denyInsertColumns ()
bool denyInsertRows ()
bool denyDeleteColumns ()
bool denyDeleteRows ()
bool denyFormatCells ()
bool denyFormatColumns ()
bool denyFormatRows ()
bool denyInsertHyperlinks ()
bool denySort ()
bool denyAutoFilter ()
bool denyPivotTables ()
bool denySelectLockedCells ()
bool denySelectUnlockedCells ()
bool setPasswordHash (std::string hash)
bool setPassword (std::string password)
bool clearPassword ()
bool clearSheetProtection ()
bool sheetProtected () const
bool objectsProtected () const
bool scenariosProtected () const
bool insertColumnsAllowed () const
bool insertRowsAllowed () const
bool deleteColumnsAllowed () const
bool deleteRowsAllowed () const
bool formatCellsAllowed () const
bool formatColumnsAllowed () const
bool formatRowsAllowed () const
bool insertHyperlinksAllowed () const
bool sortAllowed () const
bool autoFilterAllowed () const
bool pivotTablesAllowed () const
bool selectLockedCellsAllowed () const
bool selectUnlockedCellsAllowed () const
std::string passwordHash () const
bool passwordIsSet () const
std::string sheetProtectionSummary () const
void addSparkline (const std::string &location, const std::string &dataRange, XLSparklineType type=XLSparklineType::Line)
 Add a sparkline to the worksheet.
void addSparkline (const std::string &location, const std::string &dataRange, const XLSparklineOptions &options)
 Add a sparkline graph with advanced configuration options.
bool hasRelationships () const
bool hasDrawing () const
bool hasVmlDrawing () const
bool hasComments () const
bool hasThreadedComments () const
bool hasTables () const
XLDrawing & drawing ()
void addImage (const std::string &name, const std::string &data, uint32_t row, uint32_t col, uint32_t width, uint32_t height, const XLImageOptions &options=XLImageOptions())
void addImage (const std::string &name, gsl::span< const uint8_t > data, uint32_t row, uint32_t col, uint32_t width, uint32_t height, const XLImageOptions &options=XLImageOptions())
void addShape (std::string_view cellReference, const XLVectorShapeOptions &options)
 Insert an image at the specified cell with original dimensions (automatic parsing).
void addTableSlicer (std::string_view cellReference, const XLTable &table, std::string_view columnName, const XLSlicerOptions &options=XLSlicerOptions())
 Add a slicer connected to a table.
void addPivotSlicer (std::string_view cellReference, const XLPivotTable &pivotTable, std::string_view columnName, const XLSlicerOptions &options=XLSlicerOptions())
 Add a slicer connected to a Pivot Table.
XLSlicerCollection & slicers ()
 Get the slicer collection for this worksheet.
void deleteSlicer (const std::string &name)
 Delete a slicer by name, cleaning up drawings, relationships, and orphan caches.
void insertImage (const std::string &cellReference, const std::string &imagePath)
void insertImage (const std::string &cellReference, const std::string &imagePath, const XLImageOptions &options)
 Insert an image with advanced formatting options (scaling, offset, behavior).
void insertImage (const std::string &cellReference, gsl::span< const uint8_t > imageData, const XLImageOptions &options=XLImageOptions{})
void addScaledImage (const std::string &name, const std::string &data, uint32_t row, uint32_t col, double scalingFactor=1.0)
std::vector< XLDrawingItem > images ()
XLChart addChart (XLChartType type, std::string_view name, uint32_t row, uint32_t col, uint32_t width, uint32_t height)
XLChart addChart (XLChartType type, const XLChartAnchor &anchor)
std::vector< XLPivotTable > pivotTables ()
 Retrieves all pivot tables belonging to this worksheet.
XLPivotTable addPivotTable (const XLPivotTableOptions &options)
 Create and add a pivot table to this worksheet.
bool deletePivotTable (std::string_view name)
 Delete a pivot table by name from this worksheet.
XLVmlDrawing & vmlDrawing ()
XLComments & comments ()
XLThreadedComments & threadedComments ()
void addNote (std::string_view cellRef, std::string_view text, std::string_view author="")
 Add a comment to a cell seamlessly.
void deleteComment (std::string_view cellRef)
 Remove a modern threaded comment (and its replies) from a cell.
void deleteNote (std::string_view cellRef)
 Remove a legacy yellow note from a cell.
XLThreadedComment addComment (std::string_view cellRef, std::string_view text, std::string_view author="")
 Add a modern threaded comment to a cell seamlessly.
XLThreadedComment addReply (const std::string &parentId, const std::string &text, const std::string &author="")
 Add a reply to an existing threaded comment.
XLTableCollection & tables ()
void addHyperlink (std::string_view cellRef, std::string_view url, std::string_view tooltip="")
void addInternalHyperlink (std::string_view cellRef, std::string_view location, std::string_view tooltip="")
bool hasHyperlink (std::string_view cellRef) const
std::string getHyperlink (std::string_view cellRef) const
void removeHyperlink (std::string_view cellRef)
bool hasPanes () const
void freezePanes (uint16_t column, uint32_t row)
void freezePanes (const std::string &topLeftCell)
 Freeze panes at the specified top-left cell. This is a highly ergonomic method. E.g. freezePanes("B2") freezes Row 1 and Column A.
void splitPanes (double xSplit, double ySplit, std::string_view topLeftCell="", XLPane activePane=XLPane::BottomRight)
void clearPanes ()
void setZoom (uint16_t scale)
uint16_t zoom () const
void insertRowBreak (uint32_t row)
void insertColBreak (uint16_t col)
void removeRowBreak (uint32_t row)
void removeColBreak (uint16_t col)
void setSheetViewMode (std::string_view mode)
std::string sheetViewMode () const
void setShowGridLines (bool show)
bool showGridLines () const
void setShowRowColHeaders (bool show)
bool showRowColHeaders () const
void fitToPages (uint32_t fitToWidth, uint32_t fitToHeight)
Public Member Functions inherited from OpenXLSX::XLSheetBase< XLWorksheet >
 XLSheetBase ()
 Constructor.
 ~XLSheetBase ()=default
 The destructor.
XLSheetBase & operator= (const XLSheetBase &)=default
 Assignment operator.
XLSheetState visibility () const
void setVisibility (XLSheetState state)
XLColor color () const
void setColor (const XLColor &color)
uint16_t index () const
 look up sheet name via relationshipID, then attempt to match that to a sheet in XLWorkbook::sheet(uint16_t index), looping over index
void setIndex (uint16_t index)
std::string name () const
 Method to retrieve the name of the sheet.
void setName (const std::string &sheetName)
 Method for renaming the sheet.
bool isSelected () const
void setSelected (bool selected)
bool isActive () const
bool setActive ()
void clone (const std::string &newName)
 Method for cloning the sheet.
Public Member Functions inherited from OpenXLSX::XLXmlFile
 XLXmlFile ()=default
 Default constructor.
std::string xmlData (XLXmlSavingDeclaration savingDeclaration=XLXmlSavingDeclaration{}) const
 Method for getting the XML data represented by the object.
 XLXmlFile (XLXmlData *xmlData)
 Constructor. Creates an object based on the xmlData input.
 XLXmlFile (const XLXmlFile &other)=default
 Copy constructor. Default implementation used.
 XLXmlFile (XLXmlFile &&other) noexcept=default
 Move constructor. Default implementation used.
 ~XLXmlFile ()=default
 Destructor. Default implementation used.
bool valid () const
 check whether class is linked to a valid XML file
XLXmlFile & operator= (const XLXmlFile &other)=default
 The copy assignment operator. The default implementation has been used.
XLXmlFile & operator= (XLXmlFile &&other) noexcept=default
 The move assignment operator. The default implementation has been used.
XLDocument & parentDoc ()
 This function provides access to the parent XLDocument object.
const XLDocument & parentDoc () const
 This function provides access to the parent XLDocument object.
XLPackageServices & package ()
 Narrow package-services port (archive, managed XML parts, relationships, content types).
const XLPackageServices & package () const
XLPackagePartFactory & partFactory ()
 Narrow package-part factory port (chart / drawing / image / slicer / sheet accessories).
const XLPackagePartFactory & partFactory () const
const XLSharedStringTable & sharedStringTable () const
 Read-only shared string table (SST) port.
const XLSharedStrings & sharedStrings () const
 Full workbook SST (including getOrCreate / append).
XMLDocument & xmlDocument ()
 This function provides access to the underlying XMLDocument object.
const XMLDocument & xmlDocument () const
 This function provides access to the underlying XMLDocument object.
std::string getXmlPath () const
 Retrieve the path of the XML data in the .xlsx zip archive via m_xmlData->getXmlPath.
const XLXmlData * xmlDataPart () const noexcept
 Access the underlying XLXmlData pointer.
XLXmlData * xmlDataPart () noexcept
Public Member Functions inherited from OpenXLSX::IXLCellProvider
virtual ~IXLCellProvider ()=default

Static Public Member Functions

static std::string makeInternalLocation (std::string_view sheetName, std::string_view cellRef)

Friends

class XLCell
class XLRow
class XLWorkbook
class XLTableCollection
class XLSlicerCollection
class XLSheetBase< XLWorksheet >
class XLRowDataProxy

Additional Inherited Members

Protected Member Functions inherited from OpenXLSX::XLXmlFile
void setXmlData (std::string_view xmlData)
 Provide the XML data represented by the object.
std::string relationshipID () const
 This function returns the relationship ID (the ID used in the XLRelationships objects) for the object.
Protected Attributes inherited from OpenXLSX::XLXmlFile
XLXmlData * m_xmlData {nullptr}

Detailed Description

A class encapsulating an Excel worksheet. Access to XLWorksheet objects should be via the workbook object.

Constructor & Destructor Documentation

◆ XLWorksheet() [1/4]

XLWorksheet::XLWorksheet ( )

The constructor does some slight reconfiguration of the XML file, in order to make parsing easier.

◆ XLWorksheet() [2/4]

XLWorksheet::XLWorksheet ( XLXmlData * xmlData)
explicit

◆ ~XLWorksheet()

XLWorksheet::~XLWorksheet ( )
default

◆ XLWorksheet() [3/4]

XLWorksheet::XLWorksheet ( const XLWorksheet & other)

◆ XLWorksheet() [4/4]

XLWorksheet::XLWorksheet ( XLWorksheet && other)
noexcept

Member Function Documentation

◆ addChart() [1/2]

XLChart XLWorksheet::addChart ( XLChartType type,
const XLChartAnchor & anchor )

◆ addChart() [2/2]

XLChart XLWorksheet::addChart ( XLChartType type,
std::string_view name,
uint32_t row,
uint32_t col,
uint32_t width,
uint32_t height )

◆ addComment()

XLThreadedComment XLWorksheet::addComment ( std::string_view cellRef,
std::string_view text,
std::string_view author = "" )

Add a modern threaded comment to a cell seamlessly.

Parameters
cellRefThe cell reference (e.g. A1).
textThe comment text.
authorThe author of the comment.

◆ addConditionalFormatting() [1/4]

void XLWorksheet::addConditionalFormatting ( const std::string & sqref,
const XLCfRule & rule )

◆ addConditionalFormatting() [2/4]

void XLWorksheet::addConditionalFormatting ( const std::string & sqref,
const XLCfRule & rule,
const XLDxf & dxf )

◆ addConditionalFormatting() [3/4]

void XLWorksheet::addConditionalFormatting ( const XLCellRange & range,
const XLCfRule & rule )

◆ addConditionalFormatting() [4/4]

void XLWorksheet::addConditionalFormatting ( const XLCellRange & range,
const XLCfRule & rule,
const XLDxf & dxf )

◆ addHyperlink()

void XLWorksheet::addHyperlink ( std::string_view cellRef,
std::string_view url,
std::string_view tooltip = "" )

◆ addImage() [1/2]

void XLWorksheet::addImage ( const std::string & name,
const std::string & data,
uint32_t row,
uint32_t col,
uint32_t width,
uint32_t height,
const XLImageOptions & options = XLImageOptions() )

◆ addImage() [2/2]

void XLWorksheet::addImage ( const std::string & name,
gsl::span< const uint8_t > data,
uint32_t row,
uint32_t col,
uint32_t width,
uint32_t height,
const XLImageOptions & options = XLImageOptions() )

◆ addInternalHyperlink()

void XLWorksheet::addInternalHyperlink ( std::string_view cellRef,
std::string_view location,
std::string_view tooltip = "" )

◆ addNote()

void XLWorksheet::addNote ( std::string_view cellRef,
std::string_view text,
std::string_view author = "" )

Add a comment to a cell seamlessly.

Parameters
cellRefThe cell reference (e.g. A1).
textThe comment text.
authorThe author of the comment.

◆ addPivotSlicer()

void XLWorksheet::addPivotSlicer ( std::string_view cellReference,
const XLPivotTable & pivotTable,
std::string_view columnName,
const XLSlicerOptions & options = XLSlicerOptions() )

Add a slicer connected to a Pivot Table.

Parameters
cellReferenceThe top-left cell where the slicer should be anchored.
pivotTableThe Pivot Table to filter.
columnNameThe exact name of the pivot field (source column name) to filter.
optionsThe visual and naming options for the slicer.
Deprecated
Use slicers().add(cellRef, pivotTable, field) instead.

◆ addPivotTable()

XLPivotTable XLWorksheet::addPivotTable ( const XLPivotTableOptions & options)

Create and add a pivot table to this worksheet.

Parameters
optionsThe configuration options for the pivot table.
Returns
The created XLPivotTable object.

◆ addReply()

XLThreadedComment XLWorksheet::addReply ( const std::string & parentId,
const std::string & text,
const std::string & author = "" )

Add a reply to an existing threaded comment.

Parameters
parentIdThe parent threaded comment ID.
textThe comment text.
authorThe author of the comment.

◆ addScaledImage()

void XLWorksheet::addScaledImage ( const std::string & name,
const std::string & data,
uint32_t row,
uint32_t col,
double scalingFactor = 1.0 )

◆ addShape()

void XLWorksheet::addShape ( std::string_view cellReference,
const XLVectorShapeOptions & options )

Insert an image at the specified cell with original dimensions (automatic parsing).

Parameters
cellReferenceThe top-left cell where the image should be anchored (e.g. "B2").
imagePathThe file path to the local image.

◆ addSortCondition()

void XLWorksheet::addSortCondition ( const std::string & ref,
uint16_t colId,
bool descending = false )

Set the sort state for the worksheet.

Parameters
refThe cell range to apply the sort state to (e.g. "A1:C10").
colIdThe 0-based column index relative to the range to sort by.
descendingTrue for descending order, false for ascending.

◆ addSparkline() [1/2]

void XLWorksheet::addSparkline ( const std::string & location,
const std::string & dataRange,
const XLSparklineOptions & options )

Add a sparkline graph with advanced configuration options.

Parameters
locationThe cell or range where the sparkline will be rendered (e.g. "F1").
dataRangeThe source data range for the sparkline (e.g. "A1:E1").
optionsA structure containing extensive visual formatting options.

◆ addSparkline() [2/2]

void XLWorksheet::addSparkline ( const std::string & location,
const std::string & dataRange,
XLSparklineType type = XLSparklineType::Line )

Add a sparkline to the worksheet.

Parameters
locationThe cell where the sparkline is displayed (e.g., "A1").
dataRangeThe cell range containing the data (e.g., "B1:Z1").
typeThe type of the sparkline (Line, Column, Stacked).

◆ addTableSlicer()

void XLWorksheet::addTableSlicer ( std::string_view cellReference,
const XLTable & table,
std::string_view columnName,
const XLSlicerOptions & options = XLSlicerOptions() )

Add a slicer connected to a table.

Parameters
cellReferenceThe top-left cell where the slicer should be anchored (e.g. "D1").
tableThe table to filter.
columnNameThe exact name of the table column to filter.
optionsThe visual and naming options for the slicer.
Deprecated
Use slicers().add(cellRef, table, column) instead.

◆ allowAutoFilter()

bool XLWorksheet::allowAutoFilter ( bool set = true)

◆ allowDeleteColumns()

bool XLWorksheet::allowDeleteColumns ( bool set = true)

◆ allowDeleteRows()

bool XLWorksheet::allowDeleteRows ( bool set = true)

◆ allowFormatCells()

bool XLWorksheet::allowFormatCells ( bool set = true)

◆ allowFormatColumns()

bool XLWorksheet::allowFormatColumns ( bool set = true)

◆ allowFormatRows()

bool XLWorksheet::allowFormatRows ( bool set = true)

◆ allowInsertColumns()

bool XLWorksheet::allowInsertColumns ( bool set = true)

◆ allowInsertHyperlinks()

bool XLWorksheet::allowInsertHyperlinks ( bool set = true)

◆ allowInsertRows()

bool XLWorksheet::allowInsertRows ( bool set = true)

◆ allowPivotTables()

bool XLWorksheet::allowPivotTables ( bool set = true)

◆ allowSelectLockedCells()

bool XLWorksheet::allowSelectLockedCells ( bool set = true)

◆ allowSelectUnlockedCells()

bool XLWorksheet::allowSelectUnlockedCells ( bool set = true)

◆ allowSort()

bool XLWorksheet::allowSort ( bool set = true)

◆ appendRow() [1/2]

void XLWorksheet::appendRow ( const std::vector< XLCellValue > & values)

Append a new row with the given values.

Parameters
valuesA vector of XLCellValue items.

◆ appendRow() [2/2]

template<typename T, typename = std::enable_if_t<!std::is_same_v<T, std::vector<XLCellValue>> && std::is_base_of_v<std::bidirectional_iterator_tag, typename std::iterator_traits<typename T::iterator>::iterator_category>, T>>
void OpenXLSX::XLWorksheet::appendRow ( const T & values)
inline

Append a new row with the given container of values.

Template Parameters
TA container type.
Parameters
valuesThe container of values.

◆ applyAutoFilter()

void XLWorksheet::applyAutoFilter ( )

Evaluates the current autoFilter conditions and hides rows that do not match the criteria. Note: Only basic text/value matching and some simple custom filters are evaluated. Complex dynamic filters might not be supported.

◆ autoFilter()

std::string XLWorksheet::autoFilter ( ) const

◆ autoFilterAllowed()

bool XLWorksheet::autoFilterAllowed ( ) const

◆ autofilterObject()

XLAutoFilter XLWorksheet::autofilterObject ( ) const

◆ autoFitColumn()

void XLWorksheet::autoFitColumn ( uint16_t columnNumber)

Automatically adjusts the column width based on the content of its cells.

◆ cell() [1/4]

XLCellAssignable XLWorksheet::cell ( const std::string & ref) const

◆ cell() [2/4]

XLCellAssignable XLWorksheet::cell ( const XLCellReference & ref) const

◆ cell() [3/4]

XLCellAssignable XLWorksheet::cell ( uint32_t rowNumber,
uint16_t columnNumber ) const

◆ cell() [4/4]

XLCellAssignable OpenXLSX::XLWorksheet::cell ( XLRowIndex row,
XLColIndex col ) const
inline

◆ clearAllConditionalFormatting()

void XLWorksheet::clearAllConditionalFormatting ( )

◆ clearAutoFilter()

void XLWorksheet::clearAutoFilter ( )

◆ clearPanes()

void XLWorksheet::clearPanes ( )

◆ clearPassword()

bool XLWorksheet::clearPassword ( )

◆ clearSheetProtection()

bool XLWorksheet::clearSheetProtection ( )

◆ column() [1/2]

XLColumn XLWorksheet::column ( std::string const & columnRef) const

◆ column() [2/2]

XLColumn XLWorksheet::column ( uint16_t columnNumber) const

◆ columnCount()

uint16_t XLWorksheet::columnCount ( ) const
noexcept

◆ comments()

XLComments & XLWorksheet::comments ( )

◆ conditionalFormats()

XLConditionalFormats XLWorksheet::conditionalFormats ( ) const

◆ dataValidations()

XLDataValidations & XLWorksheet::dataValidations ( )

◆ deleteColumn()

bool XLWorksheet::deleteColumn ( uint16_t colNumber,
uint16_t count = 1 )

Delete one or more columns and shift subsequent columns left.

Parameters
colNumber1-based first column to delete.
countNumber of consecutive columns to delete (default 1).
Returns
true on success.

◆ deleteColumnsAllowed()

bool XLWorksheet::deleteColumnsAllowed ( ) const

◆ deleteComment()

void XLWorksheet::deleteComment ( std::string_view cellRef)

Remove a modern threaded comment (and its replies) from a cell.

Parameters
cellRefThe cell reference (e.g. A1).

◆ deleteNote()

void XLWorksheet::deleteNote ( std::string_view cellRef)

Remove a legacy yellow note from a cell.

Parameters
cellRefThe cell reference (e.g. A1).

◆ deletePivotTable()

bool XLWorksheet::deletePivotTable ( std::string_view name)

Delete a pivot table by name from this worksheet.

Parameters
nameThe name of the pivot table to delete.
Returns
True if successfully deleted, false if not found.

◆ deleteRow() [1/2]

bool XLWorksheet::deleteRow ( uint32_t rowNumber)

◆ deleteRow() [2/2]

bool XLWorksheet::deleteRow ( uint32_t rowNumber,
uint32_t count )

Delete one or more rows and shift subsequent rows up.

All subsystems (merges, formulas, drawings, validations, autoFilter) are updated automatically.

Parameters
rowNumber1-based first row to delete.
countNumber of consecutive rows to delete (default 1).
Returns
true on success.

◆ deleteRowsAllowed()

bool XLWorksheet::deleteRowsAllowed ( ) const

◆ deleteSlicer()

void XLWorksheet::deleteSlicer ( const std::string & name)

Delete a slicer by name, cleaning up drawings, relationships, and orphan caches.

Parameters
nameThe name of the slicer to delete.

◆ denyAutoFilter()

bool OpenXLSX::XLWorksheet::denyAutoFilter ( )
inline

◆ denyDeleteColumns()

bool OpenXLSX::XLWorksheet::denyDeleteColumns ( )
inline

◆ denyDeleteRows()

bool OpenXLSX::XLWorksheet::denyDeleteRows ( )
inline

◆ denyFormatCells()

bool OpenXLSX::XLWorksheet::denyFormatCells ( )
inline

◆ denyFormatColumns()

bool OpenXLSX::XLWorksheet::denyFormatColumns ( )
inline

◆ denyFormatRows()

bool OpenXLSX::XLWorksheet::denyFormatRows ( )
inline

◆ denyInsertColumns()

bool OpenXLSX::XLWorksheet::denyInsertColumns ( )
inline

◆ denyInsertHyperlinks()

bool OpenXLSX::XLWorksheet::denyInsertHyperlinks ( )
inline

◆ denyInsertRows()

bool OpenXLSX::XLWorksheet::denyInsertRows ( )
inline

◆ denyPivotTables()

bool OpenXLSX::XLWorksheet::denyPivotTables ( )
inline

◆ denySelectLockedCells()

bool OpenXLSX::XLWorksheet::denySelectLockedCells ( )
inline

◆ denySelectUnlockedCells()

bool OpenXLSX::XLWorksheet::denySelectUnlockedCells ( )
inline

◆ denySort()

bool OpenXLSX::XLWorksheet::denySort ( )
inline

◆ drawing()

XLDrawing & XLWorksheet::drawing ( )

◆ fetchRangeValues()

void XLWorksheet::fetchRangeValues ( const XLCellRange & range,
std::vector< XLCellValue > & out ) const
overridevirtual

Batch fetch values for a rectangular range into an output vector.

Avoids per-cell virtual dispatch overhead in tight calculation/export loops. Default implementation falls back to row/column iteration.

Reimplemented from OpenXLSX::IXLCellProvider.

◆ findCell() [1/3]

XLCellAssignable XLWorksheet::findCell ( const std::string & ref) const

◆ findCell() [2/3]

XLCellAssignable XLWorksheet::findCell ( const XLCellReference & ref) const

◆ findCell() [3/3]

XLCellAssignable XLWorksheet::findCell ( uint32_t rowNumber,
uint16_t columnNumber ) const

◆ fitToPages()

void XLWorksheet::fitToPages ( uint32_t fitToWidth,
uint32_t fitToHeight )

◆ formatCellsAllowed()

bool XLWorksheet::formatCellsAllowed ( ) const

◆ formatColumnsAllowed()

bool XLWorksheet::formatColumnsAllowed ( ) const

◆ formatRowsAllowed()

bool XLWorksheet::formatRowsAllowed ( ) const

◆ freezePanes() [1/2]

void XLWorksheet::freezePanes ( const std::string & topLeftCell)

Freeze panes at the specified top-left cell. This is a highly ergonomic method. E.g. freezePanes("B2") freezes Row 1 and Column A.

Parameters
topLeftCellThe cell reference where the scrolling data should start.

◆ freezePanes() [2/2]

void XLWorksheet::freezePanes ( uint16_t column,
uint32_t row )

◆ getCellFormula()

std::string XLWorksheet::getCellFormula ( uint32_t row,
uint16_t col ) const
nodiscardoverridevirtual

Get formula string at 1-based (row, column), or empty string if no formula.

Implements OpenXLSX::IXLCellProvider.

◆ getCellValue()

XLCellValue XLWorksheet::getCellValue ( uint32_t row,
uint16_t col ) const
nodiscardoverridevirtual

Get cell value at 1-based (row, column).

Implements OpenXLSX::IXLCellProvider.

◆ getColumnFormat() [1/2]

XLStyleIndex XLWorksheet::getColumnFormat ( const std::string & column) const

◆ getColumnFormat() [2/2]

XLStyleIndex XLWorksheet::getColumnFormat ( uint16_t column) const

◆ getHyperlink()

std::string XLWorksheet::getHyperlink ( std::string_view cellRef) const
nodiscard

◆ getRowFormat()

XLStyleIndex XLWorksheet::getRowFormat ( uint16_t row) const

◆ groupColumns()

void XLWorksheet::groupColumns ( uint16_t colFirst,
uint16_t colLast,
uint8_t outlineLevel = 1,
bool collapsed = false )

◆ groupRows()

void XLWorksheet::groupRows ( uint32_t rowFirst,
uint32_t rowLast,
uint8_t outlineLevel = 1,
bool collapsed = false )

◆ hasAutoFilter()

bool XLWorksheet::hasAutoFilter ( ) const

◆ hasCell()

bool XLWorksheet::hasCell ( uint32_t row,
uint16_t col ) const
nodiscardoverridevirtual

Check if cell exists and is populated.

Implements OpenXLSX::IXLCellProvider.

◆ hasComments()

bool XLWorksheet::hasComments ( ) const

◆ hasDrawing()

bool XLWorksheet::hasDrawing ( ) const

◆ hasHyperlink()

bool XLWorksheet::hasHyperlink ( std::string_view cellRef) const
nodiscard

◆ hasPanes()

bool XLWorksheet::hasPanes ( ) const
nodiscard

◆ hasRelationships()

bool XLWorksheet::hasRelationships ( ) const

◆ hasTables()

bool XLWorksheet::hasTables ( ) const

◆ hasThreadedComments()

bool XLWorksheet::hasThreadedComments ( ) const

◆ hasVmlDrawing()

bool XLWorksheet::hasVmlDrawing ( ) const

◆ headerFooter()

XLHeaderFooter XLWorksheet::headerFooter ( ) const

◆ images()

std::vector< XLDrawingItem > XLWorksheet::images ( )

◆ insertColBreak()

void XLWorksheet::insertColBreak ( uint16_t col)

◆ insertColumn()

bool XLWorksheet::insertColumn ( uint16_t colNumber,
uint16_t count = 1 )

Insert one or more empty columns before the given column number.

Parameters
colNumber1-based column to insert before.
countNumber of columns to insert (default 1).
Returns
true on success.

◆ insertColumnsAllowed()

bool XLWorksheet::insertColumnsAllowed ( ) const

◆ insertHyperlinksAllowed()

bool XLWorksheet::insertHyperlinksAllowed ( ) const

◆ insertImage() [1/3]

void XLWorksheet::insertImage ( const std::string & cellReference,
const std::string & imagePath )

◆ insertImage() [2/3]

void XLWorksheet::insertImage ( const std::string & cellReference,
const std::string & imagePath,
const XLImageOptions & options )

Insert an image with advanced formatting options (scaling, offset, behavior).

Parameters
cellReferenceThe top-left cell where the image should be anchored (e.g. "B2").
imagePathThe file path to the local image.
optionsAn XLImageOptions struct specifying formatting and behavior.

◆ insertImage() [3/3]

void XLWorksheet::insertImage ( const std::string & cellReference,
gsl::span< const uint8_t > imageData,
const XLImageOptions & options = XLImageOptions{} )

◆ insertRow()

bool XLWorksheet::insertRow ( uint32_t rowNumber,
uint32_t count = 1 )

Insert one or more empty rows before the given row number.

All rows at rowNumber and below are shifted down. Merged ranges, formulas, drawing anchors, data validations and the autoFilter reference are all updated to reflect the new layout.

Parameters
rowNumber1-based row to insert before.
countNumber of rows to insert (default 1).
Returns
true on success.

◆ insertRowBreak()

void XLWorksheet::insertRowBreak ( uint32_t row)

◆ insertRowsAllowed()

bool XLWorksheet::insertRowsAllowed ( ) const

◆ isStreamedSheet()

bool XLWorksheet::isStreamedSheet ( ) const
noexcept

◆ lastCell()

XLCellReference XLWorksheet::lastCell ( ) const
noexcept

◆ makeInternalLocation()

std::string XLWorksheet::makeInternalLocation ( std::string_view sheetName,
std::string_view cellRef )
staticnodiscard

◆ mergeCells() [1/2]

XLCellRange XLWorksheet::mergeCells ( const std::string & rangeReference,
bool emptyHiddenCells = false )

◆ mergeCells() [2/2]

XLCellRange XLWorksheet::mergeCells ( XLCellRange const & rangeToMerge,
bool emptyHiddenCells = false )

◆ merges()

XLMergeCells & XLWorksheet::merges ( )

◆ objectsProtected()

bool XLWorksheet::objectsProtected ( ) const

◆ operator=() [1/2]

XLWorksheet & XLWorksheet::operator= ( const XLWorksheet & other)

◆ operator=() [2/2]

XLWorksheet & XLWorksheet::operator= ( XLWorksheet && other)

◆ pageMargins()

XLPageMargins XLWorksheet::pageMargins ( ) const

◆ pageSetup()

XLPageSetup XLWorksheet::pageSetup ( ) const

◆ passwordHash()

std::string XLWorksheet::passwordHash ( ) const

◆ passwordIsSet()

bool XLWorksheet::passwordIsSet ( ) const

◆ peekCell() [1/4]

std::optional< XLCell > XLWorksheet::peekCell ( const std::string & ref) const

◆ peekCell() [2/4]

std::optional< XLCell > XLWorksheet::peekCell ( const XLCellReference & ref) const

◆ peekCell() [3/4]

std::optional< XLCell > XLWorksheet::peekCell ( uint32_t rowNumber,
uint16_t columnNumber ) const

◆ peekCell() [4/4]

std::optional< XLCell > OpenXLSX::XLWorksheet::peekCell ( XLRowIndex row,
XLColIndex col ) const
inline

◆ pivotTables()

std::vector< XLPivotTable > XLWorksheet::pivotTables ( )

Retrieves all pivot tables belonging to this worksheet.

Returns
A vector of XLPivotTable objects.

◆ pivotTablesAllowed()

bool XLWorksheet::pivotTablesAllowed ( ) const

◆ printOptions()

XLPrintOptions XLWorksheet::printOptions ( ) const

◆ protect()

bool XLWorksheet::protect ( const XLSheetProtectionOptions & options,
std::string_view password = "" )

Protect the worksheet with granular options.

Parameters
optionsA structure containing specific protection flags.
passwordOptional password to protect the sheet.
Returns
true if successful.

◆ protectObjects()

bool XLWorksheet::protectObjects ( bool set = true)

◆ protectScenarios()

bool XLWorksheet::protectScenarios ( bool set = true)

◆ protectSheet()

bool XLWorksheet::protectSheet ( bool set = true)

◆ range() [1/4]

XLCellRange XLWorksheet::range ( ) const

◆ range() [2/4]

XLCellRange XLWorksheet::range ( const XLCellReference & topLeft,
const XLCellReference & bottomRight ) const

◆ range() [3/4]

XLCellRange XLWorksheet::range ( std::string const & rangeReference) const

◆ range() [4/4]

XLCellRange XLWorksheet::range ( std::string const & topLeft,
std::string const & bottomRight ) const

◆ registerStreamHyperlinks()

std::string XLWorksheet::registerStreamHyperlinks ( const std::vector< XLStreamHyperlink > & links)

Register stream hyperlinks: adds external relationships and returns <hyperlinks> XML.

◆ registerStreamTable()

std::string XLWorksheet::registerStreamTable ( const XLStreamTableOptions & table)

Register a table part for stream-written sheets; returns tableParts XML fragment.

Note
Called from XLStreamWriter::close when addTable() was used.

◆ removeColBreak()

void XLWorksheet::removeColBreak ( uint16_t col)

◆ removeConditionalFormatting() [1/2]

void XLWorksheet::removeConditionalFormatting ( const std::string & sqref)

◆ removeConditionalFormatting() [2/2]

void XLWorksheet::removeConditionalFormatting ( const XLCellRange & range)

◆ removeHyperlink()

void XLWorksheet::removeHyperlink ( std::string_view cellRef)

◆ removeRowBreak()

void XLWorksheet::removeRowBreak ( uint32_t row)

◆ row()

XLRow XLWorksheet::row ( uint32_t rowNumber) const

◆ rowCount()

uint32_t XLWorksheet::rowCount ( ) const
noexcept

◆ rows() [1/3]

XLRowRange XLWorksheet::rows ( ) const

◆ rows() [2/3]

XLRowRange XLWorksheet::rows ( uint32_t firstRow,
uint32_t lastRow ) const

◆ rows() [3/3]

XLRowRange XLWorksheet::rows ( uint32_t rowCount) const

◆ scenariosProtected()

bool XLWorksheet::scenariosProtected ( ) const

◆ selectLockedCellsAllowed()

bool XLWorksheet::selectLockedCellsAllowed ( ) const

◆ selectUnlockedCellsAllowed()

bool XLWorksheet::selectUnlockedCellsAllowed ( ) const

◆ setAutoFilter()

void XLWorksheet::setAutoFilter ( const XLCellRange & range)

◆ setColumnFormat() [1/2]

bool XLWorksheet::setColumnFormat ( const std::string & column,
XLStyleIndex cellFormatIndex )

◆ setColumnFormat() [2/2]

bool XLWorksheet::setColumnFormat ( uint16_t column,
XLStyleIndex cellFormatIndex )

◆ setPassword()

bool XLWorksheet::setPassword ( std::string password)

◆ setPasswordHash()

bool XLWorksheet::setPasswordHash ( std::string hash)

◆ setPrintArea()

void XLWorksheet::setPrintArea ( const std::string & sqref)

Set the print area for this worksheet.

Parameters
sqrefThe cell range (e.g., "A1:F50").

◆ setPrintTitleCols()

void XLWorksheet::setPrintTitleCols ( uint16_t firstCol,
uint16_t lastCol )

Set columns to repeat at the left of each printed page.

Parameters
firstColThe first column to repeat (1-based).
lastColThe last column to repeat (1-based).

◆ setPrintTitleRows()

void XLWorksheet::setPrintTitleRows ( uint32_t firstRow,
uint32_t lastRow )

Set rows to repeat at the top of each printed page.

Parameters
firstRowThe first row to repeat (1-based).
lastRowThe last row to repeat (1-based).

◆ setRowFormat()

bool XLWorksheet::setRowFormat ( uint32_t row,
XLStyleIndex cellFormatIndex )

◆ setSheetViewMode()

void XLWorksheet::setSheetViewMode ( std::string_view mode)

◆ setShowGridLines()

void XLWorksheet::setShowGridLines ( bool show)

◆ setShowRowColHeaders()

void XLWorksheet::setShowRowColHeaders ( bool show)

◆ setStreamExtents()

void XLWorksheet::setStreamExtents ( uint32_t lastRow,
uint16_t maxCol )
noexcept

◆ setStreamMaterialization()

void XLWorksheet::setStreamMaterialization ( std::string filePath,
std::string memoryPayload )
noexcept

◆ setStreamWriterOpen()

void XLWorksheet::setStreamWriterOpen ( bool open)
noexcept

Internal: mark whether an XLStreamWriter for this sheet is still open (save guard).

Note
Used only by XLStreamWriter (friend).

◆ setZoom()

void XLWorksheet::setZoom ( uint16_t scale)

◆ sheetName()

std::string XLWorksheet::sheetName ( ) const
nodiscardoverridevirtual

Get sheet name.

Implements OpenXLSX::IXLCellProvider.

◆ sheetProtected()

bool XLWorksheet::sheetProtected ( ) const

◆ sheetProtectionSummary()

std::string XLWorksheet::sheetProtectionSummary ( ) const

◆ sheetViewMode()

std::string XLWorksheet::sheetViewMode ( ) const
nodiscard

◆ showGridLines()

bool XLWorksheet::showGridLines ( ) const
nodiscard

◆ showRowColHeaders()

bool XLWorksheet::showRowColHeaders ( ) const
nodiscard

◆ slicers()

XLSlicerCollection & XLWorksheet::slicers ( )

Get the slicer collection for this worksheet.

Returns a live reference to the XLSlicerCollection object, which supports:

  • range-for iteration
  • named/index access via operator[]
  • fluent slicer creation via add()
  • removal via remove()

Example:

wks.slicers().add("E2", table, "Region")
.caption("Region Filter")
.size(180, 250)
.showOnly({"North", "West"});
wks.slicers()["Region"].setCaption("New Title");
@ Dark3
Definition XLSlicer.hpp:34

◆ sortAllowed()

bool XLWorksheet::sortAllowed ( ) const

◆ splitPanes()

void XLWorksheet::splitPanes ( double xSplit,
double ySplit,
std::string_view topLeftCell = "",
XLPane activePane = XLPane::BottomRight )

◆ streamReader()

XLStreamReader XLWorksheet::streamReader ( const XLStreamReadOptions & options = {}) const

Create a stream reader for memory efficient reading of large documents.

Parameters
optionsEmpty-row policy and optional number-format application.
Returns
An XLStreamReader object.

◆ streamWriter() [1/2]

XLStreamWriter XLWorksheet::streamWriter ( bool useSharedStrings = false,
size_t maxUniqueStrings = 100000 )

Starts a high-performance, low-memory stream writer for this worksheet.

Warning
Initiating a stream writer locks the DOM for this sheet.

◆ streamWriter() [2/2]

XLStreamWriter XLWorksheet::streamWriter ( const XLStreamWriteOptions & options)

Stream writer with full options (open mode, spill threshold, shared strings, …).

◆ tables()

XLTableCollection & XLWorksheet::tables ( )

◆ threadedComments()

XLThreadedComments & XLWorksheet::threadedComments ( )

◆ unmergeCells() [1/2]

void XLWorksheet::unmergeCells ( const std::string & rangeReference)

◆ unmergeCells() [2/2]

void XLWorksheet::unmergeCells ( XLCellRange const & rangeToMerge)

◆ updateDimension()

void XLWorksheet::updateDimension ( )

◆ updateSheetName()

void XLWorksheet::updateSheetName ( const std::string & oldName,
const std::string & newName )

◆ vmlDrawing()

XLVmlDrawing & XLWorksheet::vmlDrawing ( )

◆ zoom()

uint16_t XLWorksheet::zoom ( ) const
nodiscard

◆ XLCell

friend class XLCell
friend

◆ XLRow

friend class XLRow
friend

◆ XLRowDataProxy

friend class XLRowDataProxy
friend

◆ XLSheetBase< XLWorksheet >

friend class XLSheetBase< XLWorksheet >
friend

◆ XLSlicerCollection

friend class XLSlicerCollection
friend

◆ XLTableCollection

friend class XLTableCollection
friend

◆ XLWorkbook

friend class XLWorkbook
friend

The documentation for this class was generated from the following files: