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

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


当前回答

我也遇到了同样的问题,于是谷歌了这篇文章。以上这些方法对我都没用。最后,我将我的Unicode .xls转换为.xml(选择另存为…XML电子表格2003),它产生了正确的字符。然后我编写代码来解析xml并提取内容供我使用。

其他回答

Encoding -> Convert to Ansi将其编码为Ansi /UNICODE。Utf8是Unicode的一个子集。也许在ANSI中会正确编码,但在这里我们谈论的是UTF8, @SequenceDigitale。

还有更快的方法,比如导出为csv(逗号分隔),然后用notepad++(免费)打开csv,然后Encoding > Convert to UTF8。但前提是每个文件必须执行一次。如果你需要经常更改和导出,那么最好是LibreOffice或GDocs解决方案。

我发现OpenOffice的电子表格应用程序Calc非常擅长处理CSV数据。

在“另存为…”对话框中,单击“格式选项”可获得CSV的不同编码。LibreOffice的工作原理与AFAIK相同。

使用Powershell怎么样?

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

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

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

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

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

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

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.