public class HtmlToExcel
extends java.lang.Object
implements java.io.Serializable
Modifier and Type | Class and Description |
---|---|
protected class |
HtmlToExcel.XmlBody
Inner class that defines a body node in the XML document and handles
translation of the XML body to an Excel spreadsheet sheet.
|
protected class |
HtmlToExcel.XmlCell
Inner class that defines a table cell node in the XML document and handles
translation of the XML table cell to an Excel spreadsheet cell.
|
protected class |
HtmlToExcel.XmlTable
Inner class that defines a table node in the XML document and handles
translation of the XML table to an Excel spreadsheet table.
|
Modifier and Type | Field and Description |
---|---|
protected java.text.DecimalFormat[] |
ivNumParsers
The parsers for number values.
|
protected Spreadsheet |
ivSpreadsheet
The Excel spreadsheet object.
|
protected org.w3c.dom.Document |
ivXmlDoc
The XML document object.
|
private static long |
serialVersionUID
The class' serialization version id.
|
Constructor and Description |
---|
HtmlToExcel()
Constructs a new HTML-to-Excel translator.
|
Modifier and Type | Method and Description |
---|---|
java.io.ByteArrayOutputStream |
getExcelStream(java.lang.String html)
Performs HTML-to-Excel translation and returns the results.
|
java.io.ByteArrayOutputStream |
getExcelStream(java.lang.String template,
org.apache.velocity.VelocityContext data)
Performs HTML-to-Excel translation and returns the results.
|
protected void |
recurseXml(org.w3c.dom.NodeList children)
Recurses the XML document and creates the Excel spreadsheet's content.
|
protected java.io.ByteArrayOutputStream |
translate(java.io.ByteArrayOutputStream xml)
Performs XML-to-Excel translation and returns the results.
|
void |
writeToResponse(java.io.ByteArrayOutputStream xls,
java.lang.String filename,
javax.servlet.http.HttpServletResponse response)
Writes an Excel spreadsheet to a servlet's outgoing response as a file
download with an assumed file extension of ".xlsx".
|
private static final long serialVersionUID
protected Spreadsheet ivSpreadsheet
protected org.w3c.dom.Document ivXmlDoc
protected java.text.DecimalFormat[] ivNumParsers
public java.io.ByteArrayOutputStream getExcelStream(java.lang.String html) throws java.lang.Exception
html
- (String) The HTML to process.java.lang.Exception
- - if an error occurs during translation.public java.io.ByteArrayOutputStream getExcelStream(java.lang.String template, org.apache.velocity.VelocityContext data) throws java.lang.Exception
template
- (String) The name of the HTML template file to process.data
- (VelocityContext) The data to use for substitutions or
null
if no data is to be substituted.java.lang.Exception
- - if an error occurs during translation.protected java.io.ByteArrayOutputStream translate(java.io.ByteArrayOutputStream xml) throws java.lang.Exception
xml
- (ByteArrayOutputStream) The XML to process.java.lang.Exception
- - if an error occurs during translation.protected void recurseXml(org.w3c.dom.NodeList children) throws java.lang.Exception
children
- (NodeList) The first-level child nodes of the XML
document's root.java.lang.Exception
- - if an error occurs during processing.public void writeToResponse(java.io.ByteArrayOutputStream xls, java.lang.String filename, javax.servlet.http.HttpServletResponse response) throws java.lang.Exception
xls
- (ByteArrayOutputStream) The Excel spreadsheet to write.filename
- (String) The initial name to give to the download file
sans file extension.response
- (HttpServletResponse) The servlet response to write to.java.lang.Exception
- - if an error occurs during the writing.