Hi,
Please help me.
I am exporting gridview to excel. but exported excel file can not be open.
And one another reason is i have declared .xls in my code but export in .xlsx format.
In my system it export in .xls format but on server export in .xlsx format so occur the problem.
This is My code-
DataSet ds = SqlHelper.ExecuteDataset(ErpGlobal.DBCONNECTIONSTRING, CommandType.Text, "Select EmpName,EmpAdd,sal from EMP");
DGConsumption.DataSource = ds;
DGConsumption.DataBind();
if (DGConsumption.Rows.Count > 0)
{
DataSet ds2 = SqlHelper.ExecuteDataset(ErpGlobal.DBCONNECTIONSTRING, CommandType.Text, "select LocalOrder,CustomerOrderNo,replace(convert(varchar(11),DispatchDate,106),' ','-') as dispachdate from ordermaster where orderid=" + DDOrderNo.SelectedValue + "");
DGConsumption.Style.Add("font-size", "1em");
Response.Clear();
string attachment = "attachment; filename=Production Order Wise.xlsx";
Response.ClearContent();
Response.AddHeader("content-disposition", attachment);
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
DGConsumption.GridLines = GridLines.Vertical;
DGConsumption.RenderControl(htmlWrite);
Response.Write(@"
Production Of Items :Performa Invoice No -: " + ds2.Tables[0].Rows[0]["LocalOrder"].ToString() + " |
Ship Date : | " + ds2.Tables[0].Rows[0]["dispachdate"].ToString() + " | P.O Number : | " + ds2.Tables[0].Rows[0]["CustomerOrderNo"].ToString() + " |
" + stringWrite.ToString());
Response.End();