简体   繁体   English

如何从SQL Server 2008将utf-8数据导出到Excel

[英]How to Export utf-8 data from sql server 2008 to excel

I try to export utf-8 data from sql server 2008 to excel by two option. 我尝试通过两个选项将utf-8数据从sql server 2008导出到excel。 But data-utf-8 is not correct 但是data-utf-8是不正确的
Example I have a table has Name column (Collation: SQL_Latin1_General_CP1_CI_AS, nvarchar(3000)) 示例我有一个具有“名称”列的表(整理:SQL_Latin1_General_CP1_CI_AS,nvarchar(3000))

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

If i using asp code to show it on browser with 如果我使用asp代码在浏览器上显示

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

Data will show correct like 数据将显示正确的

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

But when i export to excel with: 但是当我导出到excel时:

Option 1 i using 选项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

or Option 2: i using 或选项2:我使用

SQL Server Import and Export Wizard

But both option don't show correct data-utf-8. 但是,这两个选项均未显示正确的data-utf-8。 It still like 还是喜欢

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

How to Export utf-8 data from sql server 2008 to excel thanks 如何从SQL Server 2008将utf-8数据导出到Excel

You can try BCP bulk export, but 2008R2 您可以尝试BCP批量导出,但是2008R2

SQL Server does not support code page 65001 (UTF-8 encoding). SQL Server不支持代码页65001(UTF-8编码)。 reference 参考

You need to add -w parameter in bcp utility to specify the encoding is UTF16. 您需要在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


Then Try open csv in excel 然后尝试在excel中打开csv

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM