写一点关于导出表的吧!就实现了一下功能,实力略低,请各位指教!
引用了Microsoft Excel 16.0 object library。基本上就可以了。
下面是代码:
Dim i As Integer
Dim j As Integer
MSHFlexGrid1.Redraw = False '关闭表格重画
Set xlApp = CreateObject("Excel.Application") '创建EXCEL对象
'打开已经存在的excel工作薄文件
Set xlBook = xlApp.Workbooks.Open(App.Path & "\新建 Microsoft Excel 工作表.xlsx")
xlApp.Visible = True '设置excel对象可见
Set xlSheet = xlBook.Worksheets("Sheet1") '设置活动工作表
For i = 0 To MSHFlexGrid1.Rows - 1 '行循环
For j = 0 To MSHFlexGrid1.Cols - 1 '列循环
MSHFlexGrid1.Row = i
MSHFlexGrid1.Col = j
'保存到EXCEL
xlBook.Worksheets("Sheet1").Cells(i + 1, j + 1) = MSHFlexGrid1.Text
Next j
Next i
MSHFlexGrid1.Redraw = True