我将gridview内容导出到excel文件(xlsx扩展名)时遇到问题。 我可以像xls扩展名一样导出它,但不能导出xlsx。 我的代码是:
#region === EXPORT GRID A EXCEL ===
protected void imgBtn_Consol_Export_Click(object sender, ImageClickEventArgs e)
{
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=Lotes.xls");
Response.Charset = "";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "application/vnd.xlsx";
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
gvwLotConsol_Plant.RenderControl(htmlWrite);
//style to format numbers to string
string style = @"<style> TD { mso-number-format:\@; } </style>"; //para formato texto
Response.Write(style);
Response.Write(stringWrite.ToString());
Response.End();
}
public override void VerifyRenderingInServerForm(System.Web.UI.Control control)
{/* Verifies that the control is rendered */}
#endregion
我尝试使用xls扩展但不起作用,我试过:
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
它不起作用,如果有人请帮助我,那就太好了。
最好的问候!!!