IDEMPIERE-119 Implement Export to Excel For Account Viewer

(transplanted from 6161ebd761a2053efe0893368b6fe75c63855192)
This commit is contained in:
Heng Sin Low 2012-01-21 10:33:45 +08:00
parent 0c15934a46
commit 533e1c0a72
1 changed files with 35 additions and 15 deletions

View File

@ -17,6 +17,7 @@
package org.adempiere.webui.acct; package org.adempiere.webui.acct;
import java.io.File;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
@ -46,6 +47,7 @@ import org.compiere.model.MAcctSchemaElement;
import org.compiere.model.MColumn; import org.compiere.model.MColumn;
import org.compiere.model.X_C_AcctSchema_Element; import org.compiere.model.X_C_AcctSchema_Element;
import org.compiere.report.core.RModel; import org.compiere.report.core.RModel;
import org.compiere.report.core.RModelExcelExporter;
import org.compiere.util.CLogger; import org.compiere.util.CLogger;
import org.compiere.util.Env; import org.compiere.util.Env;
import org.compiere.util.Ini; import org.compiere.util.Ini;
@ -59,6 +61,7 @@ import org.zkoss.zkex.zul.Borderlayout;
import org.zkoss.zkex.zul.Center; import org.zkoss.zkex.zul.Center;
import org.zkoss.zkex.zul.South; import org.zkoss.zkex.zul.South;
import org.zkoss.zul.Caption; import org.zkoss.zul.Caption;
import org.zkoss.zul.Filedownload;
import org.zkoss.zul.Groupbox; import org.zkoss.zul.Groupbox;
import org.zkoss.zul.Hbox; import org.zkoss.zul.Hbox;
import org.zkoss.zul.Listhead; import org.zkoss.zul.Listhead;
@ -102,7 +105,7 @@ public class WAcctViewer extends Window implements EventListener
private Button selAcct = new Button(); private Button selAcct = new Button();
private Button bQuery = new Button(); private Button bQuery = new Button();
private Button bRePost = new Button(); private Button bRePost = new Button();
private Button bPrint = new Button(); private Button bExport = new Button();
private Button sel1 = new Button(); private Button sel1 = new Button();
private Button sel2 = new Button(); private Button sel2 = new Button();
private Button sel3 = new Button(); private Button sel3 = new Button();
@ -168,6 +171,8 @@ public class WAcctViewer extends Window implements EventListener
private Borderlayout resultPanel; private Borderlayout resultPanel;
private RModel m_rmodel;
/** Logger */ /** Logger */
private static CLogger log = CLogger.getCLogger(WAcctViewer.class); private static CLogger log = CLogger.getCLogger(WAcctViewer.class);
@ -491,16 +496,16 @@ public class WAcctViewer extends Window implements EventListener
bQuery.setTooltiptext(Msg.getMsg(Env.getCtx(), "Refresh")); bQuery.setTooltiptext(Msg.getMsg(Env.getCtx(), "Refresh"));
bQuery.addEventListener(Events.ON_CLICK, this); bQuery.addEventListener(Events.ON_CLICK, this);
bPrint.setImage("/images/Print16.png"); bExport.setImage("/images/Export16.png");
bPrint.setTooltiptext(Msg.getMsg(Env.getCtx(), "Print")); bExport.setTooltiptext(Msg.getMsg(Env.getCtx(), "Export"));
bPrint.addEventListener(Events.ON_CLICK, this); bExport.addEventListener(Events.ON_CLICK, this);
southPanel.setWidth("100%"); southPanel.setWidth("100%");
southPanel.setWidths("2%, 12%, 82%, 2%, 2%"); southPanel.setWidths("2%, 12%, 82%, 2%, 2%");
southPanel.appendChild(bRePost); southPanel.appendChild(bRePost);
southPanel.appendChild(forcePost); southPanel.appendChild(forcePost);
southPanel.appendChild(statusLine); southPanel.appendChild(statusLine);
southPanel.appendChild(bPrint); southPanel.appendChild(bExport);
southPanel.appendChild(bQuery); southPanel.appendChild(bQuery);
// Result Tab // Result Tab
@ -705,6 +710,7 @@ public class WAcctViewer extends Window implements EventListener
boolean visible = m_data.documentQuery && tabResult.isSelected(); boolean visible = m_data.documentQuery && tabResult.isSelected();
bRePost.setVisible(visible); bRePost.setVisible(visible);
bExport.setVisible(visible);
if (Ini.isPropertyBool(Ini.P_SHOW_ADVANCED)) if (Ini.isPropertyBool(Ini.P_SHOW_ADVANCED))
forcePost.setVisible(visible); forcePost.setVisible(visible);
@ -735,9 +741,8 @@ public class WAcctViewer extends Window implements EventListener
actionTable(); actionTable();
else if (source == bRePost) else if (source == bRePost)
actionRePost(); actionRePost();
else if (source == bPrint) else if (source == bExport)
;//PrintScreenPainter.printScreen(this); actionExport();
// InfoButtons
else if (source instanceof Button) else if (source instanceof Button)
actionButton((Button)source); actionButton((Button)source);
else if (source == paging) else if (source == paging)
@ -753,6 +758,21 @@ public class WAcctViewer extends Window implements EventListener
} }
} // onEvent } // onEvent
private void actionExport() {
if (m_rmodel != null && m_rmodel.getRowCount() > 0) {
RModelExcelExporter exporter = new RModelExcelExporter(m_rmodel);
File file;
try {
file = File.createTempFile(getTitle(), ".xsl");
exporter.export(file, Env.getLanguage(Env.getCtx()));
Filedownload.save(file, "application/vnd.ms-excel");
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
/** /**
* New Acct Schema * New Acct Schema
*/ */
@ -996,8 +1016,8 @@ public class WAcctViewer extends Window implements EventListener
// Set TableModel with Query // Set TableModel with Query
RModel rmodel = m_data.query(); m_rmodel = m_data.query();
m_queryData = rmodel.getRows(); m_queryData = m_rmodel.getRows();
List<ArrayList<Object>> list = null; List<ArrayList<Object>> list = null;
paging.setPageSize(PAGE_SIZE); paging.setPageSize(PAGE_SIZE);
if (m_queryData.size() > PAGE_SIZE) if (m_queryData.size() > PAGE_SIZE)
@ -1021,10 +1041,10 @@ public class WAcctViewer extends Window implements EventListener
Listhead listhead = new Listhead(); Listhead listhead = new Listhead();
listhead.setSizable(true); listhead.setSizable(true);
for (int i = 0; i < rmodel.getColumnCount(); i++) for (int i = 0; i < m_rmodel.getColumnCount(); i++)
{ {
Listheader listheader = new Listheader(rmodel.getColumnName(i)); Listheader listheader = new Listheader(m_rmodel.getColumnName(i));
listheader.setTooltiptext(rmodel.getColumnName(i)); listheader.setTooltiptext(m_rmodel.getColumnName(i));
listhead.appendChild(listheader); listhead.appendChild(listheader);
} }
@ -1039,9 +1059,9 @@ public class WAcctViewer extends Window implements EventListener
listhead.getChildren().clear(); listhead.getChildren().clear();
// add in new column header // add in new column header
for (int i = 0; i < rmodel.getColumnCount(); i++) for (int i = 0; i < m_rmodel.getColumnCount(); i++)
{ {
Listheader listheader = new Listheader(rmodel.getColumnName(i)); Listheader listheader = new Listheader(m_rmodel.getColumnName(i));
listhead.appendChild(listheader); listhead.appendChild(listheader);
} }
} }