没有合适的资源?快使用搜索试试~ 我知道了~
C#利用 oledb打开excel2003,利用ACE打开excel2007 , 精简好用 可收藏。
资源推荐
资源详情
资源评论
////////C# read Excel////////////////////////////////
string strFile = "c:\\1.xls";
string strConn = string.Empty;
if (strFile.EndsWith(".xls"))
{
strConn = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + strFile + ";"
+ "Extended Properties=Excel 8.0;";
}
else if (strFile.EndsWith(".xlsx"))
{
strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source= " + strFile +
";Extended Properties=\"Excel 12.0;HDR=YES;\"";
}
else
{
MessageBox.Show("文件类型错误!!!");
return;
}
OleDbConnection conn = new OleDbConnection(strConn);
conn.Open();
DataTable dt2 = conn.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables, null);
string sheet = dt2.Rows[0]["TABLE_NAME"].ToString();//获取excel表名,默认只取一个表
string strExcel = "select * from [" + sheet + "]";
OleDbDataAdapter myCommand = new OleDbDataAdapter(strExcel, strConn);
DataTable dt = new DataTable();
myCommand.Fill(dt);//操作dt
资源评论
rensq8808
- 粉丝: 2
- 资源: 20
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功