【问题标题】:How to Export utf-8 data from sql server 2008 to excel如何将 utf-8 数据从 sql server 2008 导出到 excel
【发布时间】:2013-09-13 22:21:53
【问题描述】:

我尝试通过两个选项将 utf-8 数据从 sql server 2008 导出到 excel。但是 data-utf-8 不正确
示例我有一个表有名称列(排序规则:SQL_Latin1_General_CP1_CI_AS,nvarchar(3000))

|Name               |
|Trưá»ng ÄH Dược|

如果我使用 asp 代码在浏览器上显示它

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

数据会正确显示

|Name               |
|Trường ĐH Dược     |

但是当我导出到 excel 时:

选项 1 我使用

Enable Ad Hoc Distributed Queries

EXEC sp_configure 'show advanced options', 1;
GO
RECONFIGURE;
GO
EXEC sp_configure 'Ad Hoc Distributed Queries', 1;
GO
RECONFIGURE;
GO


INSERT INTO OPENROWSET('Microsoft.ACE.OLEDB.12.0', 'Excel 8.0;Database=C:\testing.xls;', 'SELECT Name, Email FROM [Sheet1$]')
SELECT Name, Email FROM tblnames
GO

或选项 2:我使用

SQL Server Import and Export Wizard

但是这两个选项都没有显示正确的 data-utf-8。还是喜欢

 |Name               |
 |Trưá»ng ÄH Dược|

如何将 utf-8 数据从 sql server 2008 导出到 excel,谢谢

【问题讨论】:

    标签: sql excel sql-server-2008 utf-8


    【解决方案1】:

    你可以尝试 BCP 批量导出,但是 2008R2

    SQL Server 不支持代码页 65001(UTF-8 编码)。 reference

    您需要在 bcp 实用程序中添加 -w 参数以指定编码为 UTF16。

    DECLARE @cmd varchar(1000)
        SET @cmd = 'bcp "select * from table" queryout "d:\file.csv" -w -T -t; -Slocalhost'
        EXEC xp_cmdshell @cmd
    


    然后尝试在excel中打开csv

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-03-29
      • 2011-03-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多