vb.net - vb .net using excel automation to paste data into opened workbook -
is possible paste data opened worksheet using office automation vb.net? (i done using oledb slow.)
dim folder string = "c:\users\gm1\desktop\" dim filename string = "raw2eng.xlsx" dim connectionstring string = "provider=microsoft.ace.oledb.12.0;data source=" & folder & "\" & filename & ";extended properties=""excel 12.0;hdr=yes;""" dim myconnection new oledbconnection(connectionstring) myconnection.open() dim cmd1 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() j integer = 0 trimmedsegmentsize - 1 sb = new stringbuilder sb.append("insert [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()
oledb way faster automation. show code, may there problem.
[edit] if want use automation (because want keep workbook opened), may read article : how transfer data excel workbook using visual basic .net
Comments
Post a Comment