package support.importer; import java.util.*; import org.zkoss.poi.ss.usermodel.CellStyle; import org.zkoss.zss.model.SCellStyle; import org.zkoss.zss.range.impl.imexp.*; public class ReduceRedundantStyleImporter extends ExcelXlsxImporter { Map usedStyle = new HashMap(); protected SCellStyle importCellStyle(CellStyle poiCellStyle) { SCellStyle cellStyle = null; if ((cellStyle = usedStyle.get(poiCellStyle)) == null) { cellStyle = book.createCellStyle(true); usedStyle.put(poiCellStyle, cellStyle); 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.setFillColor(book.createColor(BookHelper.colorToBackgroundHTML(workbook, poiCellStyle.getFillForegroundColorColor()))); 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()); cellStyle.setFillPattern(PoiEnumConversion.toFillPattern(poiCellStyle.getFillPattern())); // same style always use same font cellStyle.setFont(importFont(poiCellStyle)); } return cellStyle; } }