从数据表 asp.net 在Excel中编写阿拉伯语

本文关键字:阿拉伯语 Excel 数据表 asp net | 更新日期: 2023-09-27 17:57:24

>我正在尝试将数据从数据库写入 excel 文件,但我遇到了阿拉伯语单词的问题:

它看起来像:السبت

我试过这段代码:

Application.Lock();
        SqlConnection con = Connection.Open();
        SqlCommand com = new SqlCommand("SELECT u.* FROM sarcshiftuser AS u WHERE (table_id =  (SELECT TOP (1) table_id FROM sarcshifttable ORDER BY table_id DESC)) ",con);
        SqlDataAdapter da = new SqlDataAdapter(com);
        DataTable usertable = new DataTable();
        da.Fill(usertable);
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
        string attachment = "attachment; filename=Employee.xls";
        HttpContext.Current.Response.Clear();
        HttpContext.Current.Response.Buffer = true;
        HttpContext.Current.Response.Charset = "UTF-8";
        HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8;
        HttpContext.Current.Response.AddHeader("content-disposition",  attachment );
        HttpContext.Current.Response.ContentType = "application/vnd.ms-excel";

Response.Write("السبت"); // in this row I tried to write saturday word in arabic but its appear :`السبت`
Response.End();
        Application.UnLock();

有什么帮助吗?如果可能的话,另一个问题:如何从 C# 代码隐藏合并单元格并为单元格的背景着色?

从数据表 asp.net 在Excel中编写阿拉伯语

HttpContext.Current.Response.Charset = "UTF-8";HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8;