我有一个Excel文件,其中有一些西班牙字符(波浪号等),我需要将其转换为CSV文件作为导入文件使用。然而,当我将另存为CSV时,它会破坏不是ASCII字符的“特殊”西班牙字符。它似乎也这样做的左右引号和长破折号,似乎是来自最初的用户在Mac中创建Excel文件。

由于CSV只是一个文本文件,我确信它可以处理UTF8编码,所以我猜这是Excel的限制,但我正在寻找一种方法,从Excel到CSV,并保持非ascii字符完整。


当前回答

在Excel 2016及更高版本(包括Office 365)中,有一个专门用于UTF-8格式的CSV选项。

在Office 365中,选择另存为;以前人们可能会选择CSV(逗号分隔),现在你可以保存为CSV UTF-8(逗号分隔)(*.csv)

其他回答

我无法在Mac Excel上找到这个问题的VBA解决方案。似乎根本没有办法输出UTF-8文本。

所以我最终不得不放弃VBA,咬紧牙关,学习了AppleScript。情况远没有我想的那么糟。

解决方案如下: http://talesoftech.blogspot.com/2011/05/excel-on-mac-goodbye-vba-hello.html

您可以将excel保存为unicode文本,它是制表符分隔的。

Easy way to do it: download open office (here), load the spreadsheet and open the excel file (.xls or .xlsx). Then just save it as a text CSV file and a window opens asking to keep the current format or to save as a .ODF format. select "keep the current format" and in the new window select the option that works better for you, according with the language that your file is been written on. For Spanish language select Western Europe (Windows-1252/ WinLatin 1) and the file works just fine. If you select Unicode (UTF-8), it is not going to work with the spanish characters.

您可以在Unix下使用iconv命令(也可以在Windows上作为libiconv)。

在Excel下保存为CSV后,在命令行输入:

iconv -f cp1250 -t utf-8 file-encoded-cp1250.csv > file-encoded-utf8.csv

(记住用你的编码替换cp1250)。

工作快速和伟大的大文件,如邮政编码数据库,不能导入到GoogleDocs(400.000单元格限制)。

使用Powershell怎么样?

Get-Content 'C:\my.csv' | Out-File 'C:\my_utf8.csv' -Encoding UTF8