简体   繁体   English

为什么CSV文件中的多行单元格在Excel中每行的末尾都带有问号?

[英]Why do multiline cells in my CSV file appear with a question mark at the end of each line in Excel?

I'm currently working on a project where we'd like to allow a user to export their data to CSV. 我目前正在一个项目中,我们希望允许用户将其数据导出到CSV。 Some of the data we present has multiple values for a single cell, and so we use the standard CSV method of putting each value on its own line: 我们提供的某些数据在单个单元格中具有多个值,因此我们使用标准CSV方法将每个值放在自己的行上:

Column A, Column B, Column C
Value A, "Value B1
Value B2", Value C

Most of the time this works fine, but some people are reporting seeing a small question mark in a box character appear at the end of each line when they load the file in Excel. 在大多数情况下,这可以正常工作,但是有些人报告说,在Excel中加载文件时,每行的末尾会出现一个方框问号中的小问号。 Why is this happening? 为什么会这样呢?

Although the RFC for CSV( http://www.rfc-editor.org/rfc/rfc4180.txt ) seems to imply that line breaks should be written as \\r\\n (CRLF), this is not the format that Excel outputs, and attempting to load files with this format seems to sometimes cause a problem where the [CR] character is displayed as if it were an unknown character. 尽管CSV的RFC( http://www.rfc-editor.org/rfc/rfc4180.txt )似乎暗示换行符应写为\\ r \\ n(CRLF),但这不是Excel输出的格式,并且尝试以这种格式加载文件似乎有时会导致在显示[CR]字符时就好像它是一个未知字符一样的问题。

The CSV format that Excel uses has newlines within a cell represented with a single LF character, and newlines between rows represented using CRLF. Excel使用的CSV格式在用单个LF字符表示的单元格中具有换行符,在用CRLF表示的行之间具有换行符。 So the example above should be formatted: 因此,上面的示例应采用以下格式:

Column A, Column B, Column C[CR][LF]Value A, "Value B1[LF]Value B2", Value C[CR][LF] 列A,列B,列C [CR] [LF]值A,“值B1 [LF]值B2”,值C [CR] [LF]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM