Home  Products  Purchase  Downloads  Demos  Forums  Blogs  Ticket  Wiki  API  Corporate


com.aspose.cells
Class Worksheets

java.lang.Object
  extended by com.aspose.cells.Worksheets

public class Worksheets
extends java.lang.Object

Encapsulates a collection of Worksheet objects.


Method Summary
 int addCopy(int sheetIndex)
          Adds a worksheet to the collection and copys data from an existed worksheet.
 int addCopy(java.lang.String sheetName)
          Adds a worksheet to the collection and copys data from an existed worksheet.
 Worksheet addSheet()
          Adds a new worksheet in this workbook.
 Worksheet addSheet(int type)
          Adds a new worksheet in this workbook.
 Worksheet addSheet(int type, java.lang.String sheetName)
          Adds a new worksheet in this workbook with the specified sheet name.
 Worksheet addSheet(java.lang.String sheetName)
          Adds a new worksheet in this workbook with the specified sheet name.
 void calculateFormula(int startIndex, int endIndex, boolean recursive, boolean ignoreError)
          Calculates formulas in some worksheets.
 Worksheet getActiveSheet()
          Gets the active sheet.
 int getActiveSheetIndex()
          Gets the active sheet index.
 BuiltInDocumentProperties getBuiltInDocumentProperties()
          Returns a DocumentProperties collection that represents all the built-in document properties of the spreadsheet.
 CustomDocumentProperties getCustomDocumentProperties()
          Returns a DocumentProperties collection that represents all the custom document properties of the spreadsheet.
 Name getName(java.lang.String name)
          Gets Name object by pre-defined name.
 Name getName(java.lang.String name, boolean strictScope)
          Gets Name object by pre-defined name.
 NamedRange[] getNamedRanges()
          Gets all pre-defined named ranges in the spreadsheet.
 Name[] getNames()
          Gets all pre-defined named ranges in the spreadsheet.
 int getNumberOfSheets()
          Deprecated. Replaced by size().
 NamedRange getRangeByName(java.lang.String rangeName)
          Gets NamedRange object by pre-defined name.
 NamedRange getRangeByName(java.lang.String rangeName, boolean strictScope)
          Gets NamedRange object by pre-defined name.
 Worksheet getSheet(int index)
          Returns the sheet at the specified index.
 Worksheet getSheet(java.lang.String name)
          Gets the sheet with the specified name.
 int getSheetIndex(java.lang.String name)
          Gets the sheet's index according to its name.
 java.lang.String getSheetName(int index)
          Returns the name of the sheet at the specified index.
 Name insertName(java.lang.String text, java.lang.String refersTo)
          Defines a new name.
 void moveSheet(int origin, int dest)
          Moves a worksheet.
 boolean removeName(java.lang.String text)
          Deletes given Name.
 void removeSheet(int index)
          Removes the sheet at the specified index.
 boolean removeSheet(java.lang.String sheetName)
          Removes the specified sheet from the workbook.
 boolean removeSheet(Worksheet sheet)
          Removes the specified worksheet.
 void setActiveSheet(int sheetIndex)
          Sets the active sheet index.
 void setActiveSheet(Worksheet sheet)
          Sets the active sheet.
 int size()
          Gets the number of sheets in the workbook.
 void sortNames()
          Sorts defined names.
 void swapSheet(int idx1, int idx2)
          Swaps the positions of two sheets.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

addSheet

public Worksheet addSheet()
Adds a new worksheet in this workbook. The sheet name is assigned automatically.

Returns:
the added worksheet.

addSheet

public Worksheet addSheet(int type)
Adds a new worksheet in this workbook. The sheet name is assigned automatically.

Parameters:
type - Worksheet type.It could be one of the following values:
SheetType.WORKSHEET
SheetType.CHART
Returns:
the added worksheet.
Throws:
java.lang.IllegalArgumentException - if sheet type is not Worksheet or Chart.

addSheet

public Worksheet addSheet(java.lang.String sheetName)
Adds a new worksheet in this workbook with the specified sheet name.

Parameters:
sheetName - name of the worksheet.
Returns:
the added worksheet.

addSheet

public Worksheet addSheet(int type,
                          java.lang.String sheetName)
