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

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


当前回答

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

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

其他回答

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

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

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

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

在双引号中添加空格前缀解决了这个问题!!

我在csv文件的一个列中有“7/8”这样的数据,MS-Excel将其转换为“07-Aug”。但是使用“LibreOffice Calc”就没有问题了。

为了解决这个问题,我只是给空格字符加上前缀(在7之前添加空格),比如“7/8”,这对我来说很有效。这是为Excel-2007测试的。

最简单的解决方案 我今天才想出来的。

用Word打开 用连字符替换所有连字符 保存并关闭 在Excel中打开

一旦你完成编辑,你可以再次在Word中打开它,再次用连字符替换破折号。