Obtener Cell Contenido

Aspose.Cells - Obtener Cell Contenido

El método Cells[0]o Cells[nombre] está disponible para acceder a las celdas.

C#

 Workbook workbook = new Workbook("../../data/test.xlsx");

Hoja de trabajo hoja1 = libro de trabajo.Hojas de trabajo[0];

Cells celdas = hoja 1.Cells;

Rango rango = hoja1.Cells.MaxDisplayRange;

int tcols = range.ColumnCount;

int trows = range.RowCount;

 para (int i = 0 ; i< trows; i++)

{

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

	{

		if (cells[i, j].Type != CellValueType.IsNull)

		{

			Console.WriteLine(cells[i, j].Name + " - " + cells[i, j].Value);

		}

	}

}

NPOI - HSSF XSSF - Obtener Cell Contenido

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

C#

 IWorkbook wb = new XSSFWorkbook("../../data/test.xlsx");

ISheet hoja1 = wb.GetSheetAt(0);

 para (índice int = 0; índice<= sheet1.LastRowNum; index++)

{

    IRow row = sheet1.GetRow(index);

    foreach (ICell cell in row.Cells)

    {

        CellReference cellRef = new CellReference(row.RowNum, cell.ColumnIndex);

        Console.Write(cellRef.FormatAsString());

        Console.Write(" - ");

        switch (cell.CellType)

        {

            case CellType.String:

                Console.Write(cell.StringCellValue);

                break;

            case CellType.Numeric:

                if (DateUtil.IsCellDateFormatted(cell))

                    Console.Write(cell.DateCellValue);

                else

                    Console.Write(cell.NumericCellValue);

                break;

            case CellType.Boolean:

                Console.Write(cell.BooleanCellValue);

                break;

            case CellType.Formula:

                Console.Write(cell.CellFormula);

                break;

        }

        Console.WriteLine();

    }

}

Descargar código de ejecución

DescargarObtener Cell Contenido formar cualquiera de los sitios de codificación social mencionados a continuación: