
try { InputStream caInput = new BufferedInputStream(getAssets().open( "ie_data.xls")); HSSFWorkbook workbook = new HSSFWorkbook(caInput); HSSFSheet feuille = workbook.getSheetAt(0); Cell cell = feuille.getRow(1).getCell(1); String value = cell.getNumericCellValue()+""; Toast.makeText(getApplicationContext(), value, Toast.LENGTH_LONG) .show(); } catch (IOException e1) { // TODO Auto-generated catch blocke1.printStackTrace(); }对于xlsx:
1-导入以下jar文件:
(dom4j-1.6.1.jar,poi-ooxml-3.5-FINAL.jar,poi-ooxml-
schemas-3.8-beta4.jar,poi-3.9-20121203.jar,xmlbeans-2.3.0.jar)。
第二-在try catch块内进行以下 *** 作:
如果您使用的是File对象,请执行以下 *** 作:
File file = new File("path"); InputStream caInput = new FileInputStream(file);如果您正在使用inputStram读取文件,请执行以下 *** 作:
InputStream caInput = new BufferedInputStream(getAssets().open( "ie_data.xlsx")); XSSFWorkbook workbook = new XSSFWorkbook(caInput); XSSFSheet feuille = workbook.getSheetAt(0); Cell cell = feuille.getRow(0).getCell(0); String value = cell.getStringCellValue() + ""; System.out.print("hello = " + value);但请注意,根据我的xslx文件,我正在获取StringCellValue,应检查xlsx文件,并查看其是否为字符串,并使用getStringCellValue()或Numeric并使用getNumericCellValue()。
请给我一些反馈
希望能有所帮助。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)