XLSX 包在桌面应用程序中下载为 Excel

XLSX package Download as Excel in Desktop App

我正在开发一个桌面应用程序,它是一个 Electron js App.I 我在使用 xlsx 包导出 excel 文件时遇到问题。它工作正常(我可以下载文件并显示在项目目录文件夹中)但是,该应用程序不显示目录或不提供任何警报,如 google chrome 因为它是桌面应用程序。所以客户无法理解导出按钮是否有效。对于这种情况,您有什么解决建议?

代码示例:

function exportReport(e){
        e.preventDefault();
        let ws_name = "MySheet";
        if(!Lodash.isEmpty(props.dataSource)){
            let ws = XLSX.utils.json_to_sheet(props.dataSource);
            console.log(ws)
            let wb = XLSX.utils.book_new();
            XLSX.utils.book_append_sheet(wb, ws, ws_name);
            XLSX.writeFile(wb, 'out.xlsx');

        }
    }

虽然 Electron 不提供与完整浏览器相同的下载 indicators/management UI,但它确实有一个 API,您可以使用它来创建自己的:https://www.electronjs.org/docs/api/download-item. The first code snippet in that link gives a good example of how to register callbacks for when a download starts, makes progress, and terminates. This has to run in the main process of your Electron app, but you can use IPC to send the updates to your webpage if you want to embed a progress indicator in the page. Alternatively, you can create your own progress dialog window directly from the main process or rely on libraries such as https://www.npmjs.com/package/electron-progressbar or https://www.npmjs.com/package/electron-dl 来处理一些面向用户的指标。