From 2dab2d988235dac81e78132f06b371626922a0b5 Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Wed, 24 Aug 2022 03:33:12 +0200 Subject: [PATCH] IDEMPIERE-5394 Export to XLSX in Info Windows and Account Viewer (#1450) * IDEMPIERE-5394 Export to XLSX in Info Windows and Account Viewer --- .../report/core/RModelExcelExporter.java | 4 +-- .../org/adempiere/webui/acct/WAcctViewer.java | 29 +++++++++++++++++-- .../org/adempiere/webui/info/InfoWindow.java | 18 ++++++------ 3 files changed, 38 insertions(+), 13 deletions(-) diff --git a/org.adempiere.base/src/org/compiere/report/core/RModelExcelExporter.java b/org.adempiere.base/src/org/compiere/report/core/RModelExcelExporter.java index ed98d126df..3519cfad0f 100644 --- a/org.adempiere.base/src/org/compiere/report/core/RModelExcelExporter.java +++ b/org.adempiere.base/src/org/compiere/report/core/RModelExcelExporter.java @@ -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; diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/acct/WAcctViewer.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/acct/WAcctViewer.java index 94772f2f01..23b7c8ec90 100755 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/acct/WAcctViewer.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/acct/WAcctViewer.java @@ -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 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 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); } diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/info/InfoWindow.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/info/InfoWindow.java index 12378d42aa..bb39808d45 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/info/InfoWindow.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/info/InfoWindow.java @@ -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 + private class XlsxExportAction implements EventListener { @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 uploadServicesMap = MAuthorizationAccount.getUserUploadServices(); if (view != null || uploadServicesMap.size() > 0) { WMediaOptions options = new WMediaOptions(media, view != null ? () -> {