当前位置: 首页>>代码示例>>Java>>正文


Java XSSFSheet.iterator方法代码示例

本文整理汇总了Java中org.apache.poi.xssf.usermodel.XSSFSheet.iterator方法的典型用法代码示例。如果您正苦于以下问题:Java XSSFSheet.iterator方法的具体用法?Java XSSFSheet.iterator怎么用?Java XSSFSheet.iterator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.poi.xssf.usermodel.XSSFSheet的用法示例。


在下文中一共展示了XSSFSheet.iterator方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: readExcelFile

import org.apache.poi.xssf.usermodel.XSSFSheet; //导入方法依赖的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;
}
 
开发者ID:Arquisoft,项目名称:dashboard1b,代码行数:32,代码来源:AdapterPoi.java

示例2: fillSheetAsArray

import org.apache.poi.xssf.usermodel.XSSFSheet; //导入方法依赖的package包/类
private void fillSheetAsArray(XSSFSheet sheet, ArraySheetLib arraySheet) {
	//
	Iterator<Row> rowIter = sheet.iterator();

	while (rowIter.hasNext()) {
		Row row = rowIter.next();
		Iterator<Cell> cellIter = row.iterator();
		ArrayList<String> rowCells = new ArrayList<String>(); 
		while (cellIter.hasNext()) {
			Cell cell = cellIter.next();
			String cellValue = getCellValueAsString(cell); 
			rowCells.add(cellValue);
		}
		arraySheet.addRow(rowCells.toArray(new String[rowCells.size()]));  
	}
}
 
开发者ID:nextreesoft,项目名称:expow,代码行数:17,代码来源:ExpowFileReaderLib.java

示例3: readWorksheetWithName

import org.apache.poi.xssf.usermodel.XSSFSheet; //导入方法依赖的package包/类
public List<List<String>> readWorksheetWithName(String fileName, String worksheetName)
    //Read a specific worksheet within excel spreadsheet, based on the name of the worksheet
    {
    try {
        FileInputStream file = new FileInputStream(new File(fileName));

        //Create Workbook instance holding reference to .xlsx file
        XSSFWorkbook workbook = new XSSFWorkbook(file);

        //Get first/desired sheet from the workbook based on worksheet name
        XSSFSheet sheet = workbook.getSheet(worksheetName);

        //Iterate through each rows one by one
        Iterator<Row> rowIterator = sheet.iterator();
        while (rowIterator.hasNext()) {
            Row input_row = rowIterator.next();
            tableExcelFile.add(readWorksheetRow(input_row));
        }
        file.close();
        setReturnMessage(Constants.OK);
    } catch (Exception e) {
        e.printStackTrace();
        setReturnMessage(e.toString());
    }
    return tableExcelFile;
}
 
开发者ID:consag,项目名称:fitnessefixtures,代码行数:27,代码来源:ExcelFile.java

示例4: leerCiudadanos

import org.apache.poi.xssf.usermodel.XSSFSheet; //导入方法依赖的package包/类
@Override
public ArrayList<Ciudadano> leerCiudadanos(ArrayList<Ciudadano> ciudadanos, String ruta) {
	try {
		FileInputStream file = new FileInputStream(new File(ruta));
		XSSFWorkbook workbook = new XSSFWorkbook(file);
		XSSFSheet sheet = workbook.getSheetAt(0);

		Iterator<Row> rowIterator = sheet.iterator();
		while (rowIterator.hasNext()) {
			Row row = rowIterator.next();

			ArrayList<Object> aux = new ArrayList<Object>();
			for (int i = 0; i < 7; i++) {
				aux.add(row.getCell(i) != null ? row.getCell(i).toString() : null);
			}

			String nombre = row.getCell(0) != null ? row.getCell(0).toString() : null;
			if (nombre != null && nombre.equals("Nombre"))
				continue;
			String fecha = row.getCell(3) != null ? row.getCell(3).toString() : null;

			Date date = new SimpleDateFormat("dd-MMM-yyyy").parse(fecha);
			java.sql.Date nacimiento = new java.sql.Date(date.getTime());

			Ciudadano ciudadano = new Ciudadano(aux.get(0).toString(), aux.get(1).toString(), aux.get(2).toString(),
					aux.get(4).toString(), aux.get(5).toString(), aux.get(6).toString(), nacimiento);
			
			ciudadanos.add(ciudadano);
		}

		file.close();
		workbook.close();
	} catch (Exception e) {
		System.err.println("Error al leer del excel xlsx");
	}
	return ciudadanos;
}
 
开发者ID:Arquisoft,项目名称:citizensLoader2b,代码行数:38,代码来源:Xlsx.java

示例5: convert

import org.apache.poi.xssf.usermodel.XSSFSheet; //导入方法依赖的package包/类
@Override
public ByteArrayOutputStream convert(InputStream stream) {
    ByteArrayOutputStream outStream;
    try {
        outStream = new ByteArrayOutputStream();
        // Read workbook into HSSFWorkbook
        XSSFWorkbook my_xls_workbook = new XSSFWorkbook(stream);
        // Read worksheet into HSSFSheet
        XSSFSheet my_worksheet = my_xls_workbook.getSheetAt(0);
        // To iterate over the rows
        Iterator<Row> rowIterator = my_worksheet.iterator();
        // We will create output PDF document objects at this point
        Document pdf = new Document();
        PdfWriter.getInstance(pdf, outStream);
        pdf.open();
        // we have two columns in the Excel sheet, so we create a PDF table
        // with two columns
        // Note: There are ways to make this dynamic in nature, if you want
        // to.
        PdfPTable my_table = new PdfPTable(2);
        // We will use the object below to dynamically add new data to the
        // table
        PdfPCell table_cell;
        // Loop through rows.
        printPdf(rowIterator, my_table);
        // Finally add the table to PDF document
        pdf.add(my_table);
        pdf.close();
        // we created our pdf file..
        stream.close(); // close xls
        return outStream;
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return null;

}
 
开发者ID:geetools,项目名称:geeCommerce-Java-Shop-Software-and-PIM,代码行数:38,代码来源:XslxToPdfConverter.java

示例6: readXLSX

import org.apache.poi.xssf.usermodel.XSSFSheet; //导入方法依赖的package包/类
public List<Person> readXLSX(InputStream input) {
        try {
            XSSFWorkbook wBook = new XSSFWorkbook(input);
            XSSFSheet sheet = wBook.getSheetAt(0);
            Iterator<Row> rowIterator = sheet.iterator();
            rowIterator.next();
            
            List<Person> persons = getPersonsList(rowIterator);
//            wBook.close();
            return persons;
        } catch (Exception ioe) {
            ioe.printStackTrace();
            throw new ApplicationContextException("Loadfile Error");
        }
    }
 
开发者ID:leandrocgsi,项目名称:erudio-api-oauth2,代码行数:16,代码来源:XLSXImporter.java

示例7: loadDatabaseTable

import org.apache.poi.xssf.usermodel.XSSFSheet; //导入方法依赖的package包/类
/**
 * This method loads the database table with the information in the mapping file.
 * @throws IOException This exception is thrown if there is a problem accessing the spreadsheet.
 * @throws SQLException 
 */
@Override
public void loadDatabaseTable() throws IOException, SQLException {
	
	prepareDatabase();
	
	XSSFWorkbook oWorkbook = new XSSFWorkbook (this.fisMapFile);
	 
	XSSFSheet oMapSheet = oWorkbook.getSheet(PAGE_NAME);
	if (oMapSheet != null) {
		Iterator<Row> iterDrugRow = oMapSheet.iterator();
		long lRowIndex = 0;
		while (iterDrugRow.hasNext()) {
			Row oRow = iterDrugRow.next();
			
			if ((lRowIndex > 0) ||
				((lRowIndex == 0) && (!isTitleRow(oRow)))) {
				
				RowMapping oRowMapping = new RowMapping(oRow);
				RowProcessingStatus eStatus = null;
				try {
					addRowToTermDatabase(oRowMapping);
					eStatus = RowProcessingStatus.RECORD_WRITTEN;
				}
				catch (Exception e) {
					outputRowMessage("Exception", e.getMessage(), oRowMapping);
					eStatus = RowProcessingStatus.EXCEPTION_OCCURRED;
				}
				updateStatistics(eStatus);
			}
			
			lRowIndex++;
			
			if ((lRowIndex % NUM_ROWS_PER_SECTION) == 0) {
				System.out.println("Total rows processed so far: " + lRowIndex);
			}
		}
	}
}
 
开发者ID:KRMAssociatesInc,项目名称:eHMP,代码行数:44,代码来源:JLVH2DrugsLoadUtil.java

示例8: getNumberOfRows

import org.apache.poi.xssf.usermodel.XSSFSheet; //导入方法依赖的package包/类
private static int getNumberOfRows(XSSFSheet sheet) {
  int numnberOfRows = 0;
  Iterator<Row> iterator = sheet.iterator();
  while (iterator.hasNext()) {
    Row row = iterator.next();
    numnberOfRows = Math.max(numnberOfRows, row.getRowNum());
  }
  return numnberOfRows + 1;
}
 
开发者ID:fortitudetec,项目名称:presto-plugins,代码行数:10,代码来源:XSSFSheetTable.java

示例9: loadJlvVaMedData

import org.apache.poi.xssf.usermodel.XSSFSheet; //导入方法依赖的package包/类
/**
 * This method reads the information in the JLV table that contains VA VUID to RxNORM mappings.   
 * 
 * @throws IOException This exception occurs if there is a problem reading the excel spreadsheet.
 */
private void loadJlvVaMedData() throws IOException {
	//Get the workbook instance for XLS file
	XSSFWorkbook workbook = new XSSFWorkbook (this.fisJlvVaMedFileName);
	 
	XSSFSheet oDrugsSheet = workbook.getSheet("DRUGS");
	if (oDrugsSheet != null) {
		Iterator<Row> iterDrugRow = oDrugsSheet.iterator();
		long lRowIndex = 0;
		while (iterDrugRow.hasNext()) {
			Row oRow = iterDrugRow.next();
			
			if ((lRowIndex > 0) ||
				((lRowIndex == 0) && (!isVaMapTitleRow(oRow)))) {
				
				VaDrugRowMapping oVaDrugRowMapping = new VaDrugRowMapping(oRow);
				RowProcessingStatus eStatus = null;
				try {
					eStatus = updateTermDatabase(oVaDrugRowMapping);
				}
				catch (TermLoadException e) {
					outputRowMessage("Exception", e.getMessage(), oVaDrugRowMapping);
					eStatus = RowProcessingStatus.VA_MAP_EXCEPTION_OCCURRED;
				}
				updateVaMapStatistics(eStatus);
			}
			
			lRowIndex++;
			
			if ((lRowIndex % NUM_PER_SECTION) == 0) {
				System.out.println("Total rows processed so far: " + lRowIndex);
			}
		}
	}
}
 
开发者ID:KRMAssociatesInc,项目名称:eHMP,代码行数:40,代码来源:JLVDrugLoadUtil.java

示例10: loadJlvDodMedData

import org.apache.poi.xssf.usermodel.XSSFSheet; //导入方法依赖的package包/类
/**
 * This method reads the information in the JLV table that contains VA VUID to RxNORM mappings.   
 * 
 * @throws IOException This exception occurs if there is a problem reading the excel spreadsheet.
 */
private void loadJlvDodMedData() throws IOException {
	//Get the workbook instance for XLS file
	XSSFWorkbook workbook = new XSSFWorkbook (this.fisJlvDodMedFileName);
	 
	XSSFSheet oDrugsSheet = workbook.getSheet("DOD_MEDICATIONS");
	if (oDrugsSheet != null) {
		Iterator<Row> iterDrugRow = oDrugsSheet.iterator();
		long lRowIndex = 0;
		while (iterDrugRow.hasNext()) {
			Row oRow = iterDrugRow.next();
			
			if ((lRowIndex > 0) ||
				((lRowIndex == 0) && (!isDodMapTitleRow(oRow)))) {
				
				DodDrugRowMapping oDodDrugRowMapping = new DodDrugRowMapping(oRow);
				RowProcessingStatus eStatus = null;
				try {
					eStatus = updateTermDatabase(oDodDrugRowMapping);
				}
				catch (TermLoadException e) {
					outputRowMessage("Exception", e.getMessage(), oDodDrugRowMapping);
					eStatus = RowProcessingStatus.DOD_MAP_EXCEPTION_OCCURRED;
				}
				updateDodMapStatistics(eStatus);
			}
			
			lRowIndex++;
			
			if ((lRowIndex % NUM_PER_SECTION) == 0) {
				System.out.println("Total rows processed so far: " + lRowIndex);
			}
		}
	}
}
 
开发者ID:KRMAssociatesInc,项目名称:eHMP,代码行数:40,代码来源:JLVDrugLoadUtil.java

示例11: ExcelReader

import org.apache.poi.xssf.usermodel.XSSFSheet; //导入方法依赖的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();
		}
	}
 
