javascript create and open csv file on the fly

Posted on 2001-07-25
Last Modified: 2007-12-19
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(){

Question by:xiaoxiangz
LVL 14

Accepted Solution

avner earned 50 total points
ID: 6319703
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.
LVL 53

Expert Comment

ID: 7910420
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


Expert Comment

ID: 9255431
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/" 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 -

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
function parameter and using that as array 15 23
Json Schema 8 32
Insert Button on a table 16 38
2 separate CSS animations 2 17
This article discusses how to create an extensible mechanism for linked drop downs.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question