473,379 Members | 1,253 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

Client side Javascript to download data into a csv format

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..

Aug 22 '06 #1
2 15686

xa************@gmail.com wrote:
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

Aug 22 '06 #2
"Julian Turner" <ju*******@googlemail.comwrote in
news:11**********************@74g2000cwt.googlegro ups.com:
>
xa************@gmail.com wrote:
>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.
Yes, server side is the way to go. The same server code that creates the
html table can also create a csv file on the server's hard drive. A
simple link on the web page will let the user download the csv file.
Aug 22 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: duane | last post by:
Dear Experts: I am trying to measure a HTML page download time on the client side and store the value into a textfile located in the server. I have successfully measured the page download time...
1
by: Ambush | last post by:
I am currently working on one of those projects that we all dread. The type that keeps growing out of scope faster than you can finish the component to deliver what they've already asked for. ...
18
by: cjl | last post by:
Hey all: I know that it is silly in the age of Google to 'lose' something on the internet, but I recently checked out a project that had implemented a database with a subset of SQL in pure...
5
by: KathyB | last post by:
If someone could just explain this to me...I just don't get it! I have an aspx page where I retrieve several session variables and use xmlDocument to transform xml file with xsl file into an...
2
by: Dnna | last post by:
I have a table which is bound to an Internet Explorer XML data island. I'm using ASP.NET's client-side validators for an input field in the table. The problem is that if the input fields are in...
5
by: John A Grandy | last post by:
is it possible to write a vb.net code (intended to run on the client-side) that would invoke an instance of IE, have it download a page from a certain URL, and then pre-populate some of the...
3
by: Alex K | last post by:
Hello, Would it be possible to make the browser download a resource using javascript? I'm aware there could be a security issue but I'm still wondering if this could be possible. It could save a...
22
by: Dan Rumney | last post by:
Hi all, I've been writing Javascript for quite a while now and have, of late, been writing quite a lot of AJAX and AJAX-related code. In the main, my dynamically generated pages are created...
9
by: shailaja.sheel | last post by:
Hi , This is my first attempt to do some html/javascript programming and I am totally lost. I have a questionaire form and when user clicks Submit, I want to save the data in XML file on client...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.