c#读取excel文件数据 可以用string.Format("SELECT * FROM [{0}${1}]", sheetName, sheetRange); 的SQL来限定读取的table可以看下我之前写的一个oledb读excel的类,写了很久了,很多我自己都不记得了http://user.qzone.qq.com/3183601/blog/1 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 读取excel string opnFileName = "D:\\dddd.xls"; if (File.Exists(opnFileName) == false) { return; } string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + opnFileName + ";Extended Properties=\"Excel 8.0;HDR=YES;IMEX=1\""; OleDbConnection conn = new OleDbConnection(strConn); string strExcel = ""; OleDbDataAdapter myCommand = null; DataSet ds = new DataSet(); strExcel = "select * from [sheet1$]"; try { conn.Open(); myCommand = new OleDbDataAdapter(strExcel, strConn); myCommand.Fill(ds, "dtSource"); } catch (Exception ex) { MessageBox.Show("导入出错:" + ex, "错误信息"); } finally { conn.Close(); conn.Dispose(); } 有没有不用OLEDB读取excel的方法,因为.net compact Framework不支持OLEDB。 socket连接 不知道这样的主机 如何上传个人网站 短路咯,邦个忙,写个小例子 报表的问题 [非常急]提交回来后重棒repeater里面的自定义控件消失 请教高手:Team Foundation server(tfs)获取代码,本地路径怎么没有代码啊? C# 向数据库插入一条记录后,如何获得新插入记录的自动编号(id) 水晶报表的注册码怎么注册还不行啊? Dotnetbar10的DLL文件系统注册问题 一个学要解决的问题?????????????????????????????? C#如何统计当前目录中的文件个数 C#能操作底层么??? 如监控U盘插入拔出、光驱监控的问题 进来看看
if (File.Exists(opnFileName) == false)
{
return;
}
string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
+ opnFileName + ";Extended Properties=\"Excel 8.0;HDR=YES;IMEX=1\"";
OleDbConnection conn = new OleDbConnection(strConn);
string strExcel = "";
OleDbDataAdapter myCommand = null;
DataSet ds = new DataSet();
strExcel = "select * from [sheet1$]";
try
{
conn.Open();
myCommand = new OleDbDataAdapter(strExcel, strConn);
myCommand.Fill(ds, "dtSource"); }
catch (Exception ex)
{
MessageBox.Show("导入出错:" + ex, "错误信息");
}
finally
{
conn.Close();
conn.Dispose();
}