Returning data in different file type

Returning data in different file type

Question:
We have an ASP application that queries a database and returns the data to formatted pages.

The user would also like the data returned in a .CSV format for further analysis in Excel. How can I return query results as a .csv file andwith the correct mime type so the browser opens it with Excel?

Answer:

I don’t have a real solution for you yet, but I can offer a couple of leads.

I couldn’t get Excel to recognize values that were fed into the stream when separatedby a comma. However, a tab character seemed to behave correctly as a separator.To use this method, you need to set the Content Type to application/vnd.ms-excel with no HTML tags at all. Here’s a little ASP code that demonstrates the technique using hardcoded values. You’d want to loop through your recordset to create this effect:

<%Response.ContentType="application/vnd.ms-excel"%>

January<%=chr(9)%>1<%=chr(9)%>4<%=chr(9)%>Rain
February<%=chr(9)%>2<%=chr(9)%>4<%=chr(9)%>Overcast
March<%=chr(9)%>3<%=chr(9)%>4<%=chr(9)%>Sunny Day

A more reliable solution might be to use Scripting.FileSystemObject to write therecordset data to a temporary .CSV file. You could use some scripting to format the nameof the temporary file as a hyperlink. If you click on the filename name (e.g. “199809152311.csv”), Internet Explorer should call on Excel to display and parse the data.

Although one of these kludges might get you by, let’s keep looking for an elegantsolution.

Share the Post:
Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of

kubernetes logging

Kubernetes Logging: What You Need to Know

Kubernetes from Google is one of the most popular open-source and free container management solutions made to make managing and deploying applications easier. It has a solid architecture that makes