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.
是否可以更改打开.csv文件时使用的默认数据类型?在读取.csv文件时,我希望Excel默认为文本而不是一般的列数据格式。
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.
我希望能够打开一个.csv,而不需要从我的数据中删除前导0。目前,我在读取.csv文件时使用导入外部数据向导,但我更希望能够使用file /Open或双击.csv文件。
2 个解决方案
#1
1
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)
一个选项是记录导入过程的宏,这样就可以将TextFileColumnDataTypes定义为文本。当您记录宏时,您将看到格式设置为.TextFileColumnDataTypes = Array(2,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.
其中2设置文本格式,数组中的3个元素引用3列。可以将数组设置为包含比文本文件中预期的列数更多的元素,因为任何额外的元素都将被忽略。
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).
您可以按F8来启动宏对话框,它可以缩短进程,使其类似于从文件菜单中打开(尽管仍然不如双击文件那样方便)。
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.
这将更详细地解释相关设置的作用,例如在宏中设置正确的分隔符等。
#2
0
If you have the option, you can save the data to an XML spreadsheet (I know, these files get large very fast) - to open it, just drag it to an open Excel window. This is the only way I know of to get the result you'd like. -- It is only useful for moderate to small data sets.
如果有选项,可以将数据保存到XML电子表格中(我知道,这些文件很快就会变大)——要打开它,只需将它拖放到一个打开的Excel窗口中。这是我所知道的得到你想要的结果的唯一方法。——仅适用于中、小数据集。
#1
1
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)
一个选项是记录导入过程的宏,这样就可以将TextFileColumnDataTypes定义为文本。当您记录宏时,您将看到格式设置为.TextFileColumnDataTypes = Array(2,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.
其中2设置文本格式,数组中的3个元素引用3列。可以将数组设置为包含比文本文件中预期的列数更多的元素,因为任何额外的元素都将被忽略。
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).
您可以按F8来启动宏对话框,它可以缩短进程,使其类似于从文件菜单中打开(尽管仍然不如双击文件那样方便)。
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.
这将更详细地解释相关设置的作用,例如在宏中设置正确的分隔符等。
#2
0
If you have the option, you can save the data to an XML spreadsheet (I know, these files get large very fast) - to open it, just drag it to an open Excel window. This is the only way I know of to get the result you'd like. -- It is only useful for moderate to small data sets.
如果有选项,可以将数据保存到XML电子表格中(我知道,这些文件很快就会变大)——要打开它,只需将它拖放到一个打开的Excel窗口中。这是我所知道的得到你想要的结果的唯一方法。——仅适用于中、小数据集。