在Excel中转​​换为文本格式

时间:2010-10-04 01:53:28

标签: excel ibm-midrange

我正在使用excel宏从AS400中提取一些数据。在AS400中,此特定列(Ref)显示20100729000078154,但当我将其提取为excel时,它将为2.01007E + 16。我需要hv 20100729000078154作为我的最终输出。这是我用来从AS400中提取信息的宏: -

Sub Extract()

Dim StrSQl As String

FromA = Format(Sheet1.Range("B3"))
FromB = Format(Sheet1.Range("B4"))
FromC = Format(Sheet1.Range("B5"))
FromD = Format(Sheet1.Range("B6"))

StrSQl = "select Cno,Itno,Ref from test "
StrSQl = StrSQl & " where Cno= " & FromA & " and Itno like " & FromB & " and "
StrSQl = StrSQl & " Ref >= " & FromC & " and  Ref <= " & FromD & " "
StrSQl = StrSQl & " order by Cno "

con = "Provider=IBMDA400;Data Source=xxx.xxx.xxx.xxx;User Id=yyyyy;Password=zzzzz"

Set Db = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.recordset")
Db.ConnectionString = con
Db.Open


rs.Open StrSQl, Db, 3, 3

Sheet2.Cells(1, 1).CopyFromRecordset rs

rs.Close

Set rs = Nothing
Set cn = Nothing

End Sub

1 个答案:

答案 0 :(得分:4)

如果您只想让列显示为文本,您可以为撇号添加前缀,例如(假设单个撇号文字可以在iSeries SQL中表示为'')...

StrSQl = "select Cno,Itno,CONCAT('''',Ref) as Ref from test "