We help IT Professionals succeed at work.

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

192 Views
Last Modified: 2010-04-15
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

Comment
Watch Question

This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
If you have your answer, close the question.
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.