com.jniwrapper.win32.jexcel
Class Workbook

java.lang.Object
  extended by com.jniwrapper.win32.jexcel.Workbook
All Implemented Interfaces:
com.jniwrapper.AutoDeleteParameter, GenericWorkbook

public class Workbook
extends java.lang.Object
implements GenericWorkbook

This class provides functionality for working with an Excel workbook.


Constructor Summary
Workbook(com.jniwrapper.win32.excel._Workbook workbook, Application application)
           
 
Method Summary
 void activate()
          Activates the workbook.
 void addWorkbookEventListener(WorkbookEventListener eventListener)
          Adds the listener of workbook events.
 Worksheet addWorksheet(java.lang.String name)
          Adds a worksheet to the workbook.
 Worksheet addWorksheet(Worksheet after, java.lang.String name)
          Adds a worksheet to the workbook.
 void close(boolean saveChanges)
          Closes the workbook and optionally saves changes.
 void copyWorksheet(Worksheet worksheet, Worksheet before, Worksheet after)
          Copies worksheet content to other worksheet.
 boolean equals(java.lang.Object o)
           
 void exportAsFixedFormat(java.io.File file, FixedFormatType formatType)
          Exports the workbook to the PDF or XPS file that is specified by the file argument.
 Worksheet getActiveWorksheet()
          Returns the active worksheet.
 Application getApplication()
          Returns the application object.
 java.lang.String getAuthor()
          Returns the workbook author name.
 java.io.File getFile()
          Returns the workbook file.
 FileFormat getFileFormat()
          Returns the format of the workbook file.
 com.jniwrapper.win32.excel._Workbook getNativePeer()
          Returns the appropriate native peer.
 com.jniwrapper.win32.automation.OleMessageLoop getOleMessageLoop()
          Returns the message loop thread for processing native peer function calls.
 java.lang.String getTitle()
          Returns the currently set title of the workbook.
 Window getWindow()
          Returns the windows that corresponds to the workbook.
 java.lang.String getWorkbookName()
          Returns the name of the workbook.
 Worksheet getWorksheet(int index)
          Returns the worksheet that is specified by its index.
 Worksheet getWorksheet(java.lang.String name)
          Returns the worksheet that is specified by its name.
 int getWorksheetCount()
          Returns the number of worksheets in the workbook.
 java.util.List getWorksheets()
          Returns the list of worksheets of the workbook.
 boolean hasPassword()
          Returns true if the workbook has a password.
 boolean isAutoDelete()
           
 boolean isClosed()
          Checks if the workbook is closed.
 boolean isReadOnly()
          Checks if the workbook is read only.
 boolean isSaved()
          Checks if the workbook is saved (have not benn changed since the last save operation).
 void mergeWorkbook(java.io.File wbfile)
          Copies all worksheets from workbook file to current workbook
 void mergeWorkbook(GenericWorkbook source)
          Copies all worksheets from source workbook to current workbook
 void moveWorksheet(Worksheet worksheet, Worksheet after)
          Move worksheet content to another.
 void print(int copies)
          Prints the specified number of copies of the workbook.
 void print(int firstSheet, int lastSheet, int copies)
          Prints the specified range of worksheet.
 void release()
          Releases this wrapper object.
 void removeEventHandler()
          Removes the handler of workbook events.
 void removeWorkbookEventListener(WorkbookEventListener eventListener)
          Removes the specified listener of workbook events.
 void removeWorksheet(Worksheet worksheet)
          Removes worksheet
 void save()
          Saves changes in all worksheets of the workbook.
 void saveAs(java.io.File file, FileFormat fileFormat, boolean overwrite)
          Saves the workbook to the file that is specified by the file argument.
 void saveCopyAs(java.io.File file)
          Saves a copy of the workbook to another file.
 void setAuthor(java.lang.String author)
          Specifies the workbook author name.
 void setAutoDelete(boolean value)
           
 void setEventHandler(WorkbookEventHandler eventHandler)
          Specifies the handler of workbook events.
protected  void setOleMessageLoop(com.jniwrapper.win32.automation.OleMessageLoop oleMessageLoop)
           
 void setPassword(java.lang.String password)
          Sets up a new opening password of the workbook.
 void setSaved(boolean value)
          Force setting workbook "saved" status
 void setTitle(java.lang.String title)
          Sets up the title of the workbook.
 void setWritePassword(java.lang.String password)
          Sets up a new write protection password of the workbook.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.jniwrapper.win32.jexcel.GenericWorkbook
getApplication
 

Constructor Detail

Workbook

public Workbook(com.jniwrapper.win32.excel._Workbook workbook,
                Application application)
Method Detail

addWorksheet

public Worksheet addWorksheet(java.lang.String name)
                       throws ExcelException
Description copied from interface: GenericWorkbook
Adds a worksheet to the workbook.

Specified by:
addWorksheet in interface GenericWorkbook
Parameters:
name - is the name of a new worksheet.
Returns:
the newly added worksheet.
Throws:
ExcelException - if a worksheet with such name already exists in the workbook.

addWorksheet

public Worksheet addWorksheet(Worksheet after,
                              java.lang.String name)
                       throws ExcelException
Description copied from interface: GenericWorkbook
Adds a worksheet to the workbook. The worksheet will be added to the position after the specified worksheet.

Specified by:
addWorksheet in interface GenericWorkbook
Parameters:
after - the worksheet will be added to the position after this worksheet. If the value is null, the worksheet will be added at the beginning of the worksheet list.
name - is the name of a new worksheet.
Returns:
a newly added worksheet.
Throws:
ExcelException - if a worksheet with such name already exists in the workbook.

getWorksheet

public Worksheet getWorksheet(java.lang.String name)
Description copied from interface: GenericWorkbook
Returns the worksheet that is specified by its name. If the specified worksheet was not found, the return value is null.

Specified by:
getWorksheet in interface GenericWorkbook
Parameters:
name - is the name of the worksheet.
Returns:
the worksheet of interest or null if such worksheet is not present.

getWorksheets

public java.util.List getWorksheets()
Description copied from interface: GenericWorkbook
Returns the list of worksheets of the workbook. Each element of the list is an instance of Worksheet class.

Specified by:
getWorksheets in interface GenericWorkbook
Returns:
the list of worksheets.

getWorksheet

public Worksheet getWorksheet(int index)
Description copied from interface: GenericWorkbook
Returns the worksheet that is specified by its index.

Specified by:
getWorksheet in interface GenericWorkbook
Parameters:
index - is the index of the worksheet.
Returns:
the worksheet of interest.

getActiveWorksheet

public Worksheet getActiveWorksheet()
Description copied from interface: GenericWorkbook
Returns the active worksheet.

Specified by:
getActiveWorksheet in interface GenericWorkbook
Returns:
the active worksheet.

setEventHandler

public void setEventHandler(WorkbookEventHandler eventHandler)
Description copied from interface: GenericWorkbook
Specifies the handler of workbook events.

Specified by:
setEventHandler in interface GenericWorkbook

removeEventHandler

public void removeEventHandler()
Description copied from interface: GenericWorkbook
Removes the handler of workbook events.

Specified by:
removeEventHandler in interface GenericWorkbook

addWorkbookEventListener

public void addWorkbookEventListener(WorkbookEventListener eventListener)
Description copied from interface: GenericWorkbook
Adds the listener of workbook events.

Specified by:
addWorkbookEventListener in interface GenericWorkbook

removeWorkbookEventListener

public void removeWorkbookEventListener(WorkbookEventListener eventListener)
Description copied from interface: GenericWorkbook
Removes the specified listener of workbook events.

Specified by:
removeWorkbookEventListener in interface GenericWorkbook
Parameters:
eventListener - is the listener to be removed.

setTitle

public void setTitle(java.lang.String title)
Description copied from interface: GenericWorkbook
Sets up the title of the workbook.

Specified by:
setTitle in interface GenericWorkbook
Parameters:
title - is a new title of the workbook.

getTitle

public java.lang.String getTitle()
Description copied from interface: GenericWorkbook
Returns the currently set title of the workbook.

