IDEMPIERE-5394 Export to XLSX in Info Windows and Account Viewer (#1450)

* IDEMPIERE-5394 Export to XLSX in Info Windows and Account Viewer
This commit is contained in:
Carlos Ruiz 2022-08-24 03:33:12 +02:00 committed by GitHub
parent 360861e300
commit 2dab2d9882
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 38 additions and 13 deletions

View File

@ -13,14 +13,14 @@
*****************************************************************************/
package org.compiere.report.core;
import org.adempiere.impexp.AbstractExcelExporter;
import org.adempiere.impexp.AbstractXLSXExporter;
/**
* @author Teo Sarca, SC ARHIPAC SERVICE SRL
*
*/
public class RModelExcelExporter
extends AbstractExcelExporter
extends AbstractXLSXExporter
{
private RModel m_model = null;
private int m_currentRow = 0;

View File

@ -22,10 +22,13 @@ import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import org.adempiere.base.upload.IUploadService;
import org.adempiere.util.Callback;
import org.adempiere.webui.ClientInfo;
import org.adempiere.webui.Extensions;
import org.adempiere.webui.apps.AEnv;
import org.adempiere.webui.component.Button;
import org.adempiere.webui.component.Checkbox;
@ -55,6 +58,7 @@ import org.adempiere.webui.util.ZKUpdateUtil;
import org.adempiere.webui.window.Dialog;
import org.compiere.model.MAcctSchema;
import org.compiere.model.MAcctSchemaElement;
import org.compiere.model.MAuthorizationAccount;
import org.compiere.model.MColumn;
import org.compiere.model.MFactAcct;
import org.compiere.model.MPeriod;
@ -69,6 +73,10 @@ import org.compiere.util.KeyNamePair;
import org.compiere.util.Msg;
import org.compiere.util.Util;
import org.compiere.util.ValueNamePair;
import org.idempiere.ui.zk.media.IMediaView;
import org.idempiere.ui.zk.media.Medias;
import org.idempiere.ui.zk.media.WMediaOptions;
import org.zkoss.util.media.AMedia;
import org.zkoss.zk.ui.Page;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.EventListener;
@ -799,9 +807,26 @@ public class WAcctViewer extends Window implements EventListener<Event>
RModelExcelExporter exporter = new RModelExcelExporter(m_rmodel);
File file;
try {
file = new File(FileUtil.getTempMailName(Msg.getMsg(Env.getCtx(), TITLE), ".xls"));
file = new File(FileUtil.getTempMailName(Msg.getMsg(Env.getCtx(), TITLE), ".xlsx"));
exporter.export(file, Env.getLanguage(Env.getCtx()));
Filedownload.save(file, "application/vnd.ms-excel");
AMedia media = new AMedia(file.getName(), null, Medias.EXCEL_XML_MIME_TYPE, file, true);
IMediaView view = Extensions.getMediaView(Medias.EXCEL_XML_MIME_TYPE, Medias.EXCEL_XML_FILE_EXT, ClientInfo.isMobile());
Map<MAuthorizationAccount, IUploadService> uploadServicesMap = MAuthorizationAccount.getUserUploadServices();
if (view != null || uploadServicesMap.size() > 0) {
WMediaOptions options = new WMediaOptions(media, view != null ? () -> {
Window viewWindow = new Window();
viewWindow.setWidth("100%");
viewWindow.setHeight("100%");
viewWindow.setTitle(media.getName());
viewWindow.setAttribute(Window.MODE_KEY, Mode.EMBEDDED);
AEnv.showWindow(viewWindow);
view.renderMediaView(viewWindow, media, false);
} : null, uploadServicesMap);
options.setPage(getPage());
options.doHighlighted();
} else {
Filedownload.save(file, Medias.EXCEL_XML_MIME_TYPE);
}
} catch (Exception e) {
throw new RuntimeException(e);
}

View File

@ -19,7 +19,7 @@ import java.util.logging.Level;
import org.adempiere.base.upload.IUploadService;
import org.adempiere.exceptions.AdempiereException;
import org.adempiere.impexp.AbstractExcelExporter;
import org.adempiere.impexp.AbstractXLSXExporter;
import org.adempiere.model.IInfoColumn;
import org.adempiere.model.MInfoProcess;
import org.adempiere.model.MInfoRelated;
@ -2612,7 +2612,7 @@ public class InfoWindow extends InfoPanel implements ValueChangeListener, EventL
exportButton = ButtonFactory.createNamedButton("Export", false, true);
exportButton.setId("Export");
exportButton.setEnabled(false);
exportButton.addEventListener(Events.ON_CLICK, new XlsExportAction());
exportButton.addEventListener(Events.ON_CLICK, new XlsxExportAction());
confirmPanel.addComponentsLeft(exportButton);
}
@ -2651,21 +2651,21 @@ public class InfoWindow extends InfoPanel implements ValueChangeListener, EventL
return -1;
}
private class XlsExportAction implements EventListener<Event>
private class XlsxExportAction implements EventListener<Event>
{
@Override
public void onEvent(Event evt) throws Exception
{
if(evt.getTarget() == exportButton)
{
XlsExporter exporter = new XlsExporter();
XlsxExporter exporter = new XlsxExporter();
exporter.doExport();
}
}
}
private class XlsExporter extends AbstractExcelExporter
private class XlsxExporter extends AbstractXLSXExporter
{
private ResultSet m_rs = null;
private int rowCount = -1;
@ -2677,7 +2677,7 @@ public class InfoWindow extends InfoPanel implements ValueChangeListener, EventL
String dataSql = buildDataSQL(0, 0);
File file = File.createTempFile(infoWindow.get_Translation("Name")+"_", ".xls");
File file = File.createTempFile(infoWindow.get_Translation("Name")+"_", ".xlsx");
testCount();
@ -2693,7 +2693,7 @@ public class InfoWindow extends InfoPanel implements ValueChangeListener, EventL
{
String trxName = Trx.createTrxName("InfoPanelLoad:");
trx = Trx.get(trxName, true);
trx.setDisplayName(getClass().getName()+"_exportXls");
trx.setDisplayName(getClass().getName()+"_exportXlsx");
pstmt = DB.prepareStatement(dataSql, trxName);
setParameters (pstmt, false); // no count
@ -2715,8 +2715,8 @@ public class InfoWindow extends InfoPanel implements ValueChangeListener, EventL
currentRow = -1;
}
AMedia media = new AMedia(file.getName(), null, Medias.EXCEL_MIME_TYPE, file, true);
IMediaView view = Extensions.getMediaView(Medias.EXCEL_MIME_TYPE, Medias.EXCEL_FILE_EXT, ClientInfo.isMobile());
AMedia media = new AMedia(file.getName(), null, Medias.EXCEL_XML_MIME_TYPE, file, true);
IMediaView view = Extensions.getMediaView(Medias.EXCEL_XML_MIME_TYPE, Medias.EXCEL_XML_FILE_EXT, ClientInfo.isMobile());
Map<MAuthorizationAccount, IUploadService> uploadServicesMap = MAuthorizationAccount.getUserUploadServices();
if (view != null || uploadServicesMap.size() > 0) {
WMediaOptions options = new WMediaOptions(media, view != null ? () -> {