开发者ID:adelbs,项目名称:ISO8583,代码行数:51,代码来源:ExcelReader.java

示例12: buildItemRateDescription

import org.apache.poi.xssf.usermodel.XSSFSheet; //导入方法依赖的package包/类
public List<ItemRateDescription> buildItemRateDescription(String saveDirectory,
                                                          MultipartFile multipartFile) throws IOException, BulkUploadException {
    List<ItemRateDescription> itemRateDescriptions = new ArrayList<ItemRateDescription>();
    FileInputStream fileInputStream = null;
    try {
        String path = saveDirectory + multipartFile.getOriginalFilename();
        File file = new File(path);
        fileInputStream = new FileInputStream(file);
        XSSFWorkbook workbook = new XSSFWorkbook(fileInputStream);
        for (SheetNames sheetName : SheetNames.values()) {
            XSSFSheet sheet = workbook.getSheet(sheetName.getSheetName());
            Iterator<Row> rowIterator = sheet.iterator();
            while (rowIterator.hasNext()) {
                Row row = rowIterator.next();
                ItemRateDescription itemRateDescription = new ItemRateDescription();
                if (row.getRowNum() == 0) {
                    continue;
                }
                Iterator<Cell> cellIterator = row.cellIterator();
                if (sheetName == SheetNames.MATERIAL_RATES) {
                    while (cellIterator.hasNext()) {
                        itemRateDescription = getItemDescription(row, itemRateDescription, cellIterator, Constants.MATERIAL);
                    }

                }
                if (sheetName == SheetNames.LABOUR_RATES) {
                    while (cellIterator.hasNext()) {
                        itemRateDescription = getItemDescription(row, itemRateDescription, cellIterator, Constants.LABOUR);
                    }
                }
                if (sheetName == SheetNames.MACHINERY_RATES) {
                    while (cellIterator.hasNext()) {
                        itemRateDescription = getItemDescription(row, itemRateDescription, cellIterator, Constants.MACHINERY);
                    }
                }
                if (sheetName == SheetNames.OTHER_RATES) {
                    while (cellIterator.hasNext()) {
                        itemRateDescription = getItemDescription(row, itemRateDescription, cellIterator, Constants.OTHER);
                    }
                }
                itemRateDescriptions.add(itemRateDescription);
            }
        }


    } catch (Exception e) {
        LOGGER.error("Exception while reading excel", e);
        throw new BulkUploadException("Error in Uploading the file");
    } finally {
        if (fileInputStream != null) {
            fileInputStream.close();
        }
    }
    return itemRateDescriptions;
}
 
