How to efficiently enumerate all not empty values in a range (a row of a range) in Aspose.Cells API?

How to efficiently enumerate all not empty values in a range (a row of a range) in Aspose.Cells API?

@dzmitry.martynau,

Thanks for considering Aspose APIs.

Please use Row and Range iterator() method to get its Iterator.

Please see the following code, the sample Excel file used in this code and its console output given below.

sample.zip (5.5 KB)

Java

//Load sample workbook
Workbook wb = new Workbook(dirPath + "sample.xlsx");

//Access first worksheet
Worksheet ws = wb.getWorksheets().get(0);

//Access cells iterator
Iterator itrat = ws.getCells().iterator();

//Print cells name in iterator
while(itrat.hasNext())
{
	Cell cell = (Cell)itrat.next();

	System.out.println(cell.getName());
}

Console Output

A1
H8
C16
O18

There is no an efficient way to narrow down to a range (like if a worksheet is large, and a range is large as well, but way smaller compared to a worksheet)?

@dzmitry.martynau,

Yes, as Shakeel Faiz told you that you may also use Range.iterator() to get the iterator, see the following sample code for your reference:
e.g
Sample code:

Workbook book = new Workbook("sample.xlsx");
Worksheet sheet = book.getWorksheets().get(0);
Range range = sheet.getCells().getMaxDisplayRange();//You may also create your desired range (in the worksheet) using, e.g sheet.getCells().createRange("A1", "J11");
Iterator rangeIterator = range.iterator();
while(rangeIterator.hasNext())
{
Cell cell = (Cell)rangeIterator.next();
System.out.println(cell.getName() + " is not empty");
}

Hope, this helps a bit.

Thank you.