教你用C#读写、删除、更新excel表格记录.doc





《教你用C#读写、删除、更新excel表格记录.doc》由会员分享,可在线阅读,更多相关《教你用C#读写、删除、更新excel表格记录.doc(3页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、精品文档,仅供学习与交流,如有侵权请联系网站删除教你用C#读写、删除、更新excel表格记录如下图所示,编一个程序,鼠标单击窗体视图区(右边)时,获取一对坐标(X,Y),点击保存将点保存到excel表记录中。此外,还实现了删除、更新功能以及打开excel表功能。插入和更新比较简单,和操作一般的数据库一样,但是删除稍微有点复杂,不能用delete from Sheet1$ where ID=x的方式删除,自己可以去试,主要是excel数据之间的关系不像关系数据库那么简单,oledb不提供这种方法。所以只能用专门操作excel表的(Microsoft.Office.Interop.Excel名字空
2、间下,先添加引用)来实现删除某条记录的功能。源代码:using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using System.Data.OleDb;using System.Reflection;using Excel = Microsoft.Office.Interop.Excel;namespace Leation publi
3、c partial class FrmMain : Form /定义变量 private OleDbConnection connection = null; private OleDbCommand cmd = null; private OleDbDataAdapter dataAdapter = null; private DataSet dataSet = null; private string filePath = G:points.xls; private string connStr = provider=microsoft.jet.oledb.4.0;data source=
4、G:points.xls;extended properties=Excel 8.0;HDR=yes;IMEX=2; private string selectStr = select * from Sheet1$; private string cmdStr = null; private string OID = null; /对象ID private string x = null; private string y = null; private Excel.Application excelApp = null; private Excel.Workbook book = null;
5、 private Excel.Worksheet sheet = null; private Excel.Range range = null; /构造函数 public FrmMain() InitializeComponent(); /鼠标移动事件 private void splitContainer1_Panel2_MouseMove(object sender, MouseEventArgs e) this.lblxy.Text = x= + e.X.ToString() + y= + e.Y.ToString(); /鼠标按下事件 private void splitContain
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- C# 读写 删除 更新 excel 表格 记录

限制150内