Specified by:
getTitle in interface GenericWorkbook
Returns:
the currently set title of the workbook.

getFile

public java.io.File getFile()
Description copied from interface: GenericWorkbook
Returns the workbook file.

Specified by:
getFile in interface GenericWorkbook
Returns:
the workbook file.

getFileFormat

public FileFormat getFileFormat()
Description copied from interface: GenericWorkbook
Returns the format of the workbook file.

Specified by:
getFileFormat in interface GenericWorkbook
Returns:
the format of the workbook file.

print

public void print(int copies)
           throws javax.print.PrintException
Description copied from interface: GenericWorkbook
Prints the specified number of copies of the workbook.

Specified by:
print in interface GenericWorkbook
Parameters:
copies - is the number of copies to be printed.
Throws:
javax.print.PrintException - if print problems occured.

print

public void print(int firstSheet,
                  int lastSheet,
                  int copies)
           throws javax.print.PrintException
Description copied from interface: GenericWorkbook
Prints the specified range of worksheet.

Specified by:
print in interface GenericWorkbook
Parameters:
firstSheet - is the index of the first worksheet to be printed.
lastSheet - is the index of the last worksheet to be printed.
copies - is the number of copies to be printed.
Throws:
javax.print.PrintException - if print problems occured.

getWorksheetCount

public int getWorksheetCount()
Description copied from interface: GenericWorkbook
Returns the number of worksheets in the workbook.

Specified by:
getWorksheetCount in interface GenericWorkbook
Returns:
the number of worksheets in the workbook.

setPassword

public void setPassword(java.lang.String password)
Description copied from interface: GenericWorkbook
Sets up a new opening password of the workbook.

Specified by:
setPassword in interface GenericWorkbook
Parameters:
password - is a new password to be set up.

hasPassword

public boolean hasPassword()
Description copied from interface: GenericWorkbook
Returns true if the workbook has a password.

Specified by:
hasPassword in interface GenericWorkbook
Returns:
true if the workbook has a password.

setWritePassword

public void setWritePassword(java.lang.String password)
Description copied from interface: GenericWorkbook
Sets up a new write protection password of the workbook.

Specified by:
setWritePassword in interface GenericWorkbook
Parameters:
password - is a new write protection password

getWorkbookName

public java.lang.String getWorkbookName()
Description copied from interface: GenericWorkbook
Returns the name of the workbook.

Specified by:
getWorkbookName in interface GenericWorkbook
Returns:
the name of the workbook.

isReadOnly

public boolean isReadOnly()
Description copied from interface: GenericWorkbook
Checks if the workbook is read only.

Specified by:
isReadOnly in interface GenericWorkbook
Returns:
true if the workbook is read only.

isSaved

public boolean isSaved()
Description copied from interface: GenericWorkbook
Checks if the workbook is saved (have not benn changed since the last save operation).

Specified by:
isSaved in interface GenericWorkbook
Returns:
true if the workbook is saved.

setSaved

public void setSaved(boolean value)
Force setting workbook "saved" status

Parameters:
value - - true to set saved and otherwise.

isClosed

public boolean isClosed()
Description copied from interface: GenericWorkbook
Checks if the workbook is closed.

Specified by:
isClosed in interface GenericWorkbook
Returns:
true if the workbook is closed.

close

public void close(boolean saveChanges)
Closes the workbook and optionally saves changes.

Parameters:
saveChanges - specifies whether to save changes on closing.
Throws:
java.lang.IllegalStateException - if the workbook is already closed.

save

public void save()
          throws java.io.IOException
Saves changes in all worksheets of the workbook.

Throws:
java.lang.IllegalStateException - if the workbook is closed.
java.io.IOException - if the workbook cannot be saved to the specified file.

exportAsFixedFormat

public void exportAsFixedFormat(java.io.File file,
                                FixedFormatType formatType)
Exports the workbook to the PDF or XPS file that is specified by the file argument.

Parameters:
file - specifies the file name.
formatType - specifies the file format type: XPS or PDF.
Throws:
java.lang.IllegalStateException - if the workbook is closed.
java.lang.RuntimeException - if the method is not supported by the current version of Excel.

saveAs

public void saveAs(java.io.File file,
                   FileFormat fileFormat,
                   boolean overwrite)
            throws java.io.IOException
Saves the workbook to the file that is specified by the file argument.

Parameters:
file - specifies the file name.
fileFormat - specifies the file format.
overwrite - if true then an existing file will be overwritten.
Throws:
java.lang.IllegalStateException - if the workbook is closed.
java.io.IOException - if the workbook cannot be saved to the specified file.
See Also:
FileFormat

saveCopyAs

public void saveCopyAs(java.io.File file)
                throws java.io.IOException
Description copied from interface: GenericWorkbook
Saves a copy of the workbook to another file.

Specified by:
saveCopyAs in interface GenericWorkbook
Parameters:
file - specifies the file name.
Throws:
java.io.IOException - if the workbook cannot be saved to the specified file.

activate

public void activate()
Description copied from interface: GenericWorkbook
Activates the workbook.

Specified by:
activate in interface GenericWorkbook

getWindow

public Window getWindow()
Description copied from interface: GenericWorkbook
Returns the windows that corresponds to the workbook.

Specified by:
getWindow in interface GenericWorkbook
Returns:
the windows that corresponds to the workbook.
See Also:
Window

getAuthor

public java.lang.String getAuthor()
Description copied from interface: GenericWorkbook
Returns the workbook author name.

Specified by:
getAuthor in interface GenericWorkbook
Returns:
the workbook author name.

setAuthor

public void setAuthor(java.lang.String author)
Description copied from interface: GenericWorkbook
Specifies the workbook author name.

Specified by:
setAuthor in interface GenericWorkbook
Parameters:
author - is the workbook author name.

removeWorksheet

public void removeWorksheet(Worksheet worksheet)
Removes worksheet

Specified by:
removeWorksheet in interface GenericWorkbook
Parameters:
worksheet - - target worksheet

moveWorksheet

public void moveWorksheet(Worksheet worksheet,
                          Worksheet after)
Move worksheet content to another. Source worksheet is removed after moving.

Specified by:
moveWorksheet in interface GenericWorkbook
Parameters:
worksheet - - source worksheet
after - - insert source worksheet after this instance

copyWorksheet

public void copyWorksheet(Worksheet worksheet,
                          Worksheet before,
                          Worksheet after)
Copies worksheet content to other worksheet.

Specified by:
copyWorksheet in interface GenericWorkbook
Parameters:
worksheet - - source Worksheet instance
after - - insert copy after this instance
before - - insert copy before this instance

mergeWorkbook

public void mergeWorkbook(GenericWorkbook source)
                   throws ExcelException
Copies all worksheets from source workbook to current workbook

Parameters:
source - - source workbook instance
Throws:
ExcelException - - handled Excel exception

mergeWorkbook

public void mergeWorkbook(java.io.File wbfile)
                   throws java.io.FileNotFoundException,
                          ExcelException
Copies all worksheets from workbook file to current workbook

Parameters:
wbfile - - source workbook file
Throws:
java.io.FileNotFoundException - - handled i/o exception
ExcelException - - handled Excel exception

getNativePeer

public com.jniwrapper.win32.excel._Workbook getNativePeer()
Returns the appropriate native peer.

Returns:
the appropriate native peer.

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

release

public void release()
Releases this wrapper object.


getApplication

public Application getApplication()
Returns the application object.

Returns:
the application.

getOleMessageLoop

public com.jniwrapper.win32.automation.OleMessageLoop getOleMessageLoop()
Returns the message loop thread for processing native peer function calls.

Returns:
the message loop thread for processing native peer function calls.

setOleMessageLoop

protected void setOleMessageLoop(com.jniwrapper.win32.automation.OleMessageLoop oleMessageLoop)

setAutoDelete

public void setAutoDelete(boolean value)
Specified by:
setAutoDelete in interface com.jniwrapper.AutoDeleteParameter

isAutoDelete

public boolean isAutoDelete()
Specified by:
isAutoDelete in interface com.jniwrapper.AutoDeleteParameter

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object