Solved

ASP Exporting to Excel

Posted on 2014-01-09
11
274 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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

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…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
This video discusses moving either the default database or any database to a new volume.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

707 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

11 Experts available now in Live!

Get 1:1 Help Now