Click here to Skip to main content
14,486,704 members
Rate this:
Please Sign up or sign in to vote.
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:
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

Rate this:
Please Sign up or sign in to vote.

Solution 1

You can create multiple sheets with OpenXML SDK.

Refer - Working with sheets (Open XML SDK)[^].
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, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100