-1

I have a csv file and I want to open it (in excel) with plain javascript.

I've searched a lot of websites and none of them seem to have the answer.

ANSWER

const { exec } = require('child_process');
exec('start ./csv/Fixture.csv', (err, stdout, stderr) => {});
G.Cunha
  • 1
  • 2
  • 1
    `open it (in excel) with plain javascript` can you clarify this nonsensical statement - did you want to use node.js to open a selected csv file in excel? you'll want to use something in [child_process](https://nodejs.org/api/child_process.html) - the answer coming from stackoverflow, so not sure how you missed it https://stackoverflow.com/questions/5775088/how-to-execute-an-external-program-from-within-node-js – Jaromanda X Feb 03 '20 at 00:04
  • You want your code in a browser to run a local application on a user's machine? – tshimkus Feb 03 '20 at 00:13
  • I mentioned "plain javascript" because every website was posting about using javascript on a browser – G.Cunha Feb 03 '20 at 00:25
  • @G.Cunha I just noticed your edit with a solution. It's perfectly acceptable in Stack Overflow to write both a question and an answer with it. However, you should post the answer as an actual answer, so (among other reasons) it can be voted up and down as other answers. – Pac0 Feb 03 '20 at 00:32

2 Answers2

1

You will need to use node.js or some sort of server to deliver the payload or the csv file to a JavaScript buffer such as via a websocket. Client side browser JS is a sandbox and you need to get your data from the server, or use node.js server to write javascript that runs on the server and can access files, but I think you mean you want to access a csv file on a webpage, and to do that you would need to have server side code send it to you, by using a XHR or WebSocket transfer.

Motes
  • 3,540
  • 1
  • 23
  • 22
  • This is an app that runs locally – G.Cunha Feb 03 '20 at 00:19
  • What is your JS engine? Not stating that is probably why you got downvoted, if it is node.js, use child_process as suggested in comment on main question. – Motes Feb 03 '20 at 00:21
  • https://stackoverflow.com/questions/17733849/launch-an-external-application-from-node-js – Motes Feb 03 '20 at 00:25
0

Use the new HTML anchor tag attribute, for example:

<a href="abc.csv" download> Click Here... </a>