一、读取data.xls中的第四列第五行数据并在TextView上显示出来
String file = "/sdcard/data.xls";// 打开文件路路径
InputStream is = null;
try {
is = new FileInputStream(new File(file));
Workbook wb=Workbook.getWorkbook(is);//打开工作薄
Sheet sheet=wb.getSheet(0);//打开工作表
Cell hm=sheet.getCell(3,4);//获取单元格位置
display.setText("用户基础信息:\n"+"户名:"+hm.getContents()+"\n");
//显示内容
} catch (Exception e) {
//TODO Auto-generated catch block
e.printStackTrace();
}
二、写入从EditText中输入的数据
本篇文章中的所有代码均为片段,仅供个人在使用中方便查询,在读取SD卡文件时还要在Androidmanifast.xml中加入权限代码:
详细操作可以百度。
String file = "/sdcard/data.xls";
try
{
Workbook rwb = Workbook.getWorkbook(new File(file));
//打开一个文件的副本,并且指定数据写回到原文件
WritableWorkbook wwb = Workbook.createWorkbook(new File(file),rwb);//copy
WritableSheet ws = wwb.getSheet(0);
Label label1= new Label(8,2,eta.getText().toString());//在第九行第三列填充数据
ws.addCell(label1);//添加进单元格
wwb.close();//关闭工作表
rwb.close();//关闭工作薄
}
catch(Exception e)
{
e.printStackTrace();
}