diff --git a/org.adempiere.base/src/org/adempiere/impexp/AbstractExcelExporter.java b/org.adempiere.base/src/org/adempiere/impexp/AbstractExcelExporter.java index 692fcc68e5..216af59df6 100644 --- a/org.adempiere.base/src/org/adempiere/impexp/AbstractExcelExporter.java +++ b/org.adempiere.base/src/org/adempiere/impexp/AbstractExcelExporter.java @@ -125,7 +125,7 @@ public abstract class AbstractExcelExporter private HSSFDataFormat m_dataFormat; private HSSFFont m_fontHeader = null; private HSSFFont m_fontDefault = null; - private Language m_lang = null; + protected Language m_lang = null; private int m_sheetCount = 0; // private int m_colSplit = 1; @@ -415,8 +415,7 @@ public abstract class AbstractExcelExporter * @param out * @throws Exception */ - private void export(OutputStream out) - throws Exception + protected void export(OutputStream out) throws Exception { HSSFSheet sheet= createTableSheet(); String sheetName = null; 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 9a9bbb3fd5..43e703b164 100644 --- a/org.adempiere.base/src/org/adempiere/print/export/PrintDataExcelExporter.java +++ b/org.adempiere.base/src/org/adempiere/print/export/PrintDataExcelExporter.java @@ -13,8 +13,13 @@ *****************************************************************************/ package org.adempiere.print.export; +import java.io.OutputStream; import java.sql.Timestamp; +import java.util.ArrayList; import java.util.Date; +import java.util.Iterator; +import java.util.Map; +import java.util.logging.Level; import javax.print.attribute.standard.MediaSizeName; @@ -47,30 +52,37 @@ extends AbstractExcelExporter { private PrintData m_printData; private MPrintFormat m_printFormat; + private Map childPrintFormatDetails; + private ArrayList columns; private MQuery m_query; - public PrintDataExcelExporter(PrintData printData, MPrintFormat printFormat, Boolean[] colSuppressRepeats) { - this(printData, printFormat, colSuppressRepeats, null); + public PrintDataExcelExporter(PrintData printData, MPrintFormat printFormat) { + this(printData, printFormat, null, null); } - public PrintDataExcelExporter(PrintData printData, MPrintFormat printFormat, Boolean[] colSuppressRepeats, MQuery query) { + public PrintDataExcelExporter(PrintData printData, MPrintFormat printFormat, Map childPrintFormatDetails, Boolean[] colSuppressRepeats) { + this(printData, printFormat, childPrintFormatDetails, colSuppressRepeats, null); + } + + public PrintDataExcelExporter(PrintData printData, MPrintFormat printFormat, Map childPrintFormatDetails, Boolean[] colSuppressRepeats, MQuery query) { super(); this.m_printData = printData; this.m_printFormat = printFormat; + this.childPrintFormatDetails = childPrintFormatDetails; this.colSuppressRepeats = colSuppressRepeats; this.m_query = query; } @Override public int getColumnCount() { - return m_printFormat.getItemCount(); + return columns.size(); } private PrintDataElement getPDE(int row, int col) { if (m_printData.getRowIndex() != row) m_printData.setRowIndex(row); // - MPrintFormatItem item = m_printFormat.getItem(col); + MPrintFormatItem item = (MPrintFormatItem) columns.get(col); Object obj = null; if (item.isTypeField() || item.isTypePrintFormat() && item.isImageField()) { @@ -123,12 +135,50 @@ extends AbstractExcelExporter value = pde.getValueDisplay(getLanguage()); } // + MPrintFormatItem item = null; + Object colObj = columns.get(col); + if (colObj instanceof MPrintFormatItem) + item = (MPrintFormatItem) colObj; + if(item != null && item.getAD_PrintFormatChild_ID()!=0) + { + MPrintFormat mPrintFormat = null; + + if(childPrintFormatDetails!=null) + { + for (Iterator> iter = childPrintFormatDetails.entrySet().iterator(); iter.hasNext();) + { + try { + Map.Entry entry = (Map.Entry) iter.next(); + MPrintFormatItem mPrintFormatItem = (MPrintFormatItem)entry.getKey(); + if (mPrintFormatItem.equals(item)) + { + mPrintFormat = new MPrintFormat(getCtx(), mPrintFormatItem.getAD_PrintFormatChild_ID(), null); + PrintData printData = (PrintData)entry.getValue(); + PrintDataExcelExporter exp =new PrintDataExcelExporter(printData, mPrintFormat); + exp.exportToWorkbook(m_workbook, m_lang); + break; + } + } + catch(Exception ex) + { + log.log(Level.WARNING, ex.getMessage(), ex); + break; + } + } + } + } return value; } @Override public String getHeaderName(int col) { - return m_printFormat.getItem(col).getPrintName(getLanguage()); + Object colObj = columns.get(col); + if (colObj instanceof MPrintFormatItem) { + MPrintFormatItem item = (MPrintFormatItem) colObj; + return item.getPrintName(getLanguage()); + } else { + return ""; + } } @Override @@ -138,8 +188,10 @@ extends AbstractExcelExporter @Override public boolean isColumnPrinted(int col) { - MPrintFormatItem item = m_printFormat.getItem(col); - return item.isPrinted(); + if (columns != null && col < columns.size()) + return true; + else + return false; } @Override @@ -232,6 +284,21 @@ extends AbstractExcelExporter return cellFormat; } + @Override + protected void export(OutputStream out) throws Exception { + columns = new ArrayList<>(); + for (int col = 0; col < m_printFormat.getItemCount(); col++) + { + MPrintFormatItem item = m_printFormat.getItem(col); + if (item.isPrinted()) + { + columns.add(item); + } + } + + super.export(out); + } + @Override protected void createParameter(HSSFSheet sheet) { if (!m_printFormat.isForm()) { diff --git a/org.adempiere.base/src/org/compiere/print/ReportEngine.java b/org.adempiere.base/src/org/compiere/print/ReportEngine.java index 596009bedd..0685841841 100644 --- a/org.adempiere.base/src/org/compiere/print/ReportEngine.java +++ b/org.adempiere.base/src/org/compiere/print/ReportEngine.java @@ -1470,7 +1470,7 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount) throws Exception { Boolean [] colSuppressRepeats = m_layout == null || m_layout.colSuppressRepeats == null? LayoutEngine.getColSuppressRepeats(m_printFormat):m_layout.colSuppressRepeats; - PrintDataExcelExporter exp = new PrintDataExcelExporter(getPrintData(), getPrintFormat(), colSuppressRepeats, m_query); + PrintDataExcelExporter exp = new PrintDataExcelExporter(getPrintData(), getPrintFormat(), m_layout.getChildPrintFormatDetails(), colSuppressRepeats, m_query); exp.export(outFile, language); } diff --git a/org.adempiere.base/src/org/compiere/print/layout/LayoutEngine.java b/org.adempiere.base/src/org/compiere/print/layout/LayoutEngine.java index 69916c91e2..7fe01d5aff 100644 --- a/org.adempiere.base/src/org/compiere/print/layout/LayoutEngine.java +++ b/org.adempiere.base/src/org/compiere/print/layout/LayoutEngine.java @@ -41,6 +41,7 @@ import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Properties; import java.util.logging.Level; @@ -226,6 +227,8 @@ public class LayoutEngine implements Pageable, Printable, Doc /** Image Size */ public static Dimension IMAGE_SIZE = new Dimension(10,10); + private Map childPrintFormatDetails = new HashMap(); + public Boolean[] colSuppressRepeats; static { @@ -1279,6 +1282,7 @@ public class LayoutEngine implements Pageable, Printable, Doc return null; if (log.isLoggable(Level.FINE)) log.fine(includedData.toString()); + setChildPrintFormatDetails(item, includedData); //map printdata and printformat item // element = layoutTable (format, includedData, item.getXSpace()); // handle multi page tables @@ -1980,6 +1984,16 @@ public class LayoutEngine implements Pageable, Printable, Doc return m_PrintInfo; } + public void setChildPrintFormatDetails(MPrintFormatItem printFormatItem, PrintData printData) + { + childPrintFormatDetails.put(printFormatItem, printData); + } + + public Map getChildPrintFormatDetails() + { + return childPrintFormatDetails; + } + public static Boolean [] getColSuppressRepeats (MPrintFormat format){ if (format.isForm()) return null;