當前位置: 首頁>>代碼示例>>Java>>正文


Java Sheet.getPhysicalNumberOfRows方法代碼示例

本文整理匯總了Java中org.apache.poi.ss.usermodel.Sheet.getPhysicalNumberOfRows方法的典型用法代碼示例。如果您正苦於以下問題:Java Sheet.getPhysicalNumberOfRows方法的具體用法?Java Sheet.getPhysicalNumberOfRows怎麽用?Java Sheet.getPhysicalNumberOfRows使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.poi.ss.usermodel.Sheet的用法示例。


在下文中一共展示了Sheet.getPhysicalNumberOfRows方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: unmarshal

import org.apache.poi.ss.usermodel.Sheet; //導入方法依賴的package包/類
public <T> List<T> unmarshal(Class<T> type) {
    Workbook workbook = poijiWorkbook.workbook();
    Sheet sheet = workbook.getSheetAt(options.sheetIndex());

    int skip = options.skip();
    int maxPhysicalNumberOfRows = sheet.getPhysicalNumberOfRows() + 1 - skip;
    List<T> list = new ArrayList<>(maxPhysicalNumberOfRows);

    for (Row currentRow : sheet) {

        if (skip(currentRow, skip))
            continue;

        if (isRowEmpty(currentRow))
            continue;

        if (maxPhysicalNumberOfRows > list.size()) {
            T t = deserialize0(currentRow, type);
            list.add(t);
        }
    }

    return list;
}
 
開發者ID:ozlerhakan,項目名稱:poiji,代碼行數:25,代碼來源:HSSFUnmarshaller.java

示例2: importExcel

import org.apache.poi.ss.usermodel.Sheet; //導入方法依賴的package包/類
public static <T>  ImportResult<T> importExcel(ExcelFileType fileType,InputStream inputStream,Class<T> clazz) throws Exception{
	if(importInfoMap.get(clazz) == null){//初始化信息
		initTargetClass(clazz);			
	}
	ImportInfo importInfo = importInfoMap.get(clazz);
	Integer headRow = importInfo.getHeadRow();
	Workbook workbook = createWorkbook(fileType, inputStream);
	
	int sheetNum = workbook.getNumberOfSheets();
	if(sheetNum < 1 ){
		return null;
	}
	Sheet sheet = workbook.getSheetAt(0);
	int rowCount = sheet.getPhysicalNumberOfRows();
	if(rowCount < (headRow+1)){//
		return null;
	}
	List<String> headNameList = createHeadNameList(sheet, headRow);
	return readData(clazz, importInfo, workbook,headNameList);
}
 
開發者ID:long47964,項目名稱:excel-utils,代碼行數:21,代碼來源:ExcelImportUtil.java

示例3: getLastRow

import org.apache.poi.ss.usermodel.Sheet; //導入方法依賴的package包/類
private int getLastRow(Sheet sheet) throws SheetParsingException {
	int lastRowIndex = -1;
	if (sheet.getPhysicalNumberOfRows() > 0) { // getLastRowNum() actually returns an index, not a row number
		lastRowIndex = sheet.getLastRowNum();

		// now, start at end of spreadsheet and work our way backwards until we find a
		// row having data
		for (; lastRowIndex >= 0; lastRowIndex--) {
			Row row = sheet.getRow(lastRowIndex);
			if (row != null) {
				Cell cell = row.getCell(0);
				if (cell != null && cell.getCellType() == Cell.CELL_TYPE_NUMERIC)
					break;
			}
		}
		return lastRowIndex;
	} else
		throw new SheetParsingException(sheet.getSheetName() + " is empty");
}
 
開發者ID:NeebalLearningPvtLtd,項目名稱:Excel-to-POJO,代碼行數:20,代碼來源:SheetParser.java

示例4: readStudentValue

import org.apache.poi.ss.usermodel.Sheet; //導入方法依賴的package包/類
/**
 * 讀取Excel裏麵客戶的信息
 * @param wb
 * @return
 */
