有没有人碰巧知道,如果有一个令牌,我可以添加到我的csv的某个字段,这样Excel就不会试图将它转换为日期?

我试图从我的应用程序中编写一个.csv文件,其中一个值碰巧看起来足够像一个日期,Excel会自动将它从文本转换为日期。我曾尝试将所有文本字段(包括看起来像日期的文本字段)放在双引号内,但没有效果。


当前回答

我发现在双引号前加一个'='就能达到你想要的效果。它强制数据为文本。

如。=“2008-10-03”=“文本”

编辑(根据其他帖子):由于Jeffiekins指出的Excel 2007漏洞,应该使用Andrew提出的解决方案:"=""2008-10-03""" "

其他回答

None of the solutions offered here is a good solution. It may work for individual cases, but only if you're in control of the final display. Take my example: my work produces list of products they sell to retail. This is in CSV format and contain part-codes, some of them start with zero's, set by manufacturers (not under our control). Take away the leading zeroes and you may actually match another product. Retail customers want the list in CSV format because of back-end processing programs, that are also out of our control and different per customer, so we cannot change the format of the CSV files. No prefixed'=', nor added tabs. The data in the raw CSV files is correct; it's when customers open those files in Excel the problems start. And many customers are not really computer savvy. They can just about open and save an email attachment. We are thinking of providing the data in two slightly different formats: one as Excel Friendly (using the options suggested above by adding a TAB, the other one as the 'master'. But this may be wishful thinking as some customers will not understand why we need to do this. Meanwhile we continue to keep explaining why they sometimes see 'wrong' data in their spreadsheets. Until Microsoft makes a proper change I see no proper resolution to this, as long as one has no control over how end-users use the files.

使用谷歌驱动器(如果你在Mac上,也可以使用Numbers)的解决方案:

在Excel中打开数据 将数据错误的列的格式设置为文本(format > Cells > Number > Text) 将.csv文件加载到谷歌Drive,并使用谷歌Sheets打开它 复制出错的列 将列作为文本粘贴到Excel中(编辑>粘贴特殊>文本)

或者,如果你在Mac上进行第3步,你可以在Numbers中打开数据。

我在Excel 2003和2007中找到了一个简单的方法。打开一个空白的xls工作簿。然后进入数据菜单,导入外部数据。选择您的csv文件。通过向导,然后在“列数据格式”中选择任何需要强制“文本”的列。这将以文本格式导入整个列,防止Excel试图将任何特定的单元格作为日期处理。

这个问题仍然存在于Mac Office 2011和Office 2013,我无法阻止它发生。这似乎是很基本的事情。

在我的例子中,我有诸如“1 - 2”和“7 - 12”的值,在CSV中正确地用倒逗号括起来,这将自动转换为excel中的日期,如果您尝试随后将其转换为纯文本,您将得到日期的数字表示形式,如43768。此外,它将条形码和EAN编号中的大数字重新格式化为123E+数字,再次无法转换回来。

我发现谷歌驱动器的谷歌表不能将数字转换为日期。条形码中每3个字符有一个逗号,但这些很容易被删除。它处理csv非常好,特别是在处理MAC / Windows csv时。

说不定还能救人。

(excel2007及以上版本)

如何强制excel不“检测”日期格式而不编辑源文件

:

将文件重命名为.txt 如果你不能这样做,而不是直接在excel中打开CSV文件,创建一个新的工作簿,然后转到 数据>从文本中获取外部数据>并选择您的CSV。

无论哪种方式,你都会看到导入选项,只需选择每个包含日期的列,并告诉excel格式为“文本”而不是“一般”。