和作者一样的代码,导入指定的jar包,但是出现异常,调试不成功,求指导
做JxlReadExcel练习的时候出现解析异常:
异常类型java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
开发平台:win7+MyEclipse2014+jdk1.7
有没有大侠帮下?
package com.imooc.excel; import java.io.File; import java.io.IOException; import jxl.Cell; import jxl.Sheet; import jxl.Workbook; import jxl.write.WritableWorkbook; /** * JXL解析Excel * */ public class JxlReadExcel { public static void main(String[] args) { File file = new File("jxl_text.xls"); try { //创建工作薄 WritableWorkbook workbook = Workbook.createWorkbook(file); //获取第一个工作表sheet Sheet sheet = workbook.getSheet(0); //获取数据 for (int i = 0; i < sheet.getRows(); i++) { for (int j = 0; j < sheet.getColumns(); j++) { Cell cell = sheet.getCell(j,i); System.out.print(cell.getContents()+" "); } System.out.println(); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } }