- using System;
- using System.Data.OleDb;
- namespace ConsoleApplication1
- {
- class Program
- {
- static void Main()
- {
- string connectionString = "Provider=Microsoft.Jet.OleDb.4.0; data source=c:\\\\offices.xls; Extended Properties=Excel 8.0;";
- string selectString = "INSERT INTO Office VALUES(’12345′, ‘Acme Inc’, ‘Acme Way, CA’, ‘Testy McTest’, ‘01234-987654′)"; //Office is the named range.
- 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();
- }
- }
- }
- }
- //该片段来自于http://www.codesnippet.cn/detail/210820135261.html
来源: http://www.codesnippet.cn/detail/210820135261.html