Click here to Skip to main content
16,021,115 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have read this article that exports datatable to excel file. It worked great.

C#
dt = city.GetAllCity();//your datatable
string attachment = "attachment; filename=city.xls";
Response.ClearContent();
Response.AddHeader("content-disposition", attachment);
Response.ContentType = "application/vnd.ms-excel";
string tab = "";
foreach (DataColumn dc in dt.Columns)
{
    Response.Write(tab + dc.ColumnName);
    tab = "\t";
}
Response.Write("\n");
int i;
foreach (DataRow dr in dt.Rows)
{
    tab = "";
    for (i = 0; i < dt.Columns.Count; i++)
    {
        Response.Write(tab + dr[i].ToString());
        tab = "\t";
    }
    Response.Write("\n");
}
Response.End();


but i want to apply formats to excel,how to apply the formats to excel? can any one help me

Thanks in advance.......
Posted
Comments
Kenneth Haugland 4-Oct-12 7:37am    
You seem to be using some kind of OleDb connection to excel, no? If so you cant....

1 solution

Use Excel Interop Object Model :
Tip: Format an Excel Range as a Table Programatically[^]
 
Share this answer
 

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