有没有人碰巧知道,如果有一个令牌,我可以添加到我的csv的某个字段,这样Excel就不会试图将它转换为日期?
我试图从我的应用程序中编写一个.csv文件,其中一个值碰巧看起来足够像一个日期,Excel会自动将它从文本转换为日期。我曾尝试将所有文本字段(包括看起来像日期的文本字段)放在双引号内,但没有效果。
有没有人碰巧知道,如果有一个令牌,我可以添加到我的csv的某个字段,这样Excel就不会试图将它转换为日期?
我试图从我的应用程序中编写一个.csv文件,其中一个值碰巧看起来足够像一个日期,Excel会自动将它从文本转换为日期。我曾尝试将所有文本字段(包括看起来像日期的文本字段)放在双引号内,但没有效果。
当前回答
根据Jarod的解决方案和Jeffiekins提出的问题,你可以进行修改
"May 16, 2011"
to
"=""May 16, 2011"""
其他回答
我对不断转换为科学符号的信用卡号这样做:我最终将.csv导入到谷歌Sheets中。导入选项现在允许禁用数字值的自动格式化。我将任何敏感列设置为纯文本并下载为xlsx。
这是一个糟糕的工作流程,但至少我的价值观保持了原样。
这是我知道如何在不搞乱文件本身的情况下完成这一点的唯一方法。就像使用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.
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.
下面是我们在生成csv文件时使用的简单方法,它确实会稍微改变值,所以并不适用于所有应用程序:
在csv中的所有值前加一个空格
excel将从诸如“1”、“2.3”和“-2.9e4”等数字中剥离该空格,但将保留诸如“01/10/1993”这样的日期和诸如“TRUE”这样的布尔值,从而阻止它们转换为excel的内部数据类型。
它也停止双引号被zapped在读进去,所以一个简单的方法,使文本在csv中保持不变的excel即使是一些文本,如“3.1415”是用双引号包围它,并在整个字符串前加上一个空格,即(使用单引号来显示你会键入什么)“3.1415”。然后在excel中,你总是有原始的字符串,除了它被双引号包围并以空格开头,所以你需要在任何公式中考虑这些。
如果有人还在寻找答案,下面这句话对我来说非常合适
我输入=("my_value")。 即=("04SEP2009")显示为04SEP2009,而不是09/04/2009
这同样适用于大于15位的整数。他们不再修剪了。