Fetch the cell at the end of contiguous non-empty range

In Syncfusion Xlsio, how can I get the cell at end of the current contiguous non-empty range or at the start of the next non-empty range? Is there any property that I can apply on the range to get that cell?


3 Replies

RS Ramya Sivakumar Syncfusion Team July 13, 2022 11:46 AM UTC

Hi Nivas,


Greetings from Syncfusion.


We have prepared the sample to fetch the last cell of the contiguous non-empty range. Kindly try this and let us know if it helps.


Code snippet:

FileStream inputStream = new FileStream("Sample.xlsx", FileMode.Open);

IWorkbook workbook = excelEngine.Excel.Workbooks.Open(inputStream);

IWorksheet worksheet = workbook.Worksheets[0];

IRange usedRange = worksheet.UsedRange;

var lastcell = "";

 

for (int col = 1; col <= usedRange.LastColumn; col++)

     for (int row = 1; row <= usedRange.LastRow; row++)

     {

          if( !worksheet[row, col].IsBlank )

          {

                lastcell = worksheet[row, col].AddressLocal;

          }

     }  



The complete sample can be downloaded from the below link.

Sample link - https://www.syncfusion.com/downloads/support/directtrac/general/ze/F-17616318291293


Regards,

Ramya



NI Nivas July 15, 2022 10:47 AM UTC

Hi Ramya,


Thanks for the solution. But is there anyway we can find it(last cell of the contiguous non-empty range) and also the first cell of the next contiguous non-empty range more easily? Because, having two loops definitely increases the time complexity. And also, the above solution doesn't provide the last cell of the contiguous range. It provides the last cell of the non-contiguous range. 

Thanks,

Nivas.



RS Ramya Sivakumar Syncfusion Team July 18, 2022 10:28 AM UTC

Hi Nivas,


You’re welcome. Please find the response for the queries in the below table.


Query

Response

 

But is there anyway we can find it(last cell of the contiguous non-empty range) and also the first cell of the next contiguous non-empty range more easily? Because, having two loops definitely increases the time complexity.

 

 

It is the only way to fetch the last cell of the non-empty range.

 

 And also, the above solution doesn't provide the last cell of the contiguous range. It provides the last cell of the non-contiguous range. 

 

Could you please share the Input range and Expected Output along with the Excel file which would help us to proceed further?

 


Regards,

Ramya


Loader.
Up arrow icon