本文介绍了Epplus中行和列中的最后一个单元格-C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想选择一个从行或列填充的第一个单元格到最后一个单元格的范围。在VBA中,代码使用xlDown或xlToRight保持如下所示。

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

我该怎么做在C#中使用Epplus的方式相同吗?
我将从B139单元格开始,我必须转到最后一行和最后一列

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

推荐答案

一个重要的知识关于EPPlus中工作表中的单元格对象的问题在于,它仅包含对添加了数据的单元格的引用。因此,使用LINQ一点,您可以像这样获得每个行的地址:

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);

这篇关于Epplus中行和列中的最后一个单元格-C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-21 01:47