Move to next cell in the next row in excel using c#

拈花ヽ惹草 提交于 2019-12-10 20:33:12

问题


How can I move to the next row in Excel using C#. I'm using Office PIA v 14. When I used Range.Next property, it takes me to the cell immediately right to the range. How can I move to the next row? ie. the cell immediately below.


回答1:


Range.Next returns a Range object that represents the next cell.

I'm not really the greatest expert alive but according to the documentation you should use Offset instead. http://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel.range.offset

Here is some pseudo code

var excelApp = this.Application;
int skipRows = 1;
int skipCells = 0;
var nextRange = excelApp.ActiveCell.Offset[skipRows, skipCells].Select();



回答2:


Try the following code:

Range oRng = ws.get_Range(Column + (row +1), Type.Missing);

where ws is the worksheet object.



来源:https://stackoverflow.com/questions/11929443/move-to-next-cell-in-the-next-row-in-excel-using-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!