vb.net 循环生成excel的多个sheet_Excel中各种情况下多表合并的小代码全在这里了,赶紧收藏吧!...
时间: 2023-06-25 15:05:13 浏览: 226
循环生成多个sheet的代码示例:
```
Dim xlApp As New Excel.Application
Dim xlWorkBook As Excel.Workbook
Dim xlWorkSheet As Excel.Worksheet
xlWorkBook = xlApp.Workbooks.Add()
For i As Integer = 1 To 10
xlWorkSheet = CType(xlWorkBook.Sheets.Add(), Excel.Worksheet)
xlWorkSheet.Name = "Sheet " & i.ToString()
Next i
xlWorkBook.SaveAs("C:\example.xlsx")
xlWorkBook.Close()
xlApp.Quit()
```
多个表合并的代码示例:
```
Dim xlApp As New Excel.Application
Dim xlWorkBook As Excel.Workbook
Dim xlWorkSheet As Excel.Worksheet
Dim xlRange As Excel.Range
Dim lastRow As Integer
xlWorkBook = xlApp.Workbooks.Open("C:\example1.xlsx")
xlWorkSheet = xlWorkBook.Sheets(1)
lastRow = xlWorkSheet.Cells.SpecialCells(Excel.XlCellType.xlCellTypeLastCell).Row
xlWorkSheet.Copy(After:=xlWorkBook.Sheets(xlWorkBook.Sheets.Count))
xlWorkSheet = xlWorkBook.Sheets(xlWorkBook.Sheets.Count)
xlRange = xlWorkSheet.Range("A" & (lastRow + 1).ToString() & ":F" & (lastRow + 10).ToString())
xlRange.Value = xlWorkBook.Sheets(1).Range("A2:F12").Value
xlWorkBook.SaveAs("C:\example_merged.xlsx")
xlWorkBook.Close()
xlApp.Quit()
```
阅读全文