我有一个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.

其他回答

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

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

我也有同样的问题,遇到了这个添加,它在excel 2013中工作得很好,除了excel 2007和2010,它是提到的。

“nevets1219”的第二个选项是在notepad++中打开CSV文件并将其转换为ANSI。

在顶部菜单中选择: Encoding ->转换为Ansi

看起来很有趣,我发现将180MB的电子表格保存到UTF8 CSV文件中最简单的方法是将单元格选择到Excel中,复制它们,并将剪贴板的内容粘贴到SublimeText中。

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

安装catdoc:

apt-get install catdoc

进行转换:

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

这是非常快的。

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

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