how to write to a specific range in excel ? [modified]
-
For some reason this code is not writing to my excel file and I can't figure out why. I have a premade template and it has a worksheet in it called bsheet and I also took and selected my range and hit insert/name and gave it the name btable I then put this in a button click event to test but the xls is not effected what might i be doing wrong?
private void button1_Click(object sender, EventArgs e)
{
string connectionString = "Provider=Microsoft.Jet.OleDb.4.0; data source=c:\\BookList.xls; Extended Properties=Excel 8.0;";
string selectString = "INSERT INTO btable VALUES('12345′, 'Acme Inc', 'Acme Way', 'CA')";OleDbConnection con = new OleDbConnection(connectionString); OleDbCommand cmd = new OleDbCommand(selectString, con); try { con.Open(); cmd.ExecuteNonQuery(); } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { con.Dispose(); } }
modified on Wednesday, March 3, 2010 1:52 PM
-
For some reason this code is not writing to my excel file and I can't figure out why. I have a premade template and it has a worksheet in it called bsheet and I also took and selected my range and hit insert/name and gave it the name btable I then put this in a button click event to test but the xls is not effected what might i be doing wrong?
private void button1_Click(object sender, EventArgs e)
{
string connectionString = "Provider=Microsoft.Jet.OleDb.4.0; data source=c:\\BookList.xls; Extended Properties=Excel 8.0;";
string selectString = "INSERT INTO btable VALUES('12345′, 'Acme Inc', 'Acme Way', 'CA')";OleDbConnection con = new OleDbConnection(connectionString); OleDbCommand cmd = new OleDbCommand(selectString, con); try { con.Open(); cmd.ExecuteNonQuery(); } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { con.Dispose(); } }
modified on Wednesday, March 3, 2010 1:52 PM
well i got it sorta working. The thing I'm having trouble with is one of the cells is merged D to G if i insert values "('A,'B','C','D')"; i get an error saying it can't expand. I also tried putting '' for column e,f,g and that didn't work either. Any idea how to insert a value into the merge cell? i tried to find some info online about this but came up try.