Home  Products  Purchase  Downloads  Demos  Forums  Blogs  Ticket  Wiki  API  Corporate

com.aspose.cells
Class Workbook

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

public class Workbook
extends java.lang.Object

Represents an Excel workbook.


Constructor Summary
Workbook()
          Constructs a workbook object using default settings.
 
Method Summary
 Worksheet createSheet()
          Creates a new worksheet in this workbook.
 Worksheet createSheet(java.lang.String sheetName)
          Creates a new worksheet in this workbook with the specified sheet name.
 Style createStyle()
          Creates a new style.
 Worksheet getActiveSheet()
          Gets the active sheet.
 int getActiveSheetIndex()
          Gets the active sheet index.
 int getCalculationMode()
          Returns the calculation mode.
 Style getDefaultStyle()
          Gets the default style of the workbook.
 Style getNamedStyle(java.lang.String styleName)
          Gets a style by it's name.
 Style[] getNamedStyles()
          Gets all named styles within the workbook.
 int getNumerOfSheets()
          Gets the number of sheets in the workbook.
 Palette getPalette()
          Gets the palette of the workbook.
 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.
 int insertName(java.lang.String text, java.lang.String refersTo)
          Defines a new name.
 boolean isCalculateBeforeSave()
          Whether workbooks are calculated before they're saved to disk (if the Calculation Mode is set to MANUAL).
 boolean isHorizontalScrollBarHidden()
          Checks if the horizontal scroll bar is hidden.
 boolean isSheetTabBarHidden()
          Checks if the sheet tab bar is hidden.
 boolean isVerticalScrollBarHidden()
          Checks if the vertical scroll bar is hidden.
 void moveSheet(int origin, int dest)
          Moves a worksheet.
 void read(java.io.InputStream stream)
          Reads an Excel file from the given stream.
 void read(java.lang.String fileName)
          Reads an Excel file from disk.
 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 setCalculateBeforeSave(boolean calculateBeforeSave)
          Sets whether workbooks are calculated before they're saved to disk.
 void setCalculationMode(int calculationMode)
          Sets the calculation mode.
 void setHorizontalScrollBarHidden(boolean isHidden)
          Sets the horizontal scroll bar to be hidden or not.
 void setSheetTabBarHidden(boolean isHidden)
          Sets the sheet tab bar to be hidden or not.
 void setVerticalScrollBarHidden(boolean isHidden)
          Sets the vertical scroll bar to be hidden or not.
 void swapSheet(int idx1, int idx2)
          Swaps the positions of two sheets.
 void write(java.io.OutputStream stream)
          Writes out the workbook to the given stream.
 void write(java.io.OutputStream stream, int fileFormatType)
          Writes out the workbook to the given stream.
 void write(java.lang.String fileName)
          Writes out the workbook to a file.
 void write(java.lang.String fileName, int fileFormatType)
          Writes out the workbook to a file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Workbook

public Workbook()
Constructs a workbook object using default settings. The workbook will only have one sheet with the name "Sheet1".

Method Detail

read

public void read(java.io.InputStream stream)
          throws java.io.IOException
Reads an Excel file from the given stream.

Parameters:
stream - the stream to read from.
Throws:
java.io.IOException - if an I/O error occurs.

read

public void read(java.lang.String fileName)
          throws java.io.IOException
Reads an Excel file from disk.

Parameters:
fileName - the system-dependent file name.
Throws:
java.io.IOException - if an error occurs.

write

public void write(java.io.OutputStream stream)
           throws java.io.IOException
Writes out the workbook to the given stream.

Parameters:
stream - the stream to write to.
Throws:
java.io.IOException - if an I/O error occurs.

write

public void write(java.io.OutputStream stream,
                  int fileFormatType)
           throws java.io.IOException
Writes out the workbook to the given stream.

Parameters:
stream - the stream to write to.
fileFormatType - one of the FileFormatType values whcih specifies the file format.
Throws:
java.io.IOException - if an I/O error occurs.

