C# 读取xls格式的文件
2016-07-07 11:14
351 查看
List<string> list1 = new List<string>(); //创建连接字符串 string constr = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Data\EPCPosition.xls;Extended Properties=Excel 8.0"; using (OleDbConnection con = new OleDbConnection(constr)) { string sql = "select * from [sheet1$]"; using (OleDbCommand cmd = new OleDbCommand(sql_11, con)) { using (OleDbDataReader reader = cmd.ExecuteReader()) { con.Open(); if (reader.HasRows) { while (reader.Read()) { list1.Add(reader.GetString(0)); } } } } } 注意: //读取access数据库不同的地方在于access数据库是 string constr = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Data\EPCPosition.xls;Persist Security Info=false"; //xls读取时连接字符串如下 string constr = @"Provider=Microsoft.JET.OLEDB.4.0;Data Source=C:\Data\EPCPosition.xls;Extended Properties=Excel 8.0";
相关文章推荐
- C#实现的AES加密解密完整实例
- C# 对List<T>取交集、连集及差集
- C# Access 里如何判断字符串里是不是包含数字
- .NET引用类型与值类型
- [转]说说C#的async和await
- 获得指定文件夹下的子文件目录及子文件MD5值
- C#中StreamReader读取中文文本出现乱码的解决方法
- C# 使用SMS接口实现手机短信发送功能
- C# 对路径不允许访问
- C# 获取公网IP和局域网IP
- C#使用微软语言包来获取中文汉字的拼音、拼音首字母、中文繁体
- C#中设置Excel单元格格式
- 怎样学好C#编程
- c# 服务端
- C#深拷贝 反射实现
- C#输出后台打开的所有应用程序
- c# 客户端
- C#读写中文文件
- [C#6] 5-自动属性增强
- c#.net WinForm 线程内 调用窗体控件