做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(); } } }
你是想读取excel文件中的内容吧,那不能这么用
WritableWorkbook workbook = Workbook.createWorkbook(file);
应该这么用
Workbook workbook = Workbook.getWorkbook(file);
Workbook workbook = Workbook.getWorkbook(file);
请问我的程序这条语句,执行到该语句后直接跳到程序的最后,不执行该语句的下面的了,请问是什么原因