Solved

ASP Exporting to Excel

Posted on 2014-01-09
11
276 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
  • 7
  • 4
11 Comments
 
LVL 52

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 52

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
 

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 52

Expert Comment

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

trim(response.write(myValue))
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 52

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 52

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 52

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 52

Accepted Solution

by:
Scott Fell,  EE MVE earned 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Determining if Request.Form is empty 1 45
Displaying number of records depdning on table contents - classic asp 13 37
Pass through dll 2 62
is this a cms? 8 24
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

947 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now