zoukankan      html  css  js  c++  java
  • VB输出数据到EXCEL

    Private Sub Command1_Click()
        Dim i As Long
        Dim j As Long
        Dim myData(10, 10) As Long
        Dim xlApp, WS, WB
        Set xlApp = CreateObject("Excel.Application")
        Set WB = xlApp.WorkBooks.Add
        Set WS = WB.Sheets(1)
        For i = 0 To 10
            For j = 0 To 10
                WS.Cells(i + 1, j + 1).Value = myData(i, j) '写入第i+1行,第j+1列
            Next j
        Next i
        xlApp.Visible = True
        Set xlApp = Nothing
        Set WS = Nothing
        Set WB = Nothing
    End Sub

    上面只是读取出来,如果要写入操作,也可以:

    Private Sub Command1_Click()
        Dim i As Long
        Dim j As Long
        Dim myData(10, 10) As Long
        Dim xlApp
        Set xlApp = CreateObject("Excel.Application") '创建EXCEL对象
        xlApp.WorkBooks.Open ("d:123.xls")
        xlApp.WorkSheets("Sheet1").Activate
        For i = 0 To 10
            If i > 5 Then xlApp.WorkSheets("Sheet2").Activate
            For j = 0 To 10
                xlApp.Cells(i + 1, j + 1).Value = myData(i, j) '写入第i+1行,第j+1列
            Next j
        Next i
        '保存
        'xlApp.ActiveWorkbook.Save
        '另存
        'xlApp.ActiveWorkbook.SaveAs "d:456.xls"
        '显示出来
        'xlApp.Visible = True
        '关闭
        'xlApp.WorkBooks.Close
        'xlApp.Quit
        Set xlApp = Nothing
    End Sub
  • 相关阅读:
    Nginx日志切割
    Spring Cloud Alibaba基础教程:Nacos+Dubbo
    Spring Cloud Alibaba基础教程:Sentinel
    Gogs+Drone搭建CI/CD平台
    Spring事件机制
    OpenGL 安装
    Melkman's Algorithm
    Tools: python 安装
    Tools: windbg 使用指南
    Tools: java安装指南
  • 原文地址:https://www.cnblogs.com/xiii/p/7215724.html
Copyright © 2011-2022 走看看