<pre lang="xml">private string GetConnectionString() { Dictionary<string, string> props = new Dictionary<string, string>(); // XLSX - Excel 2007, 2010, 2012, 2013 props["Provider"] = "Microsoft.ACE.OLEDB.12.0;"; props["Extended Properties"] = "Excel 12.0 XML"; props["Data Source"] = "C:\\MyExcel.xlsx"; StringBuilder sb = new StringBuilder(); foreach (KeyValuePair<string, string> prop in props) { sb.Append(prop.Key); sb.Append('='); sb.Append(prop.Value); sb.Append(';'); } return sb.ToString(); }</pre>
string connectionString = GetConnectionString(); using (OleDbConnection conn = new OleDbConnection(connectionString)) { conn.Open(); OleDbCommand cmd = new OleDbCommand(); cmd.Connection = conn; //cmd.CommandText = "CREATE TABLE [table1] (id INT);"; //cmd.ExecuteNonQuery(); cmd.CommandText = "INSERT INTO [sheet1$](id) VALUES(" + newString + ");"; cmd.ExecuteNonQuery(); conn.Close(); }
cmd.CommandText = "INSERT INTO [sheet1$](id) VALUES('" + newString + "');";
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)