vb.netのオフィスオートメーションを使用して、すでに開いているワークシートにデータを貼り付けることはできますか?(私はoledbを使用してそれを行いましたが、非常に遅いです。)
Dim Folder As String = "C:\Users\gm1\Desktop\"
Dim Filename As String = "Raw2Eng.xlsx"
Dim ConnectionString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & Folder & "\" & Filename & ";Extended Properties=""Excel 12.0;HDR=YES;"""
Dim MyConnection As New OleDbConnection(ConnectionString)
MyConnection.Open()
Dim cmd1 As New OleDbCommand
cmd1.Connection = MyConnection
cmd1.CommandText = "DROP TABLE [Sheet2$A1:E1027]"
cmd1.ExecuteNonQuery()
cmd1.CommandText = "CREATE TABLE [Sheet2$A1:E1027] (HiResAngle FLOAT, CH2 FLOAT, CH4 FLOAT, CH5 FLOAT, CH6 FLOAT)"
cmd1.ExecuteNonQuery()
For j As Integer = 0 To TrimmedSegmentSize - 1
sb = New StringBuilder
sb.Append("INSERT INTO [Sheet2$A" & 1 & ":E" & j + 1 & "] (HiResAngle, CH2, CH4, CH5, CH6) values ( '")
sb.Append(eng(i, j, 0)) : sb.Append("' , '")
sb.Append(eng(i, j, 1)) : sb.Append("' , '")
sb.Append(eng(i, j, 2)) : sb.Append("' , '")
sb.Append(eng(i, j, 3)) : sb.Append("' , '")
sb.Append(eng(i, j, 4)) : sb.Append("' )")
cmd1.CommandText = sb.ToString
cmd1.ExecuteNonQuery()
Next
MyConnection.Close()