如何在java或android中读取XLS(Excel)文件中的数据

我正在使用JExcelApi v2.6.12 jar文件。 http://www.andykhan.com/jexcelapi/download.html 。

我有一个像下面的图像的XML文件:

在这里输入图像说明

现在,我想从这个文件中获取所有的行:

我正在关注这个答案如何从XLS(Excel)文件读取数据[Java,Android]

但它不起作用,我的结果总是返回"Data not found..!"

我的代码:

 private void test(){ String iconsStoragePath = Environment.getExternalStorageDirectory() + "/SmsBaz"; File sdIconStorageDir = new File(iconsStoragePath); String filePath = sdIconStorageDir.toString() +"/m.xls"; try { List<String> resultSet = read("id",filePath); Log.e("size","=>"+resultSet.get(0)); } catch (IOException e) { e.printStackTrace(); } } public List<String> read(String key,String inputFile) throws IOException { List<String> resultSet = new ArrayList<String>(); File inputWorkbook = new File(inputFile); if(inputWorkbook.exists()){ Workbook w; try { w = Workbook.getWorkbook(inputWorkbook); // Get the first sheet Sheet sheet = w.getSheet(0); // Loop over column and lines for (int j = 0; j < sheet.getRows(); j++) { Cell cell = sheet.getCell(0, j); if(cell.getContents().equalsIgnoreCase(key)){ for (int i = 0; i < sheet.getColumns(); i++) { Cell cel = sheet.getCell(i, j); resultSet.add(cel.getContents()); } } continue; } } catch (BiffException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } } else { resultSet.add("File not found..!"); } if(resultSet.size()==0){ resultSet.add("Data not found..!"); } return resultSet; }