IDEMPIERE-2479:Printformat, Surpress Repeats doesnt works for HTML and XLS

for xls + fix minus error
This commit is contained in:
hieplq 2015-07-05 16:19:23 +07:00
parent 2d5d2b9858
commit 931ede8620
3 changed files with 25 additions and 9 deletions

View File

@ -131,6 +131,8 @@ public abstract class AbstractExcelExporter
/** Styles cache */ /** Styles cache */
private HashMap<String, HSSFCellStyle> m_styles = new HashMap<String, HSSFCellStyle>(); private HashMap<String, HSSFCellStyle> m_styles = new HashMap<String, HSSFCellStyle>();
protected boolean[] colSuppressRepeats;
public AbstractExcelExporter() { public AbstractExcelExporter() {
m_workbook = new HSSFWorkbook(); m_workbook = new HSSFWorkbook();
m_dataFormat = m_workbook.createDataFormat(); m_dataFormat = m_workbook.createDataFormat();
@ -377,6 +379,12 @@ public abstract class AbstractExcelExporter
int colnumMax = 0; int colnumMax = 0;
int rownum = isCurrentRowOnly() ? getCurrentRow() : 0; int rownum = isCurrentRowOnly() ? getCurrentRow() : 0;
int lastRowNum = isCurrentRowOnly() ? getCurrentRow()+1 : getRowCount(); 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++) for (int xls_rownum = 1; rownum < lastRowNum; rownum++, xls_rownum++)
{ {
if (!isCurrentRowOnly()) if (!isCurrentRowOnly())
@ -384,6 +392,7 @@ public abstract class AbstractExcelExporter
boolean isPageBreak = false; boolean isPageBreak = false;
HSSFRow row = sheet.createRow(xls_rownum); HSSFRow row = sheet.createRow(xls_rownum);
printColIndex = -1;
// for all columns // for all columns
int colnum = 0; int colnum = 0;
for (int col = 0; col < getColumnCount(); col++) for (int col = 0; col < getColumnCount(); col++)
@ -393,13 +402,19 @@ public abstract class AbstractExcelExporter
// //
if (isColumnPrinted(col)) if (isColumnPrinted(col))
{ {
printColIndex++;
HSSFCell cell = row.createCell(colnum); HSSFCell cell = row.createCell(colnum);
// line row // line row
Object obj = getValueAt(rownum, col); Object obj = getValueAt(rownum, col);
int displayType = getDisplayType(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)) { else if (DisplayType.isDate(displayType)) {
Timestamp value = (Timestamp)obj; Timestamp value = (Timestamp)obj;
cell.setCellValue(value); cell.setCellValue(value);
@ -433,6 +448,8 @@ public abstract class AbstractExcelExporter
} }
// //
colnum++; colnum++;
if (colSuppressRepeats != null)
preValues[printColIndex] = obj;
} // printed } // printed
} // for all columns } // for all columns
// //

View File

@ -39,10 +39,11 @@ extends AbstractExcelExporter
private PrintData m_printData; private PrintData m_printData;
private MPrintFormat m_printFormat; private MPrintFormat m_printFormat;
public PrintDataExcelExporter(PrintData printData, MPrintFormat printFormat) { public PrintDataExcelExporter(PrintData printData, MPrintFormat printFormat, boolean[] colSuppressRepeats) {
super(); super();
this.m_printData = printData; this.m_printData = printData;
this.m_printFormat = printFormat; this.m_printFormat = printFormat;
this.colSuppressRepeats = colSuppressRepeats;
} }
@Override @Override
@ -191,6 +192,4 @@ extends AbstractExcelExporter
sheet.setMargin(HSSFSheet.BottomMargin, ((double)paper.getMarginBottom()) / 72); sheet.setMargin(HSSFSheet.BottomMargin, ((double)paper.getMarginBottom()) / 72);
// //
} }
} }

View File

@ -688,7 +688,7 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount)
if (obj == null){ if (obj == null){
td.addElement("&nbsp;"); td.addElement("&nbsp;");
if (m_layout.colSuppressRepeats[printColIndex]){ if (m_layout.colSuppressRepeats[printColIndex]){
preValues[col] = null; preValues[printColIndex] = null;
} }
} }
else if (obj instanceof PrintDataElement) else if (obj instanceof PrintDataElement)
@ -931,7 +931,7 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount)
String data = ""; String data = "";
if (obj == null){ if (obj == null){
if (m_layout.colSuppressRepeats[printColIndex]){ if (m_layout.colSuppressRepeats[printColIndex]){
preValues[col] = null; preValues[printColIndex] = null;
} }
} }
else if (obj instanceof PrintDataElement) 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) public void createXLS(File outFile, Language language)
throws Exception throws Exception
{ {
PrintDataExcelExporter exp = new PrintDataExcelExporter(getPrintData(), getPrintFormat()); PrintDataExcelExporter exp = new PrintDataExcelExporter(getPrintData(), getPrintFormat(), m_layout.colSuppressRepeats);
exp.export(outFile, language); exp.export(outFile, language);
} }