看板 C_Sharp 關於我們 聯絡資訊
我只會讀的部份,就參考一下唄~~ 其他請各位高手指導一下,謝謝! using System.Data.SqlClient; using System.Data.OleDb; private void btnLoad_Click(object sender, EventArgs e) { string cnStr = "Data Source=C:\\Database\\employee.xls;Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=Excel 8.0;"; using (OleDbConnection cn = new OleDbConnection(cnStr)) { using (OleDbCommand cmd = new OleDbCommand()) { cmd.Connection = cn; cn.Open(); cmd.CommandText = "SELECT * from [data$]"; //sheet name using (OleDbDataReader dr = cmd.ExecuteReader()) { while (dr.Read()) { ListBox1.Items.Add(dr[0].ToString() + "\t" + dr[1].ToString() + "\t" + dr[2].ToString()); } } } } } ※ 引述《DearKurt ("小朋友"會自己找出路...)》之銘言: : 如果執行程式時 excel檔是關閉的 : 這樣的情況下 可以把excel檔當作資料庫去操作 : 連線方式可以去connectionstring網站找 : ※ 引述《imio24 (imio)》之銘言: : : hey Everyone, I have one question about reading and write from : : a MS. Excel file.I wanna create a function to analyze two columns in a excel : : file and write it back into the same excel file and make the function as a : : executable file(.exe). how should i start to do it? thank you -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 59.114.218.3