From 931ede86205f90775ee770668dbfea6833027f12 Mon Sep 17 00:00:00 2001 From: hieplq Date: Sun, 5 Jul 2015 16:19:23 +0700 Subject: [PATCH] IDEMPIERE-2479:Printformat, Surpress Repeats doesnt works for HTML and XLS for xls + fix minus error --- .../impexp/AbstractExcelExporter.java | 21 +++++++++++++++++-- .../print/export/PrintDataExcelExporter.java | 7 +++---- .../src/org/compiere/print/ReportEngine.java | 6 +++--- 3 files changed, 25 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 3d5d0aafca..153dfe3c1c 100644 --- a/org.adempiere.base/src/org/adempiere/impexp/AbstractExcelExporter.java +++ b/org.adempiere.base/src/org/adempiere/impexp/AbstractExcelExporter.java @@ -131,6 +131,8 @@ public abstract class AbstractExcelExporter /** Styles cache */ private HashMap m_styles = new HashMap(); + protected boolean[] colSuppressRepeats; + public AbstractExcelExporter() { m_workbook = new HSSFWorkbook(); m_dataFormat = m_workbook.createDataFormat(); @@ -377,6 +379,12 @@ public abstract class AbstractExcelExporter int colnumMax = 0; int rownum = isCurrentRowOnly() ? getCurrentRow() : 0; int lastRowNum = isCurrentRowOnly() ? getCurrentRow()+1 : getRowCount(); + Object [] preValues = null; + int printColIndex = -1; + if (colSuppressRepeats != null){ + preValues = new Object [colSuppressRepeats.length]; + } + for (int xls_rownum = 1; rownum < lastRowNum; rownum++, xls_rownum++) { if (!isCurrentRowOnly()) @@ -384,6 +392,7 @@ public abstract class AbstractExcelExporter boolean isPageBreak = false; HSSFRow row = sheet.createRow(xls_rownum); + printColIndex = -1; // for all columns int colnum = 0; for (int col = 0; col < getColumnCount(); col++) @@ -393,13 +402,19 @@ public abstract class AbstractExcelExporter // if (isColumnPrinted(col)) { + printColIndex++; HSSFCell cell = row.createCell(colnum); // line row Object obj = getValueAt(rownum, col); int displayType = getDisplayType(rownum, col); - if (obj == null) - ; + if (obj == null){ + if (colSuppressRepeats != null && colSuppressRepeats[printColIndex]){ + preValues[printColIndex] = null; + } + }else if (colSuppressRepeats != null && colSuppressRepeats[printColIndex] && obj.equals(preValues[printColIndex])){ + //suppress + } else if (DisplayType.isDate(displayType)) { Timestamp value = (Timestamp)obj; cell.setCellValue(value); @@ -433,6 +448,8 @@ public abstract class AbstractExcelExporter } // colnum++; + if (colSuppressRepeats != null) + preValues[printColIndex] = obj; } // printed } // for all columns // 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 fb5415d7fb..742c44af61 100644 --- a/org.adempiere.base/src/org/adempiere/print/export/PrintDataExcelExporter.java +++ b/org.adempiere.base/src/org/adempiere/print/export/PrintDataExcelExporter.java @@ -38,11 +38,12 @@ extends AbstractExcelExporter { private PrintData m_printData; private MPrintFormat m_printFormat; - - public PrintDataExcelExporter(PrintData printData, MPrintFormat printFormat) { + + public PrintDataExcelExporter(PrintData printData, MPrintFormat printFormat, boolean[] colSuppressRepeats) { super(); this.m_printData = printData; this.m_printFormat = printFormat; + this.colSuppressRepeats = colSuppressRepeats; } @Override @@ -191,6 +192,4 @@ extends AbstractExcelExporter sheet.setMargin(HSSFSheet.BottomMargin, ((double)paper.getMarginBottom()) / 72); // } - - } diff --git a/org.adempiere.base/src/org/compiere/print/ReportEngine.java b/org.adempiere.base/src/org/compiere/print/ReportEngine.java index 9f15cb00cd..1b14b66f71 100644 --- a/org.adempiere.base/src/org/compiere/print/ReportEngine.java +++ b/org.adempiere.base/src/org/compiere/print/ReportEngine.java @@ -688,7 +688,7 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount) if (obj == null){ td.addElement(" "); if (m_layout.colSuppressRepeats[printColIndex]){ - preValues[col] = null; + preValues[printColIndex] = null; } } else if (obj instanceof PrintDataElement) @@ -931,7 +931,7 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount) String data = ""; if (obj == null){ if (m_layout.colSuppressRepeats[printColIndex]){ - preValues[col] = null; + preValues[printColIndex] = null; } } else if (obj instanceof PrintDataElement) @@ -1229,7 +1229,7 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount) public void createXLS(File outFile, Language language) throws Exception { - PrintDataExcelExporter exp = new PrintDataExcelExporter(getPrintData(), getPrintFormat()); + PrintDataExcelExporter exp = new PrintDataExcelExporter(getPrintData(), getPrintFormat(), m_layout.colSuppressRepeats); exp.export(outFile, language); }