From 6434e17bcad133d7ec76e48caa07c336b7daeaea Mon Sep 17 00:00:00 2001 From: Diego Ruiz Date: Wed, 17 Oct 2018 17:48:00 +0200 Subject: [PATCH] IDEMPIERE-3804 - Reports exported to Excel don't use Print Format Item -> Format Pattern --- .../impexp/AbstractExcelExporter.java | 27 ++++++++++++------- .../print/export/PrintDataExcelExporter.java | 22 +++++++++++++++ 2 files changed, 40 insertions(+), 9 deletions(-) diff --git a/org.adempiere.base/src/org/adempiere/impexp/AbstractExcelExporter.java b/org.adempiere.base/src/org/adempiere/impexp/AbstractExcelExporter.java index db5d908eb9..886ab170e1 100644 --- a/org.adempiere.base/src/org/adempiere/impexp/AbstractExcelExporter.java +++ b/org.adempiere.base/src/org/adempiere/impexp/AbstractExcelExporter.java @@ -228,7 +228,6 @@ public abstract class AbstractExcelExporter String key = "cell-"+col+"-"+displayType; HSSFCellStyle cs = m_styles.get(key); if (cs == null) { - boolean isHighlightNegativeNumbers = true; cs = m_workbook.createCellStyle(); HSSFFont font = getFont(false); cs.setFont(font); @@ -238,18 +237,28 @@ public abstract class AbstractExcelExporter cs.setBorderRight((short)1); cs.setBorderBottom((short)1); // - if (DisplayType.isDate(displayType)) { - cs.setDataFormat(m_dataFormat.getFormat(DisplayType.getDateFormat(getLanguage()).toPattern())); - } - else if (DisplayType.isNumeric(displayType)) { - DecimalFormat df = DisplayType.getNumberFormat(displayType, getLanguage()); - String format = getFormatString(df, isHighlightNegativeNumbers); - cs.setDataFormat(m_dataFormat.getFormat(format)); - } + String cellFormat = getCellFormat(row, col); + if (cellFormat != null) + cs.setDataFormat(m_dataFormat.getFormat(cellFormat)); m_styles.put(key, cs); } return cs; } + + protected String getCellFormat(int row, int col) { + boolean isHighlightNegativeNumbers = true; + int displayType = getDisplayType(row, col); + String cellFormat = null; + + if (DisplayType.isDate(displayType)) { + cellFormat = DisplayType.getDateFormat(getLanguage()).toPattern(); + } else if (DisplayType.isNumeric(displayType)) { + DecimalFormat df = DisplayType.getNumberFormat(displayType, getLanguage()); + cellFormat = getFormatString(df, isHighlightNegativeNumbers); + } + + return cellFormat; + } private HSSFCellStyle getHeaderStyle(int col) { diff --git a/org.adempiere.base/src/org/adempiere/print/export/PrintDataExcelExporter.java b/org.adempiere.base/src/org/adempiere/print/export/PrintDataExcelExporter.java index c77de78b27..0dc8e4affe 100644 --- a/org.adempiere.base/src/org/adempiere/print/export/PrintDataExcelExporter.java +++ b/org.adempiere.base/src/org/adempiere/print/export/PrintDataExcelExporter.java @@ -26,6 +26,8 @@ import org.compiere.print.MPrintFormatItem; import org.compiere.print.MPrintPaper; import org.compiere.print.PrintData; import org.compiere.print.PrintDataElement; +import org.compiere.util.DisplayType; +import org.compiere.util.Util; /** * Export PrintData to Excel (XLS) file @@ -192,4 +194,24 @@ extends AbstractExcelExporter sheet.setMargin(HSSFSheet.BottomMargin, ((double)paper.getMarginBottom()) / 72); // } + + @Override + protected String getCellFormat(int row, int col) { + String cellFormat = null; + PrintDataElement pde = getPDE(row, col); + + if (pde != null && !Util.isEmpty(pde.getM_formatPattern())) { + String formatPattern = pde.getM_formatPattern(); + int displayType = pde.getDisplayType(); + if (DisplayType.isDate(displayType)) { + cellFormat = DisplayType.getDateFormat(displayType, getLanguage(), formatPattern).toPattern(); + } else if (DisplayType.isNumeric(displayType)) { + cellFormat = DisplayType.getNumberFormat(displayType, getLanguage(), formatPattern).toPattern(); + } + } else { + return super.getCellFormat(row, col); + } + + return cellFormat; + } }