VB6[1].0_导出excel_方法源代码-.pdf
《VB6[1].0_导出excel_方法源代码-.pdf》由会员分享,可在线阅读,更多相关《VB6[1].0_导出excel_方法源代码-.pdf(5页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、往链点点通共享资源,了解更多请登录www.WLVB6.0 导出 excel 方法源代码方法一:用 Msflexgrid的 Textmatrix 属性取 Msflexgrid 中每一个单元格的内容,然后填到Excel 表中,或者写成 CSV 格式方法二:直接把查询结果导出成Excel 工作表Public Sub Export(formname As Form,flexgridname As String)Dim xlApp As Object Excel.Application Dim xlBook As Object Excel.Workbook Dim xlSheet As Object E
2、xcel.Worksheet Screen.MousePointer =vbHourglass On Error GoTo Err_Proc Set xlApp =CreateObject(Excel.Application)Set xlBook =xlApp.Workbooks.Add Set xlSheet =xlBook.Worksheets(1)Begin to fill data to sheet Dim i As Long Dim j As Integer Dim k As Integer With formname.Controls(flexgridname)For i =0 T
3、o .rows -1 k =0 For j =0 To .Cols -1 If .colwidth(j)20 Or .colwidth(j)0 Then k =k +1 xlSheet.Cells(i +1,k).Value =&.TextMatrix(i,j)End If Next j Next i End With xlApp.Visible =True Screen.MousePointer =vbDefault Exit Sub Err_Proc:Screen.MousePointer =vbDefault MsgBox 请确认您的电脑已安装Excel!,vbExclamation,提
4、示 End Sub=Public Function ExporToExcel(strOpen As String)*名称:ExporToExcel *功能:导出数据到EXCEL *用法:ExporToExcel(sql查询字符串)*Dim Rs_Data As New ADODB.Recordset Dim Irowcount As Integer Dim Icolcount As Integer Dim cn As New ADODB.Connection Dim xlApp As New Excel.Application Dim xlBook As Excel.Workbook Dim
5、xlSheet As Excel.Worksheet Dim xlQuery As Excel.QueryTable With Rs_Data If .State =adStateOpen Then .Close End If .ActiveConnection =provider=msdasql;DRIVER=Microsoft Visual FoxPro Driver;UID=;Deleted=yes;Null=no;Collate=Machine;BackgroundFetch=no;Exclusive=No;SourceType=DBF;SourceDB=D:DBF;.CursorLo
6、cation =adUseClient .CursorType =adOpenStatic .Source =strOpen .Open End With With Rs_Data If .RecordCount 1 Then MsgBox (没有记录!)Exit Function End If 记录总数Irowcount =.RecordCount 字段总数Icolcount =.Fields.Count End With Set xlApp =CreateObject(Excel.Application)Set xlBook =Nothing Set xlSheet =Nothing Se
7、t xlBook =xlApp.Workbooks().Add Set xlSheet =xlBook.Worksheets(sheet1)xlApp.Visible =True 添加查询语句,导入EXCEL 数据Set xlQuery =xlSheet.QueryTables.Add(Rs_Data,xlSheet.Range(a1)xlQuery.FieldNames =True 显示字段名xlQuery.Refresh xlApp.Application.Visible =True Set xlApp =Nothing 交还控制给 Excel Set xlBook =Nothing Se
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- VB6 导出 excel_ 方法 源代码
限制150内