Does anyone happen to know if there is a token I can add to my csv for a certain field so Excel doesn\'t try to convert it to a date?
I\'m trying to write a .csv fil
WARNING: Excel '07 (at least) has a(nother) bug: if there's a comma in the contents of a field, it doesn't parse the ="field, contents" correctly, but rather puts everything after the comma into the following field, regardless of the quotation marks.
The only workaround I've found that works is to eliminate the = when the field contents include a comma.
This may mean that there are some fields that are impossible to represent exactly "right" in Excel, but by now I trust no-one is too surprised.
(Assuming Excel 2003...)
When using the Text-to-Columns Wizard has, in Step 3 you can dictate the data type for each of the columns. Click on the column in the preview and change the misbehaving column from "General" to "Text."
Hi I have the same issue,
I write this vbscipt to create another CSV file. The new CSV file will have a space in font of each field, so excel will understand it as text.
So you create a .vbs file with the code below (for example Modify_CSV.vbs), save and close it. Drag and Drop your original file to your vbscript file. It will create a new file with "SPACE_ADDED" to file name in the same location.
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
Without modifying your csv file you can:
excel will properly format and separate your csv cells as text formatted ignoring auto date formats.
Kind of a silly work around, but it beats modifying the csv data before importing. Andy Baird and Richard sort of eluded to this method, but missed a couple important steps.
I do this for credit card numbers which keep converting to scientific notation: I end up importing my .csv into Google Sheets. The import options now allow to disable automatic formatting of numeric values. I set any sensitive columns to Plain Text and download as xlsx.
It's a terrible workflow, but at least my values are left the way they should be.
Here is the simple method we use at work here when generating the csv file in the first place, it does change the values a bit so it is not suitable in all applications:
Prepend a space to all values in the csv
This space will get stripped off by excel from numbers such as " 1"," 2.3" and " -2.9e4" but will remain on dates like " 01/10/1993" and booleans like " TRUE", stopping them being converted into excel's internal data types.
It also stops double quotes being zapped on read in, so a foolproof way of making text in a csv remain unchanged by excel EVEN IF is some text like "3.1415" is to surround it with double quotes AND prepend the whole string with a space, i.e. (using single quotes to show what you would type) ' "3.1415"'. Then in excel you always have the original string, except it is surrounded by double quotes and prepended by a space so you need to account for those in any formulas etc.