Configuring a csv file and reading with Excel

2019-08-16 20:41发布

Most examples for .csv files look more or less like this:

A,B,C
1,2,3
4,"5,3",6

For larger files, with irregular length of content per field, looking for info in a text editor is way too messy. Meanwhile, opening this directly in excel puts the whole content of each line into the same column, which is normally not intended.

One common practice I've seen is to use the directive sep=<delimiter>:

sep=,
A,B,C
1,2,3
4,"5,3",6

This allows excel to promptly place each comma separated value into a separate column. Wonderful! The quotes on "5,3" even disappear, making the content of the column as 5,3. The directive sep=<delimiter> is particularly useful if someone else using the .csv might not be so keen to keep changing the default settings of Excel, nor changing them every time a new csv is opened.

With this, easy visualization of .csv files is seamlessly achieved with excel.

But what is sep=<delimiter> exactly? Is there a manual with all such directives/commands? Is there a command that could instruct excel what should be the decimal separator for that file and which encoding should to be used?

Part of my problem is that I'm writing float values in a .csv, which Excel misinterprets and then saves differently. Same goes for texts that Excel may recognize as calendar dates. There are the possibilities of adding a single quote ' before each text like cell and an = before any numerical value. But for a large file, this does not seem neither optimal nor necessary.

标签: csv text
0条回答
登录 后发表回答