| | |
Need help on export asp.net table to excel
Please support our ASP.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jul 2006
Posts: 21
Reputation:
Solved Threads: 0
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
My code behing page (on page load method)
My code behing page (on export button click)
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.
I paste my code so that anyone could point where is my mistake.
My aspx page
ASP.NET Syntax (Toggle Plain Text)
<form id="form1" runat="server"> <table style="width: 600px"> <tr> <td class="headertext" style="width: 798px" > SUMMARY REPORT SINGAPORE ( ALL) </td> </tr> <tr><td class="textfont" style="width: 798px; height: 17px;" > <asp:Label ID="lblMessage" runat="server" Text="Label" Width="264px"></asp:Label></td></tr> </table> <br /> <asp:Table ID="tblSummAllSg" runat="server" Font-Names="Verdana" BorderWidth="1" Font-Size="XX-Small"> </asp:Table> <br /> <br /> <table align="center"> <tr><td> <asp:Button ID="btnExport" runat="server" Text="Export As Excel" BorderColor="#C00000" /> </td></tr> </table> </form>
My code behing page (on page load method)
ASP.NET Syntax (Toggle Plain Text)
Dim tableHeading As TableRow = New TableRow() 'Create and add the cells that contain the CallDate column heading text. Dim DateHeading As TableHeaderCell = New TableHeaderCell() DateHeading.Text = "Call In Date" DateHeading.HorizontalAlign = HorizontalAlign.Center tableHeading.Cells.Add(DateHeading) 'Create and add the cells that contain the Calls column heading text. Dim TotalCallHeading As TableHeaderCell = New TableHeaderCell() TotalCallHeading.Text = "Total Calls" TotalCallHeading.ColumnSpan = 5 TotalCallHeading.HorizontalAlign = HorizontalAlign.Center tableHeading.Cells.Add(TotalCallHeading) Dim tableHeading2 As TableRow = New TableRow() Dim CallInDateHeading As TableCell = New TableCell() CallInDateHeading.Text = "Call In Date" CallInDateHeading.HorizontalAlign = HorizontalAlign.Center tableHeading2.Cells.Add(CallInDateHeading) Dim InBoundOutBoundHeading As TableCell = New TableCell() InBoundOutBoundHeading.Text = "InBound/OutBound" tableHeading2.Cells.Add(InBoundOutBoundHeading) tblSummAllSg.Rows.Add(tableHeading) tblSummAllSg.Rows.Add(tableHeading2) While (objreader.Read()) Dim detailsRow As TableRow = New TableRow() Dim CallInDateCell As TableCell = New TableCell() CallInDateCell.Text = objreader("CallInDate").ToString() detailsRow.Cells.Add(CallInDateCell) Dim InBoundOutBoundCell As TableCell = New TableCell() InBoundOutBoundCell.Text = objreader("InBoundOutBound").ToString() detailsRow.Cells.Add(InBoundOutBoundCell) Dim IncompletePrankCell As TableCell = New TableCell() IncompletePrankCell.Text = objreader("IncompletePrank").ToString() detailsRow.Cells.Add(IncompletePrankCell) tblSummAllSg.Rows.Add(detailsRow) End While
My code behing page (on export button click)
ASP.NET Syntax (Toggle Plain Text)
Protected Sub btnExport_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExport.Click ' binding datagrid result to export list Response.Clear() Response.AddHeader("content-disposition", "attachment;filename=DetailReport.xls") Response.Charset = "" Response.Cache.SetCacheability(HttpCacheability.NoCache) Response.ContentType = "application/vnd.xls" Dim stringWrite As IO.StringWriter = New System.IO.StringWriter() Dim htmlWrite As HtmlTextWriter = New HtmlTextWriter(stringWrite) tblSummAllSg.RenderControl(htmlWrite) Response.Write(stringWrite.ToString()) Response.End() End Sub
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.
•
•
Join Date: Jul 2008
Posts: 1
Reputation:
Solved Threads: 0
•
•
•
•
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
![]() |
Similar Threads
- Export to Excel from ASP.NET app (ASP.NET)
- Batch file in ASP.Net to convert Excel files into higher version (ASP.NET)
- ASP.NET Import/Export (ASP.NET)
- ASP.NET and Mozilla - Issues! (ASP.NET)
- plz help me to connect more than one table in the ms access database to the asp.net (ASP.NET)
- Simple ASP.Net Login Page (Using VB.Net) (ASP.NET)
Other Threads in the ASP.NET Forum
- Previous Thread: tabindex
- Next Thread: image uploading in c# +asp.net
| Thread Tools | Search this Thread |
.net 2.0 3.5 ajax alltypeofvideos appliances asp asp.net beginner box browser businesslogiclayer button c# cac checkbox class commonfunctions compatible content contenttype control countryselector courier dataaccesslayer database datagrid datagridview datalist deployment development dgv dialog dropdownlist dropdownmenu dynamic dynamically edit embeddingactivexcontrol fileuploader fill findcontrol flash flv gridview gudi iis javascript list listbox login menu microsoft mouse mssql nameisnotdeclared news novell numerical opera order panelmasterpagebuttoncontrols problem radio ratings redirect registration relationaldatabases reportemail schoolproject search security serializesmo.table sessionvariables silverlight smoobjects software sql sql-server sqlserver2005 ssl tracking treeview validatedate validation vb.net videos vista visual-studio visualstudio vs2008 web webapplications webarchitecture webdevelopment webprogramming webservice wizard xsl youareanotmemberofthedebuggerusers





