Click here to Skip to main content
15,896,428 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I want to export my datatable records to excel each row of datatable should export in separate sheet in same excel.

Here is my code:
C#
Response.ClearContent();
Response.Buffer = true;
Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", "confidential feedback.xls"));
Response.ContentType = "application/ms-excel";
Response.Write("");
Response.Write("<html xmlns:x=\"urn:schemas-microsoft-com:office:excel\">");
Response.Write("<body>");
Response.Write("<table border=0 bordercolor=black>");
Response.Write("<tr>");
Response.Write("<td colspan=9><b><center>");
Response.Write("<Font size=4 face='Times New Roman'color='blue'>Confidential Report</font>");
Response.Write("</b></center></td>");
Response.Write("</tr>");
Response.Write("<tr>");
Response.Write("</tr>");
Response.Write("<tr>");
Response.Write("<td colspan=6 align='left'><b><Font size=3 face='Times New Roman'>");
Response.Write("1(a).How much percentage of job satisfaction do you have ?");
Response.Write("</td>");
Response.Write("</tr>");
Response.Write("<tr>");
Response.Write("<td colspan=6 align='left'><Font size=3 face='Times New Roman'>");
Response.Write(dtitems.ItemArray[2].ToString().Trim());
Response.Write("</td>");
Response.Write("</tr>");
Response.Write("<tr>");
Response.Write("</tr>");
Response.Write("<tr>");
Response.Write("<td colspan=6 align='left'><b><Font size=3 face='Times New Roman'>");
Response.Write(" (b).What is required to be done to increase your job satisfaction ?");
Response.Write("</td>");
Response.Write("</tr>");
Response.Write("<tr>");
Response.Write("<td colspan=6 align='left'><Font size=3 face='Times New Roman'>");
Response.Write(dtitems.ItemArray[3].ToString().Trim());
Response.Write("</td>");
Response.Write("</tr>");

please help me
Posted
v3
Comments
F-ES Sitecore 23-Mar-15 5:00am    
It's important to note that you're not actually creating an excel spreadsheet, you're creating an html file and telling the client that if Excel is installed then show the table in Excel rather than the browser. As it's just an html file you're making you can't use anything that is specific to Excel files such as worksheets etc. You need to use Aspose, Open XML SDK etc to create actual Excel files.

1 solution

You can create multiple sheets with OpenXML SDK.

Refer - Working with sheets (Open XML SDK)[^].
 
Share this answer
 
Comments
[no name] 23-Mar-15 8:42am    
Hi,

Now I able to create multiple worksheets but while inserting worksheet using for loop table inside the worksheet is not viewing. I thinking am wrongly inserting the table tag with in worksheet tag. please clear this issue
What is the exact issue? Any errors or exceptions?
[no name] 24-Mar-15 1:23am    
I want to show each row of datatable in separate excel sheet in same table style

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900