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

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


当前回答

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.

其他回答

另一个我觉得有用的例子是: “数字”允许在保存为CSV时进行编码设置。

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

你可以在没有第三方软件的现代Windows机器上做到这一点。这种方法是可靠的,它可以处理包含引号逗号、引号制表符、CJK字符等的数据。

1. 从Excel中保存

在Excel中,使用Unicode文本(*.txt)类型将数据保存到file.txt。

2. 开始PowerShell

从开始菜单运行powershell。

3.在PowerShell中加载文件

$data = Import-Csv C:\path\to\file.txt -Delimiter "`t" -Encoding BigEndianUnicode

4. 将数据保存为CSV格式

$data | Export-Csv file.csv -Encoding UTF8 -NoTypeInformation

对于那些有崇高的文本:保存编码utf-16 LE与BOM应该这样做;-)

一个简单的解决方法是使用谷歌电子表格。粘贴(只有当您有复杂公式时才使用值)或导入工作表,然后下载CSV。我只是试了几个字符,效果相当不错。

注意:谷歌表在导入时有限制。在这里看到的。

注意:小心使用谷歌表的敏感数据。

编辑:另一种选择-基本上他们使用VB宏或插件强制保存为UTF8。我没有尝试过这些解决方案,但它们听起来很合理。