Last cell in row and column in Epplus - C#

限于喜欢 提交于 2020-04-12 21:23:45

问题


I want to select a range from the first to the last cell filled in the row or column. In VBA the code stays as below using xlDown or xlToRight.

Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select

How could I do it the same way in C # using Epplus? I will start from cell B139 and I must go to the last row and column


回答1:


An important thing to know about the Cells object in an Worksheet in EPPlus is that it contains only references to cell that have data added to it. So with a little bit of LINQ you can get the address of every "Row" like this:

var lastRowCell1 = worksheet.Cells.Last(c => c.Start.Row == 1);

var lastRowCell2 = worksheet.Cells.Last(c => c.Start.Row == 2);

var lastColCell1 = worksheet.Cells.Last(c => c.Start.Column == 1);

var lastColCell2 = worksheet.Cells.Last(c => c.Start.Column == 2);



回答2:


To get the last Ceels index you che get the value by thi way:

int numCol = worksheet.Dimension.Rows;

int numCol = worksheet.Dimension.Columns;

If you want the last address of Column or Row you cn ue this:

String lastAddress = worksheet.Dimension.Address.Last().ToString();


来源:https://stackoverflow.com/questions/42558303/last-cell-in-row-and-column-in-epplus-c-sharp

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