将csv文件导入Excel时,文本将转换为数字 [英] When importing a csv file into Excel text is converted to number
本文介绍了将csv文件导入Excel时,文本将转换为数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用以下方式将CSV文件导入Excel 2010电子表格:
I am importing a CSV file into an Excel 2010 spreadsheet using something like this:
Set wb = Workbooks.Open(Filename:=myFile, ReadOnly:=True, Notify:=False)
Set ws = wb.Worksheets(1)
Set rRng = ws.Range("A" & CStr(iFirstDataRow) & ":" & "G" & CStr(iLastRow))
rRng.Columns(2).NumberFormat = "@"
'copy file on sheet ws1
ws1.Cells.Clear
rRng.Copy ws1.Cells(1, 1)
问题在于,其中一列包含的修订号在CSV文件中显示如下:
the problem is that one of the columns is containing revision numbers that appear as follows in the CSV file:
0.0
1.0
2.2
2.20
导入后,我得到:
0
1
2.2
2.2
因为文本已转换为数字.
because text has been converted to numbers.
我该如何阻止呢?
谢谢你, M.R.
更新:
使用Opentext方法也不起作用:
using Opentext method does not work either:
Workbooks.OpenText Filename:=sFile, Origin:=xlWindows, StartRow:=1, DataType:=xlDelimited, Tab:=False, Semicolon:=False, Comma:=True, Space:=False, Other:=False, FieldInfo:=Array(Array(1, xlMDYFormat), Array(2, xlTextFormat))
由于某些原因,忽略了FieldInfo参数
For some reason FieldInfo parameter is ignored
推荐答案
使用:
Set wb = Workbooks.OpenText
具有适当的参数,用于将修订号字段定义为 String .参见:
with appropriate parameters to define the revision number field as String. See:
这篇关于将csv文件导入Excel时,文本将转换为数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文