Apache Poi Android

Apache Poi Android,第1张

Apache Poi Android

尝试对xls文件执行以下 *** 作

   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()。

请给我一些反馈

希望能有所帮助。



欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5430940.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-12-11
下一篇2022-12-12

发表评论

登录后才能评论

评论列表(0条)

    保存