diff --git a/base/src/org/adempiere/print/export/PrintDataExcelExporter.java b/base/src/org/adempiere/print/export/PrintDataExcelExporter.java new file mode 100644 index 0000000000..687f74b867 --- /dev/null +++ b/base/src/org/adempiere/print/export/PrintDataExcelExporter.java @@ -0,0 +1,128 @@ +/****************************************************************************** + * Product: Adempiere ERP & CRM Smart Business Solution * + * Copyright (C) 2008 SC ARHIPAC SERVICE SRL. All Rights Reserved. * + * This program is free software; you can redistribute it and/or modify it * + * under the terms version 2 of the GNU General Public License as published * + * by the Free Software Foundation. This program is distributed in the hope * + * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * + * See the GNU General Public License for more details. * + * You should have received a copy of the GNU General Public License along * + * with this program; if not, write to the Free Software Foundation, Inc., * + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * + *****************************************************************************/ +package org.adempiere.print.export; + +import java.sql.Timestamp; + +import org.adempiere.impexp.AbstractExcelExporter; +import org.compiere.print.MPrintFormat; +import org.compiere.print.MPrintFormatItem; +import org.compiere.print.PrintData; +import org.compiere.print.PrintDataElement; + +/** + * Export PrintData to Excel (XLS) file + * @author Teo Sarca, SC ARHIPAC SERVICE SRL + */ +public class PrintDataExcelExporter +extends AbstractExcelExporter +{ + private PrintData m_printData; + private MPrintFormat m_printFormat; + + public PrintDataExcelExporter(PrintData printData, MPrintFormat printFormat) { + super(); + this.m_printData = printData; + this.m_printFormat = printFormat; + } + + @Override + protected int getColumnCount() { + return m_printFormat.getItemCount(); + } + + private PrintDataElement getPDE(int row, int col) { + if (m_printData.getRowIndex() != row) + m_printData.setRowIndex(row); + // + MPrintFormatItem item = m_printFormat.getItem(col); + int AD_Column_ID = item.getAD_Column_ID(); + Object obj = null; + if (AD_Column_ID > 0) + obj = m_printData.getNode(Integer.valueOf(AD_Column_ID)); + if (obj != null && obj instanceof PrintDataElement) { + return (PrintDataElement)obj; + } + return null; + } + @Override + protected int getDisplayType(int row, int col) { + PrintDataElement pde = getPDE(row, col); + if (pde != null) { + return pde.getDisplayType(); + } + return -1; + // + } + + @Override + protected Object getValueAt(int row, int col) { + PrintDataElement pde = getPDE(row, col); + Object value = null; + if (pde == null) + ; + else if (pde.isDate()) { + value = (Timestamp)pde.getValue(); + } + else if (pde.isNumeric()) { + Object o = pde.getValue(); + if (o instanceof Number) { + value = ((Number)o).doubleValue(); + } + } + else if (pde.isYesNo()) { + value = pde.getValue(); + } + else if (pde.isPKey()) { + value = pde.getValueAsString(); + } + else { + value = pde.getValueDisplay(getLanguage()); + } + // + return value; + } + + @Override + protected String getHeaderName(int col) { + return m_printFormat.getItem(col).getPrintName(getLanguage()); + } + + @Override + protected int getRowCount() { + return m_printData.getRowCount(); + } + + @Override + protected boolean isColumnPrinted(int col) { + MPrintFormatItem item = m_printFormat.getItem(col); + return item.isPrinted(); + } + + @Override + protected boolean isPageBreak(int row, int col) { + PrintDataElement pde = getPDE(row, col); + return pde != null ? pde.isPageBreak() : false; + } + + @Override + protected void setCurrentRow(int row) { + m_printData.setRowIndex(row); + } + + @Override + protected boolean isFunctionRow() { + return m_printData.isFunctionRow(); + } +} diff --git a/base/src/org/compiere/print/ReportEngine.java b/base/src/org/compiere/print/ReportEngine.java index a9cc426b0d..89c4a3f87b 100644 --- a/base/src/org/compiere/print/ReportEngine.java +++ b/base/src/org/compiere/print/ReportEngine.java @@ -30,6 +30,7 @@ import javax.xml.transform.stream.*; import org.apache.ecs.*; import org.apache.ecs.xhtml.*; import org.compiere.model.*; +import org.adempiere.print.export.PrintDataExcelExporter; import org.compiere.print.layout.*; import org.compiere.process.*; import org.compiere.util.*; @@ -837,6 +838,18 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount) return false; } // createPS + /** + * Create Excel file + * @param outFile output file + * @param language + * @throws Exception if error + */ + public void createXLS(File outFile, Language language) + throws Exception + { + PrintDataExcelExporter exp = new PrintDataExcelExporter(getPrintData(), getPrintFormat()); + exp.export(outFile, language); + } /************************************************************************** * Get Report Engine for process info diff --git a/client/src/org/compiere/print/Viewer.java b/client/src/org/compiere/print/Viewer.java index 93413ed989..9e00ec864b 100644 --- a/client/src/org/compiere/print/Viewer.java +++ b/client/src/org/compiere/print/Viewer.java @@ -44,7 +44,9 @@ import org.adempiere.pdf.*; * Colin Rooney 2007/03/20 RFE#1670185 & BUG#1684142 * Extend security to Info queries * - * @author Teo Sarca, SC ARHIPAC SERVICE SRL - FR [ 1762466 ] + * @author Teo Sarca, SC ARHIPAC SERVICE SRL + *