Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

242
Vistas
¿Cómo leer xls y xlsx con la biblioteca Apache Poi?

Tengo una aplicación que lee desde un Excel. El problema es que solo puedo leer archivos xlsx. No puedo leer archivos xls. Este es mi código:

 FileInputStream file = new FileInputStream(new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)+"/"+nomeExcel)); HSSFWorkbook workbook = new HSSFWorkbook(file); HSSFSheet sheet = workbook.getSheetAt(0); int rowCtr = 34; Row myRow = sheet.getRow(rowCtr++); while (myRow != null) { Cell nif = myRow.getCell(0); Cell marcaexploracao = myRow.getCell(1); Cell numerochip = myRow.getCell(2); Cell marcaauricular = myRow.getCell(3); Cell datanascimento = myRow.getCell(4); bd.addAnimais(numerochip.toString().replace("\u00a0",""),marcaexploracao.toString().trim(),marcaauricular.toString(),datanascimento.toString(),nif.toString(),0,"","","","",0); myRow = sheet.getRow(rowCtr++); } }catch (Exception e){e.printStackTrace(); } Toast.makeText(getApplicationContext(),"Excel importado",Toast.LENGTH_SHORT).show(); } });
over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

Puede crear un WorkbookFactory.create Workbook :

 InputStream inp = new FileInputStream(new FileInputStream("/path/to/file.xls")); Workbook wb = WorkbookFactory.create(inp); Sheet sheet = wb.getSheetAt(0);
over 4 years ago · Santiago Trujillo Denunciar

0

Para leer el archivo xlsx
Workbook workbook = new XSSFWorkbook(inputStream);

Para leer archivos xls (< 2007)
Workbook workbook = new HSSFWorkbook(inputStream);

No se requieren otros cambios.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda