Obtener Cell Contenido

Aspose.Cells - Obtener Cell Contenido

El método Cells.get() está disponible para acceder a las celdas.

Java

 //Accediendo a la primera hoja de trabajo en el archivo de Excel

Hoja de trabajo hoja de trabajo = libro de trabajo.getWorksheets().get(0);

Cells celdas = hoja de trabajo.getCells();

//Acceda al rango máximo de visualización

Rango rango = hoja de trabajo.getCells().getMaxDisplayRange();

int tcols = range.getColumnCount();

int trows = range.getRowCount();

System.out.println("Total de filas:" + trows);

System.out.println("Total de columnas:" + tcols);

// Valor de acceso de Cell B4

//=====================================================

System.out.println(cells.get("B4").getValue());

Cell celda = celdas.get(3,1); //Valor de acceso de Cell B4

System.out.println(cell.getValue());

//=====================================================

RowCollection filas = celdas.getRows();

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

{

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

	{

		if (cells.get(i,j).getType() != CellValueType.IS_NULL)

		{

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

		}

	}

}

Apache POI SS - HSSF XSSF - Obtener Cell Contenido

Apache POI proporciona la clase Cell para acceder a varias propiedades de las celdas.

Java

 Sheet sheet1 = wb.getSheetAt(0);

for (Row row : sheet1) {

    for (Cell cell : row) {

        CellReference cellRef = new CellReference(row.getRowNum(), cell.getColumnIndex());

        System.out.print(cellRef.formatAsString());

        System.out.print(" - ");

        switch (cell.getCellType()) {

            case Cell.CELL_TYPE_STRING:

                System.out.println(cell.getRichStringCellValue().getString());

                break;

            case Cell.CELL_TYPE_NUMERIC:

                if (DateUtil.isCellDateFormatted(cell)) {

                    System.out.println(cell.getDateCellValue());

                } else {

                    System.out.println(cell.getNumericCellValue());

                }

                break;

            case Cell.CELL_TYPE_BOOLEAN:

                System.out.println(cell.getBooleanCellValue());

                break;

            case Cell.CELL_TYPE_FORMULA:

                System.out.println(cell.getCellFormula());

                break;

            default:

                System.out.println();

        }

    }

}

Descargar código de ejecución

Descargar código de muestra