• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 283
  • Last Modified:

ASP Exporting to Excel

I have an asp page of data.
using the following. I am able to export the page to Excel

<% Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader "Content-Disposition", "filename=excelfile.xls"%>

Works great. except the numbers on the spreadsheet are not treated as Numbers by Excel.

How do we export the numbers so they can be manipulated on the spreadsheet?
0
ParisBP
Asked:
ParisBP
  • 7
  • 4
1 Solution
 
Scott Fell, EE MVEDeveloperCommented:
Make sure there are not any spaces in the data.  You may have " 2 " when you meant "2".

<%
x=" 2 "
y=trim(x)

'I don't think this would do anything but you could try
z=cdbl(y)

%>
0
 
ParisBPAuthor Commented:
We have no spaces on the numbers in the query.
Also after I export to excel, I cannot format the cells with datat to numbers.
0
 
Scott Fell, EE MVEDeveloperCommented:
it's possible your html is creating spaces.  Your other option is in excel to multiply by 1.    If all of your numbers are in column A, Make column B =b1*a1 and that will force a number.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
ParisBPAuthor Commented:
That was a great thought. but muliplying by one is giving me #Value errors as the number isn't a number to begin with.
0
 
Scott Fell, EE MVEDeveloperCommented:
Are you using trim like I suggested?

trim(response.write(myValue))
0
 
Scott Fell, EE MVEDeveloperCommented:
Actually, make sure you are using a number.

x=trim(myValue)
if not isnumeric(x) then
   x="This was not numeric |"&x&"|"
end if
response.write x

Open in new window

0
 
Scott Fell, EE MVEDeveloperCommented:
For now, try just using

<% response.ContentType="application/vnd.ms-excel"%>
0
 
ParisBPAuthor Commented:
this did the same. i am going to try the code you pasted just above .
0
 
Scott Fell, EE MVEDeveloperCommented:
Can you post the rendered html?  Just remove the <% response.ContentType="application/vnd.ms-excel"%> and send the page to the screen, view source, copy and paste your code here.

Maybe you have some white space in the html?  <td> 2 </td> should be <td>2</td>

What if you try using a different browser?  

I do the very same thing you are doing and don't remember this issue.

What I have been doing lately is using fso and generate a csv file on the server, then have scripting that downloads the csv file and deletes from the server (I do this for very large files).  Then excel opens up the csv file.
0
 
ParisBPAuthor Commented:
Sorry got way away from this project.

Exporting to csv? what do I have to do there.

no whitespace btw tested that.
0
 
Scott Fell, EE MVEDeveloperCommented:
http://www.w3schools.com/asp/asp_ref_filesystem.asp
Make sure to give write permissions to the folder you are writing to.
<%
' Assume a recordset named rsName of contact info


dim fs,myCSV
set fs=Server.CreateObject("Scripting.FileSystemObject")
set myCSV=fs.CreateTextFile("c:\webroot\download.csv",true)
myCSV.WriteLine("Name,Address, Phone, Email")

Do Until rsName.eof
     myCSV.WriteLine(rsName("Name")&","&rsName("Address")&","&rsName("Phone")&","& rsName("Email"))

rsName.MoveNext


myCSV.Close
set myCSV=nothing
set fs=nothing
%>

Open in new window

0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 7
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now