Home > Blockchain >  JavaScript to Open Excel
JavaScript to Open Excel

Time:05-23

Is there a way of opening an excel file using JavaScript.

The file should open in a native application (eg Excel) or Excel online

CodePudding user response:

There's no way if we're talking about browser.

If you want to open a file using Node JS, you can do it like this:

const { exec } = require('node:child_process');
exec("document.docx");

Full documentation can be found here: https://nodejs.org/api/child_process.html#child_processexeccommand-options-callback

CodePudding user response:

Browsers do not allow you to open a local file on a person's computer unless the user specifically selects which file to open.

Thus if the file is hosted on your webserver, the user would have to download the file.

If the user already has the file on their system, you could provide the functionality to have them select the file and then open it using the default program (as defined by the operating system) they have installed.

There is a web worker object called FileReader which can be used for that.

  • Related