private Map<String, Object> readStudentValue(Workbook wb) {
    //得到第一個shell
    Sheet sheet = wb.getSheetAt(0);
    Map<String, Object> modelMap = new HashMap<>();
    //得到Excel的行數
    this.totalRows = sheet.getPhysicalNumberOfRows();
    //得到Excel的列數(前提是有行數)
    if (totalRows >= 1 && sheet.getRow(0) != null) {
        this.totalCells = sheet.getRow(0).getPhysicalNumberOfCells();
    }
    List<StudentEntity> studentList = new ArrayList<StudentEntity>();
    StudentEntity student;
    List<ErrorJson> errorList = new ArrayList<ErrorJson>();
    ErrorJson error;
    //循環Excel行數,從第二行開始。標題不入庫
    for (int r = 1; r < totalRows; r++) {
        Row row = sheet.getRow(r);
        if (row == null) continue;
        student = new StudentEntity();
        //循環Excel的列
        for (int c = 0; c < this.totalCells; c++) {
            Cell cell = row.getCell(c);
            if (null != cell) {
                if (c == 0) {
                    student.setStudentId((int) cell.getNumericCellValue());//學號
                } else if (c == 1) {
                    cell.setCellType(Cell.CELL_TYPE_STRING);
                    student.setStudentName(cell.getStringCellValue());//學生姓名
                } else if (c == 2) {
                    cell.setCellType(Cell.CELL_TYPE_STRING);
                    student.setClassName(cell.getStringCellValue());//班級
                } else if (c == 3) {
                    cell.setCellType(Cell.CELL_TYPE_STRING);
                    student.setMajor(cell.getStringCellValue());//專業
                }
                student.setPassword("00000000");

            }
        }
        //添加學生
        System.out.println(student);
        if (student.getStudentId() != 0 && student.getStudentName() != "" && student.getClassName() != null && student.getMajor() != "") {
            studentList.add(student);
        } else if (student.getStudentId() != 0 && student.getStudentName() == "") {
            error = new ErrorJson();
            error.setId(student.getStudentId());
            error.setErrors("名字不能為空");
            errorList.add(error);
        } else if (student.getStudentId() != 0 && student.getClassName() == null) {
            error = new ErrorJson();
            error.setId(student.getStudentId());
            error.setErrors("班級不能為空");
            errorList.add(error);
        } else if (student.getStudentId() != 0 && student.getMajor() == "") {
            error = new ErrorJson();
            error.setId(student.getStudentId());
            error.setErrors("專業不能為空");
            errorList.add(error);
        }
    }
    modelMap.put("result", studentList);
    modelMap.put("error", errorList);
    return modelMap;
}
 
開發者ID:junrui-zhao,項目名稱:Educational-Management-System,代碼行數:70,代碼來源:ReadExcel.java

示例5: readStudentValue

import org.apache.poi.ss.usermodel.Sheet; //導入方法依賴的package包/類
/**
 * 讀取Excel裏麵客戶的信息
 * @param wb
 * @return
 */
