aspx page code
<form id="form1" runat="server">
<div>
<div runat="server" id="ExportDiv">
<span class="SubSectionHeading">First Table:</span><table rules="all" cellspacing="0"
cellpadding="3" width="922">
<tr>
<th width="200px">
Item Name
</th>
<th width="100px">
Price
</th>
<th width="100px">
Market Price
</th>
<th width="100px">
Actual Price
</th>
<th width="100px">
Difference
</th>
<th width="200px">
Notes
</th>
</tr>
<tr>
<td>
Item 1
</td>
<td>
€78.00
</td>
<td>
€67.00
</td>
<td>
€67.00
</td>
<td>
€0.00
</td>
<td>
description of Item
</td>
</tr>
<tr>
<td>
Item 2
</td>
<td>
€90.00
</td>
<td>
€789.00
</td>
<td>
€90.00
</td>
<td>
-€699.00
</td>
<td>
description of Item
</td>
</tr>
<tr>
<td>
Item 3
</td>
<td>
€900.00
</td>
<td>
€700.00
</td>
<td>
€8.00
</td>
<td>
-€692.00
</td>
<td>
description of Item
</td>
</tr>
<tr>
<td>
Item 4
</td>
<td>
€789.00
</td>
<td>
€78.00
</td>
<td>
€980.00
</td>
<td>
€902.00
</td>
<td>
description of Item
</td>
</tr>
<tfoot>
<tr>
<td style="text-align: center;">
Table 1 Total
</td>
<td>
€1,857.00
</td>
<td>
€1,634.00
</td>
<td>
€1,145.00
</td>
<td>
-€489.00
</td>
<td>
</td>
</tr>
<tfoot>
</table>
</br><span class="SubSectionHeading">Second Table:</span><table rules="all" cellspacing="0"
cellpadding="3" width="922">
<tr>
<tr>
<th width="200px">
Item Name
</th>
<th width="100px">
Price
</th>
<th width="100px">
Market Price
</th>
<th width="100px">
Actual Price
</th>
<th width="100px">
Difference
</th>
<th width="200px">
Notes
</th>
</tr>
<tr>
<td>
Item 1
</td>
<td>
€45.00
</td>
<td>
€67.00
</td>
<td>
€8.00
</td>
<td>
-€59.00
</td>
<td>
description of Item
</td>
</tr>
<tr>
<td>
Item 2
</td>
<td>
€600.00
</td>
<td>
€899.00
</td>
<td>
€65.00
</td>
<td>
-€834.00
</td>
<td>
description of Item
</td>
</tr>
<tr>
<td>
Item 3
</td>
<td>
€7.00
</td>
<td>
€9.00
</td>
<td>
</td>
<td>
</td>
<td>
description of Item
</td>
</tr>
<tr>
<td>
Item 4
</td>
<td>
€78.00
</td>
<td>
€90.00
</td>
<td>
€67.00
</td>
<td>
-€23.00
</td>
<td>
description of Item
</td>
</tr>
<tr>
<td>
Item 5
</td>
<td>
€789.00
</td>
<td>
€980.00
</td>
<td>
€67.00
</td>
<td>
-€913.00
</td>
<td>
description of Item
</td>
</tr>
<tr>
<td>
Item 6
</td>
<td>
€6.00
</td>
<td>
€6.00
</td>
<td>
€78.00
</td>
<td>
€72.00
</td>
<td>
description of Item
</td>
</tr>
<tfoot>
<tr>
<td style="text-align: center;">
Table 2 Total
</td>
<td>
€1,525.00
</td>
<td>
€2,051.00
</td>
<td>
€285.00
</td>
<td>
-€1,757.00
</td>
<td>
</td>
</tr>
<tfoot>
</table>
</br><span class="SubSectionHeading">Total:</span><table rules="all" cellspacing="0"
cellpadding="3" class="rgMasterTableTotal" width="630">
<tr>
<th width="200px">
Table
</th>
<th width="100px">
Price
</th>
<th width="100px">
Market Price
</th>
<th width="100px">
Actual Price
</th>
<th width="100px">
Difference
</th>
</tr>
<tr>
<td style="text-align: center;">
Table 1
</td>
<td>
€1,857.00
</td>
<td>
€1,634.00
</td>
<td>
€1,145.00
</td>
<td>
-€489.00
</td>
</tr>
<tr>
<td style="text-align: center;">
Table 2
</td>
<td>
€1,525.00
</td>
<td>
€2,051.00
</td>
<td>
€285.00
</td>
<td>
-€1,757.00
</td>
</tr>
<tfoot>
<tr style="background-color: #404040; color: White;">
<td style="text-align: center;">
Grand Total
</td>
<td>
€3,382.00
</td>
<td>
€3,685.00
</td>
<td>
€1,430.00
</td>
<td>
-€2,246.00
</td>
</tr>
<tfoot>
</table>
</div>
<asp:Button runat="server" ID="ExportToExcelButton" OnClick="ExportToExcelButton_Click"
Text="Export To Excel" />
</div>
</form>
--------------------------------------------------------------
code hehind
protected void ExportToExcelButton_Click(object sender, EventArgs e)
{
Response.AppendHeader("content-disposition", "attachment;filename=ExportedHtml.xls");
Response.Charset = "";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "application/vnd.ms-excel";
this.EnableViewState = false;
Response.Write(ExportDiv.InnerHtml);
Response.End();
}
<form id="form1" runat="server">
<div>
<div runat="server" id="ExportDiv">
<span class="SubSectionHeading">First Table:</span><table rules="all" cellspacing="0"
cellpadding="3" width="922">
<tr>
<th width="200px">
Item Name
</th>
<th width="100px">
Price
</th>
<th width="100px">
Market Price
</th>
<th width="100px">
Actual Price
</th>
<th width="100px">
Difference
</th>
<th width="200px">
Notes
</th>
</tr>
<tr>
<td>
Item 1
</td>
<td>
€78.00
</td>
<td>
€67.00
</td>
<td>
€67.00
</td>
<td>
€0.00
</td>
<td>
description of Item
</td>
</tr>
<tr>
<td>
Item 2
</td>
<td>
€90.00
</td>
<td>
€789.00
</td>
<td>
€90.00
</td>
<td>
-€699.00
</td>
<td>
description of Item
</td>
</tr>
<tr>
<td>
Item 3
</td>
<td>
€900.00
</td>
<td>
€700.00
</td>
<td>
€8.00
</td>
<td>
-€692.00
</td>
<td>
description of Item
</td>
</tr>
<tr>
<td>
Item 4
</td>
<td>
€789.00
</td>
<td>
€78.00
</td>
<td>
€980.00
</td>
<td>
€902.00
</td>
<td>
description of Item
</td>
</tr>
<tfoot>
<tr>
<td style="text-align: center;">
Table 1 Total
</td>
<td>
€1,857.00
</td>
<td>
€1,634.00
</td>
<td>
€1,145.00
</td>
<td>
-€489.00
</td>
<td>
</td>
</tr>
<tfoot>
</table>
</br><span class="SubSectionHeading">Second Table:</span><table rules="all" cellspacing="0"
cellpadding="3" width="922">
<tr>
<tr>
<th width="200px">
Item Name
</th>
<th width="100px">
Price
</th>
<th width="100px">
Market Price
</th>
<th width="100px">
Actual Price
</th>
<th width="100px">
Difference
</th>
<th width="200px">
Notes
</th>
</tr>
<tr>
<td>
Item 1
</td>
<td>
€45.00
</td>
<td>
€67.00
</td>
<td>
€8.00
</td>
<td>
-€59.00
</td>
<td>
description of Item
</td>
</tr>
<tr>
<td>
Item 2
</td>
<td>
€600.00
</td>
<td>
€899.00
</td>
<td>
€65.00
</td>
<td>
-€834.00
</td>
<td>
description of Item
</td>
</tr>
<tr>
<td>
Item 3
</td>
<td>
€7.00
</td>
<td>
€9.00
</td>
<td>
</td>
<td>
</td>
<td>
description of Item
</td>
</tr>
<tr>
<td>
Item 4
</td>
<td>
€78.00
</td>
<td>
€90.00
</td>
<td>
€67.00
</td>
<td>
-€23.00
</td>
<td>
description of Item
</td>
</tr>
<tr>
<td>
Item 5
</td>
<td>
€789.00
</td>
<td>
€980.00
</td>
<td>
€67.00
</td>
<td>
-€913.00
</td>
<td>
description of Item
</td>
</tr>
<tr>
<td>
Item 6
</td>
<td>
€6.00
</td>
<td>
€6.00
</td>
<td>
€78.00
</td>
<td>
€72.00
</td>
<td>
description of Item
</td>
</tr>
<tfoot>
<tr>
<td style="text-align: center;">
Table 2 Total
</td>
<td>
€1,525.00
</td>
<td>
€2,051.00
</td>
<td>
€285.00
</td>
<td>
-€1,757.00
</td>
<td>
</td>
</tr>
<tfoot>
</table>
</br><span class="SubSectionHeading">Total:</span><table rules="all" cellspacing="0"
cellpadding="3" class="rgMasterTableTotal" width="630">
<tr>
<th width="200px">
Table
</th>
<th width="100px">
Price
</th>
<th width="100px">
Market Price
</th>
<th width="100px">
Actual Price
</th>
<th width="100px">
Difference
</th>
</tr>
<tr>
<td style="text-align: center;">
Table 1
</td>
<td>
€1,857.00
</td>
<td>
€1,634.00
</td>
<td>
€1,145.00
</td>
<td>
-€489.00
</td>
</tr>
<tr>
<td style="text-align: center;">
Table 2
</td>
<td>
€1,525.00
</td>
<td>
€2,051.00
</td>
<td>
€285.00
</td>
<td>
-€1,757.00
</td>
</tr>
<tfoot>
<tr style="background-color: #404040; color: White;">
<td style="text-align: center;">
Grand Total
</td>
<td>
€3,382.00
</td>
<td>
€3,685.00
</td>
<td>
€1,430.00
</td>
<td>
-€2,246.00
</td>
</tr>
<tfoot>
</table>
</div>
<asp:Button runat="server" ID="ExportToExcelButton" OnClick="ExportToExcelButton_Click"
Text="Export To Excel" />
</div>
</form>
--------------------------------------------------------------
code hehind
protected void ExportToExcelButton_Click(object sender, EventArgs e)
{
Response.AppendHeader("content-disposition", "attachment;filename=ExportedHtml.xls");
Response.Charset = "";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "application/vnd.ms-excel";
this.EnableViewState = false;
Response.Write(ExportDiv.InnerHtml);
Response.End();
}