Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Excel: Default to TEXT rather than GENERAL when opening a .csv file

Tags:

csv

excel

Is is possible to change the default data type Excel uses when opening a .csv file? I would like Excel to default to TEXT rather than General for the Column Data Format when reading a .csv file.

I would like to be able to open a .csv without having leading 0's removed from my data. Currently I use the Import External Data wizard when reading a .csv file but I would prefer to be able to use File/Open or to just double click on the .csv file.

like image 488
JayG Avatar asked Nov 17 '09 22:11

JayG


1 Answers

One option is to record a macro of the import process, that way you can define the TextFileColumnDataTypes to be Text. When you record the macro you will see that the format is set with the line .TextFileColumnDataTypes = Array(2, 2, 2)

where 2 sets the Text format and the 3 elements in the array refer to 3 columns. You can set the array to contain more elements than the number of columns you expect to have in your text files as any extra are ignored.

You can press F8 to launch the Macro dialog which shortens the process such that it';s similar to opening from the file menu (although still not as convenient as being able to double click a file).

I found a useful example macro with some further explanations here

This goes into a bit more detail eexplaining what the relevant settings do, e.g. setting the correct delimiter in the macro etc.

like image 83
ulkash Avatar answered Oct 05 '22 23:10

ulkash