Class AbstractExcelImporter

  • All Implemented Interfaces:
    SImporter, Serializable
    Direct Known Subclasses:
    ExcelXlsImporter

    public abstract class AbstractExcelImporter
    extends AbstractImporter
    implements Serializable
    Contains common importing behavior for XLS. Spreadsheet SBook model including following information: Book: name Sheet: name, (default) column width, (default) row height, hidden row (column), row (column) style, freeze, merge, protection, named range , gridline display Cell: type, value, font with color and style, type offset(normal or subscript), background color, border's type and color , data format, alignment, wrap, locked, fill pattern We use XLS common interface (e.g. CellStyle instead of XSSFCellStyle) to get content first for that codes can be easily moved to parent class.

    Note: Xlsx support in XlsxImporter since Keikai 5.0

    Since:
    3.5.0
    Author:
    Hawk
    See Also:
    Serialized Form
    • Field Detail

      • styleCache

        protected StyleCache styleCache
        Keep track of imported style during importing to avoid creating duplicated style objects.
      • book

        protected SBook book
        target book model
      • workbook

        protected Workbook workbook
        source POI book
      • _importCache

        protected boolean _importCache
    • Constructor Detail

      • AbstractExcelImporter

        public AbstractExcelImporter()
    • Method Detail

      • importDefaultCellStyles

        protected void importDefaultCellStyles()
      • importNamedStyles

        protected void importNamedStyles()
      • imports

        public SBook imports​(InputStream is,
                             String bookName)
                      throws IOException
        Import the model according to reversed dependency order among model objects: book, sheet, defined name, cells, chart, pictures, validation.
        Specified by:
        imports in interface SImporter
        Parameters:
        is - the input stream
        bookName - the book name for imported book
        Returns:
        the book instance
        Throws:
        IOException
      • setBookType

        protected abstract void setBookType​(SBook book)
      • getBookType

        public static String getBookType​(SBook book)
        Gets the book-type information ("xls" or "xlsx"), return null if not found
        Parameters:
        book -
        Returns:
      • importColumn

        protected abstract void importColumn​(Sheet poiSheet,
                                             SSheet sheet)
        When a column is hidden with default width, we don't import the width for it's 0. We also don't import the width that equals to default width for optimization.
        Parameters:
        poiSheet -
        sheet -
      • getAnchorWidthInPx

        protected abstract int getAnchorWidthInPx​(ClientAnchor anchor,
                                                  Sheet poiSheet)
        If in same column: anchorWidthInFirstColumn + anchor width in inter-columns + anchorWidthInLastColumn (dx2) no in same column: anchorWidthInLastColumn - offsetInFirstColumn (dx1)
      • getAnchorHeightInPx

        protected abstract int getAnchorHeightInPx​(ClientAnchor anchor,
                                                   Sheet poiSheet)
      • importNamedRange

        protected void importNamedRange()
        Name should be created after sheets created. A special defined name, _xlnm._FilterDatabase (xlsx) or _FilterDatabase (xls), stores the selected cells for auto-filter
      • skipName

        protected boolean skipName​(Name definedName)
      • importExternalBookLinks

        protected abstract void importExternalBookLinks()
        Excel uses external book links to map external book index and name. The formula contains full external book name or index only (e.g [book2.xlsx] or [1]). We needs such table for parsing and evaluating formula when necessary.
      • importSheetDefaultColumnWidth

        protected void importSheetDefaultColumnWidth​(Sheet poiSheet,
                                                     SSheet sheet)
      • importSheet

        protected SSheet importSheet​(Sheet poiSheet,
                                     int poiSheetIndex)
      • importPassword

        protected abstract void importPassword​(Sheet poiSheet,
                                               SSheet sheet)
      • importMergedRegions

        protected void importMergedRegions​(Sheet poiSheet,
                                           SSheet sheet)
      • importDrawings

        protected abstract void importDrawings​(Sheet poiSheet,
                                               SSheet sheet)
        Drawings includes charts and pictures.
      • importValidation

        protected abstract void importValidation​(Sheet poiSheet,
                                                 SSheet sheet)
      • importRow

        protected SRow importRow​(Row poiRow,
                                 SSheet sheet)
      • importCell

        protected SCell importCell​(Cell poiCell,
                                   int row,
                                   SSheet sheet)
      • importCellStyle

        protected SCellStyle importCellStyle​(CellStyle poiCellStyle)
        Convert CellStyle into NCellStyle
        Parameters:
        poiCellStyle -
      • importCellStyle

        protected SCellStyle importCellStyle​(CellStyle poiCellStyle,
                                             boolean inStyleTable)
      • toZssFont

        protected SFont toZssFont​(Font poiFont)
      • createZssFont

        protected SFont createZssFont​(Font poiFont)
      • getXoffsetInPixel

        protected abstract int getXoffsetInPixel​(ClientAnchor clientAnchor,
                                                 Sheet poiSheet)
      • getYoffsetInPixel

        protected abstract int getYoffsetInPixel​(ClientAnchor clientAnchor,
                                                 Sheet poiSheet)
      • importAutoFilter

        protected void importAutoFilter​(Sheet poiSheet,
                                        SSheet sheet)
        POI AutoFilter.getFilterColumn(i) sometimes returns null. A POI FilterColumn object only exists when we have set a criteria on that column. For example, if we enable auto filter on 2 columns, but we only set criteria on 2nd column. Thus, the size of filter column is 1. There is only one FilterColumn object and its column id is 1. Only getFilterColumn(1) will return a FilterColumn, other get null.
        Parameters:
        poiSheet - source POI sheet
        sheet - destination sheet
      • importAutoFilterColumns

        protected void importAutoFilterColumns​(AutoFilter poiFilter,
                                               SAutoFilter zssFilter,
                                               int numberOfColumn)
      • importSheetProtection

        protected abstract void importSheetProtection​(Sheet poiSheet,
                                                      SSheet sheet)
        POI SheetProtection.
        Parameters:
        poiSheet - source POI sheet
        sheet - destination sheet
      • importTables

        protected abstract void importTables​(Sheet poiSheet,
                                             SSheet sheet)
        POI sheet tables
        Parameters:
        poiSheet - source POI sheet
        sheet - destination sheet
        Since:
        3.8.0
      • setImportCache

        public void setImportCache​(boolean b)
        Set if import Excel cached value.
        Overrides:
        setImportCache in class AbstractImporter
        Since:
        3.7.0
      • isImportCache

        protected boolean isImportCache()
        Returns if import file cached value.
        Overrides:
        isImportCache in class AbstractImporter
        Since:
        3.7.0
      • mustCalc

        protected boolean mustCalc​(SCell cell)
      • importConditionalFormatting

        protected abstract void importConditionalFormatting​(SSheet sheet,
                                                            Sheet poiSheet)
      • importExtraStyles

        protected void importExtraStyles()
      • importTableStyles

        protected void importTableStyles()