0
我只需要从我的SD卡中选择一个XLSX文件并通过apache poi阅读它。这是我到SD卡上调用的意图,选择XLSX文件xlsx通过apache poi阅读
Intent intent = new Intent();
intent.setType("*/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Complete action using"), PICK_FROM_FILE);
}
这里是接收此选择的.xlsx文件的路径代码是错误发生,我认为它在调用的工作簿,但我不能明确它
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == PICK_FROM_FILE && resultCode == RESULT_OK) {
// File file = new File(Environment.getExternalStorageDirectory(), data.getData().toString());
Uri path =data.getData();
ContentResolver cr=this.getContentResolver();
File fpath=new File(path.toString());
try {
//imputStream
InputStream myfile=cr.openInputStream(path);
Log.e("myapp","here");
//Workbooh
Workbook wrk=new HSSFWorkbook(myfile);
//sheet
Sheet firstsheet=wrk.getSheetAt(0);
//RowIterator
Iterator<Row> iterator=firstsheet.iterator();
while(iterator.hasNext())
{
Row next=iterator.next();
//CellIterator
Iterator<Cell> cellIterator=next.cellIterator();
while(cellIterator.hasNext())
{
Cell cell=cellIterator.next();
switch (cell.getCellType())
{
case Cell.CELL_TYPE_STRING:
Toast.makeText(getApplicationContext(),cell.getStringCellValue()+" ",Toast.LENGTH_SHORT).show();
break;
case Cell.CELL_TYPE_NUMERIC:
Toast.makeText(getApplicationContext(),cell.getNumericCellValue()+" ",Toast.LENGTH_SHORT).show();
}
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
我的错误列表
04-26 12:18:17.067 2736-3126/? E/Watchdog: [email protected] 1540 [04-26 12:18:17.069]
04-26 12:18:47.067 2736-3126/? E/Watchdog: [email protected] 1541 [04-26 12:18:47.072]
04-26 12:19:17.067 2736-3126/? E/Watchdog: [email protected] 1542 [04-26 12:19:17.073]
04-26 12:19:47.072 2736-3126/? E/Watchdog: [email protected] 1543 [04-26 12:19:47.075]
04-26 12:20:17.072 2736-3126/? E/Watchdog: [email protected] 1544 [04-26 12:20:17.076]
感谢下面给出了提前帮助.....