作者rookie (rookie)
看板C_Sharp
标题Re: [问题]C# 读写excel file
时间Mon Mar 2 23:07:33 2009
我只会读的部份,就参考一下呗~~
其他请各位高手指导一下,谢谢!
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