使用c#删除单元格中的内容 [英] Remove the content in cell using c#

查看:140
本文介绍了使用c#删除单元格中的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





您能否建议如何使用c#清除excel表格中的单元格内容(B2:E4)。

Hi,

Can you advice how to clear the content of the cell (B2:E4) in excel sheet using c#.

推荐答案

参见使用MS Excel(xls / xlsx)使用MDAC和Oledb [ ^ ],或 http://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel.aspx [ ^ ]。
See Working with MS Excel(xls / xlsx) Using MDAC and Oledb[^], or http://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel.aspx[^].


使用以下解决方案清除特定范围的内容。



Use following solution to clear content for specific range.

Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application();
           Microsoft.Office.Interop.Excel.Workbook excelWorkbook = excel.Workbooks.Open(@"D:\Book1.xls");
           Microsoft.Office.Interop.Excel._Worksheet excelWorkbookWorksheet = excelWorkbook.Sheets[1];
           var rng = excelWorkbookWorksheet.get_Range("B2:E4", Type.Missing);
           rng.Cells.Clear();
           excelWorkbook.Save();


这篇关于使用c#删除单元格中的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