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


Java XSSFWorkbook.getSheetAt方法代碼示例

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


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

示例1: readXlsx

import org.apache.poi.xssf.usermodel.XSSFWorkbook; //導入方法依賴的package包/類
public static ArrayList readXlsx(String path) throws IOException {
    XSSFWorkbook xwb = new XSSFWorkbook(path);
    XSSFSheet sheet = xwb.getSheetAt(0);
    XSSFRow row;
    String[] cell = new String[sheet.getPhysicalNumberOfRows() + 1];
    ArrayList<String> arrayList = new ArrayList<>();
    for (int i = sheet.getFirstRowNum() + 1; i < sheet.getPhysicalNumberOfRows(); i++) {
        cell[i] = "";
        row = sheet.getRow(i);
        for (int j = row.getFirstCellNum(); j < row.getPhysicalNumberOfCells(); j++) {
            cell[i] += row.getCell(j).toString();
            cell[i] += " | ";
        }
        arrayList.add(cell[i]);
    }
    return arrayList;
}
 
開發者ID:inkss,項目名稱:hotelbook-JavaWeb,代碼行數:18,代碼來源:ExportExcel.java

示例2: parseExcel

import org.apache.poi.xssf.usermodel.XSSFWorkbook; //導入方法依賴的package包/類
@SuppressWarnings("resource")
private List<Map<String,Object>> parseExcel(InputStream stream) throws Exception {
	List<Map<String,Object>> mapList=new ArrayList<Map<String,Object>>();
	XSSFWorkbook wb = new XSSFWorkbook(stream);
	for (int i = 0; i < wb.getNumberOfSheets(); i++) {
		XSSFSheet sheet = wb.getSheetAt(i);
		if (sheet == null) {
			continue;
		}
		String name = sheet.getSheetName();
		Map<String,Object> map=new HashMap<String,Object>();
		map.put("name",name);
		map.put("data", buildVariables(sheet));
		mapList.add(map);
	}
	return mapList;
}
 
開發者ID:youseries,項目名稱:urule,代碼行數:18,代碼來源:PackageServletHandler.java

示例3: parse

import org.apache.poi.xssf.usermodel.XSSFWorkbook; //導入方法依賴的package包/類
/**
 * Parses an inputstream containin xlsx into an outputStream containing XML
 * 
 * @param inputStream
 *            the source
 * @param outputStream
 *            the result
 * @throws IOException
 * @throws XMLStreamException
 */
public void parse(final InputStream inputStream, final OutputStream outputStream)
		throws IOException, XMLStreamException {
	XSSFWorkbook workbook = new XSSFWorkbook(inputStream);
	XMLStreamWriter out = this.getXMLWriter(outputStream);
	out.writeStartDocument();
	out.writeStartElement("workbook");
	int sheetCount = workbook.getNumberOfSheets();
	for (int i = 0; i < sheetCount; i++) {
		final XSSFSheet sheet = workbook.getSheetAt(i);
		try {
			this.export(sheet, out);
		} catch (UnsupportedEncodingException | FileNotFoundException | XMLStreamException
				| FactoryConfigurationError e) {
			e.printStackTrace();
		}
	}
	out.writeEndElement();
	out.writeEndDocument();
	out.close();
	workbook.close();
}
 
開發者ID:Stwissel,項目名稱:Excel2XML,代碼行數:32,代碼來源:E2xCmdline.java

示例4: main

import org.apache.poi.xssf.usermodel.XSSFWorkbook; //導入方法依賴的package包/類
public static void main(String[] args) {
        //Create Workbook instance holding reference to .xlsx file
        try (FileInputStream file = new FileInputStream(
                new File("Sample.xlsx"))) {
            //Create Workbook instance holding reference to .xlsx file
            XSSFWorkbook workbook = new XSSFWorkbook(file);

            //Get first/desired sheet from the workbook
            XSSFSheet sheet = workbook.getSheetAt(0);

            //Iterate through each rows one by one
//            Iterator<Row> rowIterator = sheet.iterator();
            for(Row row : sheet) {
                for (Cell cell : row) {
                    //Check the cell type and format accordingly
                    switch (cell.getCellType()) {
                        case Cell.CELL_TYPE_NUMERIC:
                            out.print(cell.getNumericCellValue() + "\t");
                            break;
                        case Cell.CELL_TYPE_STRING:
                            out.print(cell.getStringCellValue() + "\t");
                            break;
                    }
                }
                out.println();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
 
開發者ID:PacktPublishing,項目名稱:Java-for-Data-Science,代碼行數:31,代碼來源:ReadExcelExample.java

示例5: test02

import org.apache.poi.xssf.usermodel.XSSFWorkbook; //導入方法依賴的package包/類
@Test
public void test02() throws Exception {
    File file = new File("C:\\Users\\he\\Downloads\\2016-05-10.xls");
    try (FileInputStream fis = new FileInputStream(file)) {
        XSSFWorkbook workbook = new XSSFWorkbook (fis);
        XSSFSheet spreadsheet = workbook.getSheetAt(0);
        print(spreadsheet);
    }
}
 
開發者ID:jt120,項目名稱:take,代碼行數:10,代碼來源:ExcelTest.java

示例6: setSheet

import org.apache.poi.xssf.usermodel.XSSFWorkbook; //導入方法依賴的package包/類
@Override
void setSheet() {
	XSSFWorkbook wb = Objects.requireNonNull(this.getWb(),
			"XSSFWorkbook must not be null!");
	XSSFSheet sheet = wb.getSheetAt(0);
	this.setSheet(sheet);
	this.setSheetName(this.getSheetName());
}
 
開發者ID:gp15237125756,項目名稱:PoiExcelExport,代碼行數:9,代碼來源:ExcelExportService.java

示例7: leerCiudadanos

import org.apache.poi.xssf.usermodel.XSSFWorkbook; //導入方法依賴的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

示例8: ExcelReader

import org.apache.poi.xssf.usermodel.XSSFWorkbook; //導入方法依賴的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

示例9: processXlsx

import org.apache.poi.xssf.usermodel.XSSFWorkbook; //導入方法依賴的package包/類
private XSSFWorkbook processXlsx(File input, HashMap<String, String> map) throws IOException {
    XSSFWorkbook workbook = new XSSFWorkbook(new FileInputStream(input));
    int rowindex = 0;
    int columnindex = 0;
    XSSFSheet sheet = workbook.getSheetAt(0);
    int rows = sheet.getPhysicalNumberOfRows();
    for (rowindex = 1; rowindex < rows; rowindex++) {
    	// Row만큼
        XSSFRow row = sheet.getRow(rowindex);
        if (row != null) {
        	// Row가 null이 아니면
            int cells = row.getPhysicalNumberOfCells();
            // 셀 갯수
            for (columnindex = 0; columnindex <= cells; columnindex++) {
            	// 셀 갯수만큼
                XSSFCell cell = row.getCell(columnindex);
                // row에서 셀 얻어오기
                if (cell != null && cell.getCellType() == 0) {
                	// 0 = Cell.CELL_TYPE_NUMERIC
                	// 학번임을 확인
                    String sNum = (String.valueOf((int) cell.getNumericCellValue()));
                    if (sNum != null) {
                    	// 학번이 null이 아니면
                        cell = row.getCell(columnindex + 1);
                        // 오른쪽 셀 얻어오기
                        if (cell.getCellType() == 1) {
                        	// 1 = Cell.CELL_TYPE_STRING
                        	// 학생 이름임을 확인
                            String type = map.get(sNum);
                            // 학번을 통해 잔류 상태 얻어오기
                            if (type != null) {
                            	// 잔류 상태가 null이 아니면
                                cell = row.getCell(columnindex + 2);
                                // 오른쪽 셀 얻어오기
                                cell.setCellValue(type);
                                // 잔류 상태 채우기
                            }
                        }
                    }
                }
            }
        }
    }
    return workbook;
}
 
開發者ID:DSM-DMS,項目名稱:DMS,代碼行數:46,代碼來源:ResidualDownload.java

示例10: handle

import org.apache.poi.xssf.usermodel.XSSFWorkbook; //導入方法依賴的package包/類
@Override
public void handle(RoutingContext context) {
	if(AdminManager.isAdmin(context)) {
		DataBase database = DataBase.getInstance();
		SafeResultSet resultSet;
		SafeResultSet extensionStateResultSet;

		File file = getFile();

		try {
			wb = new XSSFWorkbook(new FileInputStream(file));

			XSSFSheet sheet = wb.getSheetAt(0);

			for (Row row : sheet) {
				for (Cell cell : row) {
					switch (cell.getCellType()) {
						case Cell.CELL_TYPE_NUMERIC:
							StringBuilder sb = new StringBuilder(Double.toString(cell.getNumericCellValue()));

							String studentNumber = AES256.encrypt(sb.toString().substring(0, 4));
							int classId = 0;

							resultSet = database.executeQuery("SELECT * FROM student_data WHERE number='", studentNumber, "'");

							if (resultSet.next()) {
								String uid = resultSet.getString("uid");
								extensionStateResultSet = database.executeQuery("SELECT * FROM extension_apply WHERE uid='", uid, "'");
								if (extensionStateResultSet.next()) {
									classId = extensionStateResultSet.getInt("class");
								}
							}

							XSSFRow studentRow = sheet.getRow(cell.getRowIndex());
							XSSFCell extensionStateCell = studentRow.getCell(cell.getColumnIndex() + 2);
							extensionStateCell.setCellValue(CLASS_NAMES[classId]);

							break;
					}
				}
			}

			FileOutputStream xlsToSave = new FileOutputStream(FILE_DIR + "연장신청.xlsx");
			wb.write(xlsToSave);
			xlsToSave.close();

			String fileName = new String("연장신청.xlsx".getBytes("UTF-8"), "ISO-8859-1");
			context.response()
				.putHeader(HttpHeaders.CONTENT_DISPOSITION, "filename=" + fileName)
				.sendFile(FILE_DIR + "연장신청.xlsx");
			context.response().close();
		} catch (IOException | SQLException e) {
			context.response().setStatusCode(500).end();
			context.response().close();
		}
	}else{
		context.response().setStatusCode(400).end();
		context.response().end("You are not admin!");
		context.response().close();
	}
}
 
開發者ID:DSM-DMS,項目名稱:DMS,代碼行數:62,代碼來源:ExtensionDownloadRouter.java

示例11: handle

import org.apache.poi.xssf.usermodel.XSSFWorkbook; //導入方法依賴的package包/類
@Override
public void handle(RoutingContext context) {
	if(AdminManager.isAdmin(context)) {

		DataBase database = DataBase.getInstance();
		SafeResultSet resultSet;
		SafeResultSet stayStateResultSet;
		SafeResultSet stayDefaultResultSet;

		File file = getFile();

		try {
			wb = new XSSFWorkbook(new FileInputStream(file));

			XSSFSheet sheet = wb.getSheetAt(0);

			for (Row row : sheet) {
				for (Cell cell : row) {
					switch (cell.getCellType()) {
						case Cell.CELL_TYPE_NUMERIC:
							StringBuilder sb = new StringBuilder(Double.toString(cell.getNumericCellValue()));

							String studentNumber = AES256.encrypt(sb.toString().substring(0, 4));

							resultSet = database.executeQuery("SELECT * FROM student_data WHERE number='", studentNumber, "'");

							if (resultSet.next()) {
								String uid = resultSet.getString("uid");
								stayStateResultSet = database.executeQuery("SELECT * FROM stay_apply WHERE uid='", uid, "'");

								if (stayStateResultSet.next()) {
									// 잔류신청을 한 경우
									setCellValues(stayStateResultSet, database, sheet, cell, uid);
								} else {
									// 잔류신청 정보 없음
									stayDefaultResultSet = database.executeQuery("SELECT * FROM stay_apply_default WHERE uid='", uid, "'");
									// default 값 조회
									if (stayDefaultResultSet.next()) {
										setCellValues(stayDefaultResultSet, database, sheet, cell, uid);
									}
								}
							}
							break;
					}
				}
			}

			FileOutputStream xlsToSave = new FileOutputStream(FILE_DIR + "외출신청.xlsx");
			wb.write(xlsToSave);
			xlsToSave.close();

			String fileName = new String("외출신청.xlsx".getBytes("UTF-8"), "ISO-8859-1");
			context.response()
				.putHeader(HttpHeaders.CONTENT_DISPOSITION, "filename=" + fileName)
				.sendFile(FILE_DIR + "외출신청.xlsx");
			context.response().close();
		} catch (IOException | SQLException e) {
			e.printStackTrace();
			context.response().setStatusCode(500).end();
			context.response().close();
		}
	}else{
		context.response().setStatusCode(400);
		context.response().end("You are Not Admin");
		context.response().close();
	}
}
 
開發者ID:DSM-DMS,項目名稱:DMS,代碼行數:68,代碼來源:GoingoutDownloadRouter.java

示例12: handle

import org.apache.poi.xssf.usermodel.XSSFWorkbook; //導入方法依賴的package包/類
@Override
public void handle(RoutingContext context) {
	if(AdminManager.isAdmin(context)) {
		DataBase database = DataBase.getInstance();
		SafeResultSet reportFacilityResultSet;
		
		File file = getFile();
		
		try {
			wb = new XSSFWorkbook(new FileInputStream(file));
			
			XSSFSheet sheet = wb.getSheetAt(0);
			int rowCount = 0;
			XSSFRow titleRow = sheet.createRow(rowCount++);
			titleRow.createCell(0).setCellValue("호실");
			titleRow.createCell(1).setCellValue("작성자");
			titleRow.createCell(2).setCellValue("제목");
			titleRow.createCell(3).setCellValue("신고 내용");
			titleRow.createCell(4).setCellValue("신고 날짜");
			
			reportFacilityResultSet = database.executeQuery("SELECT * FROM facility_report");
			while(reportFacilityResultSet.next()) {
				XSSFRow row = sheet.createRow(rowCount++);
				row.createCell(0).setCellValue(reportFacilityResultSet.getString("room") + "호");
				row.createCell(1).setCellValue(reportFacilityResultSet.getString("writer"));
				row.createCell(2).setCellValue(reportFacilityResultSet.getString("title"));
				row.createCell(3).setCellValue(reportFacilityResultSet.getString("content"));
				row.createCell(4).setCellValue(reportFacilityResultSet.getString("write_date").split(" ")[0]);
			}
			
			FileOutputStream xlsToSave = new FileOutputStream(FILE_DIR + "시설고장신고.xlsx");
			wb.write(xlsToSave);
			xlsToSave.close();
			
			String fileName = new String("시설고장신고.xls".getBytes("UTF-8"), "ISO-8859-1");
			context.response()
				.putHeader(HttpHeaders.CONTENT_DISPOSITION, "filename=" + fileName)
				.sendFile(FILE_DIR + "시설고장신고.xlsx");
			context.response().close();
		} catch (IOException | SQLException e) {
			context.response().setStatusCode(500).end();
			context.response().close();
		}
	}
}
 
開發者ID:DSM-DMS,項目名稱:DMS,代碼行數:46,代碼來源:ReportDownloadRouter.java

示例13: getExcelReader

import org.apache.poi.xssf.usermodel.XSSFWorkbook; //導入方法依賴的package包/類
public static List<Map<String, String>> getExcelReader() {
	
	String[] colName = { "monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday" };
	
	List<Map<String, String>> list = new ArrayList<Map<String, String>>();
	
	try {
		
		FileInputStream fis = new FileInputStream("c:\\wdmFx\\db\\webtoonList1.xlsx");
		
		XSSFWorkbook workbook = new XSSFWorkbook(fis);
		
		// 시트 수 (첫번째에만 존재하므로 0을 준다)
		// 만약 각 시트를 읽기위해서는 FOR문을 한번더 돌려준다
		XSSFSheet sheet = workbook.getSheetAt(0);
		int rows = sheet.getPhysicalNumberOfRows();
		
		Map<String, String> map = null;

		for (int i = 0; i < rows; i++) {

			if (i != 0) {

				XSSFRow row = sheet.getRow(i); // 행을 읽는다

				String value = "";

				// 셀의 갯수를 실제 필드갯수로 지정.
				int cells = colName.length;

				map = new LinkedHashMap<String, String>();

				for (int j = 0; j < cells; j++) {

					XSSFCell cell = row.getCell(j); // 셀값을 읽는다

					if (cell != null) {
						switch (cell.getCellType()) {
						case XSSFCell.CELL_TYPE_FORMULA:
							if (!"".equals(cell.toString())) {
								value = cell.getCellFormula();
							}
							break;
						case XSSFCell.CELL_TYPE_NUMERIC:
							value = cell.getRawValue();
							break;
						case XSSFCell.CELL_TYPE_STRING:
							value = cell.getStringCellValue();
							break;
						case XSSFCell.CELL_TYPE_BLANK:
							value = "";
							break;
						case XSSFCell.CELL_TYPE_ERROR:
							value = cell.getErrorCellValue() + "";
							break;
						default:
							break;
						}

						map.put(colName[j], value);
					}

				} // end for

				if (map.get(colName[0]) != null)
					list.add(map);
				
			} // end for
			
		}
		
	} catch (IOException e) {
		e.printStackTrace();
	}

	return list;
}
 
開發者ID:kimyearho,項目名稱:WebtoonDownloadManager,代碼行數:78,代碼來源:ExcelReader.java

示例14: importXL

import org.apache.poi.xssf.usermodel.XSSFWorkbook; //導入方法依賴的package包/類
@FXML
    public void importXL(ActionEvent event) throws IOException {
        checkConnection();
        try {
            String query = "INSERT INTO shabo.AirportData (name, lastName, regNr, dateFound, timeFound, brand, lugType, arrivedFlight, locFound, mainCol, size, weight, otherChar, lugTag) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?);";
            pst = conn.prepareStatement(query);

            FileInputStream fileInput = new FileInputStream(new File("FYS_DATA.xlsx"));
            XSSFWorkbook workbook = new XSSFWorkbook(fileInput);
            XSSFSheet sheet = workbook.getSheetAt(0);

            Row row;

                row = sheet.getRow(3);

                pst.setInt(3, (int)row.getCell(3).getNumericCellValue());
//                pst.setString(2, row.getCell(1).getStringCellValue());
//                pst.setDate(3, (Date) row.getCell(2).getDateCellValue());
//                pst.setString(4, row.getCell(3).getStringCellValue());
//                pst.setString(5, row.getCell(4).getStringCellValue());
//                pst.setString(6, row.getCell(5).getStringCellValue());
//                pst.setString(7, row.getCell(6).getStringCellValue());
//                pst.setString(8, row.getCell(7).getStringCellValue());
//                pst.setString(9, row.getCell(8).getStringCellValue());
//                pst.setString(10, row.getCell(9).getStringCellValue());
//                pst.setString(11, row.getCell(10).getStringCellValue());
//                pst.setString(12, row.getCell(11).getStringCellValue());
//                pst.setString(13, row.getCell(12).getStringCellValue());
//                pst.setString(14, row.getCell(13).getStringCellValue());
//                pst.setString(15, row.getCell(14).getStringCellValue());
                pst.execute();
            
            Alert alert = new Alert(Alert.AlertType.INFORMATION);
            alert.setTitle("Alert Title");
            alert.setHeaderText(null);
            alert.setContentText("Data has been exported the database");
            alert.showAndWait();

            pst.close();
            rs.close();

        } catch (SQLException ex) {
            System.out.println("Error while importing!");
            System.out.println(ex);
        }
    }
 
開發者ID:dewarian,項目名稱:FYS_T3,代碼行數:47,代碼來源:submitController.java


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