我正在复制剪贴板中超过 20 列和 500 多行的 gridview 值,并将该值复制到 excel 文件中。
Dim excelApp As New Excel.Application
Dim aWorkbook As Excel.Workbook
aWorkbook = excelApp.Workbooks.Add()
excelApp.Visible = False
Dim strWorkSheetName As String = "MyData"
Dim aWorkSheet As Excel.Worksheet
aWorkSheet = aWorkbook.Sheets.Add()
aWorkSheet.name = TextBox1.Text
aWorkSheet.Activate()
Dim intRows As Integer = DataGridView1.SelectedRows.Count
Dim strRangeString As String = "C4:G" & intRows.ToString
'Open the existing Template
Dim _Tpath As String = Application.StartupPath & "\Template.xlsx"
aWorkbook = excelApp.Workbooks.Add(_Tpath)
Dim alpha As String
Dim num As Integer
Dim cell As String
Dim count As Integer = 0
For Each col As DataGridViewColumn In DataGridView1.Columns
alpha = Convert.ToChar(65 + count)
num = Convert.ToInt32(7)
cell = Convert.ToString(alpha & "7")
aWorkSheet.Range(cell).Value = col.HeaderText.ToString
count = count + 1
Next
For row As Integer = 0 To dt2.Rows.Count - 1
For col As Integer = 0 To dt2.Columns.Count - 1
alpha = Convert.ToChar(65 + col)
num = Convert.ToInt32(8 + row)
cell = Convert.ToString(alpha & num)
aWorkSheet.Range(cell).Value = dt2(row)(col).ToString
Next
Next
但现在我想将该剪贴板值粘贴到现有的 excel 文件(用作模板)中,假设从第 7 行及以上的特定位置开始。我已经编写了一些代码,其中值正在逐个单元格地粘贴,这需要很多时间。有没有其他方法可以将 gridview 值粘贴到现有的 excel 文件中?