[英]How to Export utf-8 data from sql server 2008 to excel
我嘗試通過兩個選項將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|
如何從SQL Server 2008將utf-8數據導出到Excel
您可以嘗試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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.