如何连接code单向code这样既iPad和Excel可以理解吗? [英] How to encode Unicode so both iPad and Excel can understand?

查看:130
本文介绍了如何连接code单向code这样既iPad和Excel可以理解吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个CSV是带UTF32 codeD。当我在IE中打开流,开放与Excel我能读懂一切。 iPad上的我流,我得到一个空白页,没有任何内容。 (我不知道如何查看iPad的来源,这样可能会有一些隐藏在HTML)。

I have a CSV that is encoded with UTF32. When I open stream in IE and open with Excel I can read everything. On iPad I stream and I get a blank page with no content whatsoever. (I don't know how to view source on iPad so there could be something hidden in HTML).

HTTP响应是写在asp.net C#

The http response is written in asp.net C#

Response.Clear();
Response.Buffer = true;

Response.ContentType = "text/comma-separated-values";
Response.AddHeader("Content-Disposition", "attachment;filename=\"InventoryCount.csv\"");

Response.RedirectLocation = "InventoryCount.csv";
Response.ContentEncoding = Encoding.UTF32;//works on Excel wrong in iPad
//Response.ContentEncoding = Encoding.UTF8;//works on iPad wrong in Excel

Response.Charset = "UTF-8";//tried also adding Charset just to see if it works somehow, but it does not.
EnableViewState = false;

NMDUtilities.Export oUtilities = new NMDUtilities.Export();

Response.Write(oUtilities.DataGridToCSV(gvExport, ","));

Response.End();

唯一想我可以做的是,iPad上无法读取UTF32,是真的吗?如何查看源在iPad上?

The only guess I can make is that iPad cannot read UTF32, is that true? How can I view source on iPad?



更新

我只是做了一项有趣的发现。当我的编码是UTF8事情在iPad上工作,字符正常显示,但是Excel中搅乱一个字符。但是当我使用UTF32逆是真实的。 iPad上显示什么,但Excel的完美。我真的不知道我能做些什么这个问题。


UPDATE
I just made an interesting discovery. When my encoding is UTF8 things work on iPad and characters are displayed properly, but Excel messes up a character. But when I use UTF32 the inverse is true. iPad displays nothing, but Excel works perfectly. I really have no idea what I can do about this.

iPad的UTF8输出=Quattrode®

Excel中UTF8输出=Quattrode®

iPad UTF8 outputs = " Quattrode® "
Excel UTF8 outputs = " Quattrode® "

iPad的UTF32输出=

Excel中UTF32输出=Quattrode®

iPad UTF32 outputs = " "
Excel UTF32 outputs = " Quattrode® "

下面是我实现DataGridToCsv的

Here's my implementation of DataGridToCsv

public string DataGridToCsv(GridView input, string delimiter)
{
    StringBuilder sb = new StringBuilder();

//iterate Gridview and put row results in stringbuilder...
   string result = HttpUtility.HtmlDecode(sb.ToString());
   return result;
}



UPDATE2 Excel是barfing在UTF8 >:{。人。我刚解开他列出,因为它不上iPad上运行的第二个选项。我不能赢得失去了这一点。


UPDATE2 Excel is barfing on UTF8 >:{. Man. I just undid the second option he lists because it doesnt work on iPad. I cant win for losing on this one.

UPDATE3
根据您的建议,我已经看过十六进制code。没有的BOM,但存在的文件格式之间的差异。

UPDATE3
Per your suggestions I have looked at the hex code. There is no BOM, but there is a difference between the file layouts.


4D 61 74 65 (MATE从第一个字材料)

UTF32
4D 00 00 00 (M从第一个字材料)

UTF8
4D 61 74 65 (MATE from the first word MATERIAL)
UTF32
4D 00 00 00 (M from the first word MATERIAL)

所以看起来UTF32勾画出来的东西在32位VS UTF8在8位这样做。我想这就是为什么Excel可以猜到。现在,我会尝​​试你的建议的修复。

So it looks like UTF32 lays things out in 32 bits vs UTF8 doing it in 8 bits. I think this is why Excel can guess. Now I will try your suggested fixes.

推荐答案

的问题是,浏览器知道你的数据的编码是UTF-8,但它没有告诉Excel的方式。当Excel打开文件时,它假设系统的缺省编码。如果复制一些非ASCII文本,粘贴到记事本中,使用UTF-8编码保存它,虽然,你会看到Excel可以正确检测到它。它的工作原理在iPad上,因为它的默认编码恰好是UTF-8。

The problem is that the browser knows your data's encoding is UTF-8, but it has no way of telling Excel. When Excel opens the file, it assumes your system's default encoding. If you copy some non-ASCII text, paste it in Notepad, and save it with UTF-8 encoding, though, you'll see that Excel can properly detect it. It works on the iPad because its default encoding just happens to be UTF-8.

原因是,记事本把正确的字节顺序标记 EF BB BF 在文件的开头的UTF-8)。您可以通过使用十六进制编辑器或其他方式尝试自己创建一个包含文件

The reason is that Notepad puts the proper byte order mark (EF BB BF for UTF-8) in the beginning of the file. You can try it yourself by using a hex editor or some other means to create a file containing

EF BB BF 20 51 75 61 74 74 72 6F 64 65 C2 AE 20

和在Excel打开该文件。 (我用Excel 2010中,但我相信它会与所有最新版本。)

and opening that file in Excel. (I used Excel 2010, but I assume it would work with all recent versions.)

尝试与前3个字节,确保你的输出开始。

Try making sure your output starts with those first 3 bytes.



如何编写C#中的BOM


How to write a BOM in C#

    byte[] BOM = new byte[] { 0xef, 0xbb, 0xbf };
    Response.BinaryWrite(BOM);//write the BOM first
    Response.Write(utility.DataGridToCSV(gvExport, ","));//then write your CSV

这篇关于如何连接code单向code这样既iPad和Excel可以理解吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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