write

public void write(java.lang.String fileName)
           throws java.io.IOException
Writes out the workbook to a file.

Parameters:
fileName - the system-dependent file name.
Throws:
java.io.IOException - if an I/O error occurs.

write

public void write(java.lang.String fileName,
                  int fileFormatType)
           throws java.io.IOException
Writes out the workbook to a file.

Parameters:
fileName - the system-dependent file name.
fileFormatType - one of the FileFormatType values whcih specifies the file format.
Throws:
java.io.IOException - if an I/O error occurs.
See Also:
FileFormatType

getNumerOfSheets

public int getNumerOfSheets()
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.

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.

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.

createSheet

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

Returns:
the created worksheet.

createSheet

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

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

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 ExcelException.

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 ExcelException.

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 ExcelException.

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

getDefaultStyle

public Style getDefaultStyle()
Gets the default style of the workbook.

Returns:
the default style of the workbook.

createStyle

public Style createStyle()
Creates a new style.

Returns:
the new style.

getNamedStyle

public Style getNamedStyle(java.lang.String styleName)
Gets a style by it's name.

Parameters:
styleName - name of the style.
Returns:
the style. Returns null if the style name is invalid.

getNamedStyles

public Style[] getNamedStyles()
Gets all named styles within the workbook.

Returns:
an array of named styles.

isHorizontalScrollBarHidden

public boolean isHorizontalScrollBarHidden()
Checks if the horizontal scroll bar is hidden.

Returns:
true if the horizontal scroll bar is hidden.

isVerticalScrollBarHidden

public boolean isVerticalScrollBarHidden()
Checks if the vertical scroll bar is hidden.

Returns:
true if the vertical scroll bar is hidden.

isSheetTabBarHidden

public boolean isSheetTabBarHidden()
Checks if the sheet tab bar is hidden.

Returns:
true if the sheet tab bar is hidden.

setHorizontalScrollBarHidden

public void setHorizontalScrollBarHidden(boolean isHidden)
Sets the horizontal scroll bar to be hidden or not.

Parameters:
isHidden - true for hidden; false otherwise.

setVerticalScrollBarHidden

public void setVerticalScrollBarHidden(boolean isHidden)
Sets the vertical scroll bar to be hidden or not.

Parameters:
isHidden - true for hidden; false otherwise.

setSheetTabBarHidden

public void setSheetTabBarHidden(boolean isHidden)
Sets the sheet tab bar to be hidden or not.

Parameters:
isHidden - true for hidden; false otherwise.

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.

getPalette

public Palette getPalette()
Gets the palette of the workbook. NOTE: Using a color that is not contained in the palette will not take effect. If you want to use a custom color in this workbook, please change the palette first.

Returns:
the palette of the workbook.

isCalculateBeforeSave

public boolean isCalculateBeforeSave()
Whether workbooks are calculated before they're saved to disk (if the Calculation Mode is set to MANUAL). This property is preserved even if you change the Calculation Mode.

Returns:
whether workbooks are calculated before they're saved to disk.

setCalculateBeforeSave

public void setCalculateBeforeSave(boolean calculateBeforeSave)
Sets whether workbooks are calculated before they're saved to disk.

Parameters:
calculateBeforeSave - whether workbooks are calculated before they're saved to disk.

getCalculationMode

public int getCalculationMode()
Returns the calculation mode.

Returns:
the calculation mode.
See Also:
setCalculationMode(int)

setCalculationMode

public void setCalculationMode(int calculationMode)
Sets the calculation mode.

Parameters:
calculationMode - calculation mode.It could be one of the following values:
CalculationMode.AUTOMATIC
CalculationMode.SEMIAUTOMATIC
CalculationMode.MANUAL
Throws:
java.lang.IllegalArgumentException - if calculation mode is invalid.

insertName

public int 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.