import java.io.File;
import java.io.IOException;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
public class SpreadsheetRead {
/**
* @param args
* @throws IOException
* @throws BiffException
*/
public static void main(String[] args) throws BiffException, IOException {
// TODO Auto-generated method stub
Workbook workbook = Workbook.getWorkbook(new File("Book1.xls"));
Sheet sheet = workbook.getSheet(0);
Cell name = sheet.getCell(0, 0);
Cell name1 = sheet.getCell(1, 0);
try {
Cell name2 = sheet.getCell(2, 0);
Cell name3 = sheet.getCell(3, 0);
}catch (Exception e){
e.printStackTrace();
}
Cell value = sheet.getCell(0, 1);
Cell value1 = sheet.getCell(1, 1);
Cell value2 = sheet.getCell(2, 1);
Cell value3 = sheet.getCell(3, 1);
System.out.println(sheet.getRows());
System.out.println(sheet.getColumns());
System.out.println(name.getContents());
System.out.println(name1.getContents());
System.out.println(value.getContents());
System.out.println(value1.getContents());
}
}
Excel 工作表内容 (Book1.xls) ... 它包含 4 行和 2 列,如下所述。
名称 值 1 乙二 C 3
此代码适用于单元格 [(0,0),(0,1),(1,0) & (1,1)] 以及其他单元格,它给出 ArrayIndexOutOfBoundException ... 请帮助
堆栈跟踪
java.lang.ArrayIndexOutOfBoundsException:2 4 2 姓名 价值 一个 在 jxl.read.biff.SheetImpl.getCell(SheetImpl.java:356) 在 SpreadsheetRead.main(SpreadsheetRead.java:25) 1