?
Solved

ASP Exporting to Excel

Posted on 2014-01-09
11
Medium Priority
?
281 Views
Last Modified: 2014-02-20
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
Comment
Question by:ParisBP
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 4
11 Comments
 
LVL 53

Expert Comment

by:Scott Fell, EE MVE
ID: 39767963
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
 

Author Comment

by:ParisBP
ID: 39768197
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
 
LVL 53

Expert Comment

by:Scott Fell, EE MVE
ID: 39768350
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
Technology Partners: 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!

 

Author Comment

by:ParisBP
ID: 39768450
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
 
LVL 53

Expert Comment

by:Scott Fell, EE MVE
ID: 39768486
Are you using trim like I suggested?

trim(response.write(myValue))
0
 
LVL 53

Expert Comment

by:Scott Fell, EE MVE
ID: 39768503
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
 
LVL 53

Expert Comment

by:Scott Fell, EE MVE
ID: 39768534
For now, try just using

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

Author Comment

by:ParisBP
ID: 39769582
this did the same. i am going to try the code you pasted just above .
0
 
LVL 53

Expert Comment

by:Scott Fell, EE MVE
ID: 39769692
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
 

Author Comment

by:ParisBP
ID: 39789770
Sorry got way away from this project.

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

no whitespace btw tested that.
0
 
LVL 53

Accepted Solution

by:
Scott Fell,  EE MVE earned 2000 total points
ID: 39789809
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

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!

Question has a verified solution.

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

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

752 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