在ASP.NET中导出Excel文件时导出格式问题 [英] Export formatting problem when export excel file in ASP.NET
问题描述
在asp.net中导出excel文件123停止此记录
我尝试过:
这么多尝试但没有解决方案...
回复。清除();
Response.Buffer = true;
Response.AddHeader(content-disposition,
attachment; filename = GridViewExport.xls);
Response.Charset =;
Response.ContentType =application / vnd.ms-excel;
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
GridView1.AllowPaging = false;
GridView1.DataBind();
row.Attributes.Add(class,textmode);
string style = @< style> .textmode {mso-number-format:\ @;}< / style>;
Response.Write(样式);
Response.Output.Write(sw.ToString());
Response.Flush();
Response.End();
您没有导出Excel文件。您正在发送HTML,但告诉浏览器它是Excel文件。 Excel正在尽力将HTML解释为Excel文件,但显然不能保留数字格式。
如果您需要精确控制格式,那么你将不得不生成一个真正的 Excel文件。有各种工具可以让你这样做 - 例如:
export excel file in asp.net when emp_number colunm 0123 value automatically change 123 stop this record
What I have tried:
so much try but no solutuion...
Response.Clear();
Response.Buffer = true;
Response.AddHeader("content-disposition",
"attachment;filename=GridViewExport.xls");
Response.Charset = "";
Response.ContentType = "application/vnd.ms-excel";
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
GridView1.AllowPaging = false;
GridView1.DataBind();
row.Attributes.Add("class", "textmode");
string style = @"<style> .textmode { mso-number-format:\@; } </style>";
Response.Write(style);
Response.Output.Write(sw.ToString());
Response.Flush();
Response.End();
You're not exporting an Excel file. You're sending HTML, but telling the browser that it's an Excel file. Excel is then trying its best to interpret the HTML as an Excel file, but it's obviously not preserving the number formatting.
If you need precise control over the formatting, then you're going to have to generate a real Excel file. There are various tools that will let you do this - for example:
这篇关于在ASP.NET中导出Excel文件时导出格式问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!