如何转义CSV文件中的逗号和语音标记,以便它们在Excel中工作? [英] How should I escape commas and speech marks in CSV files so they work in Excel?

查看:234
本文介绍了如何转义CSV文件中的逗号和语音标记,以便它们在Excel中工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在生成一个CSV文件(以逗号而不是制表符分隔)。我的用户很可能通过双击在Excel中打开CSV文件。我的数据可能包含逗号和语音标记,因此我将如下转义。

I'm generating a CSV file (delimited by commas rather than tabs). My users will most likely open the CSV file in Excel by double clicking it. My data may contain commas and speech marks, so I'm escaping those as follows.

Reference, Title, Description
1, "My little title", "My description, which may contain ""speech marks"" and commas."
2, "My other little title", "My other description, which may also contain ""speech marks"" and commas."

据我所知,这是一种方法。这是我的boggle:当我打开这个文件在Excel 2010我的转义不尊重。

As far as I know that's always been the way to do it. Here's my boggle: when I open this file in Excel 2010 my escaping is not respected. Speech marks appear on the sheet, and the comma causes new columns.

推荐答案

我们最终找到了答案。

如果列值不在前面加一个空格,Excel将只遵守逗号和语音标记的转义。所以生成的文件没有这样的空格...

Excel will only respect the escaping of commas and speech marks if the column value is NOT preceded by a space. So generating the file without spaces like this...

Reference,Title,Description
1,"My little title","My description, which may contain ""speech marks"" and commas."
2,"My other little title","My other description, which may also contain ""speech marks"" and commas."

...解决了问题。希望这有助于某人!

... fixed the problem. Hope this helps someone!

这篇关于如何转义CSV文件中的逗号和语音标记,以便它们在Excel中工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