gpt4 book ai didi

java - Android 中的 JXL 库

转载 作者:行者123 更新时间:2023-12-02 06:10:45 25 4
gpt4 key购买 nike

目前我正在尝试在android中使用Jxl lib从sd卡读取数据并获取FilenotfoudException。

我使用 stackoverflow 搜索解决方案并找到了一些。但他们似乎都不适合我。我已实现以下代码: /代码部分/

File sdcard = Environment.getExternalStorageDirectory();
//Get the text file
File Excelfile = new File(sdcard,"ExcelTest.xls");
//
try {
Workbook wrkbk = Workbook.getWorkbook(Excelfile);
Sheet sheet1 = wrkbk.getSheet(0);
//Obtain reference to the Cell using getCell(int col, int row) method of sheet
Cell colArow1 = sheet1.getCell(0, 0);
Cell colBrow1 = sheet1.getCell(1, 0);
Cell colArow2 = sheet1.getCell(0, 1);
//Read the contents of the Cell using getContents() method, which will return
//it as a String
String str_colArow1 = colArow1.getContents();
String str_colBrow1 = colBrow1.getContents();
String str_colArow2 = colArow2.getContents();
}
Catch(Exception ex){}

我总是在 Workbook wrkbk = Workbook.getWorkbook(Excelfile); 行遇到异常

我已经寻找解决方案,但似乎没有任何效果。我已经提供了读取 SD 卡上文件的所有权限(已通过读取文本文件进行检查并且工作正常)。

相同的代码可以在普通的 java 程序中运行。

请帮忙......

最佳答案

回答可能已经晚了,但您的实际文件可能位于文件夹中的某个位置。因此,您必须获得完整路径。就你而言,它是

File sdcard = Environment.getExternalStorageDirectory();

File Excelfile = new File(sdcard,"/folder_name/ExcelTest.xls");

希望这会有所帮助。

关于java - Android 中的 JXL 库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21912597/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com