Need help on export asp.net table to excel

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Jul 2006
Posts: 21
Reputation: newMeg is an unknown quantity at this point 
Solved Threads: 0
newMeg newMeg is offline Offline
Newbie Poster

Need help on export asp.net table to excel

 
0
  #1
Sep 4th, 2006
Hi im developing an asp.net report using vb language. I created the report previously using datagrid,which works well when i click the export button. It downloads the datagrid to excel format. But now i need to add anew header to the report,so i changed to using table which seems as a solution to the problem. I've managed to create the table and produce the report,but now i've to export th etable to excel format same as the one i did for my datagrid. I truied to just modify the code to my table name,but when it downloads, there is only a single empty cell in the excel file.
I paste my code so that anyone could point where is my mistake.
My aspx page

  1.  
  2. <form id="form1" runat="server">
  3. <table style="width: 600px">
  4. <tr>
  5. <td class="headertext" style="width: 798px" >
  6. SUMMARY REPORT SINGAPORE ( ALL)
  7. </td>
  8. </tr>
  9. <tr><td class="textfont" style="width: 798px; height: 17px;" >
  10. <asp:Label ID="lblMessage" runat="server" Text="Label" Width="264px"></asp:Label></td></tr>
  11. </table>
  12.  
  13. <br />
  14. <asp:Table ID="tblSummAllSg" runat="server" Font-Names="Verdana" BorderWidth="1"
  15. Font-Size="XX-Small">
  16. </asp:Table>
  17. <br />
  18. <br />
  19.  
  20.  
  21. <table align="center">
  22. <tr><td>
  23. <asp:Button ID="btnExport" runat="server" Text="Export As Excel" BorderColor="#C00000" />
  24. </td></tr>
  25. </table>
  26.  
  27. </form>


My code behing page (on page load method)

  1.  
  2. Dim tableHeading As TableRow = New TableRow()
  3.  
  4. 'Create and add the cells that contain the CallDate column heading text.
  5. Dim DateHeading As TableHeaderCell = New TableHeaderCell()
  6. DateHeading.Text = "Call In Date"
  7. DateHeading.HorizontalAlign = HorizontalAlign.Center
  8. tableHeading.Cells.Add(DateHeading)
  9.  
  10. 'Create and add the cells that contain the Calls column heading text.
  11. Dim TotalCallHeading As TableHeaderCell = New TableHeaderCell()
  12. TotalCallHeading.Text = "Total Calls"
  13. TotalCallHeading.ColumnSpan = 5
  14. TotalCallHeading.HorizontalAlign = HorizontalAlign.Center
  15. tableHeading.Cells.Add(TotalCallHeading)
  16. Dim tableHeading2 As TableRow = New TableRow()
  17.  
  18. Dim CallInDateHeading As TableCell = New TableCell()
  19. CallInDateHeading.Text = "Call In Date"
  20. CallInDateHeading.HorizontalAlign = HorizontalAlign.Center
  21. tableHeading2.Cells.Add(CallInDateHeading)
  22. Dim InBoundOutBoundHeading As TableCell = New TableCell()
  23. InBoundOutBoundHeading.Text = "InBound/OutBound"
  24. tableHeading2.Cells.Add(InBoundOutBoundHeading)
  25. tblSummAllSg.Rows.Add(tableHeading)
  26. tblSummAllSg.Rows.Add(tableHeading2)
  27. While (objreader.Read())
  28.  
  29. Dim detailsRow As TableRow = New TableRow()
  30.  
  31. Dim CallInDateCell As TableCell = New TableCell()
  32. CallInDateCell.Text = objreader("CallInDate").ToString()
  33. detailsRow.Cells.Add(CallInDateCell)
  34. Dim InBoundOutBoundCell As TableCell = New TableCell()
  35. InBoundOutBoundCell.Text = objreader("InBoundOutBound").ToString()
  36. detailsRow.Cells.Add(InBoundOutBoundCell)
  37. Dim IncompletePrankCell As TableCell = New TableCell()
  38. IncompletePrankCell.Text = objreader("IncompletePrank").ToString()
  39. detailsRow.Cells.Add(IncompletePrankCell)
  40. tblSummAllSg.Rows.Add(detailsRow)
  41. End While


My code behing page (on export button click)

  1. Protected Sub btnExport_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExport.Click
  2. ' binding datagrid result to export list
  3. Response.Clear()
  4. Response.AddHeader("content-disposition", "attachment;filename=DetailReport.xls")
  5. Response.Charset = ""
  6. Response.Cache.SetCacheability(HttpCacheability.NoCache)
  7. Response.ContentType = "application/vnd.xls"
  8. Dim stringWrite As IO.StringWriter = New System.IO.StringWriter()
  9. Dim htmlWrite As HtmlTextWriter = New HtmlTextWriter(stringWrite)
  10. tblSummAllSg.RenderControl(htmlWrite)
  11. Response.Write(stringWrite.ToString())
  12. Response.End()
  13. End Sub
  14.  




I really hope someone can help me solve this. Im not sure now if doing this report as table is a solution to the datagrid problem. Im running out of idea and time. Any help is really appreciated. Thank you in advance.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 1
Reputation: gauri_milind is an unknown quantity at this point 
Solved Threads: 0
gauri_milind gauri_milind is offline Offline
Newbie Poster

Re: Need help on export asp.net table to excel

 
0
  #2
Oct 6th, 2006
ciao ,

what you need to do is refill your tblsummallsg ....and then call
tblSummAllSg.RenderControl(htmlWrite)

because on click of the button al the data is lost ...

hope it helps...

Gauri
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 1
Reputation: giri.hanchate is an unknown quantity at this point 
Solved Threads: 0
giri.hanchate giri.hanchate is offline Offline
Newbie Poster

Re: Need help on export asp.net table to excel

 
0
  #3
Jul 11th, 2008
Originally Posted by gauri_milind View Post
ciao ,

what you need to do is refill your tblsummallsg ....and then call
tblSummAllSg.RenderControl(htmlWrite)

because on click of the button al the data is lost ...

hope it helps...

Gauri

Hi Ciao,

Even i am also facing same problem. Have you solved the problem? Tones of advance thanks if you post your code.

Have a nice weekend

Giri
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC