本文整理匯總了Java中org.apache.poi.ss.usermodel.Row.cellIterator方法的典型用法代碼示例。如果您正苦於以下問題:Java Row.cellIterator方法的具體用法?Java Row.cellIterator怎麽用?Java Row.cellIterator使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.poi.ss.usermodel.Row
的用法示例。
在下文中一共展示了Row.cellIterator方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: readExcelFile
import org.apache.poi.ss.usermodel.Row; //導入方法依賴的package包/類
/**
* Método que se encarga de leer el libro de excel
* cuya ruta recibimos en el constructor y devuelve una lista
* de ciudadanos
* @return lista de Usuarios de la base de datos
*/
public List<CitizenDB> readExcelFile(){
List<CitizenDB> citizens = new ArrayList<CitizenDB>();
// para cada una de las hojas presentes en el documento de excel
for(int i=0;i < workbook.getNumberOfSheets();i++){
XSSFSheet sheet = this.workbook.getSheetAt(i);
Iterator<Row> rowIterator = sheet.iterator();
Row row;
int counter = 0;
//para cada fila de la hoja
while(rowIterator.hasNext()){
row = rowIterator.next();
if (counter > 0) { //omitimos la cabecera (hay que mirar si hay un metodo de la API)
Iterator<Cell> cellIterator = row.cellIterator();
int j = 0;
CitizenDB user = new CitizenDB();
while (cellIterator.hasNext())
this.insertCitizenField(user, j++, cellIterator.next());
user.setPassword(new GenerationPassword().passwordGenerator());
citizens.add(user);
}
counter++;
}
}
return citizens;
}
示例2: isBlankRow
import org.apache.poi.ss.usermodel.Row; //導入方法依賴的package包/類
/**
* 判斷空行
*/
private static boolean isBlankRow(Row row) {
if (row == null) {
return true;
}
boolean result = true;
Iterator<Cell> cells = row.cellIterator();
String value = "";
while (cells.hasNext()) {
Cell cell = cells.next();
int cellType = cell.getCellType();
switch (cellType) {
case Cell.CELL_TYPE_NUMERIC:
value = String.valueOf(cell.getNumericCellValue());
break;
case Cell.CELL_TYPE_STRING:
value = cell.getStringCellValue();
break;
case Cell.CELL_TYPE_BOOLEAN:
value = String.valueOf(cell.getBooleanCellValue());
break;
case Cell.CELL_TYPE_FORMULA:
value = String.valueOf(cell.getCellFormula());
break;
}
if (StringUtils.isNotBlank(value)) {
result = false;
break;
}
}
return result;
}
示例3: ExcelReader
import org.apache.poi.ss.usermodel.Row; //導入方法依賴的package包/類
public ExcelReader(String fileName, String sheetName) {
int rowNumber = 0;
int colNumber = 0;
try {
FileInputStream file = new FileInputStream(new File(fileName));
XSSFWorkbook workbook = new XSSFWorkbook(file);
XSSFSheet sheet;
Iterator<Row> rowIterator;
if (sheetName != null)
sheet = workbook.getSheet(sheetName);
else
sheet = workbook.getSheetAt(0);
Row row;
Cell cell;
Iterator<Cell> cellIterator;
if (sheet != null) {
rowIterator = sheet.iterator();
while (rowIterator.hasNext()) {
row = rowIterator.next();
cellIterator = row.cellIterator();
colNumber = 0;
while (cellIterator.hasNext()) {
cell = cellIterator.next();
if (rowNumber == 0)
celNum.put(cellVal(cell), colNumber);
else
celValues.put("["+ rowNumber +","+ colNumber +"]", cellVal(cell));
colNumber++;
}
rowNumber++;
}
}
rowCount = rowNumber - 1;
file.close();
}
catch (Exception x) {
x.printStackTrace();
}
}