OpenXLSX 1.9.1
Loading...
Searching...
No Matches
OpenXLSX::XLWorkbook Class Reference

This class encapsulates the concept of a Workbook. It provides access to the individual sheets (worksheets or chartsheets), as well as functionality for adding, deleting, moving and renaming sheets. More...

#include <XLWorkbook.hpp>

Inheritance diagram for OpenXLSX::XLWorkbook:
OpenXLSX::XLXmlFile

Public Member Functions

 XLWorkbook ()=default
 Default constructor. Creates an empty ('null') XLWorkbook object.
 
 XLWorkbook (XLXmlData *xmlData)
 Constructor. Takes a pointer to an XLXmlData object (stored in the parent XLDocument object).
 
 XLWorkbook (const XLWorkbook &other)=default
 Copy Constructor.
 
 XLWorkbook (XLWorkbook &&other)=default
 Move constructor.
 
 ~XLWorkbook ()
 Destructor.
 
XLWorkbookoperator= (const XLWorkbook &other)=default
 Copy assignment operator.
 
XLWorkbookoperator= (XLWorkbook &&other)=default
 Move assignment operator.
 
XLSheet sheet (uint16_t index)
 Get the sheet (worksheet or chartsheet) at the given index.
 
XLSheet sheet (std::string_view sheetName)
 Get the sheet (worksheet or chartsheet) with the given name.
 
XLWorksheet worksheet (std::string_view sheetName)
 Get the worksheet with the given name.
 
XLWorksheet worksheet (uint16_t index)
 Get the worksheet at the given index.
 
XLChartsheet chartsheet (std::string_view sheetName)
 Get the chartsheet with the given name.
 
XLChartsheet chartsheet (uint16_t index)
 Get the chartsheet at the given index.
 
XLDefinedNames definedNames ()
 Get the defined names collection.
 
void deleteSheet (std::string_view sheetName)
 Delete sheet (worksheet or chartsheet) from the workbook.
 
void addWorksheet (std::string_view sheetName)
 Add a new worksheet.
 
void addChartsheet (std::string_view sheetName)
 
void cloneSheet (std::string_view existingName, std::string_view newName)
 Clone an existing sheet.
 
void setSheetIndex (std::string_view sheetName, unsigned int index)
 Move a sheet to a new index.
 
unsigned int indexOfSheet (std::string_view sheetName) const
 Get the index of a sheet.
 
XLSheetType typeOfSheet (std::string_view sheetName) const
 Get the type of a sheet.
 
XLSheetType typeOfSheet (unsigned int index) const
 Get the type of a sheet at a given index.
 
unsigned int sheetCount () const
 Get the total number of sheets in the workbook.
 
unsigned int worksheetCount () const
 Get the total number of worksheets in the workbook.
 
unsigned int chartsheetCount () const
 Get the total number of chartsheets in the workbook.
 
std::vector< std::string > sheetNames () const
 Get a list of all sheet names.
 
std::vector< std::string > worksheetNames () const
 Get a list of all worksheet names.
 
std::vector< std::string > chartsheetNames () const
 Get a list of all chartsheet names.
 
bool sheetExists (std::string_view sheetName) const
 Check if a sheet exists.
 
bool worksheetExists (std::string_view sheetName) const
 Check if a worksheet exists.
 
bool chartsheetExists (std::string_view sheetName) const
 Check if a chartsheet exists.
 
void updateSheetReferences (std::string_view oldName, std::string_view newName)
 Update references to a sheet after renaming.
 
void deleteNamedRanges ()
 Delete all named ranges.
 
void updateWorksheetDimensions ()
 Update the dimension (used range) for all worksheets in the workbook.
 
void setFullCalculationOnLoad ()
 Set a flag to force full calculation upon loading the file in Excel.
 
void protect (bool lockStructure, bool lockWindows, std::string_view password="")
 Protect the workbook.
 
void unprotect ()
 Unprotect the workbook.
 
bool isProtected () const
 Check if the workbook is protected.
 
void print (std::basic_ostream< char > &ostr) const
 Print the XML contents of the workbook.xml.
 
- 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
 
XLXmlFileoperator= (const XLXmlFile &other)=default
 The copy assignment operator. The default implementation has been used.
 
