Ola pessoal
Estou tentando usar a API POI para fazer leitura de um arquivo extenso que tenho em excel (xls) e gostaria primeiramente de ler todo o arquivo e imprimir no console mais nao estou conseguindo. segue o codigo :
Nao entendo pq mais tem um metodo (linha 34) no codigo cell.getCellNum() que nao existe, oque eu poderia usar?
Estou usando esse codigo como exemplo do proprio site.
package br.com.globalcode.util;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import org.apache.poi.hssf.util.CellReference;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.usermodel.*;
public class LeitorArquivos {
public static void main(String[] args) throws IOException, InvalidFormatException {
Workbook wb = null;
Row row = null;
Cell cell = null;
String path = "/home/daniel/Desktop/OOP/AGENDA TELEFÔNICA/AGENDA TELEFÔNICA.xls";
InputStream inp = new FileInputStream(path);
wb = WorkbookFactory.create(inp);
Sheet sheet = wb.getSheetAt(0);
System.out.println("Quantidade de linhas : " + sheet.getLastRowNum());
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 3; j++) {
CellReference cellRef = new CellReference(row.getRowNum(), cell.getCellNum());
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();
}
}
}
}
}
Obrigado.