C#和Excel删除行 [英] C# and excel deleting rows

查看:114
本文介绍了C#和Excel删除行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从我的形式写(在C#)到一个Excel试算表,如果空白删除某些行。

I want to write from my form (in C#) to an excel spread sheet and delete certain rows if blank.

我能写出完美的罚款到电子表格中以后和保存它,但可以说用户输入数据转换成排A1,A2,A3和A4,我现在想删除A4和A29之间的所有行。

I can write perfectly fine to a speadsheet and save it, but lets say the user entered data into row a1, a2, a3, and a4, I now want to delete all the rows in between a4 and a29.

所有我需要的是找出如何删除某个单元格区域。

All I need is to find out how to delete a certain range of cells.

感谢

推荐答案

您可以使用Range对象做到这一点。我这里假设你正在使用Excel互操作。

You can do it using a Range Object. I assume here that you are using Excel interop.

让说,你有你的书打开,然后设置则该范围中删除
它应该是这个样子。

Let say you have your book open, then set the range then delete it It should look something like this

ApplicationClass excel = new ApplicationClass();
//Abrir libro y seleccionar la hoja adecuada aqui
//...

Microsoft.Office.Interop.Excel.Range cel = (Range)excel.Cells[rowIndex, columnIndex];
cel.Delete();

这篇关于C#和Excel删除行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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