Adds a new worksheet in this workbook with the specified sheet name.

Parameters:
sheetName - name of the worksheet.
type - Worksheet type.
Returns:
the added worksheet.
Throws:
java.lang.IllegalArgumentException - if sheet type is not Worksheet or Chart.
See Also:
addSheet(int)

getNumberOfSheets

@Deprecated
public int getNumberOfSheets()
Deprecated. Replaced by size().

Gets the number of sheets in the workbook.

Returns:
number of sheets.

size

public int size()
Gets the number of sheets in the workbook.

Returns:
number of sheets.

getSheet

public Worksheet getSheet(int index)
Returns the sheet at the specified index.

Parameters:
index - index of the sheet.
Returns:
the sheet at the specified index.
Throws:
java.lang.IllegalArgumentException - if the index is out of range.

getSheet

public Worksheet getSheet(java.lang.String name)
Gets the sheet with the specified name.

Parameters:
name - name of the sheet.
Returns:
the sheet that has the specified name. Returns null if the sheet name is invalid.

getSheetName

public java.lang.String getSheetName(int index)
Returns the name of the sheet at the specified index.

Parameters:
index - index of the sheet.
Returns:
sheet name.
Throws:
java.lang.IllegalArgumentException - if the index is out of range.

swapSheet

public void swapSheet(int idx1,
                      int idx2)
Swaps the positions of two sheets.

Parameters:
idx1 - index of the first sheet
idx2 - index of the second sheet
Throws:
java.lang.IllegalArgumentException - if any of the positions is out of range.

moveSheet

public void moveSheet(int origin,
                      int dest)
Moves a worksheet.

Parameters:
origin - the original index of the sheet.
dest - the new index of the sheet.
Throws:
java.lang.IllegalArgumentException - if any of the indexes is out of range.

removeSheet

public void removeSheet(int index)
Removes the sheet at the specified index. Once a sheet is removed, operations on it may cause an CellsException.

Parameters:
index - index of the sheet.
Throws:
java.lang.IllegalArgumentException - if index is out of range.

removeSheet

public boolean removeSheet(Worksheet sheet)
Removes the specified worksheet. Once a sheet is removed, operations on it may cause an CellsException.

Parameters:
sheet - the sheet to remove.
Returns:
true if the sheet exists and is removed successfully.

removeSheet

public boolean removeSheet(java.lang.String sheetName)
Removes the specified sheet from the workbook. Once a sheet is removed, operations on it may cause an CellsException.

Parameters:
sheetName - name of the sheet to remove
Returns:
true if the sheet exists and is removed successfully.

getActiveSheetIndex

public int getActiveSheetIndex()
Gets the active sheet index.

Returns:
the active sheet index.

getActiveSheet

public Worksheet getActiveSheet()
Gets the active sheet.

Returns:
the active sheet.

setActiveSheet

public void setActiveSheet(int sheetIndex)
Sets the active sheet index. If you are using an evaluation license, the active is always the license sheet.

Parameters:
sheetIndex - the active sheet index.
Throws:
java.lang.IllegalArgumentException - if the sheet index is out of range.

setActiveSheet

public void setActiveSheet(Worksheet sheet)
Sets the active sheet. If you are using an evaluation license, the active is always the license sheet.

Parameters:
sheet - the active sheet.
Throws:
CellsException - if the sheet is not in this worksheets.

getSheetIndex

public int getSheetIndex(java.lang.String name)
Gets the sheet's index according to its name.

Parameters:
name - name of the sheet.
Returns:
index of the sheet. Returns -1 if the sheet name is invalid.

addCopy

public int addCopy(int sheetIndex)
Adds a worksheet to the collection and copys data from an existed worksheet.

Parameters:
sheetIndex - Index of source worksheet.
Returns:
Worksheet object index.

addCopy

public int addCopy(java.lang.String sheetName)
Adds a worksheet to the collection and copys data from an existed worksheet.

Parameters:
sheetName - name of source worksheet.
Returns:
Worksheet object index.

getRangeByName

public NamedRange getRangeByName(java.lang.String rangeName)
Gets NamedRange object by pre-defined name. It is identical to invoking getRangeByName(rangeName, true).

