迭代行和列

如何使用 Aspose.Cells for Java 迭代行和列

可以使用行和列集合来迭代行和列。

Java

 //访问最大显示范围

范围 range = worksheet.getCells().getMaxDisplayRange();

int tcols = range.getColumnCount();

int trows = range.getRowCount();

System.out.println("总行数:" + trows);

System.out.println("总列数:" + tcols);

RowCollection rows = cells.getRows();

对于 (int i = 0 ; i< rows.getCount() ; i++)

{

	for (int j = 0 ; j < tcols ; j++)

	{

		System.out.print(cells.get(i,j).getName() + " - " + cells.get(i,j).getValue() + "\t");

	}

	System.out.println("");

}

Apache POI SS - HSSF XSSF - 迭代行和列

Rows 和 Cells 可以在 Sheet 上迭代。示例代码如下:

Java

 Workbook wb = WorkbookFactory.create(inStream);

Sheet sheet = wb.getSheetAt(0);

for (Row row : sheet)

{

  for (Cell cell : row)

  {

    System.out.println("Iteration.");

  }

}

下载运行代码

下载示例代码