ContactCenters
V. 0.9.9.

umontreal.iro.lecuyer.util
Class ModifiableWorkbook

java.lang.Object
  extended by umontreal.iro.lecuyer.util.ModifiableWorkbook

public class ModifiableWorkbook
extends Object

Encapsulates a workbook from JExcel API that can be created from an already existing file, modified, and written back to the input file. JExcel API can be used to read workbooks compatible with Microsoft's Excel, or create workbooks from scratch. However, modifying already existing workbooks requires the original workbook to be read, changed in a temporary file, and copied back to the original location. This class takes care of these steps. After an instance is constructed using a file object, the method getWorkbook() can be used to get the currently opened workbook. The close() method closes the workbook.


Constructor Summary
ModifiableWorkbook(File outputFile)
          Constructs a new modifiable workbook from the Excel file referred to by outputFile.
ModifiableWorkbook(String outputFile)
          Similar to the constructor ModifiableWorkbook(File), with a string instead of a file object.
 
Method Summary
 void close()
          Closes the encapsulated workbook.
 void discardChanges()
          Discards all the changes made in the encapsulated workbook.
protected  void finalize()
          This method calls the close() method.
 File getOutputFile()
          Returns a reference to the file object representing the output file.
 WritableWorkbook getWorkbook()
          Returns a reference to the encapsulated workbook.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ModifiableWorkbook

public ModifiableWorkbook(File outputFile)
                   throws IOException,
                          jxl.read.biff.BiffException
Constructs a new modifiable workbook from the Excel file referred to by outputFile. If the given file does not exists, this method creates a new workbook. Otherwise, it reads the existing workbook, and creates a temporary file containing a new workbook starting with the existing one.

Parameters:
outputFile - the output file.
Throws:
IOException - if an error occurs when reading the output file.
jxl.read.biff.BiffException - if an error occurs while parsing an existing workbook.

ModifiableWorkbook

public ModifiableWorkbook(String outputFile)
                   throws IOException,
                          jxl.read.biff.BiffException
Similar to the constructor ModifiableWorkbook(File), with a string instead of a file object.

Throws:
IOException
jxl.read.biff.BiffException
Method Detail

getWorkbook

public WritableWorkbook getWorkbook()
Returns a reference to the encapsulated workbook.

Throws:
IllegalStateException - if this object is closed.

getOutputFile

public File getOutputFile()
Returns a reference to the file object representing the output file.

Throws:
IllegalStateException - if this object is closed.

close

public void close()
           throws WriteException,
                  IOException
Closes the encapsulated workbook. This method calls WritableWorkbook.write() followed by WritableWorkbook.close() on the encapsulated workbook returned by getWorkbook(). If the workbook was created from another one, the temporary file containing the written workbook is copied back to the output file returned by getOutputFile().

Throws:
WriteException - if an error occurs while formating the encapsulated workbook.
IOException - if an error occurs while writing the encapsulated workbook to disk.

discardChanges

public void discardChanges()
                    throws WriteException,
                           IOException
Discards all the changes made in the encapsulated workbook. This method closes the encapsulated workbook, and deletes the temporary files that contains it. If the workbook was created from an existing file, the existing file is unchanged.

Throws:
WriteException - if an error occurs while closing the workbook.
IOException - if an error occurs while closing the workbook.

finalize

protected void finalize()
                 throws Throwable
This method calls the close() method.

Overrides:
finalize in class Object
Throws:
Throwable

ContactCenters
V. 0.9.9.

To submit a bug or ask questions, send an e-mail to Richard Simard.