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. SpreadsheetSBook
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 ofXSSFCellStyle
) 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 Summary
Fields Modifier and Type Field Description protected boolean
_importCache
protected SBook
book
target book modelprotected Map<PictureData,Integer>
importedPictureData
protected StyleCache
styleCache
Keep track of imported style during importing to avoid creating duplicated style objects.protected Workbook
workbook
source 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 Workbook
createPoiBook(InputStream is)
protected SFont
createZssFont(Font poiFont)
protected abstract int
getAnchorHeightInPx(ClientAnchor anchor, Sheet poiSheet)
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)static String
getBookType(SBook book)
Gets the book-type information ("xls" or "xlsx"), return null if not foundprotected Font
getPoiFontFromRichText(Workbook book, Cell cell, RichTextString rstr, int run)
protected abstract int
getXoffsetInPixel(ClientAnchor clientAnchor, Sheet poiSheet)
protected abstract int
getYoffsetInPixel(ClientAnchor clientAnchor, Sheet poiSheet)
protected void
importAutoFilter(Sheet poiSheet, SSheet sheet)
POI AutoFilter.getFilterColumn(i) sometimes returns null.protected void
importAutoFilterColumns(AutoFilter poiFilter, SAutoFilter zssFilter, int numberOfColumn)
protected SCell
importCell(Cell poiCell, int row, SSheet sheet)
protected SCellStyle
importCellStyle(CellStyle poiCellStyle)
Convert CellStyle into NCellStyleprotected SCellStyle
importCellStyle(CellStyle poiCellStyle, boolean inStyleTable)
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.protected abstract void
importConditionalFormatting(SSheet sheet, Sheet poiSheet)
protected void
importDefaultCellStyles()
protected abstract void
importDrawings(Sheet poiSheet, SSheet sheet)
Drawings includes charts and pictures.protected abstract void
importExternalBookLinks()
Excel uses external book links to map external book index and name.protected void
importExtraStyles()
protected SFont
importFont(CellStyle poiCellStyle)
protected void
importMergedRegions(Sheet poiSheet, SSheet sheet)
protected void
importNamedRange()
Name should be created after sheets created.protected void
importNamedStyles()
protected abstract void
importPassword(Sheet poiSheet, SSheet sheet)
protected void
importPicture(List<Picture> poiPictures, Sheet poiSheet, SSheet sheet)
protected void
importRichText(Cell poiCell, RichTextString poiRichTextString0, SRichText richText)
protected SRow
importRow(Row poiRow, SSheet sheet)
SBook
imports(InputStream is, String bookName)
Import the model according to reversed dependency order among model objects: book, sheet, defined name, cells, chart, pictures, validation.protected SSheet
importSheet(Sheet poiSheet, int poiSheetIndex)
protected void
importSheetDefaultColumnWidth(Sheet poiSheet, SSheet sheet)
protected abstract void
importSheetProtection(Sheet poiSheet, SSheet sheet)
POI SheetProtection.protected abstract void
importTables(Sheet poiSheet, SSheet sheet)
POI sheet tablesprotected void
importTableStyles()
protected abstract void
importValidation(Sheet poiSheet, SSheet sheet)
protected boolean
isImportCache()
Returns if import file cached value.protected boolean
mustCalc(SCell cell)
protected abstract void
setBookType(SBook book)
void
setImportCache(boolean b)
Set if import Excel cached value.protected boolean
skipName(Name definedName)
protected ViewAnchor
toViewAnchor(Sheet poiSheet, ClientAnchor clientAnchor)
protected SFont
toZssFont(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:
imports
in 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:
setImportCache
in classAbstractImporter
- Since:
- 3.7.0
-
isImportCache
protected boolean isImportCache()
Returns if import file cached value.- Overrides:
isImportCache
in 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()
-
-