IDEMPIERE-3995 Excel Export - Include Embedded Print Format
This commit is contained in:
parent
c573b240e9
commit
d3fd2e8547
|
@ -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;
|
||||
|
|
|
@ -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<MPrintFormatItem, PrintData> childPrintFormatDetails;
|
||||
private ArrayList<Object> 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<MPrintFormatItem, PrintData> childPrintFormatDetails, Boolean[] colSuppressRepeats) {
|
||||
this(printData, printFormat, childPrintFormatDetails, colSuppressRepeats, null);
|
||||
}
|
||||
|
||||
public PrintDataExcelExporter(PrintData printData, MPrintFormat printFormat, Map<MPrintFormatItem, PrintData> 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<Map.Entry<MPrintFormatItem,PrintData>> iter = childPrintFormatDetails.entrySet().iterator(); iter.hasNext();)
|
||||
{
|
||||
try {
|
||||
Map.Entry<MPrintFormatItem,PrintData> entry = (Map.Entry<MPrintFormatItem,PrintData>) 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()) {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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<MPrintFormatItem,PrintData> childPrintFormatDetails = new HashMap<MPrintFormatItem,PrintData>();
|
||||
|
||||
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<MPrintFormatItem, PrintData> getChildPrintFormatDetails()
|
||||
{
|
||||
return childPrintFormatDetails;
|
||||
}
|
||||
|
||||
public static Boolean [] getColSuppressRepeats (MPrintFormat format){
|
||||
if (format.isForm())
|
||||
return null;
|
||||
|
|
Loading…
Reference in New Issue