| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 629 人关注过本帖
标题:请教VB msflexgrid控件导出到excel表格问题
取消只看楼主 加入收藏
芝诺
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2014-12-19
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:1 
请教VB msflexgrid控件导出到excel表格问题
界面有两个msflexgrid表格,点击command控件(只有一个)输出到excel表格。问题是:1.excel中两个表格是相互独立的,我想做到一个excel里面。2.excel表格无法调节适合大小。刚输来的有点凌乱。请教大神!!!
搜索更多相关主题的帖子: excel表格 command 
2014-12-19 11:22
芝诺
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2014-12-19
收藏
得分:0 
Dim a   As Integer
       Dim b   As Integer
       Dim d   As Integer
      On Error GoTo Ert
       Me.MousePointer = 11
       Dim Excelapp   As Excel.Application
       Set Excelapp = New Excel.Application
       On Error Resume Next
       DoEvents
       Excelapp.SheetsInNewWorkbook = 1
       Excelapp.Workbooks.Add
       Excelapp.ActiveSheet.Cells(1, 3) = s
       Excelapp.Range("C1").Select
       Excelapp.Selection.Font.FontStyle = "Bold"
       Excelapp.Selection.Font.Size = 16
       Excelapp.Caption = "输出表格"
With MSFlexGrid1
               d = MSFlexGrid1.Rows
               For a = 0 To d - 1
                       For b = 0 To 5
                             DoEvents
                             Excelapp.ActiveSheet.Cells(3 + a, b + 1) = "'" & .TextMatrix(a, b)
                       Next b
               Next a
       End With
       Me.MousePointer = 0
       Excelapp.Visible = True
      ' Excelapp.Sheets.PrintPreview
      Excelapp.Cells.EntireColumn.AutoFit
Ert:
       If Not (Excelapp Is Nothing) Then
              Excelapp.Quit
      End If
 Dim e   As String
       Dim f   As Integer
       Dim m   As Integer
       Dim n   As Integer
       On Error GoTo Ert2
       Me.MousePointer = 11
       Dim Excelapp2   As Excel.Application
       Set Excelapp2 = New Excel.Application
       On Error Resume Next
       DoEvents
       Excelapp2.SheetsInNewWorkbook = 1
       Excelapp2.Workbooks.Add
       Excelapp2.ActiveSheet.Cells(1, 3) = e
       Excelapp2.Range("C1").Select
       Excelapp2.Selection.Font.FontStyle = "Bold"
       Excelapp2.Selection.Font.Size = 16
       Excelapp2.Caption = "合计表格"
With MSFlexGrid2
               n = MSFlexGrid2.Rows
               For f = 0 To n - 1
                       For m = 0 To 5
                             DoEvents
                             Excelapp2.ActiveSheet.Cells(3 + f, m + 1) = "'" & .TextMatrix(f, m)
                              
                       Next m
               Next f
       End With
       Me.MousePointer = 0
       Excelapp2.Visible = True
      ' Excelapp2.Sheets.PrintPreview
       Excelapp2.Cells.EntireColumn.AutoFit
Ert2:
      If Not (Excelapp2 Is Nothing) Then
               Excelapp2.Quit
我写的是这样  出来的Excel表格是两个 我希望写到一个表格里面

谢谢你
2014-12-20 22:54
快速回复:请教VB msflexgrid控件导出到excel表格问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.011595 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved