VB:急急急急!!!!如何把Excel中的数据导入到msFlexGrid控件中?
- 你的回答被采纳后将获得:
- 系统奖励15(财富值+成长值)+难题奖励20(财富值+成长值)
展开全部
On Error GoTo errline
CommonDialog1.Flags = cdlCFBoth
CommonDialog1.Filter = "excel文件(*.xls) | *.xls|excel文件(*.xlsx) | *.xlsx"
CommonDialog1.CancelError = True '保证在取消对话框不报错
CommonDialog1.ShowOpen
Dim xlApp As Excel.Application, xlBook As Excel.Workbook, xlSheet As Excel.Worksheet
Dim I As Long, J As Long,BomData() as string,Num as integer
Set xlApp = New Excel.Application
xlApp.Visible = False
Set xlBook = xlApp.Workbooks.Open(Text1.Text)
Set xlSheet = xlBook.Sheets(1)
With xlSheet
RowBom = .Cells(.Rows.Count, 1).End(xlUp).Row - 1
ColBom = .Cells(1, .Columns.Count).End(xlToLeft).Column
'ReDim BomData(RowBom, ColBom)
For I = 1 To RowBom
for j = 1 to colbom
msflexgrid.textmatrix(i-1,j-1) = .cells(i,j)
next j
Next I
End With
xlBook.Close
xlApp.Quit
Set xlSheet = Nothing
Set xlBook = Nothing
Set xlApp = Nothing
text1.text = num
errline:
If Err.Number <> 0 Then
MsgBox CStr(Err.Number) + "" + Err.Description, vbOKOnly + vbInformation
End If
Err.Clear
CommonDialog1.Flags = cdlCFBoth
CommonDialog1.Filter = "excel文件(*.xls) | *.xls|excel文件(*.xlsx) | *.xlsx"
CommonDialog1.CancelError = True '保证在取消对话框不报错
CommonDialog1.ShowOpen
Dim xlApp As Excel.Application, xlBook As Excel.Workbook, xlSheet As Excel.Worksheet
Dim I As Long, J As Long,BomData() as string,Num as integer
Set xlApp = New Excel.Application
xlApp.Visible = False
Set xlBook = xlApp.Workbooks.Open(Text1.Text)
Set xlSheet = xlBook.Sheets(1)
With xlSheet
RowBom = .Cells(.Rows.Count, 1).End(xlUp).Row - 1
ColBom = .Cells(1, .Columns.Count).End(xlToLeft).Column
'ReDim BomData(RowBom, ColBom)
For I = 1 To RowBom
for j = 1 to colbom
msflexgrid.textmatrix(i-1,j-1) = .cells(i,j)
next j
Next I
End With
xlBook.Close
xlApp.Quit
Set xlSheet = Nothing
Set xlBook = Nothing
Set xlApp = Nothing
text1.text = num
errline:
If Err.Number <> 0 Then
MsgBox CStr(Err.Number) + "" + Err.Description, vbOKOnly + vbInformation
End If
Err.Clear
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询