Parameters:
rangeName - range name, can be plain name such as "name1" which means the Name's scope is workbook, or with specific sheet reference such as "Sheet1!name1" which means the Name's scope is sheet.
Returns:
NamedRange object. Returns null if the named range does not exist, or the NamedRange's scope is a sheet but not specify it in rangeName.
See Also:
getRangeByName(String, boolean)

getRangeByName

public NamedRange getRangeByName(java.lang.String rangeName,
                                 boolean strictScope)
Gets NamedRange object by pre-defined name.

Parameters:
rangeName - range name, can be plain name such as "name1" which means the Name's scope is workbook, or with specific sheet reference such as "Sheet1!name1" which means the Name's scope is sheet.
strictScope - whether restrict the searched Name's scope. If true, will only get the one whose scope is workbook or specified sheet given in rangeName; If false, will search the NamedRange object ignore its scope.
Returns:
NamedRange object.Returns null if the named range does not exist.

getName

public Name getName(java.lang.String name)
Gets Name object by pre-defined name. It is identical to invoking getName(name, true).

Parameters:
name - name of Name object, can be plain name such as "name1" which means the Name's scope is workbook, or with specific sheet reference such as "Sheet1!name1" which means the Name's scope is sheet.
Returns:
Name object. Returns null if the name does not exist, or the Name object's scope is a sheet but not specify it in name.
See Also:
getName(String, boolean)

getName

public Name getName(java.lang.String name,
                    boolean strictScope)
Gets Name object by pre-defined name.

Parameters:
name - name of Name object, can be plain name such as "name1" which means the Name's scope is workbook, or with specific sheet reference such as "Sheet1!name1" which means the Name's scope is sheet.
strictScope - whether restrict the searched Name's scope. If true, will only get the one whose scope is workbook or specified sheet given in name; If false, will search the Name object ignore its scope.
Returns:
Name object. Returns null if the named range does not exist.

getNamedRanges

public NamedRange[] getNamedRanges()
Gets all pre-defined named ranges in the spreadsheet.

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

getNames

public Name[] getNames()
Gets all pre-defined named ranges in the spreadsheet.

Returns:
An array of Name objects, including NamedRange and Name object. Returns null if the named range does not exist.

sortNames

public void sortNames()
Sorts 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


insertName

public Name insertName(java.lang.String text,
                       java.lang.String refersTo)
                throws java.io.UnsupportedEncodingException
Defines a new name.

Parameters:
text - the name text of the user-defined name.
refersTo - the formula that the name is defined to refer to, beginning with an equal sign.
Returns:
Name object index.
Throws:
java.lang.IllegalArgumentException - if refersTo is null or formulas in the refersTo are unspported.
java.io.UnsupportedEncodingException - if text contains unsupported encoding.

removeName

public boolean removeName(java.lang.String text)
Deletes given Name.

Parameters:
text - the name text of user-defined name.
Returns:
true if the given name exists. If there is no any other reference to given Name, the Name will be removed from collection. Otherwise will set the Name as Hidden and does not remove it from collection.

getBuiltInDocumentProperties

public BuiltInDocumentProperties getBuiltInDocumentProperties()
Returns a DocumentProperties collection that represents all the built-in document properties of the spreadsheet.

Returns:
a DocumentProperties collection.

getCustomDocumentProperties

public CustomDocumentProperties getCustomDocumentProperties()
Returns a DocumentProperties collection that represents all the custom document properties of the spreadsheet.

Returns:
a DocumentProperties collection.

calculateFormula

public void calculateFormula(int startIndex,
                             int endIndex,
                             boolean recursive,
                             boolean ignoreError)
                      throws FormulaCalcException
Calculates formulas in some worksheets.

Parameters:
startIndex - start worksheet index.
endIndex - end worksheet index.
recursive - True if these worksheets' cells depend on the cells of other worksheets, the dependant cells in other worksheets will be calculated too. False means all the formulas in the worksheet have been calculated and the values are right.
ignoreError - Indicates if hide the error in calculating formulas. The error may be unsupported function, external links, etc.
Throws:
FormulaCalcException - if an error occurs and not hide the error.
java.lang.IllegalArgumentException - if the startIndex or endIndex is out of range.