WorksheetCollection

WorksheetCollection class

Encapsulates a collection of Worksheet objects.

Properties

NameTypeDescription
WebExtensionTaskPanesWebExtensionTaskPaneCollectionGets the list of task panes.
WebExtensionsWebExtensionCollectionGets the list of task panes.
ThreadedCommentAuthorsThreadedCommentAuthorCollectionGets the list of threaded comment authors.
IsRefreshAllConnectionsbooleanIndicates whether refresh all connections on opening file in MS Excel.
NamesNameCollectionGets the collection of all the Name objects in the spreadsheet.
ActiveSheetNameStringRepresents the name of active worksheet when the spreadsheet is opened.
ActiveSheetIndexintRepresents the index of active worksheet when the spreadsheet is opened. Sheet index is zero based.
DxfsDxfCollectionGets the master differential formatting records.
XmlMapsXmlMapCollectionGets and sets the XML maps in the workbook.
BuiltInDocumentPropertiesBuiltInDocumentPropertyCollectionReturns a DocumentProperty collection that represents all the built-in document properties of the spreadsheet. A new pro
CustomDocumentPropertiesCustomDocumentPropertyCollectionReturns a DocumentProperty collection that represents all the custom document properties of the spreadsheet.
OleSizeObjectGets and Sets displayed size when Workbook file is used as an Ole object. Null means no ole size setting.
ExternalLinksExternalLinkCollectionRepresents external links in a workbook.
PivotCachesPivotCacheCollection
TableStylesTableStyleCollectionGets TableStyles object.
RevisionLogsRevisionLogCollectionRepresents revision logs.
SensitivityLabelsSensitivityLabelCollection
Countint
Item (int)WorksheetGets the Worksheet element at the specified index.
Item (java.lang.String)WorksheetGets the Worksheet element with the specified name.

Methods

NameDescription
setOleSizeSets displayed size when Workbook file is used as an Ole object.

This method is generally used to adjust display size i | | clearPivottables | Clears pivot tables from the spreadsheet. | | refreshAll | Refresh all pivot tables and charts with pivot source. | | refreshPivotTables | Refreshes all the PivotTables in the Excel file. | | createRange | Creates a Range object from an address of the range. | | createUnionRange | Creates a Range object from an address of the range. | | getSheetByCodeName | Gets the worksheet by the code name. | | sortNames | Sorts the defined names.

If you create a large amount of named ranges in the Excel file, please call this method after | | insert | Insert a worksheet. | | add | Adds a worksheet to the collection. | | swapSheet | Swaps the two sheets. | | registerAddInFunction | Adds addin function into the workbook | | removeAt | Removes the element at a specified name. | | clear | Clear all worksheets.

A workbook must contains a worksheet. | | addCopy | Adds a worksheet to the collection and copies data from an existed worksheet. | | getRangeByName | Gets Range object by pre-defined name. | | getNamedRanges | Gets all pre-defined named ranges in the spreadsheet. | | getNamedRangesAndTables | Gets all pre-defined named ranges in the spreadsheet. | | iterator | | | get | Reserved for internal use. | | contains | Reserved for internal use. | | indexOf | Reserved for internal use. |

WorksheetCollection.WebExtensionTaskPanes property

Gets the list of task panes.

Type: WebExtensionTaskPaneCollection

WorksheetCollection.WebExtensions property

Gets the list of task panes.

Type: WebExtensionCollection

WorksheetCollection.ThreadedCommentAuthors property

Gets the list of threaded comment authors.

Type: ThreadedCommentAuthorCollection

WorksheetCollection.IsRefreshAllConnections property

Indicates whether refresh all connections on opening file in MS Excel.

Type: boolean

WorksheetCollection.Names property

Gets the collection of all the Name objects in the spreadsheet.

Type: NameCollection

WorksheetCollection.ActiveSheetName property

Represents the name of active worksheet when the spreadsheet is opened.

Type: String

WorksheetCollection.ActiveSheetIndex property

Represents the index of active worksheet when the spreadsheet is opened. Sheet index is zero based.

