Excel从csv导入数据的编码选择
Import or export text (.txt or .csv) files
There are two ways to import data from a text file with Excel: you can open it in Excel, or you can import it as an external data range. To export data from Excel to a text file, use the Save As command and change the file type from the drop-down menu.
There are two commonly used text file formats:
-
Delimited text files (.txt), in which the TAB character (ASCII character code 009) typically separates each field of text.
-
Comma separated values text files (.csv), in which the comma character (,) typically separates each field of text.
You can change the separator character that is used in both delimited and .csv text files. This may be necessary to make sure that the import or export operation works the way that you want it to.
Note: You can import or export up to 1,048,576 rows and 16,384 columns.
Import a text file by opening it in Excel
You can open a text file that you created in another program as an Excel workbook by using the Open command. Opening a text file in Excel does not change the format of the file — you can see this in the Excel title bar, where the name of the file retains the text file name extension (for example, .txt or .csv).
-
Go to File > Open and browse to the location that contains the text file.
-
Select Text Files in the file type dropdown list in the Open dialog box.
-
Locate and double-click the text file that you want to open.
-
If the file is a text file (.txt), Excel starts the Import Text Wizard. When you are done with the steps, click Finish to complete the import operation. See Text Import Wizard for more information about delimiters and advanced options.
-
If the file is a .csv file, Excel automatically opens the text file and displays the data in a new workbook.
Note: When Excel opens a .csv file, it uses the current default data format settings to interpret how to import each column of data. If you want more flexibility in converting columns to different data formats, you can use the Import Text Wizard. For example, the format of a data column in the .csv file may be MDY, but Excel's default data format is YMD, or you want to convert a column of numbers that contains leading zeros to text so you can preserve the leading zeros. To force Excel to run the Import Text Wizard, you can change the file name extension from .csv to .txt before you open it, or you can import a text file by connecting to it (for more information, see the following section).
-
Import a text file by connecting to it
You can import data from a text file into an existing worksheet.
-
Click the cell where you want to put the data from the text file.
-
On the Data tab, in the Get External Data group, click From Text.
-
In the Import Data dialog box, locate and double-click the text file that you want to import, and click Import.
Follow the instructions in the Text Import Wizard. Click Help
on any page of the Text Import Wizard for more information about using the wizard. When you are done with the steps in the wizard, click Finish to complete the import operation.
-
In the Import Data dialog box, do the following:
-
Under Where do you want to put the data?, do one of the following:
-
To return the data to the location that you selected, click Existing worksheet.
-
To return the data to the upper-left corner of a new worksheet, click New worksheet.
-
-
Optionally, click Properties to set refresh, formatting, and layout options for the imported data.
-
Click OK.
Excel puts the external data range in the location that you specify.
-
If Excel does not convert a column of data to the format that you want, you can convert the data after you import it. For more information, see Convert numbers stored as text to numbers and Convert dates stored as text to dates.
[Test] public void Test20210519001() { Console.WriteLine(GetEncodingString(Encoding.GetEncoding(51936))); Console.WriteLine(GetEncodingString(Encoding.GetEncoding(936))); Console.WriteLine(GetEncodingString(Encoding.GetEncoding(20936))); Console.WriteLine(GetEncodingString(Encoding.GetEncoding(52936))); Console.WriteLine(GetEncodingString(Encoding.GetEncoding(50227))); Console.WriteLine(GetEncodingString(Encoding.GetEncoding(10008))); Console.WriteLine(GetEncodingString(Encoding.GetEncoding(950))); Console.WriteLine(GetEncodingString(Encoding.GetEncoding(20000))); Console.WriteLine(GetEncodingString(Encoding.GetEncoding(20002))); Console.WriteLine(GetEncodingString(Encoding.GetEncoding(10002))); } private string GetEncodingString(Encoding encoding) { return $"CodePage = {encoding.CodePage}, EncodingName = {encoding.EncodingName}, WebName = {encoding.WebName}"; }
CodePage = 51936, EncodingName = Chinese Simplified (EUC), WebName = EUC-CN
CodePage = 936, EncodingName = Chinese Simplified (GB2312), WebName = gb2312
CodePage = 20936, EncodingName = Chinese Simplified (GB2312-80), WebName = x-cp20936
CodePage = 52936, EncodingName = Chinese Simplified (HZ), WebName = hz-gb-2312
CodePage = 50227, EncodingName = Chinese Simplified (ISO-2022), WebName = x-cp50227
CodePage = 10008, EncodingName = Chinese Simplified (Mac), WebName = x-mac-chinesesimp
CodePage = 950, EncodingName = Chinese Traditional (Big5), WebName = big5
CodePage = 20000, EncodingName = Chinese Traditional (CNS), WebName = x-Chinese-CNS
CodePage = 20002, EncodingName = Chinese Traditional (Eten), WebName = x-Chinese-Eten
CodePage = 10002, EncodingName = Chinese Traditional (Mac), WebName = x-mac-chinesetrad
HZ-GB-2312中文编码详解 https://datatracker.ietf.org/doc/html/rfc1843
作者:Chuck Lu GitHub |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
2020-05-25 xml security issue
2020-05-25 Non-scalar subquery in place of a scalar
2019-05-25 域名信息备案查询 以及 国家企业信用信息公示
2019-05-25 404. Sum of Left Leaves
2019-05-25 git修改commiter date
2017-05-25 Exception: Operation xx of contract xx specifies multiple request body parameters to be serialized without any wrapper elements.
2017-05-25 如何测试WCF Rest