diff --git a/build.properties b/build.properties index 2515f24..e1b5968 100644 --- a/build.properties +++ b/build.properties @@ -24,10 +24,11 @@ app.copyright=2008-2016 app.dist=${app.home}/dist # Javac/Jikes compiler section -javac.version=1.7 +javac.version=1.8 javac.optimize=off javac.debug=on javac.deprecation=on javac.verbose=off +build.sysclasspath=last ant.tasks.dir=${app.home}/ant-tasks diff --git a/ivy.xml b/ivy.xml index 2bbd61e..05a3492 100644 --- a/ivy.xml +++ b/ivy.xml @@ -47,8 +47,8 @@ - - + + diff --git a/src/ro/nextreports/engine/exporter/XlsExporter.java b/src/ro/nextreports/engine/exporter/XlsExporter.java index 0d2b516..2a2059a 100644 --- a/src/ro/nextreports/engine/exporter/XlsExporter.java +++ b/src/ro/nextreports/engine/exporter/XlsExporter.java @@ -16,6 +16,7 @@ */ package ro.nextreports.engine.exporter; +import java.awt.Color; import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; @@ -34,10 +35,10 @@ import java.util.Date; import java.util.regex.Matcher; import java.util.regex.Pattern; -import java.awt.*; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.apache.poi.common.usermodel.HyperlinkType; import org.apache.poi.hssf.model.InternalSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.hssf.usermodel.HSSFCellStyle; @@ -56,9 +57,7 @@ import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.hpsf.SummaryInformation; import org.apache.poi.hpsf.PropertySetFactory; -import org.apache.poi.ss.usermodel.Footer; -import org.apache.poi.ss.usermodel.Header; -import org.apache.poi.ss.usermodel.PrintSetup; +import org.apache.poi.ss.usermodel.*; import org.apache.poi.ss.util.CellRangeAddress; import ro.nextreports.engine.ReleaseInfoAdapter; @@ -347,16 +346,18 @@ private HSSFCellStyle buildBandElementStyle(BandElement bandElement, Object valu } if (style.containsKey(StyleFormatConstants.FONT_STYLE_KEY)) { if (StyleFormatConstants.FONT_STYLE_NORMAL.equals(style.get(StyleFormatConstants.FONT_STYLE_KEY))) { - cellFont.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL); + cellFont.setBold(false); } if (StyleFormatConstants.FONT_STYLE_BOLD.equals(style.get(StyleFormatConstants.FONT_STYLE_KEY))) { - cellFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); - } + cellFont.setBold(true); + cellFont.setBold(true); + + } if (StyleFormatConstants.FONT_STYLE_ITALIC.equals(style.get(StyleFormatConstants.FONT_STYLE_KEY))) { cellFont.setItalic(true); } if (StyleFormatConstants.FONT_STYLE_BOLDITALIC.equals(style.get(StyleFormatConstants.FONT_STYLE_KEY))) { - cellFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); + cellFont.setBold(true); cellFont.setItalic(true); } } @@ -369,39 +370,39 @@ private HSSFCellStyle buildBandElementStyle(BandElement bandElement, Object valu } if (style.containsKey(StyleFormatConstants.BACKGROUND_COLOR)) { Color val = (Color) style.get(StyleFormatConstants.BACKGROUND_COLOR); - cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); + cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); cellStyle.setFillForegroundColor(ExcelColorSupport.getNearestColor(val)); } if (style.containsKey(StyleFormatConstants.HORIZONTAL_ALIGN_KEY)) { if (StyleFormatConstants.HORIZONTAL_ALIGN_LEFT.equals( style.get(StyleFormatConstants.HORIZONTAL_ALIGN_KEY))) { - cellStyle.setAlignment((short) 1); + cellStyle.setAlignment(HorizontalAlignment.LEFT); } if (StyleFormatConstants.HORIZONTAL_ALIGN_RIGHT.equals( style.get(StyleFormatConstants.HORIZONTAL_ALIGN_KEY))) { - cellStyle.setAlignment((short) 3); + cellStyle.setAlignment(HorizontalAlignment.RIGHT); } if (StyleFormatConstants.HORIZONTAL_ALIGN_CENTER.equals( style.get(StyleFormatConstants.HORIZONTAL_ALIGN_KEY))) { - cellStyle.setAlignment((short) 2); + cellStyle.setAlignment(HorizontalAlignment.CENTER); } } if (style.containsKey(StyleFormatConstants.VERTICAL_ALIGN_KEY)) { if (StyleFormatConstants.VERTICAL_ALIGN_TOP.equals( style.get(StyleFormatConstants.VERTICAL_ALIGN_KEY))) { - cellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_TOP); + cellStyle.setVerticalAlignment(VerticalAlignment.TOP); } if (StyleFormatConstants.VERTICAL_ALIGN_MIDDLE.equals( style.get(StyleFormatConstants.VERTICAL_ALIGN_KEY))) { - cellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); + cellStyle.setVerticalAlignment(VerticalAlignment.CENTER); } if (StyleFormatConstants.VERTICAL_ALIGN_BOTTOM.equals( style.get(StyleFormatConstants.VERTICAL_ALIGN_KEY))) { - cellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_BOTTOM); + cellStyle.setVerticalAlignment(VerticalAlignment.BOTTOM); } } else { - cellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); + cellStyle.setVerticalAlignment(VerticalAlignment.CENTER); } short left = 0, right = 0, top = 0, bottom = 0; @@ -411,13 +412,13 @@ private HSSFCellStyle buildBandElementStyle(BandElement bandElement, Object valu // left = val.shortValue(); if (left == BORDER_THIN_VALUE) { - cellStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN); + cellStyle.setBorderLeft(BorderStyle.THIN); } if (left == BORDER_MEDIUM_VALUE) { - cellStyle.setBorderLeft(HSSFCellStyle.BORDER_MEDIUM); + cellStyle.setBorderLeft(BorderStyle.MEDIUM); } if (left == BORDER_THICK_VALUE) { - cellStyle.setBorderLeft(HSSFCellStyle.BORDER_THICK); + cellStyle.setBorderLeft(BorderStyle.THICK); } Color color = (Color) style.get(StyleFormatConstants.BORDER_LEFT_COLOR); @@ -429,13 +430,13 @@ private HSSFCellStyle buildBandElementStyle(BandElement bandElement, Object valu // right = val.shortValue(); if (right == BORDER_THIN_VALUE) { - cellStyle.setBorderRight(HSSFCellStyle.BORDER_THIN); + cellStyle.setBorderRight(BorderStyle.THIN); } if (right == BORDER_MEDIUM_VALUE) { - cellStyle.setBorderRight(HSSFCellStyle.BORDER_MEDIUM); + cellStyle.setBorderRight(BorderStyle.MEDIUM); } if (right == BORDER_THICK_VALUE) { - cellStyle.setBorderRight(HSSFCellStyle.BORDER_THICK); + cellStyle.setBorderRight(BorderStyle.THICK); } Color color = (Color) style.get(StyleFormatConstants.BORDER_RIGHT_COLOR); rightColor = color; @@ -446,13 +447,13 @@ private HSSFCellStyle buildBandElementStyle(BandElement bandElement, Object valu // top = val.shortValue(); if (top == BORDER_THIN_VALUE) { - cellStyle.setBorderTop(HSSFCellStyle.BORDER_THIN); + cellStyle.setBorderTop(BorderStyle.THIN); } if (top == BORDER_MEDIUM_VALUE) { - cellStyle.setBorderTop(HSSFCellStyle.BORDER_MEDIUM); + cellStyle.setBorderTop(BorderStyle.MEDIUM); } if (top == BORDER_THICK_VALUE) { - cellStyle.setBorderTop(HSSFCellStyle.BORDER_THICK); + cellStyle.setBorderTop(BorderStyle.THICK); } Color color = (Color) style.get(StyleFormatConstants.BORDER_TOP_COLOR); topColor = color; @@ -463,13 +464,13 @@ private HSSFCellStyle buildBandElementStyle(BandElement bandElement, Object valu // bottom = val.shortValue(); if (bottom == BORDER_THIN_VALUE) { - cellStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); + cellStyle.setBorderBottom(BorderStyle.THIN); } if (bottom == BORDER_MEDIUM_VALUE) { - cellStyle.setBorderBottom(HSSFCellStyle.BORDER_MEDIUM); + cellStyle.setBorderBottom(BorderStyle.MEDIUM); } if (bottom == BORDER_THICK_VALUE) { - cellStyle.setBorderBottom(HSSFCellStyle.BORDER_THICK); + cellStyle.setBorderBottom(BorderStyle.THICK); } Color color = (Color) style.get(StyleFormatConstants.BORDER_BOTTOM_COLOR); bottomColor = color; @@ -516,18 +517,18 @@ private HSSFCellStyle updateSubreportBandElementStyle(HSSFCellStyle cellStyle, B } if (gridColumn == 0) { - cellStyle.setBorderLeft(subreportCellStyle.getBorderLeft()); + cellStyle.setBorderLeft(BorderStyle.THIN); cellStyle.setLeftBorderColor(subreportCellStyle.getLeftBorderColor()); } else if (gridColumn+colSpan-1 == bean.getReportLayout().getColumnCount()-1) { - cellStyle.setBorderRight(subreportCellStyle.getBorderRight()); + cellStyle.setBorderRight(BorderStyle.THIN); cellStyle.setRightBorderColor(subreportCellStyle.getRightBorderColor()); } if (pageRow == 0) { - cellStyle.setBorderTop(subreportCellStyle.getBorderTop()); + cellStyle.setBorderTop(BorderStyle.THIN); cellStyle.setTopBorderColor(subreportCellStyle.getTopBorderColor()); } else if ( (pageRow+1) == getRowsCount()) { - cellStyle.setBorderBottom(subreportCellStyle.getBorderBottom()); + cellStyle.setBorderBottom(BorderStyle.THIN); cellStyle.setBottomBorderColor(subreportCellStyle.getBottomBorderColor()); } @@ -575,7 +576,7 @@ private void renderCell(BandElement bandElement, String bandName, Object value, HSSFPicture picture = patriarch.createPicture(anchor, index); picture.resize(); - anchor.setAnchorType(2); + anchor.setAnchorType(ClientAnchor.AnchorType.MOVE_DONT_RESIZE); } catch (Exception ex) { c.setCellType(HSSFCell.CELL_TYPE_STRING); c.setCellValue(new HSSFRichTextString(IMAGE_NOT_LOADED)); @@ -589,7 +590,7 @@ private void renderCell(BandElement bandElement, String bandName, Object value, } else { if (bandElement instanceof HyperlinkBandElement) { Hyperlink hyp = ((HyperlinkBandElement) bandElement).getHyperlink(); - HSSFHyperlink link = new HSSFHyperlink(HSSFHyperlink.LINK_URL); + HSSFHyperlink link = wb.getCreationHelper().createHyperlink(HyperlinkType.URL); link.setAddress(hyp.getUrl()); c.setHyperlink(link); c.setCellValue(new HSSFRichTextString(hyp.getText())); @@ -661,7 +662,7 @@ private void renderCell(BandElement bandElement, String bandName, Object value, HSSFPicture picture = patriarch.createPicture(anchor, index); picture.resize(); - anchor.setAnchorType(2); + anchor.setAnchorType(ClientAnchor.AnchorType.MOVE_DONT_RESIZE); } } catch (Exception e) { e.printStackTrace(); @@ -793,17 +794,17 @@ private void renderCellToHeaderFooter(StringBuilder result, String bandName, Ban } - private short getXlsBorderValue(int border) { + private BorderStyle getXlsBorderValue(int border) { if (border == BORDER_THIN_VALUE) { - return HSSFCellStyle.BORDER_THIN; + return BorderStyle.THIN; } if (border == BORDER_MEDIUM_VALUE) { - return HSSFCellStyle.BORDER_MEDIUM; + return BorderStyle.MEDIUM; } if (border == BORDER_THICK_VALUE) { - return HSSFCellStyle.BORDER_THICK; + return BorderStyle.THICK; } - return 0; + return BorderStyle.NONE; } private void addRegions(HSSFSheet xlsSheet, List regions, HSSFWorkbook wb ) { @@ -814,27 +815,27 @@ private void addRegions(HSSFSheet xlsSheet, List regions, HSSFWorkbo xlsSheet.addMergedRegion(region); if (border != null) { - short xlsBottomBorder = getXlsBorderValue(border.getBottom()); - if (xlsBottomBorder > 0) { - HSSFRegionUtil.setBorderBottom(xlsBottomBorder, region, xlsSheet, wb); + BorderStyle xlsBottomBorder = getXlsBorderValue(border.getBottom()); + if (xlsBottomBorder != BorderStyle.NONE) { + HSSFRegionUtil.setBorderBottom(xlsBottomBorder.getCode(), region, xlsSheet, wb); HSSFRegionUtil.setBottomBorderColor(ExcelColorSupport.getNearestColor(border.getBottomColor()), region, xlsSheet, wb); } - short xlsTopBorder = getXlsBorderValue(border.getTop()); - if (xlsTopBorder > 0) { - HSSFRegionUtil.setBorderTop(xlsTopBorder,region, xlsSheet, wb); + BorderStyle xlsTopBorder = getXlsBorderValue(border.getTop()); + if (xlsTopBorder != BorderStyle.NONE) { + HSSFRegionUtil.setBorderTop(xlsTopBorder.getCode(),region, xlsSheet, wb); HSSFRegionUtil.setTopBorderColor(ExcelColorSupport.getNearestColor(border.getTopColor()), region, xlsSheet, wb); } - short xlsLeftBorder = getXlsBorderValue(border.getLeft()); - if (xlsLeftBorder > 0) { - HSSFRegionUtil.setBorderLeft(xlsLeftBorder, region, xlsSheet, wb); + BorderStyle xlsLeftBorder = getXlsBorderValue(border.getLeft()); + if (xlsLeftBorder != BorderStyle.NONE) { + HSSFRegionUtil.setBorderLeft(xlsLeftBorder.getCode(), region, xlsSheet, wb); HSSFRegionUtil.setLeftBorderColor(ExcelColorSupport.getNearestColor(border.getLeftColor()), region, xlsSheet, wb); } - short xlsRightBorder = getXlsBorderValue(border.getRight()); - if (xlsRightBorder > 0) { - HSSFRegionUtil.setBorderRight(xlsRightBorder, region, xlsSheet, wb); + BorderStyle xlsRightBorder = getXlsBorderValue(border.getRight()); + if (xlsRightBorder != BorderStyle.NONE) { + HSSFRegionUtil.setBorderRight(xlsRightBorder.getCode(), region, xlsSheet, wb); HSSFRegionUtil.setRightBorderColor(ExcelColorSupport.getNearestColor(border.getRightColor()), region, xlsSheet, wb); } diff --git a/src/ro/nextreports/engine/exporter/XlsxExporter.java b/src/ro/nextreports/engine/exporter/XlsxExporter.java index d56bef0..76a34bf 100644 --- a/src/ro/nextreports/engine/exporter/XlsxExporter.java +++ b/src/ro/nextreports/engine/exporter/XlsxExporter.java @@ -1,5 +1,6 @@ package ro.nextreports.engine.exporter; +import java.awt.Color; import java.io.IOException; import java.io.InputStream; import java.text.DateFormat; @@ -14,29 +15,20 @@ import java.util.Date; import java.util.regex.Matcher; import java.util.regex.Pattern; -import java.awt.*; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.poi.POIXMLProperties; +import org.apache.poi.common.usermodel.HyperlinkType; import org.apache.poi.openxml4j.opc.OPCPackage; -import org.apache.poi.ss.usermodel.Drawing; -import org.apache.poi.ss.usermodel.Footer; -import org.apache.poi.ss.usermodel.Header; -import org.apache.poi.ss.usermodel.Picture; -import org.apache.poi.ss.usermodel.PrintSetup; -import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.ss.usermodel.*; import org.apache.poi.ss.util.CellRangeAddress; import org.apache.poi.ss.util.RegionUtil; -import org.apache.poi.xssf.usermodel.XSSFCell; -import org.apache.poi.xssf.usermodel.XSSFCellStyle; -import org.apache.poi.xssf.usermodel.XSSFClientAnchor; -import org.apache.poi.xssf.usermodel.XSSFDataFormat; -import org.apache.poi.xssf.usermodel.XSSFFont; -import org.apache.poi.xssf.usermodel.XSSFHyperlink; -import org.apache.poi.xssf.usermodel.XSSFRow; -import org.apache.poi.xssf.usermodel.XSSFSheet; -import org.apache.poi.xssf.usermodel.XSSFWorkbook; +import org.apache.poi.xssf.streaming.SXSSFCell; +import org.apache.poi.xssf.streaming.SXSSFRow; +import org.apache.poi.xssf.streaming.SXSSFSheet; +import org.apache.poi.xssf.streaming.SXSSFWorkbook; +import org.apache.poi.xssf.usermodel.*; import ro.nextreports.engine.ReleaseInfoAdapter; import ro.nextreports.engine.Report; @@ -77,6 +69,7 @@ public class XlsxExporter extends ResultExporter { private int prevSubreportFirstColumn = 0; private int prevSubreportLastColumn = -1; private int addedPageRows = 0; + private long exportedRowCount = 0; public XlsxExporter(ExporterBean bean) { super(bean); @@ -88,26 +81,31 @@ private XlsxExporter(ExporterBean bean, XSSFCellStyle cellStyle) { subreportCellStyle = cellStyle; } - protected void initExport() throws QueryException { + protected void initExport() throws QueryException { + exportedRowCount = 0; if (hasTemplate()) { - try { + try { if (bean.getReportLayout().getTemplateName().endsWith(".xlsm")) { - wb = new XSSFWorkbook(OPCPackage.open(getTemplateInputStream())); - } else { - wb = new XSSFWorkbook(getTemplateInputStream()); + tWb = new XSSFWorkbook(OPCPackage.open(getTemplateInputStream())); + } else { + tWb = new XSSFWorkbook(getTemplateInputStream()); } + wb = new SXSSFWorkbook(tWb, 10000); } catch (Exception e) { e.printStackTrace(); LOG.error(e.getMessage(), e); - wb = new XSSFWorkbook(); + wb = new SXSSFWorkbook(10000); } } else { - wb = new XSSFWorkbook(); + wb = new SXSSFWorkbook(tWb,10000); + wb.setCompressTempFiles(true); + tWb = wb.getXSSFWorkbook(); } } - protected void finishExport() { - String sheetName = bean.getReportLayout().getSheetNames(); + protected void finishExport() { + LOG.info("Export finished with " + exportedRowCount + " records."); + String sheetName = bean.getReportLayout().getSheetNames(); if (sheetNameContainsGroup(sheetName)) { String actualName = replaceSheetNameParam(sheetName); if (wb.getSheetName(page-3).equals(actualName)) { @@ -132,16 +130,17 @@ protected void finishExport() { e.printStackTrace(); } } - } + } } - + private void createSummaryInformation(String title) { - DateFormat df = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss"); + DateFormat df = new SimpleDateFormat("yyyy-MM-DD'T'HH:mm:ss.SSSz"); - POIXMLProperties xmlProps = wb.getProperties(); + POIXMLProperties xmlProps = tWb.getProperties(); POIXMLProperties.CoreProperties coreProps = xmlProps.getCoreProperties(); + coreProps.setTitle(title); coreProps.setCreator(ReleaseInfoAdapter.getCompany()); coreProps.setDescription("NextReports " + ReleaseInfoAdapter.getVersionNumber()); @@ -162,9 +161,19 @@ protected void close() { } protected void flush() { + if (resultSetRow % FLUSH_ROWS == 0) { + flushNow(); + } } protected void flushNow() { + try { + xlsSheet.flushRows(); + + } catch (IOException e) { + e.printStackTrace(); + LOG.error("Flush XLSX error.", e); + } } @@ -174,10 +183,10 @@ protected Set getIgnoredCells(Band band) { protected void exportCell(String bandName, BandElement bandElement, Object value, int gridRow, int row, int column, int cols, int rowSpan, int colSpan, boolean isImage) { - - if (ReportLayout.PAGE_HEADER_BAND_NAME.equals(bandName)) { - renderCellToHeaderFooter(headerS, bandName, bandElement, value, gridRow, row, column, cols, rowSpan, colSpan, isImage); - } else if (ReportLayout.PAGE_FOOTER_BAND_NAME.equals(bandName)) { + + if (ReportLayout.PAGE_HEADER_BAND_NAME.equals(bandName)) { + renderCellToHeaderFooter(headerS, bandName, bandElement, value, gridRow, row, column, cols, rowSpan, colSpan, isImage); + } else if (ReportLayout.PAGE_FOOTER_BAND_NAME.equals(bandName)) { renderCellToHeaderFooter(footerS, bandName, bandElement, value, gridRow, row, column, cols, rowSpan, colSpan, isImage); } else { @@ -201,13 +210,17 @@ protected void exportCell(String bandName, BandElement bandElement, Object value // " width="+width); xlsSheet.setColumnWidth(column, width); } - + renderCell(bandElement, bandName, value, gridRow, sheetRow, column, rowSpan, colSpan, isImage); } - } + } protected void afterRowExport() { addRegions(xlsSheet, regions, wb); + exportedRowCount++; + if(exportedRowCount%10000 == 0) { + LOG.info("Export status: " + exportedRowCount); + } } protected String getNullElement() { @@ -217,37 +230,38 @@ protected String getNullElement() { ///// EXCEL stuff private int page = 1; private int fragmentsize = 1000000; - private XSSFWorkbook wb; - private XSSFSheet xlsSheet = null; - private XSSFRow xlsRow = null; + private SXSSFWorkbook wb; + private XSSFWorkbook tWb; + private SXSSFSheet xlsSheet = null; + private SXSSFRow xlsRow = null; private List regions = new ArrayList(); private Drawing patriarch; private StringBuilder headerS = new StringBuilder(); private StringBuilder footerS = new StringBuilder(); private XSSFCellStyle subreportCellStyle; - + // reuse fonts and styles // there is a maximum number of unique fonts in a workbook (512) // there is a maximum number of cell formats (4000) private Map styles = new HashMap(); // styles used by formatting conditions private Map condStyles = new HashMap(); - - + + private Map fonts = new HashMap(); // fonts used by formatting conditions private Map condFonts = new HashMap(); - + private Border border; private XSSFCellStyle buildBandElementStyle(BandElement bandElement, Object value, int gridRow, int gridColumn, int colSpan) { Map style = buildCellStyleMap(bandElement, value, gridRow, gridColumn, colSpan); XSSFCellStyle cellStyle = null; - XSSFFont cellFont = null; + Font cellFont = null; int fontKey = -1; int styleKey = -1; - // we have to create new fonts and styles if some formatting conditions are met - // also for subreports we may have a subreportCellStyle passed by ReportBandElement + // we have to create new fonts and styles if some formatting conditions are met + // also for subreports we may have a subreportCellStyle passed by ReportBandElement boolean cacheFont = false; boolean cacheAllFont = false; boolean cacheStyle = false; @@ -255,28 +269,28 @@ private XSSFCellStyle buildBandElementStyle(BandElement bandElement, Object valu if ((modifiedStyle[gridRow][gridColumn]) || bean.isSubreport()) { fontKey = getFontKey(style); if (fontKey != -1) { - cellFont = condFonts.get(fontKey); - } + cellFont = condFonts.get(fontKey); + } if (cellFont == null) { cellFont = wb.createFont(); cacheFont = true; - } + } styleKey = getStyleKey(style, bandElement); if (styleKey != -1) { cellStyle = condStyles.get(styleKey); } if (cellStyle == null) { - cellStyle = wb.createCellStyle(); + cellStyle = (XSSFCellStyle) wb.createCellStyle(); cacheStyle = true; } modifiedStyle[gridRow][gridColumn] = false; - } else { + } else { fontKey = getFontKey(style); - if (fontKey != -1) { - cellFont = fonts.get(fontKey); + if (fontKey != -1) { + cellFont = fonts.get(fontKey); } - if ((cellFont == null) && (bandElement != null)) { - cellFont = wb.createFont(); + if ((cellFont == null) && (bandElement != null)) { + cellFont = wb.createFont(); cacheAllFont = true; } styleKey = getStyleKey(style, bandElement); @@ -284,12 +298,12 @@ private XSSFCellStyle buildBandElementStyle(BandElement bandElement, Object valu cellStyle = styles.get(styleKey); } if (cellStyle == null) { - cellStyle = wb.createCellStyle(); + cellStyle = (XSSFCellStyle) wb.createCellStyle(); cacheAllStyle = true; - } + } } - // HSSFPalette cellPal = wb.getCustomPalette(); + // HSSFPalette cellPal = wb.getCustomPalette(); if (style.containsKey(StyleFormatConstants.FONT_FAMILY_KEY)) { String val = (String) style.get(StyleFormatConstants.FONT_FAMILY_KEY); cellFont.setFontName(val); @@ -304,97 +318,97 @@ private XSSFCellStyle buildBandElementStyle(BandElement bandElement, Object valu } if (style.containsKey(StyleFormatConstants.FONT_STYLE_KEY)) { if (StyleFormatConstants.FONT_STYLE_NORMAL.equals(style.get(StyleFormatConstants.FONT_STYLE_KEY))) { - cellFont.setBoldweight(XSSFFont.BOLDWEIGHT_NORMAL); + cellFont.setBold(false); } if (StyleFormatConstants.FONT_STYLE_BOLD.equals(style.get(StyleFormatConstants.FONT_STYLE_KEY))) { - cellFont.setBoldweight(XSSFFont.BOLDWEIGHT_BOLD); + cellFont.setBold(true); } if (StyleFormatConstants.FONT_STYLE_ITALIC.equals(style.get(StyleFormatConstants.FONT_STYLE_KEY))) { cellFont.setItalic(true); } if (StyleFormatConstants.FONT_STYLE_BOLDITALIC.equals(style.get(StyleFormatConstants.FONT_STYLE_KEY))) { - cellFont.setBoldweight(XSSFFont.BOLDWEIGHT_BOLD); + cellFont.setBold(true); cellFont.setItalic(true); } } - + if (cacheFont && (fontKey != -1)) { - condFonts.put(fontKey, cellFont); + condFonts.put(fontKey, (XSSFFont) cellFont); } if (cacheAllFont && (fontKey != -1)) { - fonts.put(fontKey, cellFont); + fonts.put(fontKey, (XSSFFont) cellFont); } if (style.containsKey(StyleFormatConstants.BACKGROUND_COLOR)) { Color val = (Color) style.get(StyleFormatConstants.BACKGROUND_COLOR); - cellStyle.setFillPattern(XSSFCellStyle.SOLID_FOREGROUND); + cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); cellStyle.setFillForegroundColor(ExcelColorSupport.getNearestColor(val)); } if (style.containsKey(StyleFormatConstants.HORIZONTAL_ALIGN_KEY)) { if (StyleFormatConstants.HORIZONTAL_ALIGN_LEFT.equals( style.get(StyleFormatConstants.HORIZONTAL_ALIGN_KEY))) { - cellStyle.setAlignment((short) 1); + cellStyle.setAlignment(HorizontalAlignment.LEFT); } if (StyleFormatConstants.HORIZONTAL_ALIGN_RIGHT.equals( style.get(StyleFormatConstants.HORIZONTAL_ALIGN_KEY))) { - cellStyle.setAlignment((short) 3); + cellStyle.setAlignment(HorizontalAlignment.RIGHT); } if (StyleFormatConstants.HORIZONTAL_ALIGN_CENTER.equals( style.get(StyleFormatConstants.HORIZONTAL_ALIGN_KEY))) { - cellStyle.setAlignment((short) 2); + cellStyle.setAlignment(HorizontalAlignment.CENTER); } } if (style.containsKey(StyleFormatConstants.VERTICAL_ALIGN_KEY)) { if (StyleFormatConstants.VERTICAL_ALIGN_TOP.equals( style.get(StyleFormatConstants.VERTICAL_ALIGN_KEY))) { - cellStyle.setVerticalAlignment(XSSFCellStyle.VERTICAL_TOP); + cellStyle.setVerticalAlignment(VerticalAlignment.TOP); } if (StyleFormatConstants.VERTICAL_ALIGN_MIDDLE.equals( style.get(StyleFormatConstants.VERTICAL_ALIGN_KEY))) { - cellStyle.setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER); + cellStyle.setVerticalAlignment(VerticalAlignment.CENTER); } if (StyleFormatConstants.VERTICAL_ALIGN_BOTTOM.equals( style.get(StyleFormatConstants.VERTICAL_ALIGN_KEY))) { - cellStyle.setVerticalAlignment(XSSFCellStyle.VERTICAL_BOTTOM); + cellStyle.setVerticalAlignment(VerticalAlignment.BOTTOM); } } else { - cellStyle.setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER); + cellStyle.setVerticalAlignment(VerticalAlignment.CENTER); } - short left = 0, right = 0, top = 0, bottom = 0; + short left = 0, right = 0, top = 0, bottom = 0; Color leftColor = Color.BLACK, rightColor = Color.BLACK, topColor = Color.BLACK, bottomColor = Color.BLACK; if (style.containsKey(StyleFormatConstants.BORDER_LEFT)) { Float val = (Float) style.get(StyleFormatConstants.BORDER_LEFT); // left = val.shortValue(); if (left == BORDER_THIN_VALUE) { - cellStyle.setBorderLeft(XSSFCellStyle.BORDER_THIN); + cellStyle.setBorderLeft(BorderStyle.THIN); } if (left == BORDER_MEDIUM_VALUE) { - cellStyle.setBorderLeft(XSSFCellStyle.BORDER_MEDIUM); + cellStyle.setBorderLeft(BorderStyle.MEDIUM); } if (left == BORDER_THICK_VALUE) { - cellStyle.setBorderLeft(XSSFCellStyle.BORDER_THICK); + cellStyle.setBorderLeft(BorderStyle.THICK); } - + Color color = (Color) style.get(StyleFormatConstants.BORDER_LEFT_COLOR); leftColor = color; cellStyle.setLeftBorderColor(ExcelColorSupport.getNearestColor(color)); } - if (style.containsKey(StyleFormatConstants.BORDER_RIGHT)) { + if (style.containsKey(StyleFormatConstants.BORDER_RIGHT)) { Float val = (Float) style.get(StyleFormatConstants.BORDER_RIGHT); // right = val.shortValue(); if (right == BORDER_THIN_VALUE) { - cellStyle.setBorderRight(XSSFCellStyle.BORDER_THIN); + cellStyle.setBorderRight(BorderStyle.THIN); } if (right == BORDER_MEDIUM_VALUE) { - cellStyle.setBorderRight(XSSFCellStyle.BORDER_MEDIUM); + cellStyle.setBorderRight(BorderStyle.MEDIUM); } if (right == BORDER_THICK_VALUE) { - cellStyle.setBorderRight(XSSFCellStyle.BORDER_THICK); + cellStyle.setBorderRight(BorderStyle.THICK); } - Color color = (Color) style.get(StyleFormatConstants.BORDER_RIGHT_COLOR); + Color color = (Color) style.get(StyleFormatConstants.BORDER_RIGHT_COLOR); rightColor = color; cellStyle.setRightBorderColor(ExcelColorSupport.getNearestColor(color)); } @@ -403,13 +417,13 @@ private XSSFCellStyle buildBandElementStyle(BandElement bandElement, Object valu // top = val.shortValue(); if (top == BORDER_THIN_VALUE) { - cellStyle.setBorderTop(XSSFCellStyle.BORDER_THIN); + cellStyle.setBorderTop(BorderStyle.THIN); } if (top == BORDER_MEDIUM_VALUE) { - cellStyle.setBorderTop(XSSFCellStyle.BORDER_MEDIUM); + cellStyle.setBorderTop(BorderStyle.MEDIUM); } if (top == BORDER_THICK_VALUE) { - cellStyle.setBorderTop(XSSFCellStyle.BORDER_THICK); + cellStyle.setBorderTop(BorderStyle.THICK); } Color color = (Color) style.get(StyleFormatConstants.BORDER_TOP_COLOR); topColor = color; @@ -420,13 +434,13 @@ private XSSFCellStyle buildBandElementStyle(BandElement bandElement, Object valu // bottom = val.shortValue(); if (bottom == BORDER_THIN_VALUE) { - cellStyle.setBorderBottom(XSSFCellStyle.BORDER_THIN); + cellStyle.setBorderBottom(BorderStyle.THIN); } if (bottom == BORDER_MEDIUM_VALUE) { - cellStyle.setBorderBottom(XSSFCellStyle.BORDER_MEDIUM); + cellStyle.setBorderBottom(BorderStyle.MEDIUM); } if (bottom == BORDER_THICK_VALUE) { - cellStyle.setBorderBottom(XSSFCellStyle.BORDER_THICK); + cellStyle.setBorderBottom(BorderStyle.THICK); } Color color = (Color) style.get(StyleFormatConstants.BORDER_BOTTOM_COLOR); bottomColor = color; @@ -444,7 +458,7 @@ private XSSFCellStyle buildBandElementStyle(BandElement bandElement, Object valu if (style.containsKey(StyleFormatConstants.PATTERN)) { String pattern = (String) style.get(StyleFormatConstants.PATTERN); - XSSFDataFormat format = wb.createDataFormat(); + DataFormat format = wb.createDataFormat(); cellStyle.setDataFormat(format.getFormat(pattern)); } else { cellStyle.setDataFormat((short)0); @@ -453,61 +467,61 @@ private XSSFCellStyle buildBandElementStyle(BandElement bandElement, Object valu if (bandElement != null) { cellStyle.setWrapText(bandElement.isWrapText()); } - + cellStyle = updateSubreportBandElementStyle(cellStyle, bandElement, value, gridRow, gridColumn, colSpan); - + if (cacheStyle && (styleKey != -1)) { condStyles.put(styleKey, cellStyle); } if (cacheAllStyle && (styleKey != -1)) { - styles.put(styleKey, cellStyle); + styles.put(styleKey, cellStyle); } return cellStyle; } - + // If a border style is set on a ReportBandElement we must apply it to all subreport cells private XSSFCellStyle updateSubreportBandElementStyle(XSSFCellStyle cellStyle, BandElement bandElement, Object value, int gridRow, int gridColumn, int colSpan) { if (subreportCellStyle == null) { return cellStyle; } - - if (gridColumn == 0) { - cellStyle.setBorderLeft(subreportCellStyle.getBorderLeft()); - cellStyle.setLeftBorderColor(subreportCellStyle.getLeftBorderColor()); - } else if (gridColumn+colSpan-1 == bean.getReportLayout().getColumnCount()-1) { - cellStyle.setBorderRight(subreportCellStyle.getBorderRight()); + + if (gridColumn == 0) { + cellStyle.setBorderLeft(BorderStyle.MEDIUM); + cellStyle.setLeftBorderColor(subreportCellStyle.getLeftBorderColor()); + } else if (gridColumn+colSpan-1 == bean.getReportLayout().getColumnCount()-1) { + cellStyle.setBorderRight(BorderStyle.MEDIUM); cellStyle.setRightBorderColor(subreportCellStyle.getRightBorderColor()); - } - - if (pageRow == 0) { - cellStyle.setBorderTop(subreportCellStyle.getBorderTop()); - cellStyle.setTopBorderColor(subreportCellStyle.getTopBorderColor()); - } else if ( (pageRow+1) == getRowsCount()) { - cellStyle.setBorderBottom(subreportCellStyle.getBorderBottom()); + } + + if (pageRow == 0) { + cellStyle.setBorderTop(BorderStyle.MEDIUM); + cellStyle.setTopBorderColor(subreportCellStyle.getTopBorderColor()); + } else if ( (pageRow+1) == getRowsCount()) { + cellStyle.setBorderBottom(BorderStyle.MEDIUM); cellStyle.setBottomBorderColor(subreportCellStyle.getBottomBorderColor()); - } - + } + return cellStyle; } private void renderCell(BandElement bandElement, String bandName, Object value, int gridRow, int sheetRow, int sheetColumn, int rowSpan, - int colSpan, boolean image) { - + int colSpan, boolean image) { + if (bandElement instanceof ReportBandElement) { colSpan = 1; - } - XSSFCellStyle cellStyle = buildBandElementStyle(bandElement, value, gridRow, sheetColumn, colSpan); - + } + XSSFCellStyle cellStyle = buildBandElementStyle(bandElement, value, gridRow, sheetColumn, colSpan); + // if we have a subreport on the current grid row we have to take care of the sheetColumn - if (ReportLayout.HEADER_BAND_NAME.equals(bandName) && (gridRow == prevSubreportFirstRow) && (prevSubreportLastColumn != -1)) { - sheetColumn = prevSubreportLastColumn - prevSubreportFirstColumn - 1 + sheetColumn; + if (ReportLayout.HEADER_BAND_NAME.equals(bandName) && (gridRow == prevSubreportFirstRow) && (prevSubreportLastColumn != -1)) { + sheetColumn = prevSubreportLastColumn - prevSubreportFirstColumn - 1 + sheetColumn; } - XSSFCell c = xlsRow.createCell(sheetColumn); + SXSSFCell c = xlsRow.createCell(sheetColumn); - if (image) { + if (image) { if ((value == null) || "".equals(value)) { c.setCellType(XSSFCell.CELL_TYPE_STRING); c.setCellValue(wb.getCreationHelper().createRichTextString(IMAGE_NOT_FOUND)); @@ -525,10 +539,10 @@ private void renderCell(BandElement bandElement, String bandName, Object value, if (ibe.isScaled()) { realImageHeight = ibe.getHeight(); } - short imageHeight = (short)(realImageHeight * POINTS_FOR_PIXEL/2.5); + short imageHeight = (short)(realImageHeight * POINTS_FOR_PIXEL/2.5); boolean doResize = false; if (imageHeight > height) { - xlsRow.setHeight(imageHeight); + xlsRow.setHeight(imageHeight); } else { doResize = true; } @@ -537,7 +551,7 @@ private void renderCell(BandElement bandElement, String bandName, Object value, if (doResize) { picture.resize(); } - anchor.setAnchorType(2); + anchor.setAnchorType(ClientAnchor.AnchorType.MOVE_DONT_RESIZE); } catch (Exception ex) { c.setCellType(XSSFCell.CELL_TYPE_STRING); c.setCellValue(wb.getCreationHelper().createRichTextString(IMAGE_NOT_LOADED)); @@ -551,20 +565,20 @@ private void renderCell(BandElement bandElement, String bandName, Object value, } else { if (bandElement instanceof HyperlinkBandElement) { Hyperlink hyp = ((HyperlinkBandElement) bandElement).getHyperlink(); - XSSFHyperlink link = wb.getCreationHelper().createHyperlink(XSSFHyperlink.LINK_URL); + org.apache.poi.ss.usermodel.Hyperlink link = wb.getCreationHelper().createHyperlink(HyperlinkType.URL); link.setAddress(hyp.getUrl()); c.setHyperlink(link); c.setCellValue(wb.getCreationHelper().createRichTextString(hyp.getText())); c.setCellType(XSSFCell.CELL_TYPE_STRING); } else if (bandElement instanceof ReportBandElement) { - Report report = ((ReportBandElement)bandElement).getReport(); + Report report = ((ReportBandElement)bandElement).getReport(); ExporterBean eb = null; - try { - eb = getSubreportExporterBean(report, true); + try { + eb = getSubreportExporterBean(report, true); XlsxExporter subExporter = new XlsxExporter(eb, cellStyle); - subExporter.export(); - XSSFSheet subreportSheet = subExporter.getSubreportSheet(); - + subExporter.export(); + SXSSFSheet subreportSheet = subExporter.getSubreportSheet(); + if (ReportLayout.HEADER_BAND_NAME.equals(bandName) && (gridRow == prevSubreportFirstRow)) { // other subreports on the same header line after the first sheetColumn = prevSubreportLastColumn; @@ -575,34 +589,34 @@ private void renderCell(BandElement bandElement, String bandName, Object value, addedPageRows = subreportSheet.getLastRowNum(); pageRow += addedPageRows; // if subreport is not on the first column we merge all cells in the columns before, between the rows subreport occupies - if (sheetColumn > 0) { - for (int i=0; i <= sheetColumn-1; i++) { - CellRangeAddress cra = new CellRangeAddress(sheetRow, pageRow, i, i); + if (sheetColumn > 0) { + for (int i=0; i <= sheetColumn-1; i++) { + CellRangeAddress cra = new CellRangeAddress(sheetRow, pageRow, i, i); regions.add(new XlsxRegion(cra, null)); } - } + } } - int cols = XlsxUtil.copyToSheet(xlsSheet, sheetRow, sheetColumn, subreportSheet); + int cols = XlsxUtil.copyToSheet(xlsSheet, sheetRow, sheetColumn, subreportSheet); addRegions(xlsSheet, subExporter.getSubreportRegions(), wb); if (ReportLayout.HEADER_BAND_NAME.equals(bandName)) { prevSubreportFirstRow = gridRow; prevSubreportFirstColumn = sheetColumn; - prevSubreportLastColumn = sheetColumn + cols; + prevSubreportLastColumn = sheetColumn + cols; } - } catch (Exception e) { + } catch (Exception e) { e.printStackTrace(); } finally { if ((eb != null) && (eb.getResult() != null)) { eb.getResult().close(); } - } + } } else if (bandElement instanceof ImageColumnBandElement){ - try { + try { ImageColumnBandElement icbe = (ImageColumnBandElement)bandElement; String v = StringUtil.getValueAsString(value, null); if(StringUtil.BLOB.equals(v)) { c.setCellType(XSSFCell.CELL_TYPE_STRING); - c.setCellValue(wb.getCreationHelper().createRichTextString(StringUtil.BLOB)); + c.setCellValue(wb.getCreationHelper().createRichTextString(StringUtil.BLOB)); } else { byte[] imageD = StringUtil.decodeImage(v); byte[] imageBytes = getImage(imageD, icbe.getWidth(), icbe.getHeight()); @@ -612,62 +626,62 @@ private void renderCell(BandElement bandElement, String bandName, Object value, // image is created over the cells, so if it's height is bigger we set the row height short height = xlsRow.getHeight(); - int realImageHeight = getRealImageSize(imageBytes)[1]; + int realImageHeight = getRealImageSize(imageBytes)[1]; if (icbe.isScaled()) { realImageHeight = icbe.getHeight(); } - short imageHeight = (short)(realImageHeight * POINTS_FOR_PIXEL/2.5); + short imageHeight = (short)(realImageHeight * POINTS_FOR_PIXEL/2.5); if (imageHeight > height) { xlsRow.setHeight(imageHeight); } Picture picture = patriarch.createPicture(anchor, index); picture.resize(); - anchor.setAnchorType(2); - } - } catch (Exception e) { + anchor.setAnchorType(ClientAnchor.AnchorType.MOVE_DONT_RESIZE); + } + } catch (Exception e) { e.printStackTrace(); c.setCellType(XSSFCell.CELL_TYPE_STRING); c.setCellValue(wb.getCreationHelper().createRichTextString(IMAGE_NOT_LOADED)); } - - + + } else { - + if (value == null) { c.setCellType(XSSFCell.CELL_TYPE_STRING); c.setCellValue(wb.getCreationHelper().createRichTextString("")); } else if (value instanceof Number) { c.setCellType(XSSFCell.CELL_TYPE_NUMERIC); c.setCellValue(((Number) value).doubleValue()); - } else { + } else { String pattern = null; if (bandElement instanceof FieldBandElement) { FieldBandElement fbe = (FieldBandElement) bandElement; pattern = fbe.getPattern(); } - if ((value instanceof java.sql.Date) || (value instanceof java.sql.Timestamp)) { + if ((value instanceof java.sql.Date) || (value instanceof java.sql.Timestamp)) { Date date; - if (value instanceof java.sql.Date) { + if (value instanceof java.sql.Date) { date = new Date(((java.sql.Date)value).getTime()); } else { date = (java.sql.Timestamp)value; - } + } if (cellStyle != null) { if (pattern == null) { // use default pattern if none selected Locale locale = Locale.getDefault(); - pattern = ((SimpleDateFormat)DateFormat.getDateInstance(SimpleDateFormat.MEDIUM,locale)).toPattern(); + pattern = ((SimpleDateFormat)DateFormat.getDateInstance(SimpleDateFormat.MEDIUM,locale)).toPattern(); } else { pattern = StringUtil.getI18nString(pattern, getReportLanguage()); } cellStyle.setDataFormat(wb.createDataFormat().getFormat(pattern)); } c.setCellValue(date); - } else { - c.setCellType(XSSFCell.CELL_TYPE_STRING); - String text = StringUtil.getValueAsString(value, pattern); - if ((bandElement != null) && bandElement.isWrapText()) { + } else { + c.setCellType(XSSFCell.CELL_TYPE_STRING); + String text = StringUtil.getValueAsString(value, pattern); + if ((bandElement != null) && bandElement.isWrapText()) { // try to interpret new line characters // \\n is used here to be possible to add in designer grid cell with \n if (text.contains("\\n") || text.contains("\n") || text.contains("\r") || text.contains("\r\n")) { @@ -686,21 +700,21 @@ private void renderCell(BandElement bandElement, String bandName, Object value, } } else { c.setCellValue(wb.getCreationHelper().createRichTextString(text)); - } - - } + } + + } } } if (cellStyle != null) { - if (bandElement != null) { + if (bandElement != null) { cellStyle.setRotation(bandElement.getTextRotation()); - } + } if (!(bandElement instanceof ReportBandElement)) { c.setCellStyle(cellStyle); } } - + if ((rowSpan > 1) || (colSpan > 1)) { CellRangeAddress cra = new CellRangeAddress(sheetRow, sheetRow + rowSpan - 1, sheetColumn, sheetColumn + colSpan - 1); Border beBorder = bandElement.getBorder(); @@ -710,10 +724,10 @@ private void renderCell(BandElement bandElement, String bandName, Object value, } regions.add(new XlsxRegion(cra, beBorder)); } - + } } - + private int countLines(String text) { Matcher m = Pattern.compile("(\n)|(\r)|(\r\n)|(\\\\n)").matcher(text); int lines = 1; @@ -722,11 +736,11 @@ private int countLines(String text) { } return lines; } - + // http://poi.apache.org/apidocs/org/apache/poi/xssf/usermodel/extensions/XSSFHeaderFooter.html private void renderCellToHeaderFooter(StringBuilder result, String bandName, BandElement bandElement, Object value, int gridRow, int row, int column, int cols, int rowSpan, int colSpan, boolean isImage) { - + if (newRow) { result.append("\r\n "); } else { @@ -735,40 +749,40 @@ private void renderCellToHeaderFooter(StringBuilder result, String bandName, Ban boolean specialCell = false; if (bandElement instanceof VariableBandElement) { VariableBandElement vbe = (VariableBandElement)bandElement; - Variable var = VariableFactory.getVariable(vbe.getVariable()); - if (var instanceof PageNoVariable) { + Variable var = VariableFactory.getVariable(vbe.getVariable()); + if (var instanceof PageNoVariable) { specialCell = true; result.append("&P"); - } + } } else if (bandElement instanceof ExpressionBandElement) { // special case pageNo inside an expression // bandName is not important here (it is used for groupRow computation) PrefixSuffix pf = interpretPageNo(bandElement); if (pf != null) { - result.append(pf.getPrefix()).append(" &P ").append(pf.getSuffix()); + result.append(pf.getPrefix()).append(" &P ").append(pf.getSuffix()); specialCell = true; - } + } } if (!specialCell) { result.append(value); - } + } } - private short getXlsBorderValue(int border) { + private BorderStyle getXlsBorderValue(int border) { if (border == BORDER_THIN_VALUE) { - return XSSFCellStyle.BORDER_THIN; + return BorderStyle.THIN; } if (border == BORDER_MEDIUM_VALUE) { - return XSSFCellStyle.BORDER_MEDIUM; + return BorderStyle.MEDIUM; } if (border == BORDER_THICK_VALUE) { - return XSSFCellStyle.BORDER_THICK; + return BorderStyle.THICK; } - return 0; + return BorderStyle.NONE; } - private void addRegions(XSSFSheet xlsSheet, List regions, XSSFWorkbook wb ) { + private void addRegions(SXSSFSheet xlsSheet, List regions, SXSSFWorkbook wb ) { for (int r = 0, size = regions.size(); r < size; r++) { XlsxRegion xlsRegion = regions.get(r); CellRangeAddress region = xlsRegion.getCellRangeAddress(); @@ -777,29 +791,29 @@ private void addRegions(XSSFSheet xlsSheet, List regions, XSSFWorkb try { if (border != null) { - short xlsBottomBorder = getXlsBorderValue(border.getBottom()); - if (xlsBottomBorder > 0) { - RegionUtil.setBorderBottom(xlsBottomBorder, region, xlsSheet, wb); + BorderStyle xlsBottomBorder = getXlsBorderValue(border.getBottom()); + if (xlsBottomBorder!=BorderStyle.NONE) { + RegionUtil.setBorderBottom(xlsBottomBorder, region, xlsSheet); RegionUtil.setBottomBorderColor(ExcelColorSupport.getNearestColor(border.getBottomColor()), - region, xlsSheet, wb); + region, xlsSheet); } - short xlsTopBorder = getXlsBorderValue(border.getTop()); - if (xlsTopBorder > 0) { - RegionUtil.setBorderTop(xlsTopBorder,region, xlsSheet, wb); + BorderStyle xlsTopBorder = getXlsBorderValue(border.getTop()); + if (xlsTopBorder!=BorderStyle.NONE) { + RegionUtil.setBorderTop(xlsTopBorder,region, xlsSheet); RegionUtil.setTopBorderColor(ExcelColorSupport.getNearestColor(border.getTopColor()), - region, xlsSheet, wb); + region, xlsSheet); } - short xlsLeftBorder = getXlsBorderValue(border.getLeft()); - if (xlsLeftBorder > 0) { - RegionUtil.setBorderLeft(xlsLeftBorder, region, xlsSheet, wb); + BorderStyle xlsLeftBorder = getXlsBorderValue(border.getLeft()); + if (xlsLeftBorder!=BorderStyle.NONE) { + RegionUtil.setBorderLeft(xlsLeftBorder, region, xlsSheet); RegionUtil.setLeftBorderColor(ExcelColorSupport.getNearestColor(border.getLeftColor()), - region, xlsSheet, wb); + region, xlsSheet); } - short xlsRightBorder = getXlsBorderValue(border.getRight()); - if (xlsRightBorder > 0) { - RegionUtil.setBorderRight(xlsRightBorder, region, xlsSheet, wb); + BorderStyle xlsRightBorder = getXlsBorderValue(border.getRight()); + if (xlsRightBorder!=BorderStyle.NONE) { + RegionUtil.setBorderRight(xlsRightBorder, region, xlsSheet); RegionUtil.setRightBorderColor(ExcelColorSupport.getNearestColor(border.getRightColor()), - region, xlsSheet, wb); + region, xlsSheet); } } } catch (Throwable t) { @@ -1012,7 +1026,7 @@ private int getStyleKey(Map style, BandElement bandElement) { return hashCode; } - public XSSFSheet getSubreportSheet() { + public SXSSFSheet getSubreportSheet() { return xlsSheet; } diff --git a/src/ro/nextreports/engine/exporter/util/ExcelColorSupport.java b/src/ro/nextreports/engine/exporter/util/ExcelColorSupport.java index deb70f6..46d605b 100644 --- a/src/ro/nextreports/engine/exporter/util/ExcelColorSupport.java +++ b/src/ro/nextreports/engine/exporter/util/ExcelColorSupport.java @@ -19,6 +19,7 @@ import java.awt.Color; import java.util.Hashtable; import java.util.Iterator; +import java.util.Map; import org.apache.poi.hssf.util.HSSFColor; @@ -37,7 +38,7 @@ private ExcelColorSupport() { /** * the pre-defined excel color triplets. */ - private static Hashtable triplets; + private static Map triplets; /** diff --git a/src/ro/nextreports/engine/exporter/util/XlsxUtil.java b/src/ro/nextreports/engine/exporter/util/XlsxUtil.java index 0051bd7..0685aea 100644 --- a/src/ro/nextreports/engine/exporter/util/XlsxUtil.java +++ b/src/ro/nextreports/engine/exporter/util/XlsxUtil.java @@ -7,6 +7,9 @@ import org.apache.poi.ss.usermodel.CellStyle; import org.apache.poi.ss.util.CellRangeAddress; +import org.apache.poi.xssf.streaming.SXSSFCell; +import org.apache.poi.xssf.streaming.SXSSFRow; +import org.apache.poi.xssf.streaming.SXSSFSheet; import org.apache.poi.xssf.usermodel.XSSFCell; import org.apache.poi.xssf.usermodel.XSSFRow; import org.apache.poi.xssf.usermodel.XSSFSheet; @@ -25,7 +28,7 @@ private XlsxUtil() { * @param sheet the sheet that is copied * @return column number */ - public static int copyToSheet(XSSFSheet parentSheet, int parentSheetRow, int parentSheetColumn, XSSFSheet sheet) { + public static int copyToSheet(SXSSFSheet parentSheet, int parentSheetRow, int parentSheetColumn, SXSSFSheet sheet) { return copyToSheet(parentSheet, parentSheetRow, parentSheetColumn, sheet, true); } @@ -39,12 +42,12 @@ public static int copyToSheet(XSSFSheet parentSheet, int parentSheetRow, int par * @param copyStyle true to copy the style * @return column number */ - public static int copyToSheet(XSSFSheet parentSheet, int parentSheetRow, int parentSheetColumn, XSSFSheet sheet, boolean copyStyle) { + public static int copyToSheet(SXSSFSheet parentSheet, int parentSheetRow, int parentSheetColumn, SXSSFSheet sheet, boolean copyStyle) { int maxColumnNum = 0; Map styleMap = (copyStyle) ? new HashMap() : null; for (int i = sheet.getFirstRowNum(); i <= sheet.getLastRowNum(); i++) { - XSSFRow srcRow = sheet.getRow(i); - XSSFRow destRow; + SXSSFRow srcRow = sheet.getRow(i); + SXSSFRow destRow; // subreport is not the first cell in a row if ((parentSheetColumn > 0) && (i == sheet.getFirstRowNum())) { destRow = parentSheet.getRow(parentSheetRow); @@ -70,8 +73,7 @@ public static int copyToSheet(XSSFSheet parentSheet, int parentSheetRow, int par /** * Copy a row from a sheet to another sheet * - * - * @param srcSheet the sheet to copy + * @param srcSheet the sheet to copy * @param destSheet the sheet to copy into * @param parentSheetRow the row inside destSheet where we start to copy * @param parentSheetColumn the column inside destSheet where we start to copy @@ -80,17 +82,17 @@ public static int copyToSheet(XSSFSheet parentSheet, int parentSheetRow, int par * @param styleMap style map * */ - public static void copyRow(XSSFSheet srcSheet, XSSFSheet destSheet, int parentSheetRow, int parentSheetColumn, XSSFRow srcRow, XSSFRow destRow, - Map styleMap) { + public static void copyRow(SXSSFSheet srcSheet, SXSSFSheet destSheet, int parentSheetRow, int parentSheetColumn, SXSSFRow srcRow, SXSSFRow destRow, + Map styleMap) { // manage a list of merged zone in order to not insert two times a // merged zone Set mergedRegions = new TreeSet(); destRow.setHeight(srcRow.getHeight()); // pour chaque row for (int j = srcRow.getFirstCellNum(); j <= srcRow.getLastCellNum(); j++) { - XSSFCell oldCell = srcRow.getCell(j); // ancienne cell + SXSSFCell oldCell = srcRow.getCell(j); // ancienne cell if (oldCell != null) { - XSSFCell newCell = destRow.createCell(parentSheetColumn + j); + SXSSFCell newCell = destRow.createCell(parentSheetColumn + j); copyCell(oldCell, newCell, styleMap); CellRangeAddress mergedRegion = getMergedRegion(srcSheet, srcRow.getRowNum(), (short) oldCell.getColumnIndex()); @@ -115,12 +117,11 @@ public static void copyRow(XSSFSheet srcSheet, XSSFSheet destSheet, int parentSh /** * Copy a cell to another cell - * - * @param oldCell cell to be copied + * @param oldCell cell to be copied * @param newCell cell to be created * @param styleMap style map */ - public static void copyCell(XSSFCell oldCell, XSSFCell newCell, Map styleMap) { + public static void copyCell(SXSSFCell oldCell, SXSSFCell newCell, Map styleMap) { if (styleMap != null) { if (oldCell.getSheet().getWorkbook() == newCell.getSheet().getWorkbook()) { newCell.setCellStyle(oldCell.getCellStyle()); @@ -160,7 +161,7 @@ public static void copyCell(XSSFCell oldCell, XSSFCell newCell, Map