Answer the question
In order to leave comments, you need to log in
Are there other free packages besides org.apache.poi for working with MS Excel files?
Hello.
Today it was necessary to solve the problem of loading information from an excel file into Java.
Used package org.apache.poi
working example
try {
FileInputStream file = new FileInputStream(new File("example.xlsx"));
//Create Workbook instance holding reference to .xlsx file
XSSFWorkbook workbook = new XSSFWorkbook(file);
//Get first/desired sheet from the workbook
XSSFSheet sheet = workbook.getSheetAt(0);
//Iterate through each rows one by one
Iterator<Row> rowIterator = sheet.iterator();
while (rowIterator.hasNext())
{
Row row = rowIterator.next();
//For each row, iterate through all the columns
Iterator<Cell> cellIterator = row.cellIterator();
while (cellIterator.hasNext())
{
Cell cell = cellIterator.next();
//Check the cell type and format accordingly
switch (cell.getCellType())
{
case Cell.CELL_TYPE_NUMERIC:
System.out.print(cell.getNumericCellValue() + "\t");
break;
case Cell.CELL_TYPE_STRING:
System.out.print(cell.getStringCellValue() + "\t");
break;
}
}
System.out.println("");
}
file.close();
} catch (Exception e) {
e.printStackTrace();
}
Answer the question
In order to leave comments, you need to log in
JXLS and some commercial (forgot the name), non-portable, because. works through OLE Automation.
What's wrong with POI? I use it all the time, because. A lot of things have to be imported/exported. Satisfied.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question