0

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

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

2 Answers2

0

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

  • Also, the question about opening a file using a native application in Node JS has already been asked here: https://stackoverflow.com/questions/17733849/launch-an-external-application-from-node-js – Polyakov Egor May 23 '22 at 11:16
0

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.

Lee Taylor
  • 7,761
  • 16
  • 33
  • 49
Moose
  • 86
  • 1
  • 5