/** * Import the model according to reversed dependency order among model objects: book, sheet, * defined name, cells, chart, pictures, validation. */ @Override public SBook imports(InputStream is, String bookName) throws IOException { // clear cache for reuse importedStyle.clear(); importedFont.clear(); workbook = createPoiBook(is); book = SBooks.createBook(bookName); // book.setDefaultCellStyle(importCellStyle(workbook.getCellStyleAt((short) 0), false)); // //ZSS-780 // ZSS-854 importDefaultCellStyles(); importNamedStyles(); // ZSS-1140 importExtraStyles(); setBookType(book); // ZSS-715: Enforce internal Locale.US Locale so formula is in consistent internal format Locale old = Locales.setThreadLocal(Locale.US); SBookSeries bookSeries = book.getBookSeries(); boolean isCacheClean = bookSeries.isAutoFormulaCacheClean(); try { bookSeries.setAutoFormulaCacheClean(false); // disable it to avoid // unnecessary clean up // during importing importExternalBookLinks(); int numberOfSheet = workbook.getNumberOfSheets(); for (int i = 0; i < numberOfSheet; i++) { Sheet poiSheet = workbook.getSheetAt(i); importSheet(poiSheet, i); SSheet sheet = book.getSheet(i); importTables(poiSheet, sheet); // ZSS-855, ZSS-1011 } importNamedRange(); for (int i = 0; i < numberOfSheet; i++) { SSheet sheet = book.getSheet(i); Sheet poiSheet = workbook.getSheetAt(i); for (Row poiRow : poiSheet) { importRow(poiRow, sheet); } importColumn(poiSheet, sheet); importMergedRegions(poiSheet, sheet); importDrawings(poiSheet, sheet); importValidation(poiSheet, sheet); importAutoFilter(poiSheet, sheet); importSheetProtection(poiSheet, sheet); // ZSS-576 } } finally { book.getBookSeries().setAutoFormulaCacheClean(isCacheClean); Locales.setThreadLocal(old); } return book; }
protected SFont toZssFont(Font poiFont) { if (poiFont == null) return null; // ZSS-1138 SFont font = null; final short fontIndex = poiFont.getIndex(); if (importedFont.containsKey(fontIndex)) { font = importedFont.get(fontIndex); } else { font = createZssFont(poiFont); importedFont.put(fontIndex, font); // ZSS-677 } return font; }
protected SFont importFont(CellStyle poiCellStyle) { SFont font = null; final short fontIndex = poiCellStyle.getFontIndex(); if (importedFont.containsKey(fontIndex)) { font = importedFont.get(fontIndex); } else { Font poiFont = workbook.getFontAt(fontIndex); font = createZssFont(poiFont); importedFont.put(fontIndex, font); // ZSS-677 } return font; }
protected void importPicture(List<Picture> poiPictures, Sheet poiSheet, SSheet sheet) { for (Picture poiPicture : poiPictures) { PictureData poiPicData = poiPicture.getPictureData(); Integer picDataIx = importedPictureData.get(poiPicData); // ZSS-735 if (picDataIx != null) { sheet.addPicture( picDataIx.intValue(), toViewAnchor(poiSheet, poiPicture.getClientAnchor())); } else { Format format = Format.valueOfFileExtension(poiPicData.suggestFileExtension()); if (format != null) { SPicture pic = sheet.addPicture( format, poiPicData.getData(), toViewAnchor(poiSheet, poiPicture.getClientAnchor())); importedPictureData.put(poiPicData, pic.getPictureData().getIndex()); } else { // TODO log we ignore a picture with unsupported format } } } }
protected SCellStyle importCellStyle(CellStyle poiCellStyle, boolean inStyleTable) { SCellStyle cellStyle = null; // short idx = poiCellStyle.getIndex(); // ZSS-685 if ((cellStyle = importedStyle.get(poiCellStyle)) == null) { // ZSS-685 cellStyle = book.createCellStyle(inStyleTable); importedStyle.put(poiCellStyle, cellStyle); // ZSS-685 String dataFormat = poiCellStyle.getRawDataFormatString(); if (dataFormat == null) { // just in case dataFormat = SCellStyle.FORMAT_GENERAL; } if (!poiCellStyle.isBuiltinDataFormat()) { cellStyle.setDirectDataFormat(dataFormat); } else { cellStyle.setDataFormat(dataFormat); } cellStyle.setWrapText(poiCellStyle.getWrapText()); cellStyle.setLocked(poiCellStyle.getLocked()); cellStyle.setAlignment(PoiEnumConversion.toHorizontalAlignment(poiCellStyle.getAlignment())); cellStyle.setVerticalAlignment( PoiEnumConversion.toVerticalAlignment(poiCellStyle.getVerticalAlignment())); cellStyle.setRotation(poiCellStyle.getRotation()); // ZSS-918 cellStyle.setIndention(poiCellStyle.getIndention()); // ZSS-915 Color fgColor = poiCellStyle.getFillForegroundColorColor(); Color bgColor = poiCellStyle.getFillBackgroundColorColor(); // if (fgColor == null && bgColor != null) { //ZSS-797 // fgColor = bgColor; // } // ZSS-857: SOLID pattern: switch fillColor and backColor cellStyle.setFillPattern(PoiEnumConversion.toFillPattern(poiCellStyle.getFillPattern())); SColor fgSColor = book.createColor(BookHelper.colorToForegroundHTML(workbook, fgColor)); SColor bgSColor = book.createColor(BookHelper.colorToBackgroundHTML(workbook, bgColor)); if (cellStyle.getFillPattern() == FillPattern.SOLID) { SColor tmp = fgSColor; fgSColor = bgSColor; bgSColor = tmp; } cellStyle.setFillColor(fgSColor); cellStyle.setBackColor(bgSColor); // ZSS-780 cellStyle.setBorderLeft(PoiEnumConversion.toBorderType(poiCellStyle.getBorderLeft())); cellStyle.setBorderTop(PoiEnumConversion.toBorderType(poiCellStyle.getBorderTop())); cellStyle.setBorderRight(PoiEnumConversion.toBorderType(poiCellStyle.getBorderRight())); cellStyle.setBorderBottom(PoiEnumConversion.toBorderType(poiCellStyle.getBorderBottom())); cellStyle.setBorderLeftColor( book.createColor( BookHelper.colorToBorderHTML(workbook, poiCellStyle.getLeftBorderColorColor()))); cellStyle.setBorderTopColor( book.createColor( BookHelper.colorToBorderHTML(workbook, poiCellStyle.getTopBorderColorColor()))); cellStyle.setBorderRightColor( book.createColor( BookHelper.colorToBorderHTML(workbook, poiCellStyle.getRightBorderColorColor()))); cellStyle.setBorderBottomColor( book.createColor( BookHelper.colorToBorderHTML(workbook, poiCellStyle.getBottomBorderColorColor()))); cellStyle.setHidden(poiCellStyle.getHidden()); // same style always use same font cellStyle.setFont(importFont(poiCellStyle)); } return cellStyle; }