第一个空白行在excel [英] first blank row in excel

查看:246
本文介绍了第一个空白行在excel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法使用vsto或c#在excel表中找到第一个空白行?
我一直在搜索几个小时,但找不到与之相关的任何内容。
在这方面的任何帮助将不胜感激

Is there a way to find first available blank row in excel sheet using vsto or c# ? I have been searching for hours but cant find any thing related to it. Any help in this regard will be greatly appreciated

推荐答案

如果App是您的excel应用程序,您可以循环从数字1开始的行,并使用CountA函数查找第一个空白(它返回一个Range的非空单元格数):

If App is your excel application, you can loop throught the rows starting from number 1 and look for the first empty using CountA function (it returns the number of non empty cells for a Range):

int rowIdx = 0;
int notEmpty = 1;
while (notEmpty > 0)
{
    string aCellAddress = "A" + (++rowIdx).ToString();
    Range row = App.get_Range(aCellAddress, aCellAddress).EntireRow;
    notEmpty = _App.WorksheetFunction.CountA(row);
}

当while循环退出时,rowIdx是第一个空行的索引。

When the while loop exits, rowIdx is the index of the first empty row.

CountA接收其他29个可选参数,因此您可能必须通过早期版本的框架传递Missing.Value 29次。

CountA receive other 29 optional arguments, so it is possible that you have to pass Missing.Value 29 times with earlier versions of the framework.

这篇关于第一个空白行在excel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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