Class ExcelToHtmlConverter


  • @Beta
    public class ExcelToHtmlConverter
    extends AbstractExcelConverter
    Converts xls files (97-2007) to HTML file.
    Author:
    Sergey Vladimirov (vlsergey {at} gmail {dot} com)
    • Constructor Detail

      • ExcelToHtmlConverter

        public ExcelToHtmlConverter​(org.w3c.dom.Document doc)
      • ExcelToHtmlConverter

        public ExcelToHtmlConverter​(HtmlDocumentFacade htmlDocumentFacade)
    • Method Detail

      • main

        public static void main​(java.lang.String[] args)
                         throws java.lang.Exception
        Java main() interface to interact with ExcelToHtmlConverter

        Usage: ExcelToHtmlConverter infile outfile

        Where infile is an input .xls file ( Word 97-2007) which will be rendered as HTML into outfile
        Throws:
        java.lang.Exception
      • process

        public static org.w3c.dom.Document process​(java.io.File xlsFile)
                                            throws java.io.IOException,
                                                   javax.xml.parsers.ParserConfigurationException
        Converts Excel file (97-2007) into HTML file.
        Parameters:
        xlsFile - workbook file to process
        Returns:
        DOM representation of result HTML
        Throws:
        java.io.IOException - If an error occurs reading or writing files
        javax.xml.parsers.ParserConfigurationException - If configuration is incorrect
      • process

        public static org.w3c.dom.Document process​(java.io.InputStream xlsStream)
                                            throws java.io.IOException,
                                                   javax.xml.parsers.ParserConfigurationException
        Converts Excel file (97-2007) into HTML file.
        Parameters:
        xlsStream - workbook stream to process
        Returns:
        DOM representation of result HTML
        Throws:
        java.io.IOException - If an error occurs reading or writing files
        javax.xml.parsers.ParserConfigurationException - If configuration is incorrect
      • process

        public static org.w3c.dom.Document process​(HSSFWorkbook workbook)
                                            throws java.io.IOException,
                                                   javax.xml.parsers.ParserConfigurationException
        Converts Excel file (97-2007) into HTML file.
        Parameters:
        workbook - workbook instance to process
        Returns:
        DOM representation of result HTML
        Throws:
        java.io.IOException - If an error occurs reading or writing files
        javax.xml.parsers.ParserConfigurationException - If configuration is incorrect
      • getCssClassPrefixCell

        public java.lang.String getCssClassPrefixCell()
      • getCssClassPrefixDiv

        public java.lang.String getCssClassPrefixDiv()
      • getCssClassPrefixRow

        public java.lang.String getCssClassPrefixRow()
      • getCssClassPrefixTable

        public java.lang.String getCssClassPrefixTable()
      • isUseDivsToSpan

        public boolean isUseDivsToSpan()
      • processCell

        protected boolean processCell​(HSSFCell cell,
                                      org.w3c.dom.Element tableCellElement,
                                      int normalWidthPx,
                                      int maxSpannedWidthPx,
                                      float normalHeightPt)
      • processColumnHeaders

        protected void processColumnHeaders​(HSSFSheet sheet,
                                            int maxSheetColumns,
                                            org.w3c.dom.Element table)
      • processColumnWidths

        protected void processColumnWidths​(HSSFSheet sheet,
                                           int maxSheetColumns,
                                           org.w3c.dom.Element table)
        Creates COLGROUP element with width specified for all columns. (Except first if AbstractExcelConverter.isOutputRowNumbers()==true)
      • processDocumentInformation

        protected void processDocumentInformation​(SummaryInformation summaryInformation)
      • processRow

        protected int processRow​(CellRangeAddress[][] mergedRanges,
                                 HSSFRow row,
                                 org.w3c.dom.Element tableRowElement)
        Returns:
        maximum 1-base index of column that were rendered, zero if none
      • processRowNumber

        protected void processRowNumber​(HSSFRow row,
                                        org.w3c.dom.Element tableRowNumberCellElement)
      • processSheet

        protected void processSheet​(HSSFSheet sheet)
      • processSheetHeader

        protected void processSheetHeader​(org.w3c.dom.Element htmlBody,
                                          HSSFSheet sheet)
      • processWorkbook

        public void processWorkbook​(HSSFWorkbook workbook)
      • setCssClassPrefixCell

        public void setCssClassPrefixCell​(java.lang.String cssClassPrefixCell)
      • setCssClassPrefixDiv

        public void setCssClassPrefixDiv​(java.lang.String cssClassPrefixDiv)
      • setCssClassPrefixRow

        public void setCssClassPrefixRow​(java.lang.String cssClassPrefixRow)
      • setCssClassPrefixTable

        public void setCssClassPrefixTable​(java.lang.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