https://bbs.csdn.net/topics/350170669
yyoinge https://my.csdn.net/yyoinge
OleObject xlapp
Integer li_row
String ls_filename, ls_version, ls_info
xlapp = Create oleobject
li_row = xlapp.ConnectToNewObject(
"Excel.Application"
)
If li_row < 0 Then
Messagebox(
"系统提示"
,
"不能运行Excel程序,请检查是否已安装Microsoft Excel软件!"
,Stopsign!)
Else
ls_version = String(xlapp.Version)
Choose Case ls_version
Case
'9.0'
ls_info =
"Excel 2000"
Case
'10.0'
ls_info =
"Excel 2002/XP"
Case
'11.0'
ls_info =
"Excel 2003"
Case
'12.0'
ls_info =
"Excel 2007"
Case
'14.0'
ls_info =
"Excel 2010"
Case Else
ls_info =
"未知版本"
End Choose
Messagebox(
"系统提示"
, ls_info +
" 版本号:"
+ ls_version +
"~t"
)
xlapp.DisconnectObject()
End If
哦,我知道我的问题在哪了,应该是连接字符串有问题,之前的是这样:
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;" & _
"Data Source=" & txtFile.Text & ";Extended Properties='Excel 8.0;HDR=No;IMEX=1'"
请教如果是excel2007的文件,这个字符串应该如何写?
百度到答案了,
cn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Persist Security Info=True;" & _
"Data Source=" & txtFile.Text & ";Extended Properties='Excel 12.0;HDR=Yes;IMEX=1'"
多谢楼上各位