我正在编写Java代码来读取具有列名“ Key”和“ Value”的excel文件.但是由于无法强制执行此行代码而出现错误,
行firstRow =(Row)sheet.getRow(0);
如何解决此错误,请帮帮我.
public static void main(String[] args) throws Exception {
FileInputStream fileIn = new FileInputStream("c://param_2003.xls");
POIFSFileSystem fs = new POIFSFileSystem(fileIn);
HSSFWorkbook filename = new HSSFWorkbook(fs);
HSSFSheet sheet = filename.getSheetAt(0);
String column1 = "Key";
String column2 = "Value";
Integer columnNo1 = null;
Integer columnNo2 = null;
List cells = new ArrayList();
Row firstRow =(Row)sheet.getRow(0);
for(org.apache.poi.ss.usermodel.Cell cell:firstRow){
if (cell.getStringCellValue().equals(column1)){
columnNo1 = cell.getColumnIndex();
}
}
for(org.apache.poi.ss.usermodel.Cell cell:firstRow){
if (cell.getStringCellValue().equals(column2)){
columnNo2 = cell.getColumnIndex();
}
}
System.out.println(columnNo1);
System.out.println(columnNo2);
}