转:http://bigcat.easymorse.com/?p=1648
java可以读取Excel文件,android同样也行,效果如下:
excel源文件:
读取日志如下:
首先需要引入jxl.jar包。读取的代码如下:
public void readExcelFile() {
try {Workbook book = Workbook.getWorkbook(new File(Environment.getExternalStorageDirectory().getPath()+"/mytest.xls"));
System.out.println(">>>>>>number of sheet "+book.getNumberOfSheets());
// 获得第一个工作表对象
Sheet sheet = book.getSheet(0);
int Rows = sheet.getRows();
int Cols = sheet.getColumns();
System.out.println("当前工作表的名字:" + sheet.getName());
System.out.println("总行数:" + Rows);
System.out.println("总列数:" + Cols);
for (int i = 0; i < Rows; ++i) {
for (int j = 0; j < Cols; ++j) {
// getCell(Col,Row)获得单元格的值
System.out.print((sheet.getCell(j, i)).getContents() + " ");
}
System.out.print(" ");
}
book.close();} catch (Exception e) {
System.out.println(e);
}}
具体代码不做过多解释。接下来会继续完成excel的写入和修改方法。
附上jxl.jar包:jxl.jar.zip 附上下载的地址:http://sourceforge.net/projects/jexcelapi/files/jexcelapi/