如何从XLS(Excel)文件读取数据

我已经search了stackoverflow,但我没有find明确的答案。 我怎样才能从我的Android应用程序的XLS文件的特定行和列读取数据? 我怎样才能读取XLS文件? 我不想将它转换为CSV,因为当我尝试转换它们时出现错误。

也许我可以使用这个http://www.andykhan.com/jexcelapi/tutorial.html#reading,但我甚至不知道如何将其导入到我的项目。 请帮忙。

嗨,你只需要包括一个外部jxl jar,你可以通过相同的教程,这将有助于你了解阅读excel文件的过程..为了您的保证我粘贴一些ref。 代码读取第一张excel并创build一个结果集。

public List<String> read(String key) 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; }