禁用Microsoft Excel的自动格式化date

我的情况是这样的:

我从包含date列的.CSV文件导入数据。 出于我自己的原因(我不得不稍后处理数据),我希望date列保留为Stringtypes的variables,直到稍后我进行自己的处理。

所以我从数据选项卡下的文本导入数据,select我的分隔符,并select列数据格式为文本。 当数据被移植时,一切似乎都很好。

现在因为数据是“不洁”的,date字段前后有一个空格。 所以没有问题:我写一个macros来修剪()的值,这样的话:

Dim v As String v = Cells(Row, col).Value v = Trim(v) Cells(Row, col).Value = v 

用循环来根据需要重新定义行和列。

问题是这样的:一旦macros运行,Excel识别结果string作为date格式,因此将该单元格的值转换为date格式的string。 我怎样才能把它作为一个string值?

尝试:

 Dim v As String v = Cells(Row, col).Value v = Trim(v) Cells(Row, col).Value = "'" & v 

如果你用单引号加上单元格的值,excel会把它当作一个string。

你也可以使用:

 Dim v As String v = Cells(Row, col).Value v = Trim(v) Cells(Row, col).NumberFormat = "@" Cells(Row, col).Value = v