|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.extentech.ExtenXLS.DocumentHandle
com.extentech.ExtenXLS.WorkBookHandle
public class WorkBookHandle
The WorkBookHandle provides a handle to the XLS file and includes
convenience methods for working with the WorkSheets and Cell values within
the XLS file. For example:
WorkBookHandle book = new WorkBookHandle("testxls.xls");
WorkSheetHandle sheet = book.getWorkSheet("Sheet1");
CellHandle cell = sheet.getCell("B22");
In order to improve usability ExtenXLS will convert the internal Excel
'Mulblank' record type to the 'Blank' record type when parsing the file.
The Blank records are used by Excel when there are empty Cells which have
formatting information. The conversion allows setting of values on Blank
cells without adding or deleting values. You may wish to disable this
feature to improve performance. To do so, use the following:
System.getProperties().put(WorkBookHandle.CONVERTMULBLANKS, "false");
By default, ExtenXLS will lock open WorkBook files. To close the file after
parsing and work with a temporary file instead, use the following setting:
System.getProperties().put(WorkBookHandle.USETEMPFILE, "true");
If you enable this mode you will need to periodically clean up the generated
temporary files in your working directory. All ExtenXLS temporary file names
begin with "ExtenXLS_".
Due to issues on a number of application server platforms, ExtenXLS may be unable to find required resources automatically. These include the location of the license file and the default templates for new WorkBookHandles and WorkSheetHandles.
These issues are easily resolved by setting the system properties "com.extentech.ExtenXLS.licensekey" and "com.extentech.ExtenXLS.jarloc". These should contain the license key and the fully-qualified path to the ExtenXLS JAR, respectively.
If your environment provides a mechanism for setting Java system properties,
you may use it to set them. If not, you may set them programatically as in
the following example. Note that you will need to replace the example values
below with the ones appropriate to your environment.
String licensekey = "1255087426532DDD35268256220ABTRRW";
System.setProperty("com.extentech.extenxls.licensekey", licensekey);
String jarloc = "/opt/ExtenXLS/lib/ExtenXLS.jar";
System.setProperty("com.extentech.extenxls.jarloc", jarloc);
WorkBook,
WorkSheetHandle,
CellHandle| Field Summary | |
|---|---|
static String |
CONVERTMULBLANKS
|
| Fields inherited from interface com.extentech.ExtenXLS.WorkBook |
|---|
ALLOWDUPES, CALCULATE_ALWAYS, CALCULATE_AUTO, CALCULATE_EXPLICIT, DEBUG_HIGH, DEBUG_LOW, DEBUG_MEDIUM, SHAREDUPES, STRING_ENCODING_AUTO, STRING_ENCODING_COMPRESSED, STRING_ENCODING_UNICODE |
| Constructor Summary | |
|---|---|
WorkBookHandle()
Default constructor creates a new, empty Spreadsheet with 3 WorkSheets: "Sheet1","Sheet2",and "Sheet3". |
|
WorkBookHandle(byte[] barray)
Create a new WorkBookHandle from the byte array passed in. |
|
WorkBookHandle(File fx)
constructor which takes the XLS file |
|
WorkBookHandle(InputStream inx)
constructor which takes an InputStream containing the bytes of a valid XLS file. |
|
WorkBookHandle(com.extentech.toolkit.ProgressListener pn)
Constructor which takes a ProgressListener which monitors the progress of creating a new Excel file. |
|
WorkBookHandle(String filePath)
Constructor which takes the XLS file name( |
|
WorkBookHandle(String filePath,
int debug)
constructor which takes the XLS file name and has an optional debug setting to assist with output. |
|
WorkBookHandle(String fname,
com.extentech.toolkit.ProgressListener pn)
Constructor which takes the XLS file name and a ProgressListener which monitors the progress of reading the Excel file. |
|
WorkBookHandle(URL url)
Fetches a workbook from a URL If you need to authenticate your URL connection first then use the InputStream constructor |
|
| Method Summary | |
|---|---|
boolean |
addSheetFromWorkBook(WorkBookHandle sourceBook,
String sourceSheetName,
String destSheetName)
Deprecated. - use addWorkSheet(WorkSheetHandle sht, String NewSheetName){ |
boolean |
addSheetFromWorkBookWithFormatting(WorkBookHandle sourceBook,
String sourceSheetName,
String destSheetName)
Deprecated. - use addWorkSheet(WorkSheetHandle sht, String NewSheetName){ |
WorkSheetHandle |
addWorkSheet(WorkSheetHandle sourceSheet)
Inserts a WorkSheetHandle from a separate WorkBookhandle into the current WorkBookHandle. |
WorkSheetHandle |
addWorkSheet(WorkSheetHandle sourceSheet,
String NewSheetName)
Inserts a WorkSheetHandle from a separate WorkBookhandle into the current WorkBookHandle. |
void |
calculateFormulas()
Forces immediate recalculation of every formula in the workbook. |
void |
copyChartToSheet(ChartHandle chart,
WorkSheetHandle sheet)
Copies an existing Chart to another WorkSheet |
void |
copyChartToSheet(String chartname,
String sheetname)
Copies an existing Chart to another WorkSheet |
WorkSheetHandle |
copyWorkSheet(String SourceSheetName,
String NewSheetName)
Copy (duplicate) a worksheet in the workbook and add it to the end of the workbook with a new name |
ChartHandle |
createChart(String name,
WorkSheetHandle wsh)
Creates a new Chart and places it at the end of the workbook Under development and unsupported! |
NameHandle |
createNamedRange(String name,
String rangeDef)
Create a named range in the workbook Note that the named range designation can conform to excel specs, that is, boolean values, references, or string variables can be set. |
WorkSheetHandle |
createWorkSheet(String name)
Creates a new worksheet and places it at the end of the workbook. |
WorkSheetHandle |
createWorkSheet(String name,
int sheetpos)
Creates a new worksheet and places it at the specified position. |
void |
deleteChart(String chartname,
WorkSheetHandle wsh)
delete an existing chart of the workbook |
void |
forceRecalc()
Marks every formula in the workbook as dirty. |
String[] |
getAllStrings()
Returns all strings that are in the SharedStringTable for this workbook. |
byte[] |
getBytes()
Deprecated. |
CellHandle |
getCell(String address)
Returns the Cell at the specified Location |
CellRange[] |
getCellRanges()
Returns an Array of the CellRanges existing in this WorkBook specifically the Ranges referenced in Formulas, Charts, and Named Ranges. |
CellHandle[] |
getCells()
Returns an array containing all cells in the WorkBook |
ChartHandle |
getChart(String chartname)
Returns a Chart Handle |
ChartHandle |
getChartById(int id)
retrieve a ChartHandle via id |
ChartHandle[] |
getCharts()
Returns all Chart Handles contained in the WorkBook |
FormatHandle[] |
getConditionalFormats()
Returns an array of all Conditional Formats in the workbook these are formats referenced and used by the conditionally formatted ranges in the workbook. |
FormatHandle[] |
getFormats()
Returns an array of all FormatHandles in the workbook |
int |
getFormulaCalculationMode()
Get the calculation mode for the workbook. |
FormulaHandle |
getFormulaHandle(String celladdress)
Returns a Formula Handle |
ImageHandle |
getImage(String imagename)
Returns an ImageHandle for manipulating images in the WorkBook |
ImageHandle[] |
getImages()
Returns all ImageHandles in the workbook |
boolean |
getIsExcel2007()
Returns whether the underlying spreadsheet is in Excel 2007 format by default. |
String |
getName()
Returns the name of this WorkBook |
NameHandle |
getNamedRange(String rangename)
Returns a Named Range Handle |
NameHandle |
getNamedRangeInScope(String rangename)
Returns a Named Range Handle if it exists in the specified scope. |
NameHandle[] |
getNamedRanges()
Returns all Named Range Handles |
NameHandle[] |
getNamedRangesInScope()
Returns all Named Range Handles scoped to WorkBook. |
WorkBookHandle |
getNoSheetWorkBook()
Returns a WorkBookHandle containing an empty version of this WorkBook. |
int |
getNumCells()
Returns the number of Cells in this WorkBook |
int |
getNumWorkSheets()
Returns the number of Sheets in this WorkBook |
PivotTableHandle |
getPivotTable(String ptname)
get a handle to a PivotTable in the WorkBook |
PivotTableHandle[] |
getPivotTables()
get an array of handles to all PivotTables in the WorkBook |
String |
getStats()
Return useful statistics about this workbook. |
String |
getStats(boolean usehtml)
Return useful statistics about this workbook. |
com.extentech.formats.XLS.WorkBook |
getWorkBook()
Returns a low-level WorkBook. |
WorkSheetHandle |
getWorkSheet(int sheetnum)
returns the handle to a WorkSheet by number. |
WorkSheetHandle |
getWorkSheet(String handstr)
returns the handle to a WorkSheet by name. |
WorkSheetHandle[] |
getWorkSheets()
Returns an array of handles to all of the WorkSheets in the Workbook. |
String |
getXLSVersionString()
Returns the lowest version of Excel compatible with the input file. |
boolean |
is1904()
Returns whether this WorkBook is using the '1904' date system. |
void |
recalc()
Recalculates all dirty formulas in the workbook immediately. |
void |
removeAllWorkSheets()
Removes all of the WorkSheets from this WorkBook. |
int |
searchAndReplace(String searchfor,
String replacewith)
Searches all Cells in the workbook for the string occurrence and replaces with the replacement text. |
void |
setDefaultColWidth(int t)
set Default col width Note: only affects undefined Columns containing Cells |
void |
setDefaultRowHeight(int t)
set Default row height in twips (=1/20 of a point) Note: only affects undefined Rows containing Cells |
void |
setDupeStringMode(int mode)
Set Duplicate String Handling Mode. |
void |
setFormulaCalculationMode(int CalcMode)
Set the calculation mode for the workbook. |
void |
setProtected(boolean b)
set the workbook to protected mode Note: the password cannot be decrypted or changed in Excel -- protection can only be set/removed using ExtenXLS |
void |
setShowSheetTabs(boolean show)
Sets whether the sheet selection tabs should be shown. |
void |
setStringEncodingMode(int mode)
Set Encoding mode of new Strings added to file. |
boolean |
showSheetTabs()
Returns whether the sheet selection tabs should be shown. |
void |
write(OutputStream out)
Saves the WorkBookHandle to this opened OutputStream If original file is Excel2007 Format, the template will be written in Excel 2007 (XLSX) Format. |
void |
write(OutputStream out,
boolean Excel2007Format)
Saves the WorkBookHandle to this opened OutputStream if Excel2007Format, the template will be written in Excel 2007 (XLSX) Format. |
void |
write(String fname)
Saves this WorkBookHandle to filename and path fname if the filename ends with ".xlsx" or ".xlsm", the template will be written in Excel 2007 (XLSX) Format. |
void |
write(String fname,
boolean Excel2007Format)
saves this WorkBookHandle to filename and path fname if Excel2007 Format, the template will be written in Excel 2007 (XLSX) Format. |
StringBuffer |
writeBytes(OutputStream bout)
Write the Spreadsheet bytes to an OutputStream. |
void |
writeXLSXBytes(OutputStream bout)
Explicitly write the Spreadsheet bytes to an OutputStream in Excel 2007 (XLSX) format. |
| Methods inherited from class com.extentech.ExtenXLS.DocumentHandle |
|---|
addProperty, close, finalize, getFactory, getProperties, getProperty, getVersion, getWorkingDirectory, reset, setDebugLevel, setName, setProperties, toString |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Methods inherited from interface com.extentech.ExtenXLS.WorkBook |
|---|
addProperty, getProperty, getWorkingDirectory, reset, setDebugLevel, setName, toString |
| Field Detail |
|---|
public static String CONVERTMULBLANKS
| Constructor Detail |
|---|
public WorkBookHandle()
public WorkBookHandle(InputStream inx)
InputStream - contains the valid BIFF8 bytes for readingpublic WorkBookHandle(byte[] barray)
byte[] - byte array containing the valid XLS or XLSX file for readingpublic WorkBookHandle(URL url)
urlx -
Exceptionpublic WorkBookHandle(String filePath)
String - filePath the name of the XLS file to read
public WorkBookHandle(String filePath,
int debug)
String - filePath the name of the XLS file to readDebug - levelpublic WorkBookHandle(File fx)
File - the XLS file to readDebug - levelpublic WorkBookHandle(com.extentech.toolkit.ProgressListener pn)
ProgressListener - object which is monitoring progress of WorkBook read
public WorkBookHandle(String fname,
com.extentech.toolkit.ProgressListener pn)
String - fname the name of the XLS file to readProgressListener - object which is monitoring progress of WorkBook read| Method Detail |
|---|
public int searchAndReplace(String searchfor,
String replacewith)
public String[] getAllStrings()
public boolean is1904()
public String getXLSVersionString()
public String getStats(boolean usehtml)
use - html line breaks
public String getStats()
public CellHandle getCell(String address)
throws com.extentech.formats.XLS.CellNotFoundException,
com.extentech.formats.XLS.WorkSheetNotFoundException
getCell in interface WorkBookaddress -
com.extentech.formats.XLS.CellNotFoundException
com.extentech.formats.XLS.WorkSheetNotFoundExceptionpublic CellRange[] getCellRanges()
public PivotTableHandle getPivotTable(String ptname)
throws com.extentech.formats.XLS.PivotTableNotFoundException
getPivotTable in interface WorkBookString - name of the PivotTable
com.extentech.formats.XLS.PivotTableNotFoundException
public PivotTableHandle[] getPivotTables()
throws com.extentech.formats.XLS.PivotTableNotFoundException
getPivotTables in interface WorkBookcom.extentech.formats.XLS.PivotTableNotFoundExceptionpublic void setFormulaCalculationMode(int CalcMode)
setFormulaCalculationMode in interface WorkBookCalcMode - Calculation mode to use in workbook.public int getFormulaCalculationMode()
getFormulaCalculationMode in interface WorkBookCalcMode - Calculation mode to use in workbook.public void setProtected(boolean b)
setProtected in interface DocumentsetProtected in interface WorkBookboolean - whether to protect the bookpublic void setDefaultRowHeight(int t)
setDefaultRowHeight in interface WorkBookint - Default Row Heightpublic void setDefaultColWidth(int t)
setDefaultColWidth in interface WorkBookint - Default Column width
public FormulaHandle getFormulaHandle(String celladdress)
throws com.extentech.formats.XLS.FormulaNotFoundException
com.extentech.formats.XLS.FormulaNotFoundExceptionpublic ImageHandle[] getImages()
public ImageHandle getImage(String imagename)
throws com.extentech.formats.XLS.ImageNotFoundException
imagename -
com.extentech.formats.XLS.ImageNotFoundException
public NameHandle getNamedRange(String rangename)
throws com.extentech.formats.XLS.CellNotFoundException
getNamedRange in interface WorkBookcom.extentech.formats.XLS.CellNotFoundException
public NameHandle getNamedRangeInScope(String rangename)
throws com.extentech.formats.XLS.CellNotFoundException
com.extentech.formats.XLS.CellNotFoundException
public NameHandle createNamedRange(String name,
String rangeDef)
name - The name that should be used to reference this named rangerangeDef - Range of the cells for this named range, in excel syntax including sheet name, ie "Sheet1!A1:D1"
public ChartHandle getChart(String chartname)
throws com.extentech.formats.XLS.ChartNotFoundException
getChart in interface DocumentgetChart in interface WorkBookcom.extentech.formats.XLS.ChartNotFoundExceptionpublic ChartHandle[] getCharts()
getCharts in interface DocumentgetCharts in interface WorkBook
public ChartHandle getChartById(int id)
throws com.extentech.formats.XLS.ChartNotFoundException
id -
com.extentech.formats.XLS.ChartNotFoundExceptionpublic NameHandle[] getNamedRanges()
getNamedRanges in interface WorkBookpublic NameHandle[] getNamedRangesInScope()
public String getName()
getName in interface DocumentgetName in interface WorkBookgetName in class DocumentHandlepublic CellHandle[] getCells()
getCells in interface WorkBookpublic int getNumCells()
getNumCells in interface WorkBookpublic boolean showSheetTabs()
public void setShowSheetTabs(boolean show)
public byte[] getBytes()
getBytes in interface DocumentgetBytes in interface WorkBookgetBytes in class DocumentHandleWorkBook.getBytes()public void write(String fname)
write in class DocumentHandlefname -
public void write(String fname,
boolean Excel2007Format)
write in class DocumentHandlefname - Excel2007Format -
public void write(OutputStream out,
boolean Excel2007Format)
out - Excel2007Format - public void write(OutputStream out)
write in class DocumentHandleout -
public void writeXLSXBytes(OutputStream bout)
throws Exception
FileOutputStream fileOutputStream = new FileOutputStream(fn);
BufferedOutputStream bout = new BufferedOutputStream(fileOutputStream);
bk.writeXLSXBytes(bout);
bout.flush();
bout.close();
bout -
Exceptionpublic boolean getIsExcel2007()
public StringBuffer writeBytes(OutputStream bout)
FileOutputStream fileOutputStream = new FileOutputStream(fn);
BufferedOutputStream bout = new BufferedOutputStream(fileOutputStream);
bk.writeBytes(bout);
bout.flush();
bout.close();
to output a debugging stringbuffer, you must first set the
autolockdown setting:
props.put("com.extentech.ExtenXLS.autocreatelockdown","true");
writeBytes in interface DocumentwriteBytes in interface WorkBookbout -
public WorkSheetHandle[] getWorkSheets()
getWorkSheets in interface WorkBook
public WorkSheetHandle getWorkSheet(int sheetnum)
throws com.extentech.formats.XLS.WorkSheetNotFoundException
getWorkSheet in interface WorkBookindex - of worksheet (ie: 0)
com.extentech.formats.XLS.WorkSheetNotFoundException - if the specified WorkSheet is
not found in the WorkBook.
public WorkSheetHandle getWorkSheet(String handstr)
throws com.extentech.formats.XLS.WorkSheetNotFoundException
getWorkSheet in interface WorkBookString - name of worksheet (ie: "Sheet1")
com.extentech.formats.XLS.WorkSheetNotFoundException - if the specified WorkSheet is
not found in the WorkBook.public com.extentech.formats.XLS.WorkBook getWorkBook()
getWorkBook in interface WorkBookpublic void setStringEncodingMode(int mode)
setStringEncodingMode in interface DocumentsetStringEncodingMode in interface WorkBookint - String Encoding Modepublic void setDupeStringMode(int mode)
setDupeStringMode in interface DocumentsetDupeStringMode in interface WorkBookint - Duplicate String Handling Mode
public void copyChartToSheet(String chartname,
String sheetname)
throws com.extentech.formats.XLS.ChartNotFoundException,
com.extentech.formats.XLS.WorkSheetNotFoundException
copyChartToSheet in interface WorkBookchartname - sheetname -
com.extentech.formats.XLS.ChartNotFoundException
com.extentech.formats.XLS.WorkSheetNotFoundException
public void copyChartToSheet(ChartHandle chart,
WorkSheetHandle sheet)
throws com.extentech.formats.XLS.ChartNotFoundException,
com.extentech.formats.XLS.WorkSheetNotFoundException
copyChartToSheet in interface WorkBookchart - sheet -
com.extentech.formats.XLS.ChartNotFoundException
com.extentech.formats.XLS.WorkSheetNotFoundException
public WorkSheetHandle copyWorkSheet(String SourceSheetName,
String NewSheetName)
throws com.extentech.formats.XLS.WorkSheetNotFoundException
copyWorkSheet in interface WorkBookString - the Name of the source worksheet;String - the Name of the new (destination) worksheet;
com.extentech.formats.XLS.WorkSheetNotFoundExceptionpublic void calculateFormulas()
calculateFormulas in interface WorkBookcom.extentech.formats.XLS.FunctionNotSupportedException - if an unsupported function is
used by any formula in the workbookforceRecalc(),
recalc()public void forceRecalc()
recalc()public void recalc()
You generally need not call this method. Dirty formulas will automatically be recalculated when their values are queried. This method is only useful for forcing calculation to occur at a certain time. In the case of functions such as NOW() whose value is volatile the formula will still be recalculated every time it is queried.
com.extentech.formats.XLS.FunctionNotSupportedException - if an unsupported function is
used by any formula in the workbookforceRecalc()public void removeAllWorkSheets()
removeAllWorkSheets in interface WorkBookpublic WorkBookHandle getNoSheetWorkBook()
getNoSheetWorkBook in interface WorkBookaddSheetFromWorkBook
public boolean addSheetFromWorkBook(WorkBookHandle sourceBook,
String sourceSheetName,
String destSheetName)
addSheetFromWorkBook in interface WorkBooksourceBook - - the WorkBook containing the sheet to copysourceSheetName - - the name of the sheet to copydestSheetName - - the name of the new sheet in this workbook
public boolean addSheetFromWorkBookWithFormatting(WorkBookHandle sourceBook,
String sourceSheetName,
String destSheetName)
sourceBook - - the WorkBook containing the sheet to copysourceSheetName - - the name of the sheet to copydestSheetName - - the name of the new sheet in this workbookpublic WorkSheetHandle addWorkSheet(WorkSheetHandle sourceSheet)
WorkSheetHandle - the source WorkSheetHandle;
public WorkSheetHandle addWorkSheet(WorkSheetHandle sourceSheet,
String NewSheetName)
addWorkSheet in interface WorkBookWorkSheetHandle - the source WorkSheetHandle;String - the Name of the new (destination) worksheet;
public ChartHandle createChart(String name,
WorkSheetHandle wsh)
String - the Name of the newly created Chart
public void deleteChart(String chartname,
WorkSheetHandle wsh)
throws com.extentech.formats.XLS.ChartNotFoundException
chartname -
com.extentech.formats.XLS.ChartNotFoundExceptionpublic int getNumWorkSheets()
public WorkSheetHandle createWorkSheet(String name,
int sheetpos)
name - the name of the newly created worksheetsheetpos - the index at which the sheet should be inserted
public WorkSheetHandle createWorkSheet(String name)
createWorkSheet in interface WorkBookname - the name of the newly created worksheet
public FormatHandle[] getFormats()
getFormats in interface DocumentgetFormats in interface WorkBookpublic FormatHandle[] getConditionalFormats()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||