Type: int

WorksheetCollection.Dxfs property

Gets the master differential formatting records.

Type: DxfCollection

WorksheetCollection.XmlMaps property

Gets and sets the XML maps in the workbook.

Type: XmlMapCollection

WorksheetCollection.BuiltInDocumentProperties property

Returns a DocumentProperty collection that represents all the built-in document properties of the spreadsheet. A new property cannot be added to built-in document properties list. You can only get a built-in property and change its value. The following is the built-in properties name list: Title Subject Author Keywords Comments Template Last Author Revision Number Application Name Last Print Date Creation Date Last Save Time Total Editing Time Number of Pages Number of Words Number of Characters Security Category Format Manager Company Number of Bytes Number of Lines Number of Paragraphs Number of Slides Number of Notes Number of Hidden Slides Number of Multimedia Clips

Type: BuiltInDocumentPropertyCollection

WorksheetCollection.CustomDocumentProperties property

Returns a DocumentProperty collection that represents all the custom document properties of the spreadsheet.

Type: CustomDocumentPropertyCollection

WorksheetCollection.OleSize property

Gets and Sets displayed size when Workbook file is used as an Ole object. Null means no ole size setting.

Type: Object

Represents external links in a workbook.

Type: ExternalLinkCollection

WorksheetCollection.PivotCaches property

Type: PivotCacheCollection

WorksheetCollection.TableStyles property

Gets TableStyles object.

Type: TableStyleCollection

WorksheetCollection.RevisionLogs property

Represents revision logs.

Type: RevisionLogCollection

WorksheetCollection.SensitivityLabels property

Type: SensitivityLabelCollection

WorksheetCollection.Count property

Type: int

WorksheetCollection.Item (int) property

Gets the Worksheet element at the specified index.

Type: Worksheet

WorksheetCollection.Item (java.lang.String) property

Gets the Worksheet element with the specified name.

Type: Worksheet

setOleSize(startRow, endRow, startColumn, endColumn)

Sets displayed size when Workbook file is used as an Ole object.

This method is generally used to adjust display size in ppt file or doc file.

ParameterTypeDescription
startRowintStart row index.
endRowintEnd row index.
startColumnintStart column index.
endColumnintEnd column index.

clearPivottables()

Clears pivot tables from the spreadsheet.

refreshAll()

Refresh all pivot tables and charts with pivot source.

refreshPivotTables() (1 of 2)

Refreshes all the PivotTables in the Excel file.


refreshPivotTables(option) (2 of 2)

Refreshes all the PivotTables in the Excel file.

ParameterTypeDescription
optionPivotTableRefreshOptionThe option for refreshing data source of the pivot tables.

createRange(address, sheetIndex)

Creates a Range object from an address of the range.

ParameterTypeDescription
addressStringThe address of the range.
sheetIndexintThe sheet index.

Returns: A Range object

createUnionRange(address, sheetIndex)

Creates a Range object from an address of the range.

ParameterTypeDescription
addressStringThe address of the range.
sheetIndexintThe sheet index.

Returns: A Range object

getSheetByCodeName(codeName)

Gets the worksheet by the code name.

ParameterTypeDescription
codeNameStringWorksheet code name.

Returns: The element with the specified code name.

sortNames()

Sorts the defined names.

If you create a large amount of named ranges in the Excel file, please call this method after all named ranges are created and before saving

insert(index, sheetType) (1 of 2)

Insert a worksheet.

ParameterTypeDescription
indexintThe sheet index
sheetTypeintA SheetType value. The sheet type.

Returns: Returns an inserted worksheet.


insert(index, sheetType, sheetName) (2 of 2)

Insert a worksheet.

ParameterTypeDescription
indexintThe sheet index
sheetTypeintA SheetType value. The sheet type.
sheetNameStringThe sheet name.

Returns: Returns an inserted worksheet.

add(type) (1 of 4)

Adds a worksheet to the collection.

ParameterTypeDescription
typeintA SheetType value. Worksheet type.

Returns: Worksheet object index.

