Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

237
Views
¿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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!