FR [ 1894640 ] Report Engine: Excel Export support
This commit is contained in:
parent
0c7d4e1056
commit
aea3de1fb0
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
* <li>FR [ 1762466 ] Add "Window" menu to report viewer.
|
||||
* <li>FR [ 1894640 ] Report Engine: Excel Export support
|
||||
*/
|
||||
public class Viewer extends CFrame
|
||||
implements ActionListener, ChangeListener, WindowStateListener
|
||||
|
@ -837,6 +839,7 @@ public class Viewer extends CFrame
|
|||
chooser.addChoosableFileFilter(new ExtensionFileFilter("txt", Msg.getMsg(m_ctx, "FileTXT")));
|
||||
chooser.addChoosableFileFilter(new ExtensionFileFilter("ssv", Msg.getMsg(m_ctx, "FileSSV")));
|
||||
chooser.addChoosableFileFilter(new ExtensionFileFilter("csv", Msg.getMsg(m_ctx, "FileCSV")));
|
||||
chooser.addChoosableFileFilter(new ExtensionFileFilter("xls", Msg.getMsg(m_ctx, "FileXLS")));
|
||||
//
|
||||
if (chooser.showSaveDialog(this) != JFileChooser.APPROVE_OPTION)
|
||||
return;
|
||||
|
@ -865,6 +868,7 @@ public class Viewer extends CFrame
|
|||
log.config( "File=" + outFile.getPath() + "; Type=" + ext);
|
||||
|
||||
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
|
||||
try {
|
||||
if (ext.equals("pdf"))
|
||||
m_reportEngine.createPDF(outFile);
|
||||
else if (ext.equals("ps"))
|
||||
|
@ -879,8 +883,16 @@ public class Viewer extends CFrame
|
|||
m_reportEngine.createCSV(outFile, '\t', m_reportEngine.getPrintFormat().getLanguage());
|
||||
else if (ext.equals("html") || ext.equals("htm"))
|
||||
m_reportEngine.createHTML(outFile, false, m_reportEngine.getPrintFormat().getLanguage());
|
||||
else if (ext.equals("xls"))
|
||||
m_reportEngine.createXLS(outFile, m_reportEngine.getPrintFormat().getLanguage());
|
||||
else
|
||||
ADialog.error(m_WindowNo, this, "FileInvalidExtension");
|
||||
}
|
||||
catch (Exception e) {
|
||||
ADialog.error(m_WindowNo, this, "Error", e.getLocalizedMessage());
|
||||
if (CLogMgt.isLevelFinest())
|
||||
e.printStackTrace();
|
||||
}
|
||||
cmd_drill(); // setCursor
|
||||
} // cmd_export
|
||||
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
-- 18.02.2008 12:02:24 EET
|
||||
-- FR [ 1894640 ] Report Engine: Excel Export support
|
||||
INSERT INTO AD_Message (AD_Client_ID,AD_Message_ID,AD_Org_ID,Created,CreatedBy,EntityType,IsActive,MsgText,MsgType,Updated,UpdatedBy,Value) VALUES (0,53026,0,TO_DATE('2008-02-18 12:02:11','YYYY-MM-DD HH24:MI:SS'),0,'D','Y','xls - Excel file','E',TO_DATE('2008-02-18 12:02:11','YYYY-MM-DD HH24:MI:SS'),0,'FileXLS')
|
||||
;
|
||||
|
||||
-- 18.02.2008 12:02:24 EET
|
||||
-- FR [ 1894640 ] Report Engine: Excel Export support
|
||||
INSERT INTO AD_Message_Trl (AD_Language,AD_Message_ID, MsgText,MsgTip, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy) SELECT l.AD_Language,t.AD_Message_ID, t.MsgText,t.MsgTip, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy FROM AD_Language l, AD_Message t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Message_ID=53026 AND EXISTS (SELECT * FROM AD_Message_Trl tt WHERE tt.AD_Language!=l.AD_Language OR tt.AD_Message_ID!=t.AD_Message_ID)
|
||||
;
|
|
@ -0,0 +1,10 @@
|
|||
-- 18.02.2008 12:02:24 EET
|
||||
-- FR [ 1894640 ] Report Engine: Excel Export support
|
||||
INSERT INTO AD_Message (AD_Client_ID,AD_Message_ID,AD_Org_ID,Created,CreatedBy,EntityType,IsActive,MsgText,MsgType,Updated,UpdatedBy,Value) VALUES (0,53026,0,TO_TIMESTAMP('2008-02-18 12:02:11','YYYY-MM-DD HH24:MI:SS'),0,'D','Y','xls - Excel file','E',TO_TIMESTAMP('2008-02-18 12:02:11','YYYY-MM-DD HH24:MI:SS'),0,'FileXLS')
|
||||
;
|
||||
|
||||
-- 18.02.2008 12:02:24 EET
|
||||
-- FR [ 1894640 ] Report Engine: Excel Export support
|
||||
INSERT INTO AD_Message_Trl (AD_Language,AD_Message_ID, MsgText,MsgTip, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy) SELECT l.AD_Language,t.AD_Message_ID, t.MsgText,t.MsgTip, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy FROM AD_Language l, AD_Message t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Message_ID=53026 AND EXISTS (SELECT * FROM AD_Message_Trl tt WHERE tt.AD_Language!=l.AD_Language OR tt.AD_Message_ID!=t.AD_Message_ID)
|
||||
;
|
||||
|
Loading…
Reference in New Issue