Search code examples
javascriptreactjselectronxlsx

XLSX package Download as Excel in Desktop App


I am developing a desktop app which is an Electron js App.I am having a problem with exporting excel file using xlsx package. It works properly (i can download the file and it shows in project directory folder) however, the app doesn't show directory or not giving any alerts like in google chrome because its a desktop app. So client can't understand the export button works or not. What are your solution suggestions for this situation?

Code Example:

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');

        }
    }

Solution

  • While Electron doesn't provide the same download indicators/management UI as a full browser, it does have an API that you can use to create your own: 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 to handle some of the user-facing indicators.