Click here to Skip to main content
16,011,949 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to create only empty excel file using programmatically in asp.net
Posted

1 solution

Hi

I think this may help u
C#
public void ExportTableData(DataTable dtdata)
{
    string attach = "attachment;filename=Sample.xls";
    Response.ClearContent();
    Response.AddHeader("content-disposition", attach);
    Response.ContentType = "application/ms-excel";
    if (dtdata != null)
    {
       // foreach (DataColumn dc in dtdata.Columns) // if u need to add data uncomment this
       // {
       //     Response.Write(dc.ColumnName + "\t");

       //}
       // Response.Write(System.Environment.NewLine);
       // foreach (DataRow dr in dtdata.Rows)
       //{
       //     for (int i = 0; i < dtdata.Columns.Count; i++)
       //     {
       //         Response.Write(dr[i].ToString() + "\t");
       //     }
       //     Response.Write("\n");
       }
        Response.End();
    }
}
 
Share this answer
 
v2

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