private Map<String, Object> readStudentValue(Workbook wb) {
    //得到第一個shell
    Sheet sheet = wb.getSheetAt(0);
    Map<String, Object> modelMap = new HashMap<>();
    //得到Excel的行數
    this.totalRows = sheet.getPhysicalNumberOfRows();
    //得到Excel的列數(前提是有行數)
    if (totalRows >= 1 && sheet.getRow(0) != null) {
        this.totalCells = sheet.getRow(0).getPhysicalNumberOfCells();
    }
    List<ClassroomEntity> classList = new ArrayList<ClassroomEntity>();
    ClassroomEntity classroom;
    List<ErrorCJson> errorList = new ArrayList<ErrorCJson>();
    ErrorCJson error;
    //循環Excel行數,從第二行開始。標題不入庫
    for (int r = 1; r < totalRows; r++) {
        Row row = sheet.getRow(r);
        if (row == null) continue;
        classroom = new ClassroomEntity();
        //循環Excel的列
        for (int c = 0; c < this.totalCells; c++) {
            Cell cell = row.getCell(c);
            if (null != cell) {
                if (c == 0) {
                    cell.setCellType(Cell.CELL_TYPE_STRING);
                    classroom.setClassroom(cell.getStringCellValue());//教室名
                } else if (c == 1) {
                    classroom.setPeopleNum((int) cell.getNumericCellValue());//教室容量
                }

            }
        }
        System.out.println(classroom);
        if (classroom.getClassroom() != null && classroom.getPeopleNum() >=0 && classroom.getPeopleNum() <1000 ) {
            classList.add(classroom);
        }else if(classroom.getPeopleNum() <0 && classroom.getPeopleNum() >1000){
            error = new ErrorCJson();
            error.setCourseId(classroom.getClassroom());
            error.setErrors("教室容量過小或過大");
        }
    }
    modelMap.put("result", classList);
    modelMap.put("error", errorList);
    return modelMap;
}
 
開發者ID:junrui-zhao,項目名稱:Educational-Management-System,代碼行數:51,代碼來源:ReadRExcel.java

示例6: readInfoValue

import org.apache.poi.ss.usermodel.Sheet; //導入方法依賴的package包/類
/**
 * 讀取Excel裏麵客戶的信息
 * @param wb
 * @return
 */
private Map<String, Object> readInfoValue(Workbook wb) {
    //得到第一個shell
    Sheet sheet = wb.getSheetAt(0);
    Map<String, Object> modelMap = new HashMap<>();
    //得到Excel的行數
    this.totalRows = sheet.getPhysicalNumberOfRows();
    //得到Excel的列數(前提是有行數)
    if (totalRows >= 1 && sheet.getRow(0) != null) {
        this.totalCells = sheet.getRow(0).getPhysicalNumberOfCells();
    }
    List<InfoEntity> infoList = new ArrayList<InfoEntity>();
    InfoEntity info;
    List<ErrorJson> errorList = new ArrayList<ErrorJson>();
    ErrorJson error;
    //循環Excel行數,從第二行開始。標題不入庫
    for (int r = 1; r < totalRows; r++) {
        Row row = sheet.getRow(r);
        if (row == null) continue;
        info = new InfoEntity();
        //循環Excel的列
        for (int c = 0; c < this.totalCells; c++) {
            Cell cell = row.getCell(c);
            if (null != cell) {
                if (c == 0) {
                    cell.setCellType(Cell.CELL_TYPE_STRING);
                    info.setTitle(cell.getStringCellValue());//title

                } else if (c == 1) {
                    cell.setCellType(Cell.CELL_TYPE_STRING);
                    info.setContext(cell.getStringCellValue());//context
                } else if (c == 2) {
                    Date ti =new Date();
                    Timestamp time = new Timestamp(ti.getTime());
                    info.setTime(time);//time
                } else if (c == 3) {
                    cell.setCellType(Cell.CELL_TYPE_STRING);
                    info.setSender(cell.getStringCellValue());//sender
                }
                else if (c == 4) {
                    info.setStudentId((int) cell.getNumericCellValue());//學號

                }

            }
        }
        //添加學生
        System.out.println(info);
        if (info.getStudentId()!=0&&info.getTitle()!=""&&info.getContext()!=""&&info.getTime()!=null&&info.getSender()!="") {
            infoList.add(info);
        } else if (info.getStudentId()==0) {
            error = new ErrorJson();
            error.setId(info.getId());
            error.setErrors("學號不能為空");
            errorList.add(error);
        } else if ( info.getTitle()=="") {
            error = new ErrorJson();
            error.setId(info.getId());
            error.setErrors("title不能為空");
            errorList.add(error);
        } else if (info.getId() != 0 && info.getContext() == "") {
            error = new ErrorJson();
            error.setId(info.getId());
            error.setErrors("內容不能為空");
            errorList.add(error);
        } else if (info.getId() != 0 && info.getSender() == "") {
            error = new ErrorJson();
            error.setId(info.getId());
            error.setErrors("發送者不能為空");
            errorList.add(error);
        }
    }
    modelMap.put("result", infoList);
    modelMap.put("error", errorList);
    return modelMap;
}
 
開發者ID:junrui-zhao,項目名稱:Educational-Management-System,代碼行數:81,代碼來源:ReadInfoExcel.java

示例7: read

import org.apache.poi.ss.usermodel.Sheet; //導入方法依賴的package包/類
private List<List<String>> read(Workbook wb, int sheetIndex) {
    List<List<String>> dataLst = Lists.newArrayList();
    Sheet sheet = wb.getSheetAt(sheetIndex);
    this.totalRows = sheet.getPhysicalNumberOfRows();
    if ((this.totalRows >= 1) && (sheet.getRow(0) != null)) {
        this.totalCells = sheet.getRow(0).getLastCellNum(); // 獲取最後一個不為空的列是第幾個
    }
    for (int r = 0; r < this.totalRows; r++) {
        Row row = sheet.getRow(r);
        if (row != null) {
            List<String> rowLst = Lists.newArrayList();
            for (int c = 0; c < getTotalCells(); c++) {
                Cell cell = row.getCell(c);

                String cellValue = "";
                if (cell != null) {
                    switch (cell.getCellType()) {
                        case 0:
                            if (HSSFDateUtil.isCellDateFormatted(cell)) {
                                Date date = cell.getDateCellValue();

                                cellValue = DateUtils.dateToStr(date,
                                        "yyyy-MM-dd HH:mm:ss");

                            } else {
                                Integer num = (int) cell.getNumericCellValue();
                                cellValue = String.valueOf(num);
                            }
                            break;
                        case 1:
                            cellValue = cell.getStringCellValue().trim();
                            break;
                        case 4:
                            cellValue = String.valueOf(cell.getBooleanCellValue());
                            break;
                        case 2:
                            cellValue = cell.getCellFormula();
                            break;
                        case 3:
                            cellValue = "";
                            break;
                        case 5:
                            cellValue = "非法字符";
                            break;
                        default:
                            cellValue = "未知類型";
                    }
                }
                rowLst.add(cellValue);
            }
            dataLst.add(rowLst);
        }
    }
    return dataLst;
}
 
開發者ID:DreamYa0,項目名稱:zeratul,代碼行數:56,代碼來源:HandleExcel.java

示例8: mergeColumns

import org.apache.poi.ss.usermodel.Sheet; //導入方法依賴的package包/類
/**
 * 合並列
 */
private void mergeColumns(Sheet sheet, CellStyle cellStyle) {
    // 行數
    int rowsCount = sheet.getPhysicalNumberOfRows();
    // 列數
    int colsCount = sheet.getRow(0).getPhysicalNumberOfCells();

    Row row = null;
    Cell cell1 = null;
    Cell cell2 = null;

    int colSpan = 0;

    for (int r = 0; r < rowsCount; r++) {
        row = sheet.getRow(r);
        // 重置
        colSpan = 0;
        row = sheet.getRow(r);
        for (int c = 0; c < colsCount; c++) {
            cell1 = row.getCell(c);
            cell2 = row.getCell(c + 1);
            if (cell1 == null) {// 如果當前單元格是空的,跳過,繼續當前行的後一個單元格查找
                if (c == colsCount - 1) {
                    break;
                } else {
                    continue;
                }
            }
            if (cell2 == null) {// 說明當前行已經到最後一個單元格了
                if (colSpan >= 1) {// 判斷colSpan是否大於等於1,大於1就要合並了
                    // 合並行中連續相同的值的單元格
                    sheet.addMergedRegion(new CellRangeAddress(r, r, c - colSpan, c));
                    break;
                }
            }
            if (cell1 != null && cell2 != null) {
                // 如果當前單元格和下一個單元格內容相同,那麽colSpan加1
                if (cell1.getStringCellValue().equals(cell2.getStringCellValue())) {
                    colSpan++;
                } else {
                    // 如果當前單元格和下一個不等,那麽判斷colSpan是否大於等於1
                    if (colSpan >= 1) {
                        // 合並行中連續相同的值的單元格
                        sheet.addMergedRegion(new CellRangeAddress(r, r, c - colSpan, c));
                        Cell nowCell = sheet.getRow(r).getCell(c - colSpan);
                        nowCell.setCellStyle(cellStyle);
                        // 合並後重置colSpan
                        colSpan = 0;
                        continue;
                    }
                }
            }

        }
    }

}
 
開發者ID:warlock-china,項目名稱:azeroth,代碼行數:60,代碼來源:ExcelWriter.java

示例9: readDatas

import org.apache.poi.ss.usermodel.Sheet; //導入方法依賴的package包/類
public final static PartitionMap<String ,RCell> readDatas(Sheet i_Sheet ,Integer i_BeginRow ,Integer i_EndRow)
{
    PartitionMap<String ,RCell> v_Ret      = new TablePartition<String ,RCell>();
    Sheet                       v_Sheet    = i_Sheet;
    int                         v_BeginRow = 0;
    int                         v_EndRow   = 0;
    
    if ( i_BeginRow != null )
    {
        v_BeginRow = i_BeginRow.intValue();
        
        if ( v_BeginRow < 0 )
        {
            v_BeginRow = 0;
        }
    }
    
    if ( i_EndRow != null )
    {
        v_EndRow = i_EndRow.intValue();
    }
    else
    {
        v_EndRow = v_Sheet.getPhysicalNumberOfRows();
    }
    
    for (int v_RowNo=v_BeginRow; v_RowNo<=v_EndRow; v_RowNo++)
    {
        Row v_Row = v_Sheet.getRow(v_RowNo);
        if ( v_Row == null )
        {
            continue;
        }
        
        short v_CellCount = v_Row.getLastCellNum();
        
        for (int v_ColumnNo=0; v_ColumnNo<v_CellCount; v_ColumnNo++)
        {
            Cell v_Cell = v_Row.getCell(v_ColumnNo);
            if ( v_Cell == null )
            {
                continue;
            }
            
            if ( v_Cell.getCellTypeEnum() == CellType.STRING )
            {
                String v_Value = v_Cell.getStringCellValue();
                
                if ( !Help.isNull(v_Value) )
                {
                    RCell        v_RCell    = new RCell(v_RowNo ,v_ColumnNo);
                    List<String> v_Decimals = StringHelp.getString(v_Cell.getCellStyle().getDataFormatString() ,$Decimal);
                    if ( !Help.isNull(v_Decimals) )
                    {
                        v_RCell.setDecimal(v_Decimals.get(0).split("\\.")[1].length());
                    }
                    
                    v_Ret.putRow(v_Value.trim() ,v_RCell);
                }
            }
            else if ( v_Cell.getCellTypeEnum() == CellType.NUMERIC )
            {
                if ( HSSFDateUtil.isCellDateFormatted(v_Cell) ) 
                {
                    if ( v_Cell.getDateCellValue() != null )
                    {
                        v_Ret.putRow((new Date(v_Cell.getDateCellValue())).getFull() ,new RCell(v_RowNo ,v_ColumnNo));
                    }
                } 
                else 
                {
                    v_Ret.putRow(String.valueOf(v_Cell.getNumericCellValue()) ,new RCell(v_RowNo ,v_ColumnNo));
                }
            }
        }
    }
    
    return v_Ret;
}
 
開發者ID:HY-ZhengWei,項目名稱:hy.common.report,代碼行數:80,代碼來源:ExcelHelp.java


注:本文中的org.apache.poi.ss.usermodel.Sheet.getPhysicalNumberOfRows方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。