本文介绍了将希腊字符写入excel文件使用C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

=

<pre>           string attachment = "attachment; filename=download.xls";
                Response.ClearContent();
                Response.AddHeader("content-disposition", attachment);
                Response.ContentType = "application/vnd.xls";

                //Response.BinaryWrite(UTF8Encoding.UTF8.GetBytes(attachment));

                Response.Charset = UnicodeEncoding.UTF8.WebName;
                Response.HeaderEncoding = UnicodeEncoding.UTF8;
                Response.ContentEncoding = UnicodeEncoding.UTF8;

                string tab = " ";
                foreach (DataColumn dc in dt.Columns)
                {
                    Response.Write(tab + dc.ColumnName);
                    tab = "\t";
                }
                Response.Write("\n");
                int i;

                UTF8Encoding utf8 = new UTF8Encoding();
                foreach (DataRow dr in dt.Rows)
                {

                    tab = "";
                    for (i = 0; i < dt.Columns.Count - 1; i++)
                    {

                        Console.WriteLine(dr[i].ToString());
                        tab = "\t";
                    }
                    Response.Write("\n");

                }
                Response.End()





我的尝试:



我想用希腊文字符导出excel文件...为什么不工作???



What I have tried:

I want to export an excel file with greeks characters ...why not working???

推荐答案

string attachment = "attachment; filename=download.xls";
              Response.ClearContent();
              Response.AddHeader("content-disposition", attachment);
              Response.ContentEncoding = System.Text.Encoding.UTF32 ;
              Response.BinaryWrite(System.Text.Encoding.UTF32.GetPreamble());
              Response.ContentType = "application/vnd.xls";







谢谢:)




thanks :)



Response.BinaryWrite(UnicodeEncoding.UTF8.GetPreamble());

您还要创建一个TAB分隔文本文件(一个CSV文件,其中TAB为分隔符而不是逗号)。然后,您不应将其声明为Excel文件( application / vnd.xls )并使用 .xls 文件扩展名。改为使用 application / octet-stream .txt 扩展名。



另请注意,您实际上并非将内容写入流但是写入控制台。

You are also creating a TAB separated text file (a CSV file with the TAB as separator instead of the comma). Then you should not declare it as Excel file (application/vnd.xls) and use the .xls file extension. Use application/octet-stream and a .txt extension instead.

Note also that you are actually not writing the content to the stream but to the console.


这篇关于将希腊字符写入excel文件使用C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-28 22:17
查看更多