您好,欢迎来到华佗小知识。
搜索
您的当前位置:首页在VB中把EXCEL文件导入MSFlexGrid

在VB中把EXCEL文件导入MSFlexGrid

来源:华佗小知识


在VB中把EXCEL文件导入MSFLEXGRID

首先需要引用Excel库:

从\"工程\"菜单中选择\"引用\"栏;选择Microsoft Excel 11.0 Object Library(EXCEL2003),然后选择\"确定\"。表示在工程中要引用EXCEL类型库。

Private Sub Command1_Click()

Dim ExcelApp As Excel.Application

Set ExcelApp = CreateObject(\"excel.application\")

ExcelApp.Workbooks.Open (App.Path & \" est2.xls\")

With MSFlexGrid1

.Rows = ExcelApp.Sheets(1).UsedRange.Rows.Count

.Cols = 4

For r = 0 To .Rows - 1

For c = 1 To .Cols

If c = 1 Then

.TextMatrix(r, c - 1) = Year(Date) & \"-\" & ExcelApp.Sheets(1).Cells(r + 1, c + 1) & \"-\" & ExcelApp.Sheets(1).Cells(r + 1, c)

Else

.TextMatrix(r, c - 1) = ExcelApp.Sheets(1).Cells(r + 1, c + 1)

End If

Next

Next

End With

ExcelApp.Quit

End Sub

Private Sub Command2_Click()

Open App.Path & \"导出.txt\" For Output As #1

With MSFlexGrid1

For r = 0 To .Rows - 1

For c = 0 To .Cols - 1

Print #1, .TextMatrix(r, c);

If c < .Cols - 1 Then Print #1, \

Next

Print #1,

Next

End With

Close #1

MsgBox \"导出完毕\"

End Sub

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- huatuo0.cn 版权所有 湘ICP备2023017654号-2

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务