List of usage examples for org.apache.poi.hssf.usermodel HSSFWorkbook getSheetAt
@Override public HSSFSheet getSheetAt(int index)
From source file:com.sammyun.service.impl.ExcelServiceImpl.java
License:Open Source License
@Override public List<DictStudent> getDictStudents(InputStream inputStream, DictSchool dictSchool, HttpServletRequest request) throws Exception { HSSFWorkbook hssfWorkbook = new HSSFWorkbook(inputStream); List<DictStudent> dictStudents = new ArrayList<DictStudent>(); // start--//from www.j av a 2 s . c o m for (int numSheet = 0; numSheet < hssfWorkbook.getNumberOfSheets(); numSheet++) { HSSFSheet hssfSheet = hssfWorkbook.getSheetAt(numSheet); if (hssfSheet == null) { continue; } int infoSize = hssfSheet.getRow(0).getLastCellNum();// ? int rowSize = hssfSheet.getLastRowNum();// ??? // start Row for (int rowNum = 1; rowNum <= hssfSheet.getLastRowNum(); rowNum++) { HSSFRow studentInfo = hssfSheet.getRow(rowNum); if (studentInfo == null) { continue; } DictStudent dictStudent = new DictStudent(); dictStudent.setCreateDate(new Date()); dictStudent.setModifyDate(new Date()); dictStudent.setStudentStatus(StudentStatus.active); String studentName = null; String studentNo = null; DictClass dictClass = new DictClass(); // start_?? for (int i = 0; i < studentInfo.getLastCellNum(); i++) { HSSFCell studentCell = studentInfo.getCell(i); if (studentCell == null) { continue; } if (i == 0) { // ? studentNo = studentCell.toString(); studentNo = studentNo.trim(); dictStudent.setStudentNo(studentNo); } if (i == 1) { // ?? studentName = studentCell.toString(); studentName = studentName.trim(); dictStudent.setStudentName(studentName); } if (i == 2) { // ? String className = studentCell.toString(); className = className.trim(); List<DictClass> classes = dictClassDao.getClassByName(className, dictSchool); if (classes != null) { if (classes.size() > 0) { dictClass = classes.get(0); dictStudent.setDictClass(dictClass); } } } if (i == 3) { // ? String memberString = studentCell.toString(); memberString = memberString.trim(); memberString = memberString.replaceAll("", ","); dictStudent.setStuRmark(memberString); } } // end___?? dictStudents.add(dictStudent); } } // end return dictStudents; }
From source file:com.saucelabs.TestData.java
TestData(String filePath, WebDriver driver) throws Exception { this.teststeps = new ArrayList<TestStep>(); FileInputStream file = new FileInputStream(new File(System.getProperty("user.dir") + "\\" + filePath)); HSSFWorkbook workbook = new HSSFWorkbook(file); HSSFSheet sheet = workbook.getSheetAt(0); Iterator<Row> rowIterator = sheet.iterator(); rowIterator.next();/* ww w.java2 s . co m*/ while (rowIterator.hasNext()) { TestStep t = new TestStep(driver); Row row = rowIterator.next(); t.Action = (row.getCell(1) != null ? row.getCell(1).getStringCellValue() : ""); t.Field = (row.getCell(2) != null ? row.getCell(2).getStringCellValue() : ""); t.FieldType = (row.getCell(3) != null ? row.getCell(3).getStringCellValue() : ""); t.Associate = (row.getCell(4) != null ? row.getCell(4).getStringCellValue() : ""); teststeps.add(t); } file.close(); }
From source file:com.schneider.tsm.process.addXPRDataManager.java
private void add2ExistingReport() throws InterruptedException { final SwingWorker worker = new SwingWorker() { @Override/*from www . j av a 2s . c o m*/ protected Object doInBackground() throws Exception { try { FileInputStream file = new FileInputStream(new File( "C:\\softwaretest\\FileOutput\\Manager\\NPR_CPR_Report_" + requestorManager + ".xls")); HSSFWorkbook workbook = new HSSFWorkbook(file); HSSFSheet sheet = workbook.getSheetAt(0); int sheetsize = sheet.getPhysicalNumberOfRows(); Cell cell = null; int numm = 1; for (int i = 7; i < sheetsize; i++) { cell = sheet.getRow(i).getCell(1); if (cell == null || cell.getCellType() == Cell.CELL_TYPE_BLANK) { cell.setCellValue("" + numm); cell = sheet.getRow(i).getCell(2); cell.setCellValue(requestID); cell = sheet.getRow(i).getCell(3); cell.setCellValue(requestorID); cell = sheet.getRow(i).getCell(4); cell.setCellValue(dayFromSubmit); cell = sheet.getRow(i).getCell(5); cell.setCellValue(requestStatus); cell = sheet.getRow(i).getCell(6); cell.setCellValue(submitDate); cell = sheet.getRow(i).getCell(7); cell.setCellValue(requestType); i = sheetsize; } numm++; } file.close(); FileOutputStream outFile = new FileOutputStream(new File( "C:\\softwaretest\\FileOutput\\Manager\\NPR_CPR_Report_" + requestorManager + ".xls")); workbook.write(outFile); outFile.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; } }; worker.execute(); Thread.sleep(160); }
From source file:com.schneider.tsm.process.addXPRDataManager.java
private void createNewFileReport() throws InterruptedException { final SwingWorker worker = new SwingWorker() { @Override//from w ww . j ava 2s . c o m protected Object doInBackground() throws Exception { try { FileInputStream file = new FileInputStream(new File("C:\\softwaretest\\template.xls")); HSSFWorkbook workbook = new HSSFWorkbook(file); HSSFSheet sheet = workbook.getSheetAt(0); Cell cell = null; cell = sheet.getRow(7).getCell(1); cell.setCellValue("1"); cell = sheet.getRow(7).getCell(2); cell.setCellValue(requestID); cell = sheet.getRow(7).getCell(3); cell.setCellValue(requestorID); cell = sheet.getRow(7).getCell(4); cell.setCellValue(dayFromSubmit); cell = sheet.getRow(7).getCell(5); cell.setCellValue(requestStatus); cell = sheet.getRow(7).getCell(6); cell.setCellValue(submitDate); cell = sheet.getRow(7).getCell(7); cell.setCellValue(requestType); file.close(); FileOutputStream outFile = new FileOutputStream(new File( "C:\\softwaretest\\FileOutput\\Manager\\NPR_CPR_Report_" + requestorManager + ".xls")); workbook.write(outFile); outFile.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; } }; worker.execute(); Thread.sleep(160); }
From source file:com.schneider.tsm.process.addXPRDataManager.java
private String getManager() { String manager = "No_Manager_Assigned"; try {/*from w ww. j av a2s .c om*/ FileInputStream file = new FileInputStream(new File("C:\\softwaretest\\LibraryTest.xls")); HSSFWorkbook workbook = new HSSFWorkbook(file); HSSFSheet sheet = workbook.getSheetAt(0); Cell cell = null; int sheetsize = sheet.getPhysicalNumberOfRows(); for (int i = 1; i < sheetsize; i++) { cell = sheet.getRow(i).getCell(0); if (cell.getStringCellValue().equals(requestorID)) { cell = sheet.getRow(i).getCell(2); manager = cell.getStringCellValue(); } } file.close(); FileOutputStream outFile = new FileOutputStream(new File("C:\\softwaretest\\LibraryTest.xls")); workbook.write(outFile); outFile.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return manager; }
From source file:com.schneider.tsm.process.addXPRDataQuality.java
private void add2ExistingReport() throws InterruptedException { final SwingWorker worker = new SwingWorker() { @Override//from ww w.j av a 2 s. c o m protected Object doInBackground() throws Exception { try { FileInputStream file = new FileInputStream(new File( "C:\\softwaretest\\FileOutput\\Quality\\NPR_CPR_Report_" + requestorQuality + ".xls")); HSSFWorkbook workbook = new HSSFWorkbook(file); HSSFSheet sheet = workbook.getSheetAt(0); int sheetsize = sheet.getPhysicalNumberOfRows(); Cell cell = null; int numm = 1; for (int i = 7; i < sheetsize; i++) { cell = sheet.getRow(i).getCell(1); if (cell == null || cell.getCellType() == Cell.CELL_TYPE_BLANK) { cell.setCellValue("" + numm); cell = sheet.getRow(i).getCell(2); cell.setCellValue(requestID); cell = sheet.getRow(i).getCell(3); cell.setCellValue(requestorID); cell = sheet.getRow(i).getCell(4); cell.setCellValue(dayFromSubmit); cell = sheet.getRow(i).getCell(5); cell.setCellValue(requestStatus); cell = sheet.getRow(i).getCell(6); cell.setCellValue(submitDate); cell = sheet.getRow(i).getCell(7); cell.setCellValue(requestType); i = sheetsize; } numm++; } file.close(); FileOutputStream outFile = new FileOutputStream(new File( "C:\\softwaretest\\FileOutput\\Quality\\NPR_CPR_Report_" + requestorQuality + ".xls")); workbook.write(outFile); outFile.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; } }; worker.execute(); Thread.sleep(160); }
From source file:com.schneider.tsm.process.addXPRDataQuality.java
private void createNewFileReport() throws InterruptedException { final SwingWorker worker = new SwingWorker() { @Override//ww w .java 2 s . com protected Object doInBackground() throws Exception { try { FileInputStream file = new FileInputStream(new File("C:\\softwaretest\\template.xls")); HSSFWorkbook workbook = new HSSFWorkbook(file); HSSFSheet sheet = workbook.getSheetAt(0); Cell cell = null; cell = sheet.getRow(7).getCell(1); cell.setCellValue("1"); cell = sheet.getRow(7).getCell(2); cell.setCellValue(requestID); cell = sheet.getRow(7).getCell(3); cell.setCellValue(requestorID); cell = sheet.getRow(7).getCell(4); cell.setCellValue(dayFromSubmit); cell = sheet.getRow(7).getCell(5); cell.setCellValue(requestStatus); cell = sheet.getRow(7).getCell(6); cell.setCellValue(submitDate); cell = sheet.getRow(7).getCell(7); cell.setCellValue(requestType); file.close(); FileOutputStream outFile = new FileOutputStream(new File( "C:\\softwaretest\\FileOutput\\Quality\\NPR_CPR_Report_" + requestorQuality + ".xls")); workbook.write(outFile); outFile.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; } }; worker.execute(); Thread.sleep(160); }
From source file:com.schneider.tsm.process.addXPRDataQuality.java
private String getManager() { String manager = null;//from w w w.j av a2 s . c o m try { FileInputStream file = new FileInputStream(new File("C:\\softwaretest\\LibraryTest.xls")); HSSFWorkbook workbook = new HSSFWorkbook(file); HSSFSheet sheet = workbook.getSheetAt(0); Cell cell = null; int sheetsize = sheet.getPhysicalNumberOfRows(); for (int i = 1; i < sheetsize; i++) { cell = sheet.getRow(i).getCell(0); if (cell.getStringCellValue().equals(requestorID)) { cell = sheet.getRow(i).getCell(2); manager = cell.getStringCellValue(); } } file.close(); FileOutputStream outFile = new FileOutputStream(new File("C:\\softwaretest\\LibraryTest.xls")); workbook.write(outFile); outFile.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return manager; }
From source file:com.schneider.tsm.process.addXPRDataQuality.java
private String getQuality() { String Quality = "No_Exist"; try {//from ww w. jav a 2s .co m FileInputStream file = new FileInputStream(new File("C:\\softwaretest\\LibraryTest.xls")); HSSFWorkbook workbook = new HSSFWorkbook(file); HSSFSheet sheet = workbook.getSheetAt(0); Cell cell = null; int sheetsize = sheet.getPhysicalNumberOfRows(); for (int i = 1; i < sheetsize; i++) { cell = sheet.getRow(i).getCell(0); if (cell.getStringCellValue().equals(requestorID)) { cell = sheet.getRow(i).getCell(4); Quality = cell.getStringCellValue(); } } file.close(); FileOutputStream outFile = new FileOutputStream(new File("C:\\softwaretest\\LibraryTest.xls")); workbook.write(outFile); outFile.close(); } catch (FileNotFoundException e) { } catch (IOException e) { } return Quality; }
From source file:com.schneider.tsm.process.addXPRDataTSEAlert.java
private void add2ExistingReport() throws InterruptedException { final SwingWorker worker = new SwingWorker() { @Override/* ww w. j a v a2 s . co m*/ protected Object doInBackground() throws Exception { try { Thread.sleep(160); FileInputStream file = new FileInputStream( new File("C:\\softwaretest\\FileOutput\\TSE_Manager\\NPR_CPR_Report_" + requestorManager + ".xls")); HSSFWorkbook workbook = new HSSFWorkbook(file); HSSFSheet sheet = workbook.getSheetAt(0); int sheetsize = sheet.getPhysicalNumberOfRows(); Cell cell = null; int numm = 1; for (int i = 7; i < sheetsize; i++) { cell = sheet.getRow(i).getCell(1); if (cell == null || cell.getCellType() == Cell.CELL_TYPE_BLANK) { cell.setCellValue("" + numm); cell = sheet.getRow(i).getCell(2); cell.setCellValue(requestID); cell = sheet.getRow(i).getCell(3); cell.setCellValue(requestorID); cell = sheet.getRow(i).getCell(4); cell.setCellValue(dayFromSubmit); cell = sheet.getRow(i).getCell(5); cell.setCellValue(requestStatus); cell = sheet.getRow(i).getCell(6); cell.setCellValue(submitDate); cell = sheet.getRow(i).getCell(7); cell.setCellValue(requestType); i = sheetsize; } numm++; } file.close(); FileOutputStream outFile = new FileOutputStream( new File("C:\\softwaretest\\FileOutput\\TSE_Manager\\NPR_CPR_Report_" + requestorManager + ".xls")); workbook.write(outFile); outFile.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; } }; worker.execute(); Thread.sleep(160); }