Avatar of praneethkavula
praneethkavula
Flag 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

C#Microsoft ExcelASP.NET

Avatar of undefined
Last Comment
Faheem Shaikh

8/22/2022 - Mon
Faheem Shaikh

ASKER CERTIFIED SOLUTION
praneethkavula

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Faheem Shaikh

If you have your answer, close the question.
Your help has saved me hundreds of hours of internet surfing.
fblack61