如何将带有中文字符的Excel文件导出到CSV? [英] How do I export an Excel file with Chinese characters to a CSV?
问题描述
我有一个Excel文档,其数据表包含汉字.我正在尝试将此Excel电子表格导出为CSV文件,以导入到MySQL数据库中.
I having a Excel document with a data table containing Chinese characters. I am trying to export this Excel spreadsheet to a CSV file for importing into a MySQL database.
但是,当我将Excel文档另存为CSV文件时,记事本会显示生成的CSV文件的汉字作为问号.导入MySQL会保留问号,而完全忽略了原始汉字是什么.
However, when I save the Excel document as a CSV file, Notepad displays the resulting CSV file's Chinese characters as question marks. Importing into MySQL preserves the question marks, completely ignoring what the original Chinese characters are.
我怀疑这可能与使用具有UTF-8编码的Excel有关.感谢您的帮助!
I'm suspecting this may have to do with using Excel with UTF-8 encoding. Thanks for your help!
推荐答案
以下方法已经过测试,可用于在MongoDB中导入CSV文件,因此应该可以使用:
The following method has been tested and used to import CSV files in MongoDB, so it should work:
-
在Excel工作表中,转到文件">另存为".
In your Excel worksheet, go to File > Save As.
命名文件,然后从保存为类型"旁边的下拉列表中选择Unicode文本(* .txt),然后单击保存".
Name the file and choose Unicode Text (*.txt) from the drop-down list next to "Save as type", and then click Save.
使用您喜欢的文本编辑器(例如记事本)打开unicode .txt文件.
Open the unicode .txt file using your preferred text editor, for example Notepad.
由于我们的Unicode文本文件是制表符分隔的文件,并且我们希望将Excel转换为CSV(逗号分隔)文件,因此我们需要用逗号替换所有制表符.
Since our unicode text file is a tab-delimited file and we want to convert Excel to CSV (comma-separated) file, we need to replace all tabs with commas.
选择一个制表符,右键单击它,然后从上下文菜单中选择复制",或仅按CTRL + C,如下面的屏幕快照所示.
Select a tab character, right click it and choose Copy from the context menu, or simply press CTRL+C as shown in the screenshot below.
按CTRL + H打开替换"对话框,然后将复制的选项卡(CTRL + V)粘贴到查找内容"字段中.当您执行此操作时,光标将向右移动,指示已粘贴该选项卡.在替换为"字段中键入逗号,然后单击全部替换".
Press CTRL+H to open the Replace dialog and paste the copied tab (CTRL+V) in the Find what field. When you do this, the cursor will move rightwards indicating that the tab was pasted. Type a comma in the Replace with field and click Replace All.
单击文件>另存为,输入文件名并将编码更改为UTF-8.然后单击保存"按钮.
Click File > Save As, enter a file name and change the encoding to UTF-8. Then click the Save button.
直接在记事本的另存为"对话框中将.txt扩展名更改为.csv,然后选择另存为"类型旁边的所有文件(.)",如下面的屏幕快照所示.
Change the .txt extension to .csv directly in Notepad's Save as dialog and choose All files (.) next to Save as type, as shown in the screenshot below.
通过单击文件>打开>文本文件(.prn,.txt,.csv)从Excel中打开CSV文件,并验证数据是否可以.
Open the CSV file from Excel by clicking File > Open > Text files (.prn, .txt, .csv) and verify if the data is Okay.
来源此处
这篇关于如何将带有中文字符的Excel文件导出到CSV?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!