XLXmlFileoperator= (XLXmlFile &&other) noexcept=default
 The move assignment operator. The default implementation has been used.
 
XLDocumentparentDoc ()
 This function provides access to the parent XLDocument object.
 
const XLDocumentparentDoc () const
 This function provides access to the parent XLDocument object.
 
XMLDocumentxmlDocument ()
 This function provides access to the underlying XMLDocument object.
 
const XMLDocumentxmlDocument () 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.
 

Friends

class XLSheet
 
class XLDocument
 

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
XLXmlDatam_xmlData {nullptr}
 

Detailed Description

This class encapsulates the concept of a Workbook. It provides access to the individual sheets (worksheets or chartsheets), as well as functionality for adding, deleting, moving and renaming sheets.

Constructor & Destructor Documentation

◆ XLWorkbook() [1/4]

OpenXLSX::XLWorkbook::XLWorkbook ( )
default

Default constructor. Creates an empty ('null') XLWorkbook object.

◆ XLWorkbook() [2/4]

XLWorkbook::XLWorkbook ( XLXmlData xmlData)
explicit

Constructor. Takes a pointer to an XLXmlData object (stored in the parent XLDocument object).

Parameters
xmlDataA pointer to the underlying XLXmlData object, which holds the XML data.
Note
Do not create an XLWorkbook object directly. Access via XLDocument::workbook().

◆ XLWorkbook() [3/4]

OpenXLSX::XLWorkbook::XLWorkbook ( const XLWorkbook other)
default

Copy Constructor.

Parameters
otherThe XLWorkbook object to be copied.

◆ XLWorkbook() [4/4]

OpenXLSX::XLWorkbook::XLWorkbook ( XLWorkbook &&  other)
default

Move constructor.

Parameters
otherThe XLWorkbook to be moved.

◆ ~XLWorkbook()

XLWorkbook::~XLWorkbook ( )
default

Destructor.

Member Function Documentation

◆ addChartsheet()

void XLWorkbook::addChartsheet ( std::string_view  sheetName)

◆ addWorksheet()

void XLWorkbook::addWorksheet ( std::string_view  sheetName)

Add a new worksheet.

Parameters
sheetNameThe name of the new worksheet.

◆ chartsheet() [1/2]

XLChartsheet XLWorkbook::chartsheet ( std::string_view  sheetName)

Get the chartsheet with the given name.

Parameters
sheetNameThe name of the desired chartsheet.
Returns

◆ chartsheet() [2/2]

XLChartsheet XLWorkbook::chartsheet ( uint16_t  index)

Get the chartsheet at the given index.

Parameters
indexThe index (1-based) at which the desired sheet is located.
Returns

◆ chartsheetCount()

unsigned int XLWorkbook::chartsheetCount ( ) const

Get the total number of chartsheets in the workbook.

◆ chartsheetExists()

bool XLWorkbook::chartsheetExists ( std::string_view  sheetName) const

Check if a chartsheet exists.

◆ chartsheetNames()

std::vector< std::string > XLWorkbook::chartsheetNames ( ) const

Get a list of all chartsheet names.

◆ cloneSheet()

void XLWorkbook::cloneSheet ( std::string_view  existingName,
std::string_view  newName 
)

Clone an existing sheet.

Parameters
existingNameThe name of the sheet to clone.
newNameThe name of the new cloned sheet.

◆ definedNames()

XLDefinedNames XLWorkbook::definedNames ( )

Get the defined names collection.

Returns
An XLDefinedNames object.

◆ deleteNamedRanges()

void XLWorkbook::deleteNamedRanges ( )

Delete all named ranges.

◆ deleteSheet()

void XLWorkbook::deleteSheet ( std::string_view  sheetName)

Delete sheet (worksheet or chartsheet) from the workbook.

Parameters
sheetNameName of the sheet to delete.
Exceptions
XLExceptionAn exception will be thrown if trying to delete the last worksheet in the workbook

◆ indexOfSheet()

unsigned int XLWorkbook::indexOfSheet ( std::string_view  sheetName) const

Get the index of a sheet.

Parameters
sheetNameThe name of the sheet.
Returns
The 1-based index of the sheet.

◆ isProtected()

bool XLWorkbook::isProtected ( ) const

Check if the workbook is protected.

◆ operator=() [1/2]

XLWorkbook & OpenXLSX::XLWorkbook::operator= ( const XLWorkbook other)
default

Copy assignment operator.

◆ operator=() [2/2]

XLWorkbook & OpenXLSX::XLWorkbook::operator= ( XLWorkbook &&  other)
default

Move assignment operator.

◆ print()

void XLWorkbook::print ( std::basic_ostream< char > &  ostr) const

Print the XML contents of the workbook.xml.

◆ protect()

void XLWorkbook::protect ( bool  lockStructure,
bool  lockWindows,
std::string_view  password = "" 
)

Protect the workbook.

Parameters
lockStructureIf true, the structure of the workbook is locked.
lockWindowsIf true, the windows of the workbook are locked.
passwordThe password to protect the workbook with.

◆ setFullCalculationOnLoad()

void XLWorkbook::setFullCalculationOnLoad ( )

Set a flag to force full calculation upon loading the file in Excel.

◆ setSheetIndex()

void XLWorkbook::setSheetIndex ( std::string_view  sheetName,
unsigned int  index 
)

Move a sheet to a new index.

Parameters
sheetNameThe name of the sheet to move.
indexThe index (1-based) where the sheet shall be moved to.

◆ sheet() [1/2]

XLSheet XLWorkbook::sheet ( std::string_view  sheetName)

Get the sheet (worksheet or chartsheet) with the given name.

Parameters
sheetNameThe name of the desired sheet.
Returns
A pointer to an XLAbstractSheet with the sheet at the index.

◆ sheet() [2/2]

XLSheet XLWorkbook::sheet ( uint16_t  index)

Get the sheet (worksheet or chartsheet) at the given index.

Parameters
indexThe index at which the desired sheet is located.
Returns
A pointer to an XLAbstractSheet with the sheet at the index.
Note
The index must be 1-based (rather than 0-based) as this is the default for Excel spreadsheets.

◆ sheetCount()

unsigned int XLWorkbook::sheetCount ( ) const

Get the total number of sheets in the workbook.

◆ sheetExists()

bool XLWorkbook::sheetExists ( std::string_view  sheetName) const

Check if a sheet exists.

◆ sheetNames()

std::vector< std::string > XLWorkbook::sheetNames ( ) const

Get a list of all sheet names.

◆ typeOfSheet() [1/2]

XLSheetType XLWorkbook::typeOfSheet ( std::string_view  sheetName) const

Get the type of a sheet.

Parameters
sheetNameThe name of the sheet.
Returns
The type of the sheet.

◆ typeOfSheet() [2/2]

XLSheetType XLWorkbook::typeOfSheet ( unsigned int  index) const

Get the type of a sheet at a given index.

Parameters
indexThe 1-based index.
Returns
The type of the sheet.

◆ unprotect()

void XLWorkbook::unprotect ( )

Unprotect the workbook.

◆ updateSheetReferences()

void XLWorkbook::updateSheetReferences ( std::string_view  oldName,
std::string_view  newName 
)

Update references to a sheet after renaming.

◆ updateWorksheetDimensions()

void XLWorkbook::updateWorksheetDimensions ( )

Update the dimension (used range) for all worksheets in the workbook.

◆ worksheet() [1/2]

XLWorksheet XLWorkbook::worksheet ( std::string_view  sheetName)

Get the worksheet with the given name.

Parameters
sheetNameThe name of the desired worksheet.
Returns

◆ worksheet() [2/2]

XLWorksheet XLWorkbook::worksheet ( uint16_t  index)

Get the worksheet at the given index.

Parameters
indexThe index (1-based) at which the desired sheet is located.
Returns

◆ worksheetCount()

unsigned int XLWorkbook::worksheetCount ( ) const

Get the total number of worksheets in the workbook.

◆ worksheetExists()

bool XLWorkbook::worksheetExists ( std::string_view  sheetName) const

Check if a worksheet exists.

◆ worksheetNames()

std::vector< std::string > XLWorkbook::worksheetNames ( ) const

Get a list of all worksheet names.

Friends And Related Symbol Documentation

◆ XLDocument

friend class XLDocument
friend

◆ XLSheet

friend class XLSheet
friend

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