最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
OLEDB打开Excel文件的实现方法
时间:2022-06-30 10:08:39 编辑:袖梨 来源:一聚教程网
| 代码如下 | 复制代码 |
classclsoledb { OleDbConnection connection; publicvoidOpenConnection(stringxlsFils) { if(!File.Exists(xlsFils)) { MessageBox.Show("文件"+ xlsFils +"不存在","提示"); return; } stringconn ="Provider = Microsoft.Jet.OLEDB.4.0;Data Source ="+ xlsFils +";Extended Properties='Excel 8.0;HDR=NO;IMEX=1;'"; connection =newOleDbConnection(conn); try { connection.Open(); } catch(OleDbException ex) { if(ex.ErrorCode == -2147467259) { connection.ConnectionString ="Provider = Microsoft.Ace.OLEDB.12.0;Data Source ="+ xlsFils +";Extended Properties='Excel 12.0;HDR=NO;IMEX=1;'"; connection.Open(); } } }
publicDataTable Select() { DataTable dt =newDataTable(); stringSql ="select * from [$A1:R65536]"; OleDbDataAdapter mycommand =newOleDbDataAdapter(Sql, connection); mycommand.Fill(dt);
if(dt.Rows.Count > 0) { DataRow dr = dt.Rows[0]; for(intcol = 0; col < dt.Columns.Count; col++) { dt.Columns[col].ColumnName = dr[col].ToString(); } dt.Rows[0].Delete(); dt.AcceptChanges(); } returndt; }
} | |
相关文章
- 绯月絮语阵容怎么搭配 绯月絮语阵容搭配推荐 12-23
- 千机阵在哪预约 千机阵预约入口 12-23
- 千机阵官网网址是什么 千机阵官网入口 12-23
- 塞尔达无双封印战记疾风突击使用指南 疾风突击怎么用 12-23
- 艾尔登法环黑夜君临据点怎么选 四大据点主要情况介绍 12-23
- 艾尔登法环黑夜君临符文怎么获得 如何获得强力符文 12-23