How to export multiple tables to multiple excel sheet using c#? Below code is working but only for 1 html table.
Response.ContentType = "application/x-msexcel";
Response.AddHeader("Content-Disposition", "attachment; filename=ExcelFile.xls");
Response.ContentEncoding = Encoding.UTF8;
StringWriter tw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(tw);
tbl.RenderControl(hw);
Response.Write(tw.ToString());
Response.End();
Below are tables in *.aspx page. And i want to both tables in one excel with multiple sheet.
for Example : Table 1 is in worksheet 1 table 2 is in worksheet 2
<table id="tbl" border="1" runat="server" >
<tr>
<td>Product</td>
<td>Price</td>
<td>Available</td>
<td>Count</td>
</tr>
<tr>
<td>Bred</td>
<td>1
</td>
<td>2
</td>
<td>3
</td>
</tr>
<tr>
<td>Butter</td>
<td>4
</td>
<td>5
</td>
<td>6
</td>
</tr>
</table>
<table id="tbl2" border="1" runat="server" >
<tr>
<td>KD</td>
<td>Dabhi</td>
<td>Qnil</td>
<td>Dabhi</td>
</tr>
<tr>
<td>Bred</td>
<td>1
</td>
<td>2
</td>
<td>3
</td>
</tr>
<tr>
<td>Butter</td>
<td>4
</td>
<td>5
</td>
<td>6
</td>
</tr>
</table>
<asp:Button runat="server" ID="ExportToExcelButton" OnClick="ExportToExcelButton_Click"
Text="Export To Excel" />