Pkg.XLSB — API for parsing Microsoft Excel XLSB files¶
Parsing an XLSB File¶
The following code example demonstrates how to parse an XLSB file and list its sheets, defined names and shared strings:
from Pro.Core import *
from Pkg.XLSB import *
def parseXLSB(fname):
c = createContainerFromFile(fname)
if c.isNull():
return
obj = XLSBObject()
if not obj.Load(c):
return
obj.SetEntries(obj.RetrieveEntries())
# list all sheets
for sheet in obj.GetSheets():
print("sheet:", sheet["name"], sheet["type"], sheet["state"])
# list defined names
for name, formula in obj.GetDefinedNames():
print("name:", name, "=", formula)
# list shared strings
for s in obj.GetSharedStrings():
print("string:", s)
Module API¶
Pkg.XLSB module API.
Classes:
This class represents an Excel XLSB (binary) file.
- class XLSBObject¶
Bases:
Pro.Zip.ZipObjectThis class represents an Excel XLSB (binary) file.
Methods:
Creates a Silicon spreadsheet workspace that can be used for macro emulation.
Retrieves the [Content_Types].xml file from the XLSB package.
Retrieves all defined names in the workbook.
GetFile(name)Retrieves a file from the XLSB package.
Retrieves the shared strings used in the workbook.
Retrieves the binary shared strings part from the XLSB package.
Retrieves information about all sheets in the workbook.
Retrieves the binary styles part from the XLSB package.
GetTypes()Retrieves a mapping from MIME content types to their associated file names within the XLSB package.
Retrieves the binary workbook part (
xl/workbook.bin) from the XLSB package.Retrieves the relationships XML file associated with the workbook.
GetWorksheetPart(idx)Retrieves the binary worksheet part for the given index (1-based).
GetWorksheetRels(idx)Retrieves the relationships part for the worksheet at the given index (1-based).
GetXMLFile(fname)Retrieves and parses an XML file from the XLSB package.
Parses an XML file from a given container.
Checks whether the workbook contains any hidden or very-hidden sheets.
Checks whether the workbook contains any Excel 4.0 macro sheets.
- CreateSpreadsheetWorkspace() → Pro.SiliconSpreadsheet.SiliconSpreadsheetWorkspace¶
Creates a Silicon spreadsheet workspace that can be used for macro emulation.
- Returns
Returns the workspace.
- Return type
- GetContentTypes() → Optional[Pro.Core.NTXml]¶
Retrieves the [Content_Types].xml file from the XLSB package.
- Returns
Returns an XML object if successful; otherwise returns
None.- Return type
Optional[NTXml]
See also
GetTypes().
- GetDefinedNames() → List[Tuple[str, str]]¶
Retrieves all defined names in the workbook.
- Returns
Returns a list of tuples containing defined names and their associated formulas.
- Return type
List[Tuple[str, str]]
- GetFile(name: str) → Pro.Core.NTContainer¶
Retrieves a file from the XLSB package.
- Parameters
name (str) – The name of the file within the XLSB package to retrieve.
- Returns
Returns a container for the specified file within the XLSB package.
- Return type
Retrieves the shared strings used in the workbook.
- Returns
Returns a list of shared strings.
- Return type
List[str]
Retrieves the binary shared strings part from the XLSB package.
- Returns
Returns a container for the shared strings part.
- Return type
See also
GetSharedStrings().
- GetSheets() → List[Dict[str, str]]¶
Retrieves information about all sheets in the workbook.
Each entry contains the keys
name,type(e.g.worksheetormacrosheet),loc,rIdandstate(visible,hiddenorveryhidden).
- Returns
Returns a list of dictionaries, each containing information about a sheet.
- Return type
List[Dict[str, str]]
See also
HasMacroSheets()andHasHiddenSheets().
- GetStylesPart() → Pro.Core.NTContainer¶
Retrieves the binary styles part from the XLSB package.
- Returns
Returns a container for the styles part.
- Return type
- GetTypes() → Dict[str, str]¶
Retrieves a mapping from MIME content types to their associated file names within the XLSB package.
- Returns
Returns a dictionary mapping MIME content types to file names.
- Return type
Dict[str, str]
See also
GetContentTypes().
- GetWorkbookPart() → Pro.Core.NTContainer¶
Retrieves the binary workbook part (
xl/workbook.bin) from the XLSB package.
- Returns
Returns a container for the workbook part.
- Return type
See also
GetWorkbookRels().
- GetWorkbookRels() → Optional[Pro.Core.NTXml]¶
Retrieves the relationships XML file associated with the workbook.
- Returns
Returns an XML object if successful; otherwise returns
None.- Return type
Optional[NTXml]
See also
GetWorkbookPart().
- GetWorksheetPart(idx: int) → Pro.Core.NTContainer¶
Retrieves the binary worksheet part for the given index (1-based).
- Parameters
idx (int) – The 1-based worksheet index.
- Returns
Returns a container for the worksheet part.
- Return type
See also
GetWorksheetRels().
- GetWorksheetRels(idx: int) → Pro.Core.NTContainer¶
Retrieves the relationships part for the worksheet at the given index (1-based).
- Parameters
idx (int) – The 1-based worksheet index.
- Returns
Returns a container for the worksheet relationships part.
- Return type
See also
GetWorksheetPart().
- GetXMLFile(fname: str) → Optional[Pro.Core.NTXml]¶
Retrieves and parses an XML file from the XLSB package.
- Parameters
fname (str) – The name of the XML file within the XLSB package to retrieve.
- Returns
Returns an XML object if successful; otherwise returns
None.- Return type
Optional[NTXml]
- GetXMLFromFile(c: Pro.Core.NTContainer) → Optional[Pro.Core.NTXml]¶
Parses an XML file from a given container.
- Parameters
c (NTContainer) – The container representing the file from which to extract XML content.
- Returns
Returns an XML object if successful; otherwise returns
None.- Return type
Optional[NTXml]
- HasHiddenSheets() → bool¶
Checks whether the workbook contains any hidden or very-hidden sheets.
- Returns
Returns
Trueif at least one sheet is hidden; otherwise returnsFalse.- Return type
bool
See also
GetSheets().
- HasMacroSheets() → bool¶
Checks whether the workbook contains any Excel 4.0 macro sheets.
- Returns
Returns
Trueif at least one sheet is a macro sheet; otherwise returnsFalse.- Return type
bool
See also
GetSheets().