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


Java HSSFRow.cellIterator方法代碼示例

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


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

示例1: generateValueTree

import org.apache.poi.hssf.usermodel.HSSFRow; //導入方法依賴的package包/類
/**
 * Returns a new {@link Map} from the given row with the values for the
 * selected columns. It is possible to specify the selected
 * {@link TypeTreeNode}s.
 *
 * @param actualRow
 * @param selectedColumnTitles
 * @param columnTitles
 * @param timeStampColumnIndex
 * @return
 */
private Map<String, Serializable> generateValueTree(final HSSFRow actualRow, final List<String> selectedColumnTitles, final List<TypeTreeNode> selectedAttributes, final List<String> columnTitles, final int timeStampColumnIndex) {
	final Map<String, Serializable> values = new HashMap<String, Serializable>();
	final Iterator<Cell> cellIterator = actualRow.cellIterator();
	AttributeTypeEnum attributeType = null;
	while (cellIterator.hasNext()) {
		final Cell actualCell = cellIterator.next();
		final String attributeName = columnTitles.get(actualCell.getColumnIndex());
		for (final TypeTreeNode attribute : selectedAttributes) {
			if (attribute.getName().equals(attributeName)) {
				attributeType = attribute.getType();
			}
		}
		if (selectedColumnTitles.contains(attributeName) && actualCell.getColumnIndex() != timeStampColumnIndex) {
			final Serializable attributeValue = this.getAttributeValue(attributeType, actualCell);
			values.put(attributeName, attributeValue);
		}
	}
	return values;
}
 
開發者ID:bptlab,項目名稱:Unicorn,代碼行數:31,代碼來源:ExcelImporter.java

示例2: readSheetHead

import org.apache.poi.hssf.usermodel.HSSFRow; //導入方法依賴的package包/類
/**
    * 記錄每一列對應的column
    * @param sheet
    * @param columnJson
    * @param rowNumber
    * @return
    */
private static Map<Integer, String> readSheetHead(HSSFSheet sheet, JSONObject columnJson, int rowNumber) {
	if (logger.isDebugEnabled()) {
		logger.debug("readSheetHead(HSSFSheet, JSONObject, int) - start"); //$NON-NLS-1$
	}

	Map<Integer, String> map = new Hashtable<Integer, String>();
	if(sheet!=null){
		HSSFRow row = sheet.getRow(rowNumber++);
		if (row!=null) {
			Iterator<Cell> iterator = row.cellIterator();
			while (iterator.hasNext()) {
				Cell cell = iterator.next();
				if (cell!=null) {
					String cellValue = cell.getStringCellValue();
					if (StringUtils.isNotBlank(cellValue) && columnJson.containsKey(cellValue)) {
						map.put(cell.getColumnIndex(), columnJson.getString(cellValue));// 記錄cell每一列對應的columnName
					}
				}
			}
		}
	}

	if (logger.isDebugEnabled()) {
		logger.debug("readSheetHead(HSSFSheet, JSONObject, int) - end"); //$NON-NLS-1$
	}
	return map;
}
 
開發者ID:leiyong0326,項目名稱:phone,代碼行數:35,代碼來源:ExcelUtil.java

示例3: readSheetBody

import org.apache.poi.hssf.usermodel.HSSFRow; //導入方法依賴的package包/類
/**
 * 讀取excel到JsonArray
 * @param sheet
 * @param map 列對應的column
 * @param rowNumber
 * @param array
 * @return 當前的rowNumber
 */
   private static int readSheetBody(HSSFSheet sheet, Map<Integer, String> map, int rowNumber, JSONArray array) {
	if (logger.isDebugEnabled()) {
		logger.debug("readSheetBody(HSSFSheet, Map<Integer,String>, int, JSONArray) - start"); //$NON-NLS-1$
	}

   	if(sheet!=null){
		int end = sheet.getLastRowNum();//獲取最後一行
		for (; rowNumber<=end;rowNumber++) {
			HSSFRow row = sheet.getRow(rowNumber);
			if (row!=null) {
				JSONObject jsonObject = new JSONObject();
				Iterator<Cell> iterator = row.cellIterator();
				while (iterator.hasNext()) {
					Cell cell = iterator.next();
					if (cell!=null) {
						int cellIndex = cell.getColumnIndex();
						String key = map.get(cellIndex);
						String cellValue = getStringValue(cell);
						if (key!=null&&cellValue!=null&&!cellValue.equals("null")) {
							readSheetCell(jsonObject,key,cellValue);
						}
						
					}
				}
				array.add(jsonObject);
			}
		}
	}

	if (logger.isDebugEnabled()) {
		logger.debug("readSheetBody(HSSFSheet, Map<Integer,String>, int, JSONArray) - end"); //$NON-NLS-1$
	}
	return rowNumber;
}
 
開發者ID:leiyong0326,項目名稱:phone,代碼行數:43,代碼來源:ExcelUtil.java

示例4: getColumnIndexForIdentifier

import org.apache.poi.hssf.usermodel.HSSFRow; //導入方法依賴的package包/類
private int getColumnIndexForIdentifier(final HSSFRow row, final String identifierBookingNumber)
		throws ExceptionFileFormat {
	final Iterator<Cell> cellIterator = row.cellIterator();
	while (cellIterator.hasNext()) {
		final Cell nextCell = cellIterator.next();
		final String cellContent = nextCell.getStringCellValue();
		if (cellContent.equals(identifierBookingNumber)) {
			return nextCell.getColumnIndex();
		}
	}
	throw new ExceptionFileFormat("Failed to parse " + identifierBookingNumber);
}
 
開發者ID:DrBookings,項目名稱:drbookings,代碼行數:13,代碼來源:RunnableImportCSVBooking.java

示例5: isRowEmpty

import org.apache.poi.hssf.usermodel.HSSFRow; //導入方法依賴的package包/類
/**
 * Returns true, if a {@link HSSFRow} has no values.
 *
 * @param actualRow
 */
private boolean isRowEmpty(final HSSFRow actualRow) {
	boolean emptyRow = true;
	final Iterator<Cell> cellIterator = actualRow.cellIterator();
	while (cellIterator.hasNext()) {
		final Cell actualCell = cellIterator.next();
		emptyRow = (actualCell.getCellType() != Cell.CELL_TYPE_BLANK) ? false : true;
	}
	return emptyRow;
}
 
開發者ID:bptlab,項目名稱:Unicorn,代碼行數:15,代碼來源:ExcelImporter.java

示例6: readExcelFile

import org.apache.poi.hssf.usermodel.HSSFRow; //導入方法依賴的package包/類
public static ArrayList<Question> readExcelFile(Uri uri) {

        questionArrayList.clear();

        try{
            // Creating Input Stream
            File file = new File(uri.getPath());
            FileInputStream myInput = new FileInputStream(file);

            // Create a POIFSFileSystem object
            POIFSFileSystem myFileSystem = new POIFSFileSystem(myInput);

            // Create a workbook using the File System
            HSSFWorkbook myWorkBook = new HSSFWorkbook(myFileSystem);

            // Get the first sheet from workbook
            HSSFSheet mySheet = myWorkBook.getSheetAt(0);

            /** We now need something to iterate through the cells.**/
            Iterator rowIter = mySheet.rowIterator();

            while(rowIter.hasNext()){
                HSSFRow myRow = (HSSFRow) rowIter.next();
                Iterator cellIter = myRow.cellIterator();
                int i = 1;
                while(cellIter.hasNext()){
                    HSSFCell myCell = (HSSFCell) cellIter.next();
                    if(i == 1) {
                        quesSt = myCell.toString();
                        i++;
                    }
                    else if(i == 2) {
                        op1 = myCell.toString();
                        i++;
                    }
                    else if(i == 3) {
                        op2 = myCell.toString();
                        i++;
                    }
                    else if(i == 4) {
                        op3 = myCell.toString();
                        i++;
                    }
                    else if(i == 5) {
                        op4 = myCell.toString();
                        i++;
                    }
                    else if(i == 6) {
                        ca = (int)Double.parseDouble(String.valueOf(myCell));
                        i++;
                    }
                    Log.d(TAG, "Cell Value: " +  myCell.toString());
                    //Toast.makeText(context, "Cell Value: " + myCell.toString(), Toast.LENGTH_SHORT).show();
                }
                questionArrayList.add(new Question(quesSt,op1,op2,op3,op4,ca));
            }
            myInput.close();
        }catch (Exception e){e.printStackTrace(); }
        return questionArrayList;
    }
 
開發者ID:suchoX,項目名稱:Simplify,代碼行數:61,代碼來源:ReadExcelFile.java


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