本文整理匯總了Java中org.apache.poi.hssf.usermodel.HSSFSheet.getPhysicalNumberOfRows方法的典型用法代碼示例。如果您正苦於以下問題:Java HSSFSheet.getPhysicalNumberOfRows方法的具體用法?Java HSSFSheet.getPhysicalNumberOfRows怎麽用?Java HSSFSheet.getPhysicalNumberOfRows使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.poi.hssf.usermodel.HSSFSheet
的用法示例。
在下文中一共展示了HSSFSheet.getPhysicalNumberOfRows方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: readExcel
import org.apache.poi.hssf.usermodel.HSSFSheet; //導入方法依賴的package包/類
public static void readExcel(String filePth) throws Exception {
InputStream is = new FileInputStream(filePth);
//創建工作薄
//XSSFWorkbook hwb = new XSSFWorkbook(is);
HSSFWorkbook hwb = new HSSFWorkbook(new POIFSFileSystem(is));
//得到sheet
for (int i = 0; i < hwb.getNumberOfSheets(); i++) {
HSSFSheet sheet = hwb.getSheetAt(i);
int rows = sheet.getPhysicalNumberOfRows();
//遍曆每一行
for (int j = 0; j < rows; j++) {
HSSFRow hr = sheet.getRow(j);
Iterator<?> it = hr.iterator();
while(it.hasNext()){
String context = it.next().toString();
System.out.println(context);
}
}
}
hwb.close();
}
示例2: buildMaxColumn
import org.apache.poi.hssf.usermodel.HSSFSheet; //導入方法依賴的package包/類
private int buildMaxColumn(HSSFSheet sheet){
int rowCount=sheet.getPhysicalNumberOfRows();
int maxColumnCount=0;
for(int i=0;i<rowCount;i++){
HSSFRow row=sheet.getRow(i);
if(row==null){
continue;
}
int columnCount=row.getPhysicalNumberOfCells();
if(columnCount>maxColumnCount){
maxColumnCount=columnCount;
}
}
return maxColumnCount;
}
示例3: readExcel2003
import org.apache.poi.hssf.usermodel.HSSFSheet; //導入方法依賴的package包/類
public static ArrayList<ArrayList<ArrayList<Object>>> readExcel2003(File file){
try{
ArrayList<ArrayList<ArrayList<Object>>> sheetArray = new ArrayList<ArrayList<ArrayList<Object>>> ();
HSSFWorkbook wb = new HSSFWorkbook(new FileInputStream(file));
for(int sheetNum = 0;sheetNum < wb.getNumberOfSheets();sheetNum++){
ArrayList<ArrayList<Object>> rowList = new ArrayList<ArrayList<Object>>();
ArrayList<Object> colList;
HSSFSheet sheet = wb.getSheetAt(sheetNum);
HSSFRow row;
HSSFCell cell;
Object value;
for(int i = 0 , rowCount = 0; rowCount < sheet.getPhysicalNumberOfRows() ; i++ ){
row = sheet.getRow(i);
colList = new ArrayList<Object>();
if(row == null){
//����ȡ��Ϊ��ʱ
if(i != sheet.getPhysicalNumberOfRows()){//�ж��Ƿ������һ��
rowList.add(colList);
}
continue;
}else{
rowCount++;
}
for( int j = 0 ; j <= row.getLastCellNum() ;j++){
cell = row.getCell(j);
if(cell == null ){
//���õ�Ԫ��Ϊ��
if(j != row.getLastCellNum()){//�ж��Ƿ��Ǹ��������һ����Ԫ��
colList.add("");
}
continue;
}
switch(cell.getCellType()){
case XSSFCell.CELL_TYPE_STRING:
value = cell.getStringCellValue();
break;
case XSSFCell.CELL_TYPE_NUMERIC:
if ("@".equals(cell.getCellStyle().getDataFormatString())) {
value = df.format(cell.getNumericCellValue());
} else if ("General".equals(cell.getCellStyle()
.getDataFormatString())) {
value = nf.format(cell.getNumericCellValue());
} else {
value = sdf.format(HSSFDateUtil.getJavaDate(cell
.getNumericCellValue()));
}
break;
case XSSFCell.CELL_TYPE_BOOLEAN:
value = Boolean.valueOf(cell.getBooleanCellValue());
break;
case XSSFCell.CELL_TYPE_BLANK:
value = "";
break;
default:
value = cell.toString();
}// end switch
colList.add(value);
}//end for j
rowList.add(colList);
}//end for i
sheetArray.add(rowList);
}// end sheetNum
return sheetArray;
}catch(Exception e){
return null;
}
}