Home > Back-end >  POI frame row. GetLastCellNum () method error null pointer
POI frame row. GetLastCellNum () method error null pointer

Time:09-29

//1, to read EXCEL document name 
The String filename="E: \ \ test \ \ XXX. XLS";
//2, create the input stream
FileInputStream input=new FileInputStream (filename);
//3, through the workbook factory class to create a workbook object
Workbook Workbook=WorkbookFactory. Create (input);
//4, obtain the worksheet
Sheet Sheet=workbook. GetSheet (" SQL Results ");
////5, access line
//the Row Row=sheet. GetRow (1);
////6, get cell
//Cell Cell=row. GetCell (1);
////7, reads the cell content
//System. Out. Println (cell getStringCellValue ());
//to get total number of rows
Int rownum=sheet. GetPhysicalNumberOfRows ();
//Map The map=new HashMap ();
ArrayList List=new ArrayList<> (a);
//get the first line of cell number
for(int j=1; JEach line//access to
The Row Row=sheet. GetRow (j);
//get the current line number of effective cell number (several)
//int cellnum=row. GetPhysicalNumberOfCells ();
Int cellnum=row. GetLastCellNum ();//null pointer error say this line has a problem, but my data can be displayed normal,
System. The out. Println (cellnum);
//for each line of the whole cell
For (int x=0; XThe Cell Cell=row. GetCell (x);
//a map. The put (cell. Get);
//cell type, obtain corresponding data
If (cell==null) {
List. The add (" ");
continue;
}
CellType CellType=cell. GetCellType ();
If (cellType==cellType. STRING) {
List. The add (cell. GetStringCellValue ());
} else if (cellType==cellType. NUMERIC) {
List. The add (String. The valueOf (cell getNumericCellValue ()));
} else if (cellType==cellType. BOOLEAN) {
List. The add (String. The valueOf (cell getBooleanCellValue ()));
} else if (cellType==cellType. BLANK) {
List. The add (" ");
}
}
System. The out. Println (" ");
for (int i=0; ISystem. The out. Print (list. Get (I) + "|");
}
}



Troublesome everybody, help to look at, thank you!
  • Related