0

我尝试通过两个选项将 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 谢谢

4

1 回答 1

0

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

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

您需要在 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

于 2015-05-08T13:25:03.930 回答