|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.softartisans.excelwriter.ExcelTemplate
The ExcelTemplate object represents a template* spreadsheet, that is, a file created in Microsoft Excel that contains data markers. A data marker specifies a database column, variable, or array to insert in the spreadsheet column containing the marker.
In the ExcelWriter documentation, the term "template" refers to an ExcelWriter template, not a Microsoft Excel template (.xlt). However, ExcelWriter can open and generate both .xls and .xlt files. Use an .xlt file the same way you would an .xls file. To create an instance of the ExcelTemplate object:
Note: The ExcelTemplate object supports Excel's BIFF8 (Excel 97/2000/XP) format only; ExcelTemplate does not support BIFF7 (Excel 95) format templates, and will not generate BIFF7 format files.
(The ExcelApplication object can produce either Excel 97/2000/XP (BIFF8) format files or Excel 95 (BIFF7) format files.)
| Field Summary | |
static int |
ALL_ROWS
The maximum number of rows that can be inserted into a spreadsheet. |
| Constructor Summary | |
ExcelTemplate()
Creates a new ExcelTemplate object. |
|
| Method Summary | |
java.lang.String |
getContentType()
Returns the current setting for the ContentType header sent to a web browser. |
java.lang.String |
getDecryptPassword()
Returns the current value of the DecryptPassword. |
java.lang.String |
getEncryptPassword()
Returns the current value of the EncryptPassword. |
boolean |
getExcludeMacros()
Return the current setting of ExcludeMacros. |
java.lang.String |
getLicenseKey()
Returns the license key used for this instance of ExcelWriter. |
boolean |
getPreserveStrings()
Returns the current setting of PreserveStrings. |
boolean |
getRemoveExtraDataMarkers()
Returns the current value of the RemoveExtraDataMarkers flag. |
int |
getSpreadsheetsCreatedToday()
Returns the number of spreadsheets created in the last 24 hours. |
static java.lang.String |
getVersion()
Returns the exact version of the ExcelWriter product. |
void |
open(java.io.InputStream stream)
Opens an ExcelWriter template spreadsheet from an InputStream. |
void |
open(java.lang.String fileName)
Opens an ExcelWriter template spreadsheet, that is, a file created in Microsoft Excel that contains data markers where values will be inserted. |
void |
process()
Enters datasource values into a new spreadsheet, based on the data marker values in the template. |
void |
save(javax.servlet.http.HttpServletResponse response)
Returns output spreadsheet to the browser. |
void |
save(javax.servlet.http.HttpServletResponse response,
java.lang.String fileNameToSend,
boolean bOpenInBrowser)
Returns output spreadsheet to the browser. |
void |
save(java.io.OutputStream stream)
Returns the processed spreadsheet to a specified output stream. |
void |
save(java.lang.String fileName)
Writes the processed spreadsheet to a specified output file, by path name. |
void |
setCellDataSource(java.lang.Object cellData,
java.lang.String dataMarkerName)
Set an Object as a data source to bind to a single cell in the template. |
void |
setColumnDataSource(java.lang.Object[] columnData,
java.lang.String dataMarkerName)
Set an array of Objects as a data source to bind to a single column in the template. |
void |
setColumnDataSource(java.lang.Object[] columnData,
java.lang.String dataMarkerName,
int maxRows)
Set an array of Objects as a data source to bind to a single column in the template. |
void |
setContentType(java.lang.String contentType)
Sets the value of the ContentType header sent to a web browser through the save(HttpServletResponse) method. |
void |
setDataSource(java.lang.Object[][] arrayData,
java.lang.String[] columnNames,
java.lang.String dataMarkerName)
Set a two-dimensional array of Objects as a data source to bind to datamarkers in the template. |
void |
setDataSource(java.lang.Object[][] arrayData,
java.lang.String[] columnNames,
java.lang.String dataMarkerName,
int maxRows,
boolean transposeToRowCol)
Set a two-dimensional array of Objects as a data source to bind to datamarkers in the template. |
void |
setDataSource(java.sql.ResultSet source,
java.lang.String dataMarkerName)
Set a ResultSet as a data source to bind to template data markers. |
void |
setDataSource(java.sql.ResultSet source,
java.lang.String dataMarkerName,
int maxRows)
Set a ResultSet as a data source to bind to template data markers. |
void |
setDecryptPassword(java.lang.String password)
Sets the DecryptPassword. |
void |
setEncryptPassword(java.lang.String password)
Sets the EncryptPassword. |
void |
setExcludeMacros(boolean bExcludeMacros)
Sets whether ExcelWriter should remove macros from the resulting template or leave them in. |
void |
setLicenseKey(java.lang.String licenseKey)
Instructs ExcelTemplate to use a particular license key for the duration of this instance, rather than obtaining one programatically from the License.jar file in the classpath. |
void |
setPreserveStrings(boolean bPreserveStrings)
Determines whether data inserted into a template is kept as a string or if an attempt to convert to an Excel data type is made. |
void |
setRemoveExtraDataMarkers(boolean bRemoveDataMarkers)
Sets whether ExcelWriter should ignore and remove data markers in the template which don't bind to data sources. |
void |
setRowDataSource(java.lang.Object[] rowData,
java.lang.String[] columnNames,
java.lang.String dataMarkerName)
Set an array of Objects as a data source to bind to a row in the template. |
java.lang.String |
toString()
Returns a string representation of the ExcelTemplate object, which gives a summary of the values currently used in the object. |
| Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
public static final int ALL_ROWS
| Constructor Detail |
public ExcelTemplate()
| Method Detail |
public java.lang.String toString()
Object.toString()
public java.lang.String getLicenseKey()
throws java.lang.Exception
java.lang.Exception - if a valid license key cannot be found in the classpath.
public void setLicenseKey(java.lang.String licenseKey)
throws java.lang.Exception
licenseKey - the license key to use for the duration of this instance.
java.lang.Exception - if the license key is invalid for any reason.public int getSpreadsheetsCreatedToday()
public static java.lang.String getVersion()
SoftArtisans.ProductName Edition Major.Minor.Patch.Build (mmddyyyy-hhmmss-buildMachineId)where:
public void setPreserveStrings(boolean bPreserveStrings)
bPreserveStrings - If true, ExcelWriter will insert all data into the template as strings.
If false, ExcelWriter attempts to convert the data to Excel types
(numbers, dates, etc).public boolean getPreserveStrings()
public void setRemoveExtraDataMarkers(boolean bRemoveDataMarkers)
bRemoveDataMarkers - if set to true,
ExcelWriter skips extra data markers, does not render them.public boolean getRemoveExtraDataMarkers()
public void setExcludeMacros(boolean bExcludeMacros)
bExcludeMacros - if set to true, macros in the template will be
excluded from the generated spreadsheet.public boolean getExcludeMacros()
public java.lang.String getContentType()
public void setContentType(java.lang.String contentType)
contentType - The value to send for the ContentType header.
public void setDataSource(java.sql.ResultSet source,
java.lang.String dataMarkerName)
throws java.lang.Exception
source - The ResultSet to use as the data source.dataMarkerName - The data source name specified by the
data marker, for example, "Orders" corresponds
to the data marker "%%=Orders.OrderID".
The string passed must begin with a letter.
Passing null or the empty string ("") is allowed
for the first setDataSource call only; that
DataSource will be the implicit data source and can
be referred to as "%%=#1.java.lang.Exception - on error.
public void setDataSource(java.sql.ResultSet source,
java.lang.String dataMarkerName,
int maxRows)
throws java.lang.Exception
source - The ResultSet to use as the data source.dataMarkerName - The data source name specified by the
data marker, for example, "Orders" corresponds
to the data marker "%%=Orders.OrderID".
The string passed must begin with a letter.
Passing null or the empty string ("") is allowed
for the first setDataSource call only; that
DataSource will be the implicit data source and can
be referred to as "%%=#1.maxRows - The maximum number of rows to insert for
this data source, per template row. To use the
maximum rows available, use the constant ExcelTemplate.ALL_ROWS.
java.lang.Exception - on error.
public void setCellDataSource(java.lang.Object cellData,
java.lang.String dataMarkerName)
throws java.lang.Exception
cellData - An object to insert as data into the spreadsheet. If it is
a primitive type wrapper, such as Integer, ExcelWriter will
attempt to convert it into an Excel type. Otherwise,
ExcelWriter will call the toString() method on the object.dataMarkerName - The data source name specified by the
data marker, for example, "Orders" corresponds
to the data marker "%%=Orders.OrderID".
The string passed must begin with a letter.
Passing null or the empty string ("") is allowed
for the first setDataSource call only; that
DataSource will be the implicit data source and can
be referred to as "%%=#1.java.lang.Exception - on error.
public void setColumnDataSource(java.lang.Object[] columnData,
java.lang.String dataMarkerName)
throws java.lang.Exception
columnData - An array of objects to insert as data into the spreadsheet.
If each Object is a primitive type wrapper, such as Integer,
ExcelWriter will attempt to convert it into an Excel type. Otherwise,
ExcelWriter will call the toString() method on the object.dataMarkerName - The data source name specified by the
data marker, for example, "Orders" corresponds
to the data marker "%%=Orders.OrderID".
The string passed must begin with a letter.
Passing null or the empty string ("") is allowed
for the first setDataSource call only; that
DataSource will be the implicit data source and can
be referred to as "%%=#1.java.lang.Exception - on error.
public void setColumnDataSource(java.lang.Object[] columnData,
java.lang.String dataMarkerName,
int maxRows)
throws java.lang.Exception
columnData - An array of objects to insert as data into the spreadsheet.
If each Object is a primitive type wrapper, such as Integer,
ExcelWriter will attempt to convert it into an Excel type. Otherwise,
ExcelWriter will call the toString() method on the object.dataMarkerName - The data source name specified by the
data marker, for example, "Orders" corresponds
to the data marker "%%=Orders.OrderID".
The string passed must begin with a letter.
Passing null or the empty string ("") is allowed
for the first setDataSource call only; that
DataSource will be the implicit data source and can
be referred to as "%%=#1.maxRows - The maximum number of rows to insert for
this data source, per template row. To use the
maximum rows available, use the constant ExcelTemplate.ALL_ROWS.
java.lang.Exception - on error.
public void setRowDataSource(java.lang.Object[] rowData,
java.lang.String[] columnNames,
java.lang.String dataMarkerName)
throws java.lang.Exception
rowData - An array of objects to insert as data into the spreadsheet.
If each Object is a primitive type wrapper, such as Integer,
ExcelWriter will attempt to convert it into an Excel type. Otherwise,
ExcelWriter will call the toString() method on the object.columnNames - An array of strings which gives a unique identification to each
element in rowData. It must be the same length as rowData.
If this parameter is null, binding can only be performed by ordinal.dataMarkerName - The data source name specified by the
data marker, for example, "Orders" corresponds
to the data marker "%%=Orders.OrderID".
The string passed must begin with a letter.
Passing null or the empty string ("") is allowed
for the first setDataSource call only; that
DataSource will be the implicit data source and can
be referred to as "%%=#1.java.lang.Exception - on error.
public void setDataSource(java.lang.Object[][] arrayData,
java.lang.String[] columnNames,
java.lang.String dataMarkerName)
throws java.lang.Exception
| A | X |
| B | Y |
| C | Z |
arrayData - A 2D array of objects to insert as data into the spreadsheet, in the
form [Column][Row].
If each Object is a primitive type wrapper, such as Integer,
ExcelWriter will attempt to convert it into an Excel type. Otherwise,
ExcelWriter will call the toString() method on the object.columnNames - An array of strings which gives a unique identification to each
element in rowData. It must be the same length as rowData.
If this parameter is null, binding can only be performed by ordinal.dataMarkerName - The data source name specified by the
data marker, for example, "Orders" corresponds
to the data marker "%%=Orders.OrderID".
The string passed must begin with a letter.
Passing null or the empty string ("") is allowed
for the first setDataSource call only; that
DataSource will be the implicit data source and can
be referred to as "%%=#1.java.lang.Exception - on error.
public void setDataSource(java.lang.Object[][] arrayData,
java.lang.String[] columnNames,
java.lang.String dataMarkerName,
int maxRows,
boolean transposeToRowCol)
throws java.lang.Exception
| A | X |
| B | Y |
| C | Z |
| A | B | C |
| X | Y | Z |
arrayData - A 2D array of objects to insert as data into the spreadsheet, in the
form [Column][Row].
If each Object is a primitive type wrapper, such as Integer,
ExcelWriter will attempt to convert it into an Excel type. Otherwise,
ExcelWriter will call the toString() method on the object.columnNames - An array of strings which gives a unique identification to each
element in rowData. It must be the same length as rowData.
If this parameter is null, binding can only be performed by ordinal.dataMarkerName - The data source name specified by the
data marker, for example, "Orders" corresponds
to the data marker "%%=Orders.OrderID".
The string passed must begin with a letter.
Passing null or the empty string ("") is allowed
for the first setDataSource call only; that
DataSource will be the implicit data source and can
be referred to as "%%=#1.maxRows - The maximum number of rows to insert for
this data source, per template row. To use the
maximum rows available, use the constant ExcelTemplate.ALL_ROWS.transposeToRowCol - If true, interprets the array as [row][column] rather than [column][row].
java.lang.Exception - on error.
public void open(java.lang.String fileName)
throws java.io.IOException
Note: The ExcelTemplate object supports Excel's BIFF8 (Excel 97/2000/XP) format only. ExcelTemplate does not support BIFF7 (Excel 95) templates, and will not generate BIFF7 format files.
Note: ... actually, the file is not opened here. This method just checks that the file name looks reasonable, and then remembers the file name. The actual file-open is done in the "process" method, so that the process method can be sure to close the file handles at the end of process(), even if there is an error during processing. For this reason, certain file errors may be detected later, during the "process()" method.
fileName - The file name of the template .xls file to open.
java.io.IOException - if there is a problem accessing the file.
public void open(java.io.InputStream stream)
throws java.io.IOException
Note: if the stream object does not support the mark/reset methods, you will not be able to call process() multiple times for a single template open() call.
stream - An InputStream of the template .xls file to read.
java.io.IOException - if there is a problem opening the accessing
the input stream or a problem with the template in the stream.
public void process()
throws java.lang.Exception
java.lang.Exception - if there is a problem processing the data into
the template or writing to the stream.
public void save(javax.servlet.http.HttpServletResponse response)
throws java.io.IOException,
java.lang.Exception
response - the response object of this page.
For a servlet or JSP page, this is the variable "response".
java.lang.Exception - If a problem arises in the template object, the HttpServletResponse object, or in the processed spreadsheet.
java.io.IOException - If an exception occured while writing to the output stream.
public void save(javax.servlet.http.HttpServletResponse response,
java.lang.String fileNameToSend,
boolean bOpenInBrowser)
throws java.lang.Exception,
java.io.IOException
response - the response object of this page.
For a servlet or JSP page, this is the variable "response".fileNameToSend - the name of the file to show in the browser.
If an invalid name, empty string, or
null is specified, the default name of "generated.xls" will
be sent.bOpenInBrowser - If true, the Content-Disposition header is
set to open the file in the browser (IE only).
If false, the browser is sent as an attachment and the user is
prompted to save the file.
Browsers which cannot embed
Excel (i.e., browsers other than Microsoft Internet
Explorer) will always open or save the file outside the
browser.
java.lang.Exception - If a problem arises in the template object, the HttpServletResponse object, or in the processed spreadsheet.
java.io.IOException - If an exception occured while writing to the output stream.
public void save(java.io.OutputStream stream)
throws java.lang.Exception,
java.io.IOException
stream - the output stream to write a copy of the currently
processed spreadsheet to.
java.lang.Exception - If a problem arises in the template object or in the processed spreadsheet.
java.io.IOException - If an exception occured while writing to the output stream.
public void save(java.lang.String fileName)
throws java.io.IOException,
java.lang.Exception
fileName - The name of a file to write the currently processed
spreadsheet to. Any current contents of the file will be overwritten.
java.lang.Exception - If a problem arises while processing template, data sources, or file.
java.io.IOException
public void setEncryptPassword(java.lang.String password)
throws java.lang.Exception
password - The password used to encrypt the spreadsheet.
java.lang.Exception - An Exception will be thrown if the password is longer than 15 characters.public java.lang.String getEncryptPassword()
public void setDecryptPassword(java.lang.String password)
throws java.lang.Exception
password - The password used to decrypt the spreadsheet.
java.lang.Exception - An Exception will be thrown if the password is longer than 15 characters.public java.lang.String getDecryptPassword()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||