本文整理匯總了Java中org.apache.poi.ss.usermodel.Sheet.iterator方法的典型用法代碼示例。如果您正苦於以下問題:Java Sheet.iterator方法的具體用法?Java Sheet.iterator怎麽用?Java Sheet.iterator使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.poi.ss.usermodel.Sheet
的用法示例。
在下文中一共展示了Sheet.iterator方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getStartRow
import org.apache.poi.ss.usermodel.Sheet; //導入方法依賴的package包/類
private int getStartRow(Sheet sheet) throws SheetParsingException {
Iterator<Row> rit = sheet.iterator();
while (rit.hasNext()) {
Row row = rit.next();
Cell cell = row.getCell(0);
if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
/*
* In my case first column is Sr.no. and Data starts where sr. no is 1 ,so this
* is start row index
*/
if (cell.getNumericCellValue() == 1.0)
return row.getRowNum();
}
}
throw new SheetParsingException("no start index found for data");
}
示例2: parseSheet
import org.apache.poi.ss.usermodel.Sheet; //導入方法依賴的package包/類
/**
* 解析表格
* @param workbook
* @return
*/
protected List<List<Object>> parseSheet(Workbook workbook) {
List<List<Object>> data = new ArrayList<List<Object>>();
Iterator<Sheet> sheetIterator = workbook.iterator();
int sheetCount=0;
List<Object> headerRowData=null;
// 遍曆excel多個sheet
while (sheetIterator.hasNext()) {
Sheet sheet = sheetIterator.next();
Iterator<Row> rowIterator = sheet.iterator();
int rowNumber=0;
// 遍曆行
while (rowIterator.hasNext()) {
Row row = rowIterator.next();
List<Object> rowData = parseRow(row);
//獲取第一頁 第一行數據
if(sheetCount==0&&rowNumber==0){
headerRowData=rowData;
}
//比較剩餘sheet第一行數據是否相等
if(sheetCount>1&&rowNumber==0){
if(compareRow(headerRowData,rowData)){
continue;
}
}
data.add(rowData);
rowNumber++;
}
sheetCount++;
}
return data;
}
示例3: convertWithConstructor
import org.apache.poi.ss.usermodel.Sheet; //導入方法依賴的package包/類
public static <T> T convertWithConstructor(Map<String,Sheet> sheetMap, Class<T> clazz, boolean hasHeader) throws IllegalAccessException, InstantiationException, InvocationTargetException {
// T object = (T) UnsafeUtil.getUnsafe().allocateInstance(clazz);
T object = clazz.newInstance(); //可能沒有無參構造方法
Field[] fields = clazz.getDeclaredFields();
for (Field field : fields) {
if(field.isAnnotationPresent(ExcelSheetField.class)){
ExcelSheetField annotation = field.getAnnotation(ExcelSheetField.class);
Sheet sheet = sheetMap.get(annotation.name());
if(sheet == null) continue;
Iterator<Row> iterator = sheet.iterator();
Class type = field.getType();
boolean isList = type.isAssignableFrom(List.class);
if(isList){
type = TypeUtils.getRawType(((ParameterizedType) field.getGenericType()).getActualTypeArguments()[0],null);
}
List<T> list = convertWithConstructor(iterator, type, hasHeader);
if (isList) {
setMethod(field, clazz).invoke(object, list);
} else {
if(CollectionUtils.isNotEmpty(list)){
setMethod(field, clazz).invoke(object, list.get(0));
}
}
}
}
return object;
}