vb.net操作excel汇集



        Dim xl As New Excel.Application
        Dim xlBook As Excel.Workbook = xl.Workbooks.Open(strSaveExcelFile)
        Dim xlSheet As Excel.Worksheet = xlBook.Sheets(1)
        Dim col As Integer
        Dim row As Integer

        xlSheet.Range(xlSheet.Cells(1, 1), xlSheet.Cells(80, 80)).NumberFormat = "@" '文本格式

        For i = 0 To Rlevel.GetUpperBound(0) '标题
            row = 1 + i * 7 + 1
            xlSheet.Cells(1, row) = Rlevel(i) & "分钟累积"
            xlSheet.Cells(1, row + 1) = "结束时间"
            '............
        Next

        '............

        xlSheet.Cells.Font.Size = 9
        xlSheet.Cells.HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter '所有单元水平居中
        xlSheet.Cells.VerticalAlignment = Excel.XlVAlign.xlVAlignCenter   '所有单元垂直居中

        xlSheet.Cells.EntireColumn.AutoFit()                              '所有列自适合单元宽度
        xlSheet.Range("B2").Activate()
        xl.Application.ActiveWindow.FreezePanes = True                    '冻结窗口B2单元

        xlBook.Save()
        xlBook.Close()
        xl.Quit()


你可能感兴趣的:(Excel,VB.NET)