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

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


当前回答

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

其他回答

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

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

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.

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

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

对于那些寻找完全程序化(或者至少是服务器端)解决方案的人来说,我使用catdoc的xls2csv工具取得了巨大的成功。

安装catdoc:

apt-get install catdoc

进行转换:

xls2csv -d utf-8 file.xls > file-utf-8.csv 

这是非常快的。

请注意,包含-d utf-8标志非常重要,否则它将以默认的cp1252编码方式对输出进行编码,并且您将面临丢失信息的风险。

注意,xls2csv也只适用于.xls文件,它不适用于.xlsx文件。