Package org.apache.poi.hssf.converter
Class ExcelToHtmlConverter
- java.lang.Object
-
- org.apache.poi.hssf.converter.AbstractExcelConverter
-
- org.apache.poi.hssf.converter.ExcelToHtmlConverter
-
@Beta public class ExcelToHtmlConverter extends AbstractExcelConverter
Converts xls files (97-2007) to HTML file.
-
-
Field Summary
-
Fields inherited from class org.apache.poi.hssf.converter.AbstractExcelConverter
_formatter
-
-
Constructor Summary
Constructors Constructor Description ExcelToHtmlConverter(HtmlDocumentFacade htmlDocumentFacade)ExcelToHtmlConverter(Document doc)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected StringbuildStyle(HSSFWorkbook workbook, HSSFCellStyle cellStyle)StringgetCssClassPrefixCell()StringgetCssClassPrefixDiv()StringgetCssClassPrefixRow()StringgetCssClassPrefixTable()DocumentgetDocument()protected StringgetStyleClassName(HSSFWorkbook workbook, HSSFCellStyle cellStyle)booleanisUseDivsToSpan()static voidmain(String[] args)Java main() interface to interact with ExcelToHtmlConverterstatic Documentprocess(File xlsFile)Converts Excel file (97-2007) into HTML file.static Documentprocess(InputStream xlsStream)Converts Excel file (97-2007) into HTML file.static Documentprocess(HSSFWorkbook workbook)Converts Excel file (97-2007) into HTML file.protected booleanprocessCell(HSSFCell cell, Element tableCellElement, int normalWidthPx, int maxSpannedWidthPx, float normalHeightPt)protected voidprocessColumnHeaders(HSSFSheet sheet, int maxSheetColumns, Element table)protected voidprocessColumnWidths(HSSFSheet sheet, int maxSheetColumns, Element table)Creates COLGROUP element with width specified for all columns.protected voidprocessDocumentInformation(SummaryInformation summaryInformation)protected intprocessRow(CellRangeAddress[][] mergedRanges, HSSFRow row, Element tableRowElement)protected voidprocessRowNumber(HSSFRow row, Element tableRowNumberCellElement)protected voidprocessSheet(HSSFSheet sheet)protected voidprocessSheetHeader(Element htmlBody, HSSFSheet sheet)voidprocessWorkbook(HSSFWorkbook workbook)voidsetCssClassPrefixCell(String cssClassPrefixCell)voidsetCssClassPrefixDiv(String cssClassPrefixDiv)voidsetCssClassPrefixRow(String cssClassPrefixRow)voidsetCssClassPrefixTable(String cssClassPrefixTable)voidsetUseDivsToSpan(boolean useDivsToSpan)Allows converter to wrap content into two additional DIVs with tricky styles, so it will wrap across empty cells (like in Excel).-
Methods inherited from class org.apache.poi.hssf.converter.AbstractExcelConverter
getColumnName, getColumnWidth, getDefaultColumnWidth, getFontReplacer, getRowName, isOutputColumnHeaders, isOutputHiddenColumns, isOutputHiddenRows, isOutputLeadingSpacesAsNonBreaking, isOutputRowNumbers, isTextEmpty, setFontReplacer, setOutputColumnHeaders, setOutputHiddenColumns, setOutputHiddenRows, setOutputLeadingSpacesAsNonBreaking, setOutputRowNumbers
-
-
-
-
Constructor Detail
-
ExcelToHtmlConverter
public ExcelToHtmlConverter(Document doc)
-
ExcelToHtmlConverter
public ExcelToHtmlConverter(HtmlDocumentFacade htmlDocumentFacade)
-
-
Method Detail
-
main
public static void main(String[] args) throws Exception
Java main() interface to interact with ExcelToHtmlConverterUsage: ExcelToHtmlConverter infile outfile
Where infile is an input .xls file ( Word 97-2007) which will be rendered as HTML into outfile- Throws:
Exception
-
process
public static Document process(File xlsFile) throws IOException, ParserConfigurationException
Converts Excel file (97-2007) into HTML file.- Parameters:
xlsFile- workbook file to process- Returns:
- DOM representation of result HTML
- Throws:
IOException- If an error occurs reading or writing filesParserConfigurationException- If configuration is incorrectRuntimeException- a number of runtime exceptions can be thrown, especially if there are problems with the input format
-
process
public static Document process(InputStream xlsStream) throws IOException, ParserConfigurationException
Converts Excel file (97-2007) into HTML file.- Parameters:
xlsStream- workbook stream to process- Returns:
- DOM representation of result HTML
- Throws:
IOException- If an error occurs reading or writing filesParserConfigurationException- If configuration is incorrectRuntimeException- a number of runtime exceptions can be thrown, especially if there are problems with the input format
-
process
public static Document process(HSSFWorkbook workbook) throws IOException, ParserConfigurationException
Converts Excel file (97-2007) into HTML file.- Parameters:
workbook- workbook instance to process- Returns:
- DOM representation of result HTML
- Throws:
IOException- If an error occurs reading or writing filesParserConfigurationException- If configuration is incorrectRuntimeException- a number of runtime exceptions can be thrown, especially if there are problems with the input format
-
buildStyle
protected String buildStyle(HSSFWorkbook workbook, HSSFCellStyle cellStyle)
-
getCssClassPrefixCell
public String getCssClassPrefixCell()
-
getCssClassPrefixDiv
public String getCssClassPrefixDiv()
-
getCssClassPrefixRow
public String getCssClassPrefixRow()
-
getCssClassPrefixTable
public String getCssClassPrefixTable()
-
getDocument
public Document getDocument()
- Specified by:
getDocumentin classAbstractExcelConverter
-
getStyleClassName
protected String getStyleClassName(HSSFWorkbook workbook, HSSFCellStyle cellStyle)
-
isUseDivsToSpan
public boolean isUseDivsToSpan()
-
processCell
protected boolean processCell(HSSFCell cell, Element tableCellElement, int normalWidthPx, int maxSpannedWidthPx, float normalHeightPt)
-
processColumnHeaders
protected void processColumnHeaders(HSSFSheet sheet, int maxSheetColumns, Element table)
-
processColumnWidths
protected void processColumnWidths(HSSFSheet sheet, int maxSheetColumns, Element table)
Creates COLGROUP element with width specified for all columns. (Except first ifAbstractExcelConverter.isOutputRowNumbers()==true)
-
processDocumentInformation
protected void processDocumentInformation(SummaryInformation summaryInformation)
-
processRow
protected int processRow(CellRangeAddress[][] mergedRanges, HSSFRow row, Element tableRowElement)
- Returns:
- maximum 1-base index of column that were rendered, zero if none
-
processSheet
protected void processSheet(HSSFSheet sheet)
-
processWorkbook
public void processWorkbook(HSSFWorkbook workbook)
-
setCssClassPrefixCell
public void setCssClassPrefixCell(String cssClassPrefixCell)
-
setCssClassPrefixDiv
public void setCssClassPrefixDiv(String cssClassPrefixDiv)
-
setCssClassPrefixRow
public void setCssClassPrefixRow(String cssClassPrefixRow)
-
setCssClassPrefixTable
public void setCssClassPrefixTable(String cssClassPrefixTable)
-
setUseDivsToSpan
public void setUseDivsToSpan(boolean useDivsToSpan)
Allows converter to wrap content into two additional DIVs with tricky styles, so it will wrap across empty cells (like in Excel).Warning: after enabling this mode do not serialize result HTML with INDENT=YES option, because line breaks will make additional (unwanted) changes
-
-