poi를 이용하여 excel 데이터 가져오기, 코드 번거로운 문제 수정
                                            
 4562 단어  Excel
                    
그래서 excel 데이터 가져오는 추상적인 클래스를 얻었다
직접 코드:
excel 읽기 방법
	public List<List<Object>> readFormExcel(File file, int startRow,
			int startColumn) throws Exception {
		List<List<Object>> list = new ArrayList<List<Object>>();
		Workbook workbook = null;
		if (file.getName().toUpperCase().endsWith(".XLS")) {
			workbook = createWorkBook(file);
		} else {
			workbook = createWorkbook2007(file);
		}
		Sheet sheet = workbook.getSheetAt(0);
		if (sheet == null) {
			throw new IllegalArgumentException(" ");
		}
		int rowNumbers = sheet.getLastRowNum();
		if (startRow > rowNumbers) {
			throw new IllegalArgumentException(" ");
		}
		int headColumnCount = sheet.getRow(0).getLastCellNum();
		for (int i = startRow; i <= rowNumbers; i++) {
			Row row = sheet.getRow(i);
			if (row == null) {
				continue;
			}
			int columnNumber = row.getLastCellNum();
			if (columnNumber < headColumnCount) {
				columnNumber = headColumnCount;
				// , 3 , 2 , 2 , 2 . 3 . .. , 
			}
			List<Object> cellList = new ArrayList<Object>();
			for (int j = startColumn; j < columnNumber; j++) {
				Cell cell = row.getCell(j);
				if (cell == null) {
					cellList.add("");
					continue;
				}
				Object value = null;
				switch (cell.getCellType()) {
				case Cell.CELL_TYPE_BLANK: {
					value = "";
					cellList.add(value);
					break;
				}
				case Cell.CELL_TYPE_FORMULA: {
					value = cell.getCellFormula();
					cellList.add(value);
					break;
				}
				case Cell.CELL_TYPE_NUMERIC: {
					if (workbook instanceof HSSFWorkbook) {
						if (HSSFDateUtil.isCellDateFormatted(cell)) {
							value = cell.getDateCellValue();
							cellList.add(value);
						} else {
							value = cell.getNumericCellValue();
							cellList.add(value);
						}
					} else {
						if (DateUtil.isCellDateFormatted(cell)) {
							value = cell.getDateCellValue();
							cellList.add(value);
						} else {
							value = cell.getNumericCellValue();
							cellList.add(value);
						}
					}
					break;
				}
				case Cell.CELL_TYPE_STRING: {
					value = cell.getRichStringCellValue().getString();
					cellList.add(value);
					break;
				}
				case Cell.CELL_TYPE_BOOLEAN: {
					value = cell.getBooleanCellValue();
					cellList.add(value);
					break;
				}
				default: {
					value = cell.getRichStringCellValue().getString();
					cellList.add(value);
					break;
				}
				}
			}
			list.add(cellList);
		}
		return list;
	}
클라이언트 호출 방법
	/**
	 * 
	 * @param file
	 *            execute 
	 * @param startRow
	 *             
	 * @param startColumn
	 *             
	 * @param requestData
	 *             
	 * @return  
	 * @throws Exception
	 */
	public int executeDataImport(File file, int startRow, int startColumn,
			Map<String, Object> requestData) throws Exception {
		String text = file.getName();
		List<List<Object>> importDatas = readFormExcel(file, startRow,
				startColumn);
		if (importDatas == null || importDatas.size() == 0) {
			return 0;
		}
		int resultCount = processBatchData(importDatas, requestData);
		return resultCount;
	}실제 입고 추상적 방법
	/**
	 * 
	 * @param importDatas
	 *            excel 
	 * @param requestData
	 *             
	 * @return
	 */
	public abstract int processBatchData(List<List<Object>> importDatas,
			Map<String, Object> requestData);이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Excel Grep toolExcel Grep tool ■히나가타 ■ 시트 구성 ExcelGrep.cls...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.