我正在尝试读取一个 excel 文件。该文件保存在我的工作空间中名为RoCom_DB
的文件夹中,文件名为RoCom.xlsx
.
我正在尝试使用以下代码读取文件:
public String readComplexExcelFile(Context context){
try{
// Creating Input Stream
File file = new File(Environment.getExternalStorageDirectory()
+ "/Android/data/" + getApplicationContext().getPackageName()
+ "/RoCom_DB/", "RoCom.xlsx");
FileInputStream myInput = new FileInputStream(file);
// Create a POIFSFileSystem object
POIFSFileSystem myFileSystem = new POIFSFileSystem(myInput);
// Create a workbook using the File System
HSSFWorkbook myWorkBook = new HSSFWorkbook(myFileSystem);
// Get the first sheet from workbook
HSSFSheet mySheet = myWorkBook.getSheetAt(0);
/** We now need something to iterate through the cells.**/
Iterator<Row> rowIter = mySheet.rowIterator();
while(rowIter.hasNext()){
HSSFRow myRow = (HSSFRow) rowIter.next();
Iterator<Cell> cellIter = myRow.cellIterator();
while(cellIter.hasNext()){
HSSFCell myCell = (HSSFCell) cellIter.next();
Log.d("", "Cell Value: " + myCell.toString());
Toast.makeText(context, "cell Value: " + myCell.toString(), Toast.LENGTH_SHORT).show();
}
}
}catch (Exception e){
e.printStackTrace();
}
return "";
}
问题是每次我尝试读取文件时,我都会得到一个File not found exception
. 我已经使用了这个必要poi-3.7.jar
的,并将这段代码保存在我的manifest.xml
:
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
我不想使用assets
目录中的 excel,因为它只支持最大 1 mb 的 excel,而且我的文件有可能增加大小。
谁能告诉我我做错了什么?任何帮助是极大的赞赏 。谢谢 。