Link to home
Start Free TrialLog in
Avatar of praneethkavula
praneethkavulaFlag for India

asked on

How do I save a Table generated using ASP.net into an Excel File?

I am generating a formatted table in the form of HTML to add that in a panel, this was working fine to display the table in the required format.

No my requirement is to save the formatted table in a excel file in the server and send that as an email attachment.

My requirement is to save the table in a excel file programatically and send that file as an email attachment

Thanks...

Table tblDailyDetailPayrollReport = ddReport.createReport();
if(tblDailyDetailPayrollReport != null)
{
       pnlReport.Controls.Add(tblDailyDetailPayrollReport);
        try
	{
		string sTableStart = @"<HTML><BODY><TABLE Border=1>";
		string sTableEnd = @"</TABLE></BODY></HTML>"; 					
		StringBuilder sTableData = new StringBuilder();
		for(int iRows = 0 ; iRows < tblDailyDetailPayrollReport.Rows.Count ; iRows++)
		{
			sTableData.Append(@"<tr>");
			for(int iCols = 0; iCols < tblDailyDetailPayrollReport.Rows[iRows].Cells.Count; iCols++) 
			{
				sTableData.Append(@"<td>");
				sTableData.Append(tblDailyDetailPayrollReport.Rows[iRows].Cells[iCols].Text);
				sTableData.Append(@"</td>");
			}
			sTableData.Append(@"</tr>");
		}					
        string sTable = sTableStart + sTableData.ToString() + sTableEnd;
}

Open in new window

Avatar of Faheem Shaikh
Faheem Shaikh
Flag of India image

ASKER CERTIFIED SOLUTION
Avatar of praneethkavula
praneethkavula
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If you have your answer, close the question.