Example:

workbook = Workbook()
workbook.getWorksheets().add(SheetType.CHART)
cells = workbook.getWorksheets().get(0).getCells()
cells.get("c2").putValue(5000)
cells.get("c3").putValue(3000)
cells.get("c4").putValue(4000)
cells.get("c5").putValue(5000)
cells.get("c6").putValue(6000)
charts = workbook.getWorksheets().get(1).getCharts()
chartIndex = charts.add(ChartType.COLUMN, 10, 10, 20, 20)
chart = charts.get(chartIndex)
chart.getNSeries().add("Sheet1!C2:C6", True)
workbook.save("Book1.xlsx")

add() (2 of 4)

Adds a worksheet to the collection.

Returns: Worksheet object index.


add(sheetName) (3 of 4)

Adds a worksheet to the collection.

ParameterTypeDescription
sheetNameStringWorksheet name

Returns: Worksheet object.


add(value) (4 of 4)

Reserved for internal use.

swapSheet(sheetIndex1, sheetIndex2)

Swaps the two sheets.

ParameterTypeDescription
sheetIndex1intThe first worksheet.
sheetIndex2intThe second worksheet.

registerAddInFunction(addInFile, functionName, lib) (1 of 2)

Adds addin function into the workbook

ParameterTypeDescription
addInFileStringthe file contains the addin functions
functionNameStringthe addin function name
libbooleanwhether the given addin file is in the directory or sub-directory of Workbook Add-In library. This flag takes effect and makes difference when given addInFile is of relative path: true denotes the path is relative to Add-In library and false denotes the path is relative to this Workbook.

Returns: ID of the data which contains given addin function


registerAddInFunction(id, functionName) (2 of 2)

Adds addin function into the workbook

ParameterTypeDescription
idintID of the data which contains addin functions, can be got by the first call of registerAddInFunction(java.lang.String, java.lang.String, boolean) for the same addin file.
functionNameStringthe addin function name

Returns: URL of the addin file which contains addin functions

removeAt(name) (1 of 2)

Removes the element at a specified name.

ParameterTypeDescription
nameStringThe name of the element to remove.

removeAt(index) (2 of 2)

Removes the element at a specified index.

ParameterTypeDescription
indexintThe index value of the element to remove.

clear()

Clear all worksheets.

A workbook must contains a worksheet.

addCopy(sheetName) (1 of 3)

Adds a worksheet to the collection and copies data from an existed worksheet.

ParameterTypeDescription
sheetNameStringName of source worksheet.

Returns: Worksheet object index.


addCopy(sheetIndex) (2 of 3)

Adds a worksheet to the collection and copies data from an existed worksheet.

ParameterTypeDescription
sheetIndexintIndex of source worksheet.

Returns: Worksheet object index.


addCopy(source, destSheetNames) (3 of 3)

Copy a group of worksheets.

ParameterTypeDescription
sourceWorksheet[]The source worksheets.
destSheetNamesString[]The names of the copied sheets.

getRangeByName(rangeName) (1 of 2)

Gets Range object by pre-defined name.

ParameterTypeDescription
rangeNameStringName of range.

Returns: Range object. Returns null if the named range does not exist.


getRangeByName(rangeName, currentSheetIndex, includeTable) (2 of 2)

Gets Range by pre-defined name or table’s name

ParameterTypeDescription
rangeNameStringName of range or table’s name.
currentSheetIndexintThe sheet index. -1 represents global .
includeTablebooleanIndicates whether checking all tables.

getNamedRanges()

Gets all pre-defined named ranges in the spreadsheet.

Returns: An array of Range objects. If the defined Name’s reference is external or has multiple ranges, no Range object will be returned for this Name. Returns null if the named range does not exist.

getNamedRangesAndTables()

Gets all pre-defined named ranges in the spreadsheet.

Returns: An array of Range objects. Returns null if the named range does not exist.

iterator()

get(index)

Reserved for internal use.

contains(value)

Reserved for internal use.

indexOf(value)

Reserved for internal use.