comet.CExcelBook¶
- class comet.CExcelBook¶
This section describes all functions for the comet.CExcelBook class.
See also
- Module
comet.excel
Accessor and utility functions for excel files.
CExcelBook represents an opened Excel file in memory. This class can be used to query the Excel sheets for information and content.
Important: When querying cell attributed like border styles etc…, you have to fetch them from the actual indices and not the anchor cell.n e.g. When trying to determine the right border of a cell merged from column 0-1, you have to query the right border color at column 1.
Methods¶
- CExcelBook.getSheetCount()¶
Returns the number of sheets in the excel document.
- Returns:
The number of sheets
- Return type:
- Raises:
TypeError – When parameter types are invalid
CometError – On internal error
- Available:
InDesign® comet_pdf® Illustrator®
- CScript:
- CExcelBook.getSheetName(sheetIndex=0)¶
Returns the name of the sheet at the provided index
- Parameters:
sheetIndex (int) – The index of the sheet to get the name for
- Returns:
The name of the sheet
- Return type:
- Raises:
TypeError – When parameter types are invalid
ValueError – When sheetIndex is not in a valid range
CometError – On internal error
- Available:
InDesign® comet_pdf® Illustrator®
- CScript:
- CExcelBook.getFirstRow(sheet)¶
Returns the first row in the sheet that contains a used cell.
- Parameters:
sheet (str) –
Name of data sheet
Empty str : First data sheet
- Returns:
The 0-based row index
- Return type:
- Raises:
TypeError – When parameter types are invalid
CometError – On internal error
- Available:
InDesign® comet_pdf® Illustrator®
- CScript:
- CExcelBook.getLastRow(sheet)¶
Returns the zero-based index of the row after the last row in the sheet that contains a used cell.
- Parameters:
sheet (str) –
Name of data sheet
Empty str : First data sheet
- Returns:
The 0-based row index
- Return type:
- Raises:
TypeError – When parameter types are invalid
CometError – On internal error
- Available:
InDesign® comet_pdf® Illustrator®
- CScript:
- CExcelBook.getFirstColumn(sheet)¶
Returns the first column in the sheet that contains a used cell.
- Parameters:
sheet (str) –
Name of data sheet
Empty str : First data sheet
- Returns:
The 0-based column index
- Return type:
- Raises:
TypeError – When parameter types are invalid
CometError – On internal error
- Available:
InDesign® comet_pdf® Illustrator®
- CScript:
- CExcelBook.getLastColumn(sheet)¶
Returns the zero-based index of the column after the last column in the sheet that contains a used cell.
- Parameters:
sheet (str) –
Name of data sheet
Empty str : First data sheet
- Returns:
The 0-based column index
- Return type:
- Raises:
TypeError – When parameter types are invalid
CometError – On internal error
- Available:
InDesign® comet_pdf® Illustrator®
- CScript:
- CExcelBook.getCellType(sheet, column, row)¶
Get the type of cell of an Excel sheet.
- Parameters:
- Returns:
The type of the cell.
One of Excel cell types
- Return type:
- Raises:
TypeError – When parameter types are invalid
ValueError – When parameter row or column have invalid values
CometError – On internal error
- Available:
InDesign® comet_pdf® Illustrator®
- CScript:
- CExcelBook.getCellFormula(sheet, column, row)¶
Get the formula of a cell of an Excel sheet.
- Parameters:
- Returns:
The cell formula
- Return type:
- Raises:
TypeError – When parameter types are invalid
ValueError – When parameter row or column have invalid values
CometError – On internal error
- Available:
InDesign® comet_pdf® Illustrator®
- CScript:
- CExcelBook.getCellFormat(sheet, column, row)¶
Get the format of a cell of an Excel sheet.
- Parameters:
- Returns:
Format ID and user defined format statement if any.
Format ID < 164: Excel standard format
Format ID >= 164: User defined format. In this case the result contains the format statement
- Return type:
- Raises:
TypeError – When parameter types are invalid
ValueError – When parameter row or column have invalid values
On internal error
When cell has no formula set
- Available:
InDesign® comet_pdf® Illustrator®
- CScript:
- CExcelBook.getCellFormatTags(sheet, column, row, format=0)¶
Get the format tags determined by the cell format which can be used to insert the cell content in a formatted manner into the host application.
Note that the format tags are determined by the cell settings which are applied to the entire content.
For inline formatting which changes throughout the cell content use
getCellContent()
.- Parameters:
sheet (str) –
Name of data sheet
Empty str : First data sheet
column (int) – 0-based column of the table
row (int) – 0-based row of the table
format (int) –
The target tag format.
Default is
constants.kExportPlain
- Valid values are:
constants.kExportPlain
:The result is two empty str since plain text does not contain any formatting.
constants.kExportTagged
Result contains opening and closing tags for InDesign® tagged text.
constants.kExportHTML
Result contains opening and closing tags for HTML text with inline CSS applied.
- Returns:
The opening and closing tags to put before and after the unformatted cell content.
- Return type:
- Raises:
TypeError – When parameter types are invalid
ValueError – When parameter row or column have invalid values
CometError – On internal error
- Available:
InDesign® comet_pdf® Illustrator®
- CScript:
- CExcelBook.getCellArea(sheet, column, row)¶
Determine the merged area of a cell.
- Parameters:
- Returns:
Indices as tuple: (column start, column end, row start, row end)
- Return type:
- Raises:
TypeError – When parameter types are invalid
ValueError – When parameter row or column have invalid values
CometError – On internal error
- Available:
InDesign® comet_pdf® Illustrator®
- CScript:
- CExcelBook.getRowHeight(sheet, row)¶
Get the height of a row of an Excel sheet.
- Parameters:
- Returns:
Height of the row in points
- Return type:
- Raises:
TypeError – When parameter types are invalid
ValueError – When parameter row has invalid value
CometError – On internal error
- Available:
InDesign® comet_pdf® Illustrator®
- CScript:
- CExcelBook.getColumnWidth(sheet, column)¶
Get the width of a column of an Excel sheet.
- Parameters:
- Returns:
Width of the column in points
- Return type:
- Raises:
TypeError – When parameter types are invalid
ValueError – When parameter column has invalid value
CometError – On internal error
- Available:
InDesign® comet_pdf® Illustrator®
- CScript:
- CExcelBook.getColor(sheet, column, row, which)¶
Determine the configured colors of a cell.
- Parameters:
sheet (str) –
Name of data sheet
Empty str : First data sheet
column (int) – 0-based column of the table
row (int) – 0-based row of the table
which (int) –
Which color data to fetch.
One of Excel selectors
- Returns:
RGB Color
- Return type:
- Raises:
TypeError – When parameter types are invalid
When parameter sheet points to invalid sheet
When parameter row or column are out of bounds
When parameter which has invalid value
CometError – On internal error
- Available:
InDesign® comet_pdf® Illustrator®
- CScript:
- CExcelBook.getBorderStyle(sheet, column, row, which)¶
Determine the border style of a cell.
- Parameters:
sheet (str) –
Name of data sheet
Empty str : First data sheet
column (int) – 0-based column of the table
row (int) – 0-based row of the table
which (int) –
Which attribute to query.
One of Excel selectors in range (0, 3)
- Returns:
The border style for that cell border.
One of Excel border styles
- Return type:
- Raises:
TypeError – When parameter types are invalid
When parameter sheet points to invalid sheet
When parameter row or column are out of bounds
When parameter which has invalid value
CometError – On internal error
- Available:
InDesign® comet_pdf® Illustrator®
- CScript:
- CExcelBook.getFontFamily(sheet, column, row)¶
Get the name of the font family of the given cell.
- Parameters:
- Returns:
The name of the font family
- Return type:
- Raises:
TypeError – When parameter types are invalid
ValueError – When parameter row or column has invalid value
CometError – On internal error
- Available:
InDesign® comet_pdf® Illustrator®
- CScript:
- CExcelBook.getFontFace(sheet, column, row)¶
Get the name of the font face of the given cell.
- Parameters:
- Returns:
Name of the font face with taking bold and italic into account.
The font face is useful for the <cTypeface:…> tag of TaggedText.
For HTML output the font face is not needed.
- Return type:
- Raises:
TypeError – When parameter types are invalid
ValueError – When parameter row or column has invalid value
CometError – On internal error
- Available:
InDesign® comet_pdf® Illustrator®
- CScript:
- CExcelBook.getFontSize(sheet, column, row)¶
Get the font size of a given cell.
- Parameters:
- Returns:
The font size of the given cell
- Return type:
- Raises:
TypeError – When parameter types are invalid
ValueError – When parameter row or column has invalid value
CometError – On internal error
- Available:
InDesign® comet_pdf® Illustrator®
- CScript:
- CExcelBook.getFontColor(sheet, column, row)¶
Get the font color of the given cell.
- Parameters:
- Returns:
The font color of the given cell as an RGB color.
- Return type:
- Raises:
TypeError – When parameter types are invalid
ValueError – When parameter row or column has invalid value
CometError – On internal error
- Available:
InDesign® comet_pdf® Illustrator®
- CScript:
- CExcelBook.getFontStrikeThrough(sheet, column, row)¶
Get whether the font in the cell is striked through
- Parameters:
- Returns:
Whether the font in the cell is striked through
- Return type:
- Raises:
TypeError – When parameter types are invalid
ValueError – When parameter row or column has invalid value
CometError – On internal error
- Available:
InDesign® comet_pdf® Illustrator®
- CScript:
- CExcelBook.getFontUnderline(sheet, column, row)¶
Get the underline state of the cell.
- Parameters:
- Returns:
The underline state.
One of Excel underline styles
- Return type:
- Raises:
TypeError – When parameter types are invalid
ValueError – When parameter row or column has invalid value
CometError – On internal error
- Available:
InDesign® comet_pdf® Illustrator®
- CScript:
- CExcelBook.getFontPosition(sheet, column, row)¶
Get the font position
- Parameters:
- Returns:
The font position state.
One of Excel font positions
- Return type:
- Raises:
TypeError – When parameter types are invalid
ValueError – When parameter row or column has invalid value
CometError – On internal error
- Available:
InDesign® comet_pdf® Illustrator®
- CScript:
- CExcelBook.getFontWeight(sheet, column, row)¶
Get whether font weight
- Parameters:
- Returns:
The font weight
- Return type:
- Raises:
TypeError – When parameter types are invalid
ValueError – When parameter row or column has invalid value
CometError – On internal error
- Available:
InDesign® comet_pdf® Illustrator®
- CScript:
- CExcelBook.getFontItalic(sheet, column, row)¶
Get whether the font is italic
- Parameters:
- Returns:
Whether the font is italic
- Return type:
- Raises:
TypeError – When parameter types are invalid
ValueError – When parameter row or column has invalid value
CometError – On internal error
- Available:
InDesign® comet_pdf® Illustrator®
- CScript:
- CExcelBook.getCellContent(sheet, column, row, format=None)¶
Get the content of a cell.
The cell contents are output without applying number formatting.
- Parameters:
sheet (str) –
Name of data sheet
Empty str : First data sheet
column (int) – 0-based column of the table
row (int) – 0-based row of the table
format (int) –
Output format to apply.
When this parameter is not
None
, the result is forced tostr
with formatting applied from the cell settings.- Valid values are:
constants.kExportPlain
Force result to
str
and do not apply formatting.
constants.kExportTagged
Force result to
str
and apply InDesign® TaggedText formatting.
constants.kExportHTML
Force result to
str
and apply HTML formatting.
Any other value will raise a ValueError
- Returns:
The fetched value from the Excel file. Type depends on the type of the cell.
See also
The result is
None
when the cell has never has any content.- Return type:
- Raises:
TypeError – When parameter types are invalid
ValueError – When parameter row, column or type have invalid values
CometError – On internal error
- Available:
InDesign® comet_pdf® Illustrator®
- CScript:
- CExcelBook.setCellContent(sheet, column, row, value)¶
Set the content of a cell.
- Parameters:
- Returns:
None
- Raises:
TypeError – When parameter types are invalid
ValueError – When parameter row or column or have invalid values
CometError – On internal error
- Available:
InDesign® comet_pdf® Illustrator®
- CScript:
- CExcelBook.save()¶
Save an Excel file.
- Returns:
None
- Raises:
CometError – On internal error
- Available:
InDesign® comet_pdf® Illustrator®
- CScript:
- CExcelBook.close()¶
Close an Excel file and remove the object from memory.
Any subsequent calls to this object will raise an exception!
- Returns:
None
- Raises:
CometError – On internal error
- Available:
InDesign® comet_pdf® Illustrator®
- CScript: