有没有人碰巧知道,如果有一个令牌,我可以添加到我的csv的某个字段,这样Excel就不会试图将它转换为日期?
我试图从我的应用程序中编写一个.csv文件,其中一个值碰巧看起来足够像一个日期,Excel会自动将它从文本转换为日期。我曾尝试将所有文本字段(包括看起来像日期的文本字段)放在双引号内,但没有效果。
有没有人碰巧知道,如果有一个令牌,我可以添加到我的csv的某个字段,这样Excel就不会试图将它转换为日期?
我试图从我的应用程序中编写一个.csv文件,其中一个值碰巧看起来足够像一个日期,Excel会自动将它从文本转换为日期。我曾尝试将所有文本字段(包括看起来像日期的文本字段)放在双引号内,但没有效果。
当前回答
2018
唯一适合我的解决方案(也没有修改CSV)。
Excel 2010:
创建新工作簿 数据>从文本>选择您的CSV文件 在弹出框中选择“Delimited”单选按钮,然后点击“Next >” 分隔符复选框:只勾选“逗号”,取消勾选其他选项,然后单击“下一步>” 在“数据预览”中,滚动到最右,然后按住shift并单击最后一列(这将选中所有列)。现在在“列数据格式”中选择单选按钮“文本”,然后单击“完成”。
Excel office365:(客户端版本)
创建新工作簿 数据>从文本/CSV >选择您的CSV文件 数据类型检测>不检测
注意:Excel office365 (web版本),当我写这篇文章时,你将无法做到这一点。
其他回答
在我的案例中,使用R生成的csv文件中的“Sept8”被Excel 2013转换为“8-Sept”。该问题通过使用xlsx包中的write.xlsx2()函数生成xlsx格式的输出文件来解决,该输出文件可以由Excel加载,而无需进行不必要的转换。因此,如果给你一个csv文件,你可以尝试将它加载到R中,并使用write.xlsx2()函数将其转换为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.
SELECT CONCAT('\'',NOW(),'\''), firstname, lastname
FROM your_table
INTO OUTFILE 'export.csv'
FIELDS TERMINATED BY ','
ENCLOSED BY '\"'
LINES TERMINATED BY '\n'
在微软Office 2016版本中,这仍然是一个问题,这让我们这些研究基因名称的人感到不安,如MARC1、MARCH1、SEPT1等。 我发现最实用的解决方案是在R中生成一个“。csv”文件,然后将与Excel用户打开/共享:
以文本(记事本)形式打开CSV文件 复制它(ctrl+a, ctrl+c)。 粘贴到一个新的excel表格中-它将全部粘贴在一列作为长文本字符串。 选择/选择此列。 转到Data-“Text to columns…”,在打开的窗口中选择“delimited”(下一步)。检查“逗号”被标记(标记它将显示数据与下面列的分离)(下一步),在这个窗口中,您可以选择您想要的列并将其标记为文本(而不是通用)(完成)。
HTH
而创建字符串要写入我的CSV文件在c#中,我必须这样格式化它:
"=\"" + myVariable + "\""