是否可以使用vb.net中的辦公自動化將數據粘貼到已打開的工作表中? (我使用oledb完成,但速度很慢。)vb .net使用excel automation將數據粘貼到打開的工作簿
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()
看來你有一個surrouding循環(與變量i)。它有什麼作用 ? – 2013-03-25 09:02:27
除了聲明(第1行4),代碼將重複i次。所以輸出會隨着我遍歷3D數組的第一維而變化。謝謝。 – Gergo 2013-03-25 09:18:37