我刚接触java,当我尝试在Array List中存储读取列时,我得到此异常jxl.read.biff.NumberValue无法强制转换为Collection.ExcelReader。请告诉我我犯的错误。提前谢谢
import java.io.IOException;
import java.util.ArrayList;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
import jxl.write.WriteException;
class ExcelReader {
private Workbook workbook;
private Sheet sheet;
ArrayList<ExcelReader> getRollNo=new ArrayList<Excelreader>;
public void getExcelContents() throws BiffException, IOException, WriteException
{
workbook= Workbook.getWorkbook(new File("C://Student_Record.xls"));
sheet=workbook.getSheet(0);
int rowLen=sheet.getRows();
for(int i=1;i<rowLen;i++ )
{
getRollNo.add((ExcelReader)sheet.getCell(1,i));
System.out.println(getRollNo);
}
}
}
主类:
import java.io.IOException;
import jxl.read.biff.BiffException;
import jxl.write.WriteException;
public class MainExcelReader {
public static void main(String[] args) throws BiffException, WriteException, IOException {
// TODO Auto-generated method stub
ExcelReader er=new ExcelReader();
er.getExcelContents();
}
}
答案 0 :(得分:0)
尝试在getcontents方法中使用此for循环,希望它有效。
for (int i = 1; i < rowLen; i++) {
Cell cell = this.sheet.getCell(1, i);
this.getRollNo.add(cell.getContents());
System.out.println(this.getRollNo);
}