【C#】C#删除Excel整行,更新单元格内容
2016-04-24 20:34
561 查看
</pre><pre name="code" class="csharp">using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Reflection; using Excel = Microsoft.Office.Interop.Excel; namespace DelExcel { public partial class Form1 : Form { private Excel._Application excelApp = null; private Excel.Workbook book = null; private Excel.Worksheet sheet = null; private Excel.Range range = null; string filePath = @"E:\2010.xls"; public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { delExcel(filePath); } private void delExcel(string filePath) { excelApp = new Microsoft.Office.Interop.Excel.Application(); excelApp.Visible = false; book = excelApp.Workbooks.Open(filePath, Missing.Value, false, Missing.Value, Missing.Value, Missing.Value, true, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value); int wsCount = book.Worksheets.Count; for (int i = 1; i <= wsCount; i++) { sheet = (Excel.Worksheet)book.Worksheets[i]; //获取编辑范围 range = (Excel.Range)sheet.Rows[1, Missing.Value]; //删除整行 range.Delete(Excel.XlDirection.xlDown); //更新单元格内容 sheet.Cells[1, 3] = "pcID"; //保存编辑 book.Save(); } //关闭book book.Close(Missing.Value, Missing.Value, Missing.Value); //退出excel application,可以将前面的excelApp.Visible = false改为excelApp.Visible = true看看; excelApp.Workbooks.Close(); excelApp.Quit(); } } }
相关文章推荐
- C# 利用DotRas 操作adsl
- C# MVC跳转
- K 均值聚类算法-C#
- 【C#语法】C#中强转和as、is的区别
- 第五章变量的更多内容
- C#_会员管理系统:开发六(数据搜索)
- 在C#中使用NPOI2.0操作Excel2003和Excel2007
- CSharpGL(19)用glReadPixels把渲染的内容保存为PNG图片(C#)
- 简单对比C#程序中的单线程与多线程设计
- 【FTP】C# System.Net.FtpClient库连接ftp服务器(下载文件)
- C#详解struct和class的区别
- 关于C# 委托(delegate)与事件(event)的用法及事例
- [转]LibreOffice-SDK 开发实战:嵌入MFC-View 和 C# Winform
- C#OOP之三 控制结构
- C#OOP之三 控制结构
- C#OOP之三 控制结构
- c# 中button加图片
- C#基础-replace()过滤非法字符
- C# 通过循环清空窗体中所有 TextBox 的值
- c# winform笔记