Related packages
// XLSX workbook XSSFWorkbook xsswb = null ; // XLSX sheet XSSFSheet xsssheet = null ; // XLSX row XSSFRow xssrow = null ; // XLS workbook HSSFWorkbook hsswb = null ; // XLS worksheets HSSFSheet hsssheet = null ; / / XLS line HSSFRow hssrow = null ; // Analyzing extension file type IF ( ".xlsx" .equals (fileExte)) { // get xlsx workbook object xsswb = new new XSSFWorkbook ( new newThe FileInputStream (fullFilePath)); // get xlsx worksheet object xsssheet = xsswb.getSheetAt (0 ); // get the number of effective lines xlsx endRowIndex = xsssheet.getLastRowNum (); } the else { // get xls workbook object hsswb = new new HSSFWorkbook ( new new the FileInputStream (fullFilePath)); // get xls worksheet object hsssheet = hsswb.getSheetAt (0 ); // get the number of effective lines xls endRowIndex = hsssheet.getLastRowNum (); } // progressive excel parsing data for ( intthe startRowIndex = I; I <= endRowIndex; I ++ ) { // determine the file extension IF ( ".xlsx" .equals (fileExte)) { // get the current row data xssrow = xsssheet.getRow (I); // if the article no data is recorded, it is xssrow null IF (xssrow == null ) { // out of the cycle does not resolve the Bank Continue ; } // fourth column is empty does not resolve the Bank value = getExcelCellValue (xssrow,. 3); // Get current data row in the fourth column, available from the data acquisition uniqueness iF ( "" .equals (value)) { // determines whether the data is empty, empty out this cycle can not resolve Bank Continue ; } // Get the total number of columns in the row int the RowCount = xssrow.getPhysicalNumberOfCells (); // from the four-frame start cell for ( int J =. 3; J <= the RowCount; J ++ ) { // Get value corresponding value = getExcelCellValue ( xssrow, J); // data from the beginning of the fourth column } } the else { // xls file analytically // Get current row data xls hssrow = hsssheet.getRow (I); // Get the total number of columns xls hssrow .getPhysicalNumberOfCells (); for ( int. 3 = J; J <= the RowCount; J ++ ) { // Get the value of the corresponding value = getExcelCellValue (xssrow, J); // data starting from the fourth row } } } // get a cell data Private static String getExcelHSSFCellValue ( Row HSSFRow, int colIndex,) { String CellValue = StringUtils.EMPTY; // get a cell data HSSFCell cell = row.getCell (colIndex,); // data not empty when the type judgment value IF ! (cell = null ) { Switch ( cell.getCellType ()) { Case HSSFCell.CELL_TYPE_NUMERIC: cellValue = String.valueOf(cell.getNumericCellValue()); break; case HSSFCell.CELL_TYPE_FORMULA: try { cellValue = String.valueOf(cell.getNumericCellValue()); } catch (IllegalStateException e) { cellValue = String.valueOf(cell.getRichStringCellValue()); } break; case HSSFCell.CELL_TYPE_BLANK: cellValue = StringUtils.EMPTY; break; case HSSFCell.CELL_TYPE_BOOLEAN: cellValue = String.valueOf(cell.getBooleanCellValue()); break; case HSSFCell.CELL_TYPE_ERROR: cellValue = String.valueOf(cell.getErrorCellValue()); break; default: cellValue = String.valueOf(cell.getRichStringCellValue()); break; } } //返回转换后的数据值 return cellValue; }
Methods and data analysis means xlsx almost xls
Have any data available for determining the grid, and processing, if it needs to resolve the data line,