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

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


当前回答

在微软Office 2016版本中,这仍然是一个问题,这让我们这些研究基因名称的人感到不安,如MARC1、MARCH1、SEPT1等。 我发现最实用的解决方案是在R中生成一个“。csv”文件,然后将与Excel用户打开/共享:

以文本(记事本)形式打开CSV文件 复制它(ctrl+a, ctrl+c)。 粘贴到一个新的excel表格中-它将全部粘贴在一列作为长文本字符串。 选择/选择此列。 转到Data-“Text to columns…”,在打开的窗口中选择“delimited”(下一步)。检查“逗号”被标记(标记它将显示数据与下面列的分离)(下一步),在这个窗口中,您可以选择您想要的列并将其标记为文本(而不是通用)(完成)。

HTH

其他回答

SELECT CONCAT('\'',NOW(),'\''), firstname, lastname 
FROM your_table
INTO OUTFILE 'export.csv' 
FIELDS TERMINATED BY ',' 
ENCLOSED BY '\"' 
LINES TERMINATED BY '\n'

我对不断转换为科学符号的信用卡号这样做:我最终将.csv导入到谷歌Sheets中。导入选项现在允许禁用数字值的自动格式化。我将任何敏感列设置为纯文本并下载为xlsx。

这是一个糟糕的工作流程,但至少我的价值观保持了原样。

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.

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

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

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

在Excel 2010中打开一个新工作表。 在“数据”ribbon上单击“从文本中获取外部数据”。 选择您的CSV文件,然后单击“打开”。 单击“下一步”。 取消“Tab”,在“逗号”旁边打勾,然后点击“下一步”。 单击第一列上的任意位置。 按住shift键拖动滑块,直到可以单击最后一列,然后松开shift键。 点击“文本”单选按钮,然后点击“完成”

所有列都将作为文本导入,就像它们在CSV文件中一样。