有没有人碰巧知道,如果有一个令牌,我可以添加到我的csv的某个字段,这样Excel就不会试图将它转换为日期?
我试图从我的应用程序中编写一个.csv文件,其中一个值碰巧看起来足够像一个日期,Excel会自动将它从文本转换为日期。我曾尝试将所有文本字段(包括看起来像日期的文本字段)放在双引号内,但没有效果。
有没有人碰巧知道,如果有一个令牌,我可以添加到我的csv的某个字段,这样Excel就不会试图将它转换为日期?
我试图从我的应用程序中编写一个.csv文件,其中一个值碰巧看起来足够像一个日期,Excel会自动将它从文本转换为日期。我曾尝试将所有文本字段(包括看起来像日期的文本字段)放在双引号内,但没有效果。
当前回答
对于同样的问题,我所做的是在每个csv值之前添加以下内容: “=”“” 在Excel中打开文件之前,在每个CSV值后加上双引号。以以下值为例:
012345,00198475
在Excel中打开之前,这些应该更改为:
"="""012345","="""00198475"
这样做之后,每个单元格值在Excel中都显示为公式,因此不会格式化为数字、日期等。例如,012345的值显示为:
="012345"
其他回答
在Excel 2010中打开一个新工作表。 在“数据”ribbon上单击“从文本中获取外部数据”。 选择您的CSV文件,然后单击“打开”。 单击“下一步”。 取消“Tab”,在“逗号”旁边打勾,然后点击“下一步”。 单击第一列上的任意位置。 按住shift键拖动滑块,直到可以单击最后一列,然后松开shift键。 点击“文本”单选按钮,然后点击“完成”
所有列都将作为文本导入,就像它们在CSV文件中一样。
不是Excel。Windows可以识别公式、数据作为日期并自动更正。你必须更改Windows的设置。
“控制面板”(->“切换到经典视图”)->“区域和语言” 选项”->选项卡“区域选项”->“自定义…”->选项卡“数字”->和 然后根据你想要的改变符号。
http://www.pcreview.co.uk/forums/enable-disable-auto-convert-number-date-t3791902.html
它将在您的计算机上工作,如果这些设置没有更改,例如在您的客户的计算机上,他们将看到日期而不是数据。
这个问题仍然存在于Mac Office 2011和Office 2013,我无法阻止它发生。这似乎是很基本的事情。
在我的例子中,我有诸如“1 - 2”和“7 - 12”的值,在CSV中正确地用倒逗号括起来,这将自动转换为excel中的日期,如果您尝试随后将其转换为纯文本,您将得到日期的数字表示形式,如43768。此外,它将条形码和EAN编号中的大数字重新格式化为123E+数字,再次无法转换回来。
我发现谷歌驱动器的谷歌表不能将数字转换为日期。条形码中每3个字符有一个逗号,但这些很容易被删除。它处理csv非常好,特别是在处理MAC / Windows csv时。
说不定还能救人。
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.
嗨,我也有同样的问题,
我写这个vbscipt来创建另一个CSV文件。新的CSV文件将在每个字段的字体中有一个空格,因此excel将把它理解为文本。
所以你用下面的代码创建了一个。vbs文件(例如Modify_CSV.vbs),保存并关闭它。将原始文件拖放到vbscript文件中。它将在相同的位置创建一个文件名为“SPACE_ADDED”的新文件。
Set objArgs = WScript.Arguments
Set objFso = createobject("scripting.filesystemobject")
dim objTextFile
dim arrStr ' an array to hold the text content
dim sLine ' holding text to write to new file
'Looping through all dropped file
For t = 0 to objArgs.Count - 1
' Input Path
inPath = objFso.GetFile(wscript.arguments.item(t))
' OutPut Path
outPath = replace(inPath, objFso.GetFileName(inPath), left(objFso.GetFileName(inPath), InStrRev(objFso.GetFileName(inPath),".") - 1) & "_SPACE_ADDED.csv")
' Read the file
set objTextFile = objFso.OpenTextFile(inPath)
'Now Creating the file can overwrite exiting file
set aNewFile = objFso.CreateTextFile(outPath, True)
aNewFile.Close
'Open the file to appending data
set aNewFile = objFso.OpenTextFile(outPath, 8) '2=Open for writing 8 for appending
' Reading data and writing it to new file
Do while NOT objTextFile.AtEndOfStream
arrStr = split(objTextFile.ReadLine,",")
sLine = "" 'Clear previous data
For i=lbound(arrStr) to ubound(arrStr)
sLine = sLine + " " + arrStr(i) + ","
Next
'Writing data to new file
aNewFile.WriteLine left(sLine, len(sLine)-1) 'Get rid of that extra comma from the loop
Loop
'Closing new file
aNewFile.Close
Next ' This is for next file
set aNewFile=nothing
set objFso = nothing
set objArgs = nothing