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

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


当前回答

(EXCEL 2016及以后版本,实际上我没有尝试过旧版本)

打开新空白页 转到“数据”标签 点击“来自文本/CSV”,选择CSV文件 检查预览您的数据是否正确。 在сase中,当某些列被转换为日期时,单击“编辑”,然后通过单击列头部的日历选择类型文本 点击“关闭并加载”

其他回答

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

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

如果在字段的开头放置一个倒置逗号,它将被解释为文本。

例子: 25/12/2008变成了25/12/2008

您还可以在导入时选择字段类型。

这是我知道如何在不搞乱文件本身的情况下完成这一点的唯一方法。就像使用Excel一样,我用头在桌子上敲了几个小时才学会这一点。

Change the .csv file extension to .txt; this will stop Excel from auto-converting the file when it's opened. Here's how I do it: open Excel to a blank worksheet, close the blank sheet, then File => Open and choose your file with the .txt extension. This forces Excel to open the "Text Import Wizard" where it'll ask you questions about how you want it to interpret the file. First you choose your delimiter (comma, tab, etc...), then (here's the important part) you choose a set columns of columns and select the formatting. If you want exactly what's in the file then choose "Text" and Excel will display just what's between the delimiters.

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

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

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

(假设Excel 2003…)

当使用文本到列向导时,在步骤3中,您可以为每个列指定数据类型。单击预览中的列,将行为不端的列从“常规”更改为“文本”。