表格数据输出到Excel中

Sub ImpExcel(GRid As Object, n As Integer)
  Dim xlApp As Excel.Application
  Dim i, j, r, file1, ob1
  file1 = App.Path & "/xhdn/项目分类查询统计" & Date & ".xls"
 FileCopy "xhdn/xh01.xls", file1
 DoEvents
  Set xlApp = New Excel.Application
  Set xlApp = CreateObject("Excel.Application")
 '激活EXCEL应用程序
 xlApp.Visible = False '隐藏EXCEL应用程序窗口
 
 Set xlBook = xlApp.Workbooks.Open(file1)
 '打开工作簿,strDestination为一个EXCEL报表文件
 Set xlSheet = xlBook.Worksheets(1)
 'xlsheet.range("G12").Select
 'xlsheet.Pictures.Insert("C:/01.gif").Select   图像文件处理
 'xlApp.Selection.ShapeRange.ScaleWidth 2.76, msoFalse, msoScaleFromTopLeft
 'xlApp.Selection.ShapeRange.ScaleHeight 2.77, msoFalse, msoScaleFromTopLeft
 
  xlSheet.Cells(2, 1) = P_setup1(6) & "项目分类查询统计"
  xlSheet.Cells(4, 1) = "制表日期:" & Date
   ob1 = ""
With GRid
    For i = 1 To GRid.Rows - 1
       If ob <> .TextMatrix(i, 1) Then   '重复数据处理
         xlSheet.Cells(5 + i, 1) = .TextMatrix(i, 1)
         ob = .TextMatrix(i, 1)
       Else
         xlSheet.Cells(5 + i, 1).Borders(xlEdgeTop).LineStyle = xlNone   '线型处理
         xlSheet.Cells(5 + i, 1).Borders(xlEdgeBottom).LineStyle = xlNone
       End If
     For j = 2 To 4
       xlSheet.Cells(5 + i, j) = .TextMatrix(i, j)
      Next j
      If .TextMatrix(i, 1) = "合计:" Then
       r = "A" & 5 + i & ":D" & 5 + i
       With xlSheet.Range(r).Interior
        .ColorIndex = 15
        .Pattern = xlSolid
      End With
      End If
      xlSheet.Cells(5 + i + 1, j).EntireRow.Insert
       r = "A" & 5 + i + 1 & ":D" & 5 + i + 1
        xlSheet.Range(r).Interior.ColorIndex = xlNone
    Next i
 End With
 
   If n = 1 Then
    
      'xlsheet.PrintPreview = False
      xlSheet.PrintOut
      xlBook.Save
      xlApp.Quit
    Else
       xlApp.Visible = True
    End If
   Set xlApp = Nothing
  
    
    
End Sub 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值