|
发表于 2020-2-23 12:00:02
|
显示全部楼层
我是把excel中的数据导入到MSHFlexGrid1.TextMatrix(i, 1)控件里的!供楼主参考
Private Sub MnuInput_Click()
Rem 保存表格中的数据
Dim FileName As String '''''''''''将数据保存到Excel表里
Dim i As Integer
CommonDialog1.FileName = ""
CommonDialog1.Filter = "Excel 表|*.xls"
CommonDialog1.ShowOpen
FileName = CommonDialog1.FileName
If FileName = "" Then
Exit Sub
End If
Set xlApp = CreateObject("Excel.Application")
''Set xlBook = xlApp.Workbooks ''.Add ''添加新工作表
Set xlBook = xlApp.Workbooks.Open(FileName)
‘’’Set xlBook = xlApp.Workbooks.Open(“c:\lizi.xls”) ‘’’具体路径
Set xlSheet = xlBook.Worksheets(1) ''''''打开Excel表
xlSheet.Activate ''激活工作表
For i = 0 To 27
''For Alfi = 0 To 90 Step 18
MSHFlexGrid1.TextMatrix(i, 1) = xlSheet.Cells(i + 1, 1) '''''将MSFlexGrid数据导入到Excel 中
MSHFlexGrid1.TextMatrix(i, 2) = xlSheet.Cells(i + 1, 2)
''Next Alfi
Next i
'''xlBook.SaveAs FileName
xlBook.RunAutoMacros (xlAutoClose) '''执行Excel关闭宏
xlBook.Close (True) '''''关闭Excel工作表
xlApp.Quit '''''''''关闭Excel工作本
Set xlApp = Nothing
End Sub
|
|