参考自:
亲测,OK!
import java.io.*;
import jxl.*;
import jxl.read.biff.BiffException;
//import jxl.read.biff.*;
public class ReadExcel
{
public static void main(String args[]) throws BiffException, IOException
{
String filepath = "D:\\交叉验证平台\\测试报告\\DRU出厂测试报告8.xls";
File xlsFile = new File(filepath);
// 获得工作簿对象
Workbook workbook = Workbook.getWorkbook(xlsFile);
// 获得所有工作表
Sheet[] sheets = workbook.getSheets();
// 遍历工作表
if (sheets != null)
{
for (Sheet sheet : sheets)
{
// 获得行数
int rows = sheet.getRows();
// 获得列数
int cols = sheet.getColumns();
// 读取数据
for (int row = 0; row < rows; row++)
{
for (int col = 0; col < cols; col++)
{
Cell cell = sheet.getCell(col, row);
System.out.print(cell.getContents() + " ");
}
System.out.println();
}
}
}
workbook.close();
}
}
如报错:Exception in thread "main" jxl.read.biff.BiffException:unable to recongnize olestream
降低Excel版本即可