vb怎样调用对话框,选择excel文件,并将选中的文件sheet1导入到MSHFlexGrid1中显示
如题,vb怎样调用对话框,选择excel文件,并将选中的文件sheet1导入到MSHFlexGrid1中显示
谢谢! MSHFLEXGRID
[解决办法]
Dim FileName As String
Private Sub Command1_Click()
'引用ado:工程--->引用--->Microsoft ActiveX Data Object 2.x(版本号)
'引用控件 Microsoft Common Dialog Control 6.X(版本号)
'工程中有一个 MSHFlexGrid1 控件 ;一个CommonDialog1控件; 一个Command1控件
MSHFlexGrid1.FixedCols = 0
MSHFlexGrid1.FixedRows = 1
CommonDialog1.Filter = "*.Xls(Excel文件)
[解决办法]
*.Xls"
CommonDialog1.ShowOpen
If Len(CommonDialog1.FileName) = 0 Then Exit Sub
FileName = CommonDialog1.FileName
On Error Resume Next
Dim cn As New ADODB.Connection, rs As New ADODB.Recordset
cn.CursorLocation = adUseClient
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=" & FileName & ";Extended Properties='Excel 8.0;HDR=Yes'"
rs.Open "select * from [Sheet1$]", cn, adOpenDynamic, adLockOptimistic
Set MSHFlexGrid1.DataSource = rs
End Sub