《MicrosoftJetOLEDB操作excel.pdf》由会员分享,可在线阅读,更多相关《MicrosoftJetOLEDB操作excel.pdf(1页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Data.OleDb;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;namespace OleExclepublic partial class Form1 : Form public Form1() Init
2、ializeComponent(); private void button1_Click(object sender, EventArgs e) OpenFileDialog ofd = new OpenFileDialog();if (ofd.ShowDialog() = DialogResult.OK) string sql1 = INSERT INTO Sheet1$ VALUES(1,elmer,password);string sql2 = UPDATE Sheet1$ SET name=elmer2 WHERE num=2;if(writeExcel1(ofd.FileName,
3、 sql2)=1) MessageBox.Show(操作成功!); public int writeExcel1(string fileName, string sql) /目标电子表格第一行必须有数据String sConnectionString = Provider=Microsoft.Jet.OLEDB.4.0; + Data Source=+ fileName + ; + Extended Properties=Excel 8.0;OleDbConnection myConn = new OleDbConnection(sConnectionString); myConn.Open();OleDbCommand com = new OleDbCommand(sql, myConn);int result=com.ExecuteNonQuery(); myConn.Close();return result;