" /"从gridview导出到excel的问题 [英] "/" problem in export to excel from gridview

查看:87
本文介绍了" /"从gridview导出到excel的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我在从gridview数据导出到Excel时遇到问题。

我有正向数据在其中一个列中的数据(/)中斜线,这些列像字符/(在这种情况下更倾斜)而不是/。同一个文件正在上传到其他一些应用程序中,这个角色在其结尾处被视为一些垃圾字符。



Ex:

实际值:25515 / DT9NN2BJ_PCDG_2015

Excel显示值:25515/DT9NN2BJ_PCDG_2015



上述值的差异在于斜线。请仔细观察。



请尽快帮助。



这是我的代码。



Hi All,

I am facing a problem in Export to Excel from a gridview data.
I have the data with forward slash in the data ("/") in one of the columns which is diplaying like a character "⁄" (slant is more in this case) instead of "/". The same file is uploading in some other application and this character is taking as some junk characters at their end.

For Ex:
Actual Value:25515/DT9NN2BJ_PCDG_2015
Displayed Value in Excel:25515⁄DT9NN2BJ_PCDG_2015

The difference in above values is in "slash". please observe it carefully.

Please help ASAP.

here is my code.

DataGrid dgExport = new DataGrid();
dgExport.DataSource = dtExport;
dgExport.DataBind();

string Excelfilename = "Test_Excel_Export" + DateTime.Now;
Response.Clear();
Response.Buffer = true;
Response.ContentType = "application/vnd.ms-excel";
Response.AppendHeader("Content-Disposition:", "attachment; filename=" + Excelfilename + ".xls");
Response.Charset = "";
Response.ContentEncoding = Encoding.Unicode;
Response.BinaryWrite(Encoding.Unicode.GetPreamble());
this.EnableViewState = false;
System.IO.StringWriter oStringWriter = new System.IO.StringWriter();          System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
dgExport.RenderControl(oHtmlTextWriter);
Response.Write(oStringWriter.ToString());
Response.End







虽然我在下面添加了两行代码,但仍然是同样的问题仍然存在。






Though I have added below two lines of code, still the same problem persists.

Response.ContentEncoding = Encoding.Unicode;
Response.BinaryWrite(Encoding.Unicode.GetPreamble());







问候

Surya




Regards
Surya

推荐答案

通过编码导出数据



Export Data with Encoding it

Response.ContentEncoding = Encoding.Unicode;
Response.BinaryWrite(Encoding.Unicode.GetPreamble());





参考此链接



http:// asheej .blogspot.in / 2012/03 / how-to-export-gridview-data-to-excel.html [ ^ ]


这篇关于" /"从gridview导出到excel的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