Client side Javascript to download data into a csv format

X

xander.zone.3x

How can we download data in tables in a html page into a csv file using
client side Javascript. I should click a button and a table's data
should be downloaded into a csv in local drive. The os used is m$
windows..
 
J

Julian Turner

How can we download data in tables in a html page into a csv file using
client side Javascript. I should click a button and a table's data
should be downloaded into a csv in local drive. The os used is m$
windows..

The simplest option is to perhaps create the csv on the server, and ask
the client to go to a download page and save the csv file themselves.

If you want to do this on the client side, then:-

The creation of the csv string can be done using JavaScript and the
HTML DOM, by cycling through the rows and cells collections of the
TABLE object.

You could then insert the results in a TEXTAREA and let the client cut
and paste them into a text editor.

If you want JavaScript to sav the csv string to the client's local
disk, this is a different matter.

JavaScript does not natively have any local file handling capability.

However, if the client is running Internet Explorer, then the client is
likely to have the Scripting.FileSystemObject ActiveX COM object
installed, which JavaScript may be able to access using:-

var fileSystem = new ActiveXObject("Scripting.FileSystemObject").

Firefox also has file handling components based on XPCOM.

However, whether these components will work will obviously depend on
the client security settings. If the client's browser has blocked
ActiveX objects, then you will not be able to do this without the
client granting the appropriate permissions. There is no way round
this, for the obvious reason that unrestricted access to a file system
would be a danagerous thing on the internet.

Regards

Julian
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top