c# - Import data from opened excel files -
i need import data application on c# curently opened files ms excel 2010/2013. im using vs 2010 express, can't use microsoft.office.interop.excel. im trying use lib spreadsheetlight, not solve problem. how can it?
try code:
oledbconnection oledbconn = new oledbconnection(); try { string path = httpcontext.current.server.mappath("~/virtual path file"); if (path.getextension(path) == ".xls") { oledbconn = new oledbconnection("provider=microsoft.jet.oledb.4.0;data source=" + path + ";extended properties=\"excel 8.0;hdr=yes;imex=2\""); } else if (path.getextension(path) == ".xlsx") { oledbconn = new oledbconnection(@"provider=microsoft.ace.oledb.12.0;data source=" + path + ";extended properties='excel 12.0;hdr=yes;imex=1;';"); } oledbconn.open(); oledbcommand cmd = new oledbcommand(); ; oledbdataadapter oleda = new oledbdataadapter(); dataset ds = new dataset(); cmd.connection = oledbconn; cmd.commandtype = commandtype.text; cmd.commandtext = "select * [sheet1$]"; oleda = new oledbdataadapter(cmd); oleda.fill(ds, "your_temp_table_name"); foreach (datarow item in ds.tables["your_temp_table_name"].rows) { ....
Comments
Post a Comment