• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 9031
  • Last Modified:

javascript create and open csv file on the fly

Hi, I am trying to use below code to create a csv
on the fly and open it use Excel.
In netscape, it actually pop up a window asking whether
use Excel to open . Then the browser freezed.
In IE, it does not do anything.  Any help. Thanks.

    function test(){
    var myWindow=window.open("","new","")

1 Solution
As far as I know you cannot really don something like that.

To actually write Excel file on the file you need to use excel methods and not the DOM interface.
This question has been abandoned. I will make a recommendation to the
moderators on its resolution in a week or two. I appreciate any comments
that would help me to make a recommendation.
   In the absence of responses, I may recommend DELETE unless it is clear
   to me that it has value as a PAQ.  Silence = you don't care

For client side files, avner is correct as far as he/she went -

You could start excel, populate and use  excel's file saveas to create a CSV file -

Or you could use the File System Object to write a file - I posted an example of writing a CSV file using client side javascripting and the fso at


There is no MIME type used, needed or involved on the client side - the MIME type tells the browser what kind of file it is receiving from a server - when you're creating a file using client side scripting, the browser already received the file from the server -

For server side, both of those procedures would work as well, with some additional considerations -

If Excel contains macros, button customizations and/or other sordid items, then it must be sent as a binary file - Microsoft Knowledge Base Article - 193998 has the details of how to send an "application/x-msexcel" to a browser -  while not a CSV file, it would 'force' the browser to open the file with Excel - it basically involves opening Excel, populating it and saving it as an XLS file - then streaming that data in that file byte by byte to a browser -

If Excel file contains only data,  then you can send the data in an HTML table to a browser as an "application/vnd.ms-excel" file - Microsoft Knowledge Base Article - 199841 has the details - this is not a CSV file either - it is an HTML file, but the browser would be 'forced' to use Excel to open the file with - it involves creating a server side HTML file which is then sent to the browser as an Active Server Page -

I'm not sure, but if Excel isn't available, then some kind of 'application can't be found message will probably be generated leading to the 'Open with' dialog box the 'Open with' dialog box might as well be cancelled as there is no alternative to using Excel to view XLS files - and in the unlikely event a user had reassigned the file association for XLS, a foreign application is probably going to crash trying to open an Excel file -

For a server side CSV, you could use Excel as above and saveas a CSV file - MIME type "text/csv" - and send the CSV file to the browser, which will probably open it with Excel -

NB: If it's a 'windows' computer which doesn't have Excel installed on it -
or if it's a 'non-windows' computer -
or if the user has adjusted the file associations for CSV files,
then the browser 'may' use some other application to open the file with - in as much as a CSV file is pure ASCII, there are a lot of applications that will successfully open a CSV file - although the display may be a bit ugly -

You could also use the fso instead of Excel to create the CSV file with on the server and send it to the browser as a "text/csv" file - however, the same caveats apply - there is no guarantee that the file will displayed to the user with Excel -

There is a free Excel viewer file available from MS which would let a non-Excel computer display the contents of an Excel file -
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now