Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Output data to a local client directory

Posted on 2003-03-14
Medium Priority
Last Modified: 2013-12-25
I've recently 'inherited' a web app written in CGI, which queries a database and displays the results on a browser page.

I need to add some functionality to allow the user to download the results of the query to their local drive. I'm not sure what format this file should be at the moment.....Excel would be perfect, but I'd settle for a csv file if that is easier.

How do I go about doing this?

Ideally I'd like to prompt the user to select a file location using a common dialog, and then have the query results saved to the appropriate file format in the appropriate location.

Question by:mrt1
  • 2
LVL 48

Accepted Solution

Tintin earned 500 total points
ID: 8139739
Just output an appropriate MIME type, eg:

Content-Type:  application/ms-excel

You didn't say what language the app is written in, so I'll leave it to you to add the appropriate print (or equivalent) statement.

Assisted Solution

MatrixDud earned 500 total points
ID: 8141258
For a CSV file, which will open in Excel all you need to do to format the file is use comma (,) delimiters with a newline at the end. And of course as Tintin posted you need to specify the content-type in the header (not the <head>).

Here's a good page on CSV:

Here's a couple on Content-Types and headers:

Author Comment

ID: 8150884
Application is written in Perl. Any advice how I access the contents of the current html page and ouptu these to Excel or a csv file?

I'm new to Perl, so any example would be appreciated.

Author Comment

ID: 8153036
I've managed to get the export to Excel to work using the 'application/vnd.ms-excel' type (thanks for the help on this!). It is taking too long to download, though - I guess this is because the data has to be read from database, converted to HTML and then converted into Excel format.

I would rather download straight to a csv format, which should be faster and will get over Excel's row limit limitation.

What syntax do I need to do this? Is there a different content-type I can use?

I have a DB connection:
        my $dbh = DBI->connect($DBIPARAM,$user,$password,RaiseError=>1,PrintError=>1})

and a query to run ($query).

Can someone show me a rough outline of the code I need to create a .csv file of data on the client workstation?


Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Question has a verified solution.

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

In this tutorial I will show you how to make a simple HTML bar chart with the usage of WhizBase, If you want more information about WhizBase please read my previous articles at http://www.experts-exchange.com/ARTH_5123186.html (http://www.experts-ex…
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Suggested Courses

564 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