Package io.keikai.range.impl.imexp
Class AbstractExcelImporter
- java.lang.Object
-
- io.keikai.range.impl.imexp.AbstractImporter
-
- io.keikai.range.impl.imexp.AbstractExcelImporter
-
- All Implemented Interfaces:
SImporter,Serializable
- Direct Known Subclasses:
ExcelXlsImporter
public abstract class AbstractExcelImporter extends AbstractImporter implements Serializable
Contains common importing behavior for XLS. SpreadsheetSBookmodel 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 ofXSSFCellStyle) to get content first for that codes can be easily moved to parent class.Note: Xlsx support in
XlsxImportersince Keikai 5.0- Since:
- 3.5.0
- Author:
- Hawk
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean_importCacheprotected SBookbooktarget book modelprotected Map<PictureData,Integer>importedPictureDataprotected StyleCachestyleCacheKeep track of imported style during importing to avoid creating duplicated style objects.protected Workbookworkbooksource POI book-
Fields inherited from class io.keikai.range.impl.imexp.AbstractImporter
BOOK_TYPE_KEY
-
-
Constructor Summary
Constructors Constructor Description AbstractExcelImporter()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract WorkbookcreatePoiBook(InputStream is)protected SFontcreateZssFont(Font poiFont)protected abstract intgetAnchorHeightInPx(ClientAnchor anchor, Sheet poiSheet)protected abstract intgetAnchorWidthInPx(ClientAnchor anchor, Sheet poiSheet)If in same column: anchorWidthInFirstColumn + anchor width in inter-columns + anchorWidthInLastColumn (dx2) no in same column: anchorWidthInLastColumn - offsetInFirstColumn (dx1)static StringgetBookType(SBook book)Gets the book-type information ("xls" or "xlsx"), return null if not foundprotected FontgetPoiFontFromRichText(Workbook book, Cell cell, RichTextString rstr, int run)protected abstract intgetXoffsetInPixel(ClientAnchor clientAnchor, Sheet poiSheet)protected abstract intgetYoffsetInPixel(ClientAnchor clientAnchor, Sheet poiSheet)protected voidimportAutoFilter(Sheet poiSheet, SSheet sheet)POI AutoFilter.getFilterColumn(i) sometimes returns null.protected voidimportAutoFilterColumns(AutoFilter poiFilter, SAutoFilter zssFilter, int numberOfColumn)protected SCellimportCell(Cell poiCell, int row, SSheet sheet)protected SCellStyleimportCellStyle(CellStyle poiCellStyle)Convert CellStyle into NCellStyleprotected SCellStyleimportCellStyle(CellStyle poiCellStyle, boolean inStyleTable)protected abstract voidimportColumn(Sheet poiSheet, SSheet sheet)When a column is hidden with default width, we don't import the width for it's 0.protected abstract voidimportConditionalFormatting(SSheet sheet, Sheet poiSheet)protected voidimportDefaultCellStyles()protected abstract voidimportDrawings(Sheet poiSheet, SSheet sheet)Drawings includes charts and pictures.protected abstract voidimportExternalBookLinks()Excel uses external book links to map external book index and name.protected voidimportExtraStyles()protected SFontimportFont(CellStyle poiCellStyle)protected voidimportMergedRegions(Sheet poiSheet, SSheet sheet)protected voidimportNamedRange()Name should be created after sheets created.protected voidimportNamedStyles()protected abstract voidimportPassword(Sheet poiSheet, SSheet sheet)protected voidimportPicture(List<Picture> poiPictures, Sheet poiSheet, SSheet sheet)protected voidimportRichText(Cell poiCell, RichTextString poiRichTextString0, SRichText richText)protected SRowimportRow(Row poiRow, SSheet sheet)SBookimports(InputStream is, String bookName)Import the model according to reversed dependency order among model objects: book, sheet, defined name, cells, chart, pictures, validation.protected SSheetimportSheet(Sheet poiSheet, int poiSheetIndex)protected voidimportSheetDefaultColumnWidth(Sheet poiSheet, SSheet sheet)protected abstract voidimportSheetProtection(Sheet poiSheet, SSheet sheet)POI SheetProtection.protected abstract voidimportTables(Sheet poiSheet, SSheet sheet)POI sheet tablesprotected voidimportTableStyles()protected abstract voidimportValidation(Sheet poiSheet, SSheet sheet)protected booleanisImportCache()Returns if import file cached value.protected booleanmustCalc(SCell cell)protected abstract voidsetBookType(SBook book)voidsetImportCache(boolean b)Set if import Excel cached value.protected booleanskipName(Name definedName)protected ViewAnchortoViewAnchor(Sheet poiSheet, ClientAnchor clientAnchor)protected SFonttoZssFont(Font poiFont)-
Methods inherited from class io.keikai.range.impl.imexp.AbstractImporter
imports, imports
-
-
-
-
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
-
importedPictureData
protected Map<PictureData,Integer> importedPictureData
-
_importCache
protected boolean _importCache
-
-
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:
importsin interfaceSImporter- Parameters:
is- the input streambookName- the book name for imported book- Returns:
- the book instance
- Throws:
IOException
-
createPoiBook
protected abstract Workbook createPoiBook(InputStream is) throws IOException
- 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)
-
importDrawings
protected abstract void importDrawings(Sheet poiSheet, SSheet sheet)
Drawings includes charts and pictures.
-
importRichText
protected void importRichText(Cell poiCell, RichTextString poiRichTextString0, SRichText richText)
-
importCellStyle
protected SCellStyle importCellStyle(CellStyle poiCellStyle)
Convert CellStyle into NCellStyle- Parameters:
poiCellStyle-
-
importCellStyle
protected SCellStyle importCellStyle(CellStyle poiCellStyle, boolean inStyleTable)
-
toViewAnchor
protected ViewAnchor toViewAnchor(Sheet poiSheet, ClientAnchor clientAnchor)
-
getXoffsetInPixel
protected abstract int getXoffsetInPixel(ClientAnchor clientAnchor, Sheet poiSheet)
-
getYoffsetInPixel
protected abstract int getYoffsetInPixel(ClientAnchor clientAnchor, Sheet poiSheet)
-
importPicture
protected void importPicture(List<Picture> poiPictures, Sheet poiSheet, SSheet sheet)
-
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 sheetsheet- destination sheet
-
importAutoFilterColumns
protected void importAutoFilterColumns(AutoFilter poiFilter, SAutoFilter zssFilter, int numberOfColumn)
-
getPoiFontFromRichText
protected Font getPoiFontFromRichText(Workbook book, Cell cell, RichTextString rstr, int run)
-
importSheetProtection
protected abstract void importSheetProtection(Sheet poiSheet, SSheet sheet)
POI SheetProtection.- Parameters:
poiSheet- source POI sheetsheet- destination sheet
-
importTables
protected abstract void importTables(Sheet poiSheet, SSheet sheet)
POI sheet tables- Parameters:
poiSheet- source POI sheetsheet- destination sheet- Since:
- 3.8.0
-
setImportCache
public void setImportCache(boolean b)
Set if import Excel cached value.- Overrides:
setImportCachein classAbstractImporter- Since:
- 3.7.0
-
isImportCache
protected boolean isImportCache()
Returns if import file cached value.- Overrides:
isImportCachein classAbstractImporter- 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()
-
-