开发者ID:devintqa,项目名称:pms,代码行数:56,代码来源:ItemRateDescriptionBuilder.java

示例13: loadDatabaseTable

import org.apache.poi.xssf.usermodel.XSSFSheet; //导入方法依赖的package包/类
/**
 * This method loads the database table with the information in the mapping file.
 * @throws IOException This exception is thrown if there is a problem accessing the spreadsheet.
 * @throws SQLException 
 */
@Override
public void loadDatabaseTable() throws IOException, SQLException {
	
	prepareDatabase();
	
	XSSFWorkbook oWorkbook = new XSSFWorkbook (this.fisMapFile);
	 
	XSSFSheet oMapSheet = oWorkbook.getSheet(PAGE_NAME);
	if (oMapSheet != null) {
		Iterator<Row> iterDrugRow = oMapSheet.iterator();
		long lRowIndex = 0;
		while (iterDrugRow.hasNext()) {
			Row oRow = iterDrugRow.next();
			
			if ((lRowIndex > 0) ||
				((lRowIndex == 0) && (!isTitleRow(oRow)))) {
				
				RowMapping oRowMapping = new RowMapping(oRow);
				RowProcessingStatus eStatus = null;
				if (containsValidData(oRowMapping)) {
					try {
						addRowToTermDatabase(oRowMapping);
						eStatus = RowProcessingStatus.RECORD_WRITTEN;
					}
					catch (Exception e) {
						outputRowMessage("Exception", e.getMessage(), oRowMapping);
						eStatus = RowProcessingStatus.EXCEPTION_OCCURRED;
					}
				}
				else {
					outputRowMessage("Error", "The row contained invalid data.", oRowMapping);
					eStatus = RowProcessingStatus.INVALID_ROW_DATA;
				}
				updateStatistics(eStatus);
			}
			
			lRowIndex++;
			
			if ((lRowIndex % NUM_ROWS_PER_SECTION) == 0) {
				System.out.println("Total rows processed so far: " + lRowIndex);
			}
		}
	}
}
 
开发者ID:KRMAssociatesInc,项目名称:eHMP,代码行数:50,代码来源:JLVH2LoincLoadUtil.java


注:本文中的org.apache.poi.xssf.usermodel.XSSFSheet.iterator方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。