hi Mudassar,
My Problem solved.
as i seen this article from u r site.
i just passes dataset and get what i need
http://www.aspsnippets.com/Articles/Solution-ASPNet-GridView-Export-to-Excel-The-file-you-are-trying-to-open-is-in-a-different-format-than-specified-by-the-file-extension.aspx
my code is as follows..
public DataSet Fill_Dataset()
{
DataSet ds = new DataSet();
DataTable dt1 = new DataTable("Cust_Info");
dt1.Columns.AddRange(new DataColumn[3] { new DataColumn("Id", typeof(int)), new DataColumn("Name", typeof(string)), new DataColumn("Country", typeof(string)) });
dt1.Rows.Add(1, "Rajesh", "India");
dt1.Rows.Add(2, "R1", "India");
dt1.Rows.Add(3, "R2", "India");
dt1.Rows.Add(4, "R3", "India");
DataTable dt2 = new DataTable("Emp_Info");
dt2.Columns.AddRange(new DataColumn[3] { new DataColumn("Id", typeof(int)), new DataColumn("Name", typeof(string)), new DataColumn("Country", typeof(string)) });
dt2.Rows.Add(1, "aaaaaa", "aaaaa");
dt2.Rows.Add(2, "bbbbbb", "bbbbb");
dt2.Rows.Add(3, "ccccc", "cccc");
dt2.Rows.Add(4, "ddddd", "dddd");
ds.Tables.Add(dt1);
ds.Tables.Add(dt2);
return ds;
}
protected void btn_Export_Click(object sender, EventArgs e)
{
DataSet ds = Fill_Dataset();
using (XLWorkbook wb = new XLWorkbook())
{
wb.Worksheets.Add(ds);
wb.Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center;
wb.Style.Font.Bold = true;
Response.Clear();
Response.Buffer = true;
Response.Charset = "";
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
Response.AddHeader("content-disposition", "attachment;filename=Summary_Rpt.xlsx");
using (MemoryStream MyMemoryStream = new MemoryStream())
{
wb.SaveAs(MyMemoryStream);
MyMemoryStream.WriteTo(Response.OutputStream);
Response.Flush();
Response.End();
}
}
}