有没有人碰巧知道,如果有一个令牌,我可以添加到我的csv的某个字段,这样Excel就不会试图将它转换为日期?
我试图从我的应用程序中编写一个.csv文件,其中一个值碰巧看起来足够像一个日期,Excel会自动将它从文本转换为日期。我曾尝试将所有文本字段(包括看起来像日期的文本字段)放在双引号内,但没有效果。
有没有人碰巧知道,如果有一个令牌,我可以添加到我的csv的某个字段,这样Excel就不会试图将它转换为日期?
我试图从我的应用程序中编写一个.csv文件,其中一个值碰巧看起来足够像一个日期,Excel会自动将它从文本转换为日期。我曾尝试将所有文本字段(包括看起来像日期的文本字段)放在双引号内,但没有效果。
当前回答
在微软Office 2016版本中,这仍然是一个问题,这让我们这些研究基因名称的人感到不安,如MARC1、MARCH1、SEPT1等。 我发现最实用的解决方案是在R中生成一个“。csv”文件,然后将与Excel用户打开/共享:
以文本(记事本)形式打开CSV文件 复制它(ctrl+a, ctrl+c)。 粘贴到一个新的excel表格中-它将全部粘贴在一列作为长文本字符串。 选择/选择此列。 转到Data-“Text to columns…”,在打开的窗口中选择“delimited”(下一步)。检查“逗号”被标记(标记它将显示数据与下面列的分离)(下一步),在这个窗口中,您可以选择您想要的列并将其标记为文本(而不是通用)(完成)。
HTH
其他回答
I know this is an old question, but the problem is not going away soon. CSV files are easy to generate from most programming languages, rather small, human-readable in a crunch with a plain text editor, and ubiquitous. The problem is not only with dates in text fields, but anything numeric also gets converted from text to numbers. A couple of examples where this is problematic: ZIP/postal codes telephone numbers government ID numbers which sometimes can start with one or more zeroes (0), which get thrown away when converted to numeric. Or the value contains characters that can be confused with mathematical operators (as in dates: /, -). Two cases that I can think of that the "prepending =" solution, as mentioned previously, might not be ideal is where the file might be imported into a program other than MS Excel (MS Word's Mail Merge function comes to mind), where human-readability might be important. My hack to work around this If one pre/appends a non-numeric and/or non-date character in the value, the value will be recognized as text and not converted. A non-printing character would be good as it will not alter the displayed value. However, the plain old space character (\s, ASCII 32) doesn't work for this as it gets chopped off by Excel and then the value still gets converted. But there are various other printing and non-printing space characters that will work well. The easiest however is to append (add after) the simple tab character (\t, ASCII 9). Benefits of this approach: Available from keyboard or with an easy-to-remember ASCII code (9), It doesn't bother the importation, Normally does not bother Mail Merge results (depending on the template layout - but normally it just adds a wide space at the end of a line). (If this is however a problem, look at other characters e.g. the zero-width space (ZWSP, Unicode U+200B) is not a big hindrance when viewing the CSV in Notepad (etc), and could be removed by find/replace in Excel (or Notepad etc). You don't need to import the CSV, but can simply double-click to open the CSV in Excel. If there's a reason you don't want to use the tab, look in an Unicode table for something else suitable. Another option might be to generate XML files, for which a certain format also is accepted for import by newer MS Excel versions, and which allows a lot more options similar to .XLS format, but I don't have experience with this. So there are various options. Depending on your requirements/application, one might be better than another. Addition It needs to be said that newer versions (2013+) of MS Excel don't open the CSV in spreadsheet format any more - one more speedbump in one's workflow making Excel less useful... At least, instructions exist for getting around it. See e.g. this Stackoverflow: How to correctly display .csv files within Excel 2013? .
这是我知道如何在不搞乱文件本身的情况下完成这一点的唯一方法。就像使用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.
警告:Excel '07(至少)有一个(另一个)错误:如果字段的内容中有逗号,它不会正确解析="field, contents",而是将逗号后的所有内容放入下面的字段中,而不管引号是什么。
我发现唯一有效的解决方法是当字段内容包含逗号时消除=。
这可能意味着有些字段不可能在Excel中完全“正确”地表示,但到目前为止,我相信没有人会感到太惊讶。
这周我刚刚遇到了这个惯例,它似乎是一个很好的方法,但我在任何地方都找不到它。有人熟悉吗?你能举出出处吗?我没有找了几个小时,但我希望有人会认识到这种方法。
例1:=("012345678905")显示为012345678905
例2:=("1954-12-12")显示为1954-12-12,而不是12/12/1954。
在双引号中添加空格前缀解决了这个问题!!
我在csv文件的一个列中有“7/8”这样的数据,MS-Excel将其转换为“07-Aug”。但是使用“LibreOffice Calc”就没有问题了。
为了解决这个问题,我只是给空格字符加上前缀(在7之前添加空格),比如“7/8”,这对我来说很有效。这是为Excel-2007测试的。