473,406 Members | 2,847 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Export to Excel from ASP

Hi there ,
Can anyone help me out!!

I have a report (basically retrieving of records from the database and show it in a htm table format)
which is displayed on the browser as htm table..
Now my problem comes here..
I was asked to program such that the report is shown in excel rather than as html table..
with great enthusiasm I started working only to find out i am not able to do..

when I click on the button, the excel is opening, but only that it is completely blank and not showing any records
if i turn off content type, then I am able to display in html table..
Pls help me out!!
the delivarable is only a day away:(
I am posting my code here :
on top of page i added this
Expand|Select|Wrap|Line Numbers
  1.  <% 
  2. Response.Buffer = TRUE
  3. Response.ContentType = "application/vnd.ms-excel"%>
  4.  
  5. After that the record set is retreived like this:
  6. <tr valign=top>    
  7. <% while iCnt <=7%>
  8. <td >        
  9. <table border="1" cellpadding="0" cellspacing="0" width=100% class=formtable>
  10. <%str = "Exec sp_printanydate '" & cdate(request("StartDate"))& "', '" & request.QueryString("cid") & "', "& iCnt&" " 
  11. rs.Open str,conn,1,3
  12. while not rs.EOF %>
  13. <tr valign=top >    
  14. <td valign=top bgcolor=<%=color_value%> >
  15. <%if isnull(rs("subjectname")) then%>
  16.         -
  17. <%else%>
  18. <%=rs("subjectname")%>
  19. <%end if %>    <br>        
  20. <%if isnull(rs("classname")) then%>
  21.     - 
  22. <%else%>
  23. <%=rs("classname")%>
  24. <%end if %>    <br>        
  25. <%=rs("fromtime")%> - <%=rs("totime")%><br>
  26. <%if isnull(rs("room")) then%>
  27. <%else%>
  28. <%=rs("room")%>
  29. <%end if %>        <br>    
  30. </td>    
  31. </tr>                
  32. <%
  33. rs.MoveNext        
  34. wend
  35. rs.Close
  36. %>                        
  37. </table>        
  38. </td>    
  39. <%iCnt=iCnt+1
  40. wend%>
  41. </tr>        
  42. </table>
  43.  
Thanks very much in advance
Regards
Nov 25 '05 #1
3 21429
Niheel
2,460 Expert Mod 2GB
Here is an example on the net:
Export to Excel using ASP

Comparing yours with the sample, it seems you forgot the AddHeader line:

Expand|Select|Wrap|Line Numbers
  1. Response.ContentType = "application/vnd.ms-excel"
  2. Response.AddHeader "Content-Disposition", "attachment; filename=Sample_File.xls"
  3.  
Nov 29 '05 #2
I have this code, and works with no problem.

Expand|Select|Wrap|Line Numbers
  1. <%@ Language=VBScript %>
  2. <% Response.ContentType="application/vnd.ms-excel" %>
  3. <Table>
  4.  
  5. <TR>
  6. <TD>Col1</TD>
  7. <TD>Col2</TD>
  8. <TD>Col3</TD>
  9. <TD>Total</TD>
  10. </TR>
  11.  
  12. <TR>
  13. <TD><div align="center" class="style1">10</div></TD>
  14. <TD>20</TD>
  15. <TD>2</TD>
  16. <TD>=sum(a2:b2)</TD>
  17. </TR>
  18.  
  19. <TR>
  20. <TD>30</TD>
  21. <TD>40</TD>
  22. <TD></TD>
  23. <TD>=sum(a3:b3)</TD>
  24. </TR>
  25. </TABLE>
Nov 28 '07 #3
Hi there,

I have tired this
Expand|Select|Wrap|Line Numbers
  1.  Response.ContentType = "application/vnd.ms-excel" 
  2. Response.AddHeader "Content-Disposition", "attachment; filename=Enquiry_List.xls"
  3. Response.Charset="UTF-8"
  4.  
which works fine for me. My only problem is that, i am not getting my data in UTF-8 format. Any idea? I have searched many articles on export to excel in ASP. I have not found either in one anything regarding the Encoding issue.

Any help would be appreciated.

Thanks,
Menon
May 30 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Matt | last post by:
I have an ASP page that calls ASP routines that I created that execute a database query and return the results to a recordset. I then iterate through the recordset and display the data in a table....
5
by: Maria L. | last post by:
Hi, I need to export the content of a DataGrid (in Windows application in C#), into an Excel spreadsheet. Anyone knows how to do this? Any code snippets would help! thanks a lot, Maria
2
by: Siu | last post by:
Hi, I use the following code to export and import a file Excel from resp. into a Web page with the following code: //EXPORT Response.Clear(); Response.Buffer = true; Response.ContentType =...
6
by: Elena | last post by:
I'm trying to export data to an Excel worksheet. I can export the data in the cell values perfectly. I need the code to change a header and footer for the worksheet, not for the columns. Is...
13
by: Hemant Sipahimalani | last post by:
The following piece of code is being used to export HTML to excel. HttpContext.Current.Response.ContentType = "application/vnd.ms-excel"...
5
by: Simon | last post by:
Dear reader, With the export command you can export a query to Excel. By activate this command a form pop's up with the following text:
1
by: smaczylo | last post by:
Hello, I've recently been asked to work with Microsoft Access, and while I feel quite comfortable with Excel, I'm at a complete loss with databases. If someone could help me with this issue I'm...
1
by: CoolFactor | last post by:
MY CODE IS NEAR THE BOTTOM I want to export this Access query into Excel using a command button on an Access form in the following way I describe below. Below you will find the simple query I am...
3
by: =?Utf-8?B?YzY3NjIyOA==?= | last post by:
Hi all, I have a question for you. I have a .csv file which has many lines of data. Each line has many data fields which are delimited by ",". Now I need to extract part of data from this...
2
hemantbasva
by: hemantbasva | last post by:
Note We need to have a template on server for generating report in multiple sheet as we do not had msoffice on server moreover this require a batch job to delete excel file created by the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.