List of usage examples for org.apache.poi.ss.usermodel Sheet getPhysicalNumberOfRows
int getPhysicalNumberOfRows();
From source file:au.com.onegeek.lambda.parser.Excel2SeleniumParser.java
License:Apache License
private void parse(InputStream stream) throws CannotCompileException, NotFoundException, CannotCreateTestClassException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { logger.debug("Parsing..."); if (this.dataMap != null && this.tests != null) { return;/*from w w w . j a v a 2 s. c o m*/ } this.dataMap = new ArrayList<Map<String, Object>>(); this.tests = new ArrayList<Class<Test>>(); Workbook workbook = null; try { workbook = new XSSFWorkbook(stream); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } logger.debug("workbook" + workbook.toString()); for (int i = 0; i < workbook.getNumberOfSheets(); i++) { Sheet sheet = workbook.getSheetAt(i); if (sheet.getSheetName().startsWith("data")) { // parse key\value pairs HashMap<String, Object> map = new HashMap<String, Object>(); dataMap.add(map); boolean done = false; Row row = sheet.getRow(sheet.getFirstRowNum()); while (!done && row != null && row.getPhysicalNumberOfCells() > 0) { // TODO: parse numerics correctly (i.e. don't add decimal points if not needed) String key = (String) XslxUtil.objectFrom(workbook, row.getCell(0)); String value = null; try { value = (String) XslxUtil.objectFrom(workbook, row.getCell(1)); logger.debug("Adding variable to map: " + key + ":" + value); map.put(key, value); row = sheet.getRow(row.getRowNum() + 1); if (row == null || (row.getRowNum() == sheet.getLastRowNum() + 1)) { done = true; } } catch (NullPointerException e) { //throw new CannotCreateVariableException("No value found for variable '" + key + "' in dataset: " + sheet.getSheetName()); done = true; } } } } JavassistTestBuilderImpl builder = JavassistTestBuilderImpl.getInstance(); // Parse Test sheets into Test objects for (int s = 0; s < workbook.getNumberOfSheets(); s++) { Sheet sheet = workbook.getSheetAt(s); int i = 0; // Ignore data sheets if (sheet.getSheetName().startsWith("suite")) { int maxRows = sheet.getPhysicalNumberOfRows(); int currentRow = sheet.getFirstRowNum(); logger.debug("Nr rows in sheet: " + maxRows); // Create Test Class String testCaseName = "Test" + Excel2SeleniumParser.toCamelCase(sheet.getSheetName()); logger.debug("Creating Test class with name: " + testCaseName); builder.makeTestClass(testCaseName, this.dataMap); boolean testCaseInProgress = false; boolean dataProviderAdded = false; // Get First row, containing the test name and the data to be injected while (i < maxRows) { logger.debug("i: " + i); logger.debug("currentRow: " + currentRow); Row row = sheet.getRow(currentRow); TestCommand command = null; // Check for empty row if (row != null && row.getPhysicalNumberOfCells() != 0) { i++; // Get Cells Iterator<Cell> iterator = row.cellIterator(); while (iterator.hasNext()) { Cell cell = iterator.next(); String cellValue = (cell == null || cell.toString() == "") ? "" : XslxUtil.objectFrom(workbook, cell).toString(); logger.debug("Cell: " + cellValue); if (cellValue.startsWith("test")) { logger.debug("Test case found: " + cellValue + ". Creating Test Case"); // Create new Test CASE try { builder.addTest(cellValue); testCaseInProgress = true; dataProviderAdded = false; } catch (CannotModifyTestMethodException e) { e.printStackTrace(); throw new CannotCreateTestClassException( "Could not create Test Class as there was a variable not found in test assertion. Embedded exception: " + e.getMessage()); } catch (VariableNotFoundException e) { e.printStackTrace(); throw new CannotCreateTestClassException( "Could not create Test Class as there was a variable not found in test assertion. Embedded exception: " + e.getMessage()); } break; } else { if (command == null & !cellValue.equals("")) { logger.debug("Command found: " + cellValue + ". Creating new TestCommand"); command = new TestCommand(cellValue); } else if (!cellValue.equals("")) { logger.debug("Command argument found: " + cellValue); command.addParameter(cellValue); } } } } else { // Blank row could mean a test case has just been completed // Complete last test case by adding a data provider if (testCaseInProgress && !dataProviderAdded) { try { logger.debug("In Progress Test Case now being closed off and added to class..."); builder.addDataProvider(); dataProviderAdded = true; logger.debug("In Progress Test Case now closed off!"); } catch (CannotCreateDataProviderException e) { throw new CannotCreateTestClassException( "Could not create Test case as a DataProvider for the method could not be created. Embedded exception: " + e.getMessage()); } } } try { if (command != null) { logger.debug("Adding command to method"); builder.appendTestToLastMethod(command); } } catch (CannotModifyTestMethodException e) { throw new CannotCreateTestClassException("Unable to add Test Case '" + command.toString() + "' to Test Class. Embedded exception: " + e.getMessage()); } catch (VariableNotFoundException e) { throw new CannotCreateTestClassException("Unable to add Test Case '" + command.toString() + "' to Test Class as a variable was not found. Embedded exception: " + e.getMessage()); } currentRow++; } // Blank row could mean a test case has just been completed // Complete last test case by adding a data provider logger.debug( "End of rows...Checking if In Progress Test Case now being closed off and added to class..."); if (testCaseInProgress && !dataProviderAdded) { logger.debug(" In Progress Test Case now being closed off and added to class..."); try { builder.addDataProvider(); dataProviderAdded = true; logger.debug("In Progress Test Case now closed off!"); } catch (CannotCreateDataProviderException e) { throw new CannotCreateTestClassException( "Could not create Test case as a DataProvider for the method could not be created. Embedded exception: " + e.getMessage()); } } if (testCaseInProgress) { logger.debug("Generating class file"); try { this.tests.add(builder.getCreatedClass()); } catch (CannotModifyTestMethodException e) { e.printStackTrace(); throw new CannotCreateTestClassException( "Could not create Test case as a DataProvider for the method could not be created. Embedded exception: " + e.getMessage()); } testCaseInProgress = false; } } } try { stream.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } logger.info("Looking at our classes..."); // Look at the Test Objects for (Class<Test> clazz : tests) { logger.info("Class: " + clazz.getName()); for (Method m : clazz.getMethods()) { logger.info("Method: " + m); if (m.getName().equalsIgnoreCase("testRetailDataProvider")) { logger.info("invoking data provider"); Test test = clazz.newInstance(); Object[][] data = (Object[][]) m.invoke(test); for (Object[] obs : data) { for (Object o : obs) { logger.info("data value: " + o); } } } } } }
From source file:bad.robot.excel.row.Row.java
License:Apache License
private static org.apache.poi.ss.usermodel.Row createRow(Sheet sheet) { if (sheet.getPhysicalNumberOfRows() == 0) return sheet.createRow(0); return sheet.createRow(sheet.getLastRowNum() + 1); }
From source file:ch.oakmountain.tpa.parser.TpaParser.java
License:Apache License
public void addCatalogue(MacroscopicTopology macroscopicTopology, TrainPathSlotCatalogue catalogue) { String colLayoutString = getPropertyValue(tpaProps.TRAINPATHS_COL_LAYOUT); List<ColumnIdentifier> cols = new ArrayList<ColumnIdentifier>(trainPathLayout.values().length); for (trainPathLayout l : trainPathLayout.values()) { cols.add(l);/* w ww . ja v a 2 s.co m*/ } Map<ColumnIdentifier, Integer> colLayoutMapping = getColLayoutMapping(colLayoutString, cols); int deptimeColIndex = colLayoutMapping.get(trainPathLayout.DEPTIME); int arrtimeColIndex = colLayoutMapping.get(trainPathLayout.ARRTIME); int idColIndex = colLayoutMapping.get(trainPathLayout.ID); for (PeriodicalTrainPathSlot periodicalTrainPathSlot : catalogue.getTrainPathSlots()) { String linkName = periodicalTrainPathSlot.getTrainPathSectionName(); // Create sheet if it does not exist yet if (wb.getSheet(linkName) == null) { Sheet sheet = wb.createSheet(linkName); // header Row headerRow = sheet.createRow(0); for (ColumnIdentifier col : colLayoutMapping.keySet()) { int i = colLayoutMapping.get(col); Cell cell = headerRow.getCell(i, Row.CREATE_NULL_AS_BLANK); cell.setCellValue(col.name()); } } Sheet sheet = wb.getSheet(linkName); int rowNb; for (rowNb = 1; rowNb < sheet.getPhysicalNumberOfRows(); rowNb++) { if (sheet.getRow(rowNb) == null || StringUtils.isBlank( getCellValueString(sheet.getRow(rowNb).getCell(idColIndex, Row.CREATE_NULL_AS_BLANK)))) { break; } } Row row = sheet.createRow(rowNb); TrainPathSlot slot = periodicalTrainPathSlot.getSlots().get(0); int depHour = slot.getStartTime().getHourOfDay(); int depMinutes = slot.getStartTime().getMinuteOfHour(); int arrHour = slot.getEndTime().getHourOfDay(); int arrMinutes = slot.getEndTime().getMinuteOfHour(); double deptime = DateUtil .convertTime(String.format("%02d", depHour) + ":" + String.format("%02d", depMinutes)); double arrtime = DateUtil .convertTime(String.format("%02d", arrHour) + ":" + String.format("%02d", arrMinutes)); Cell cell = row.getCell(deptimeColIndex, Row.CREATE_NULL_AS_BLANK); cell.setCellStyle(timestyle); cell.setCellValue(deptime); cell = row.getCell(arrtimeColIndex, Row.CREATE_NULL_AS_BLANK); cell.setCellStyle(timestyle); cell.setCellValue(arrtime); cell = row.getCell(idColIndex, Row.CREATE_NULL_AS_BLANK); cell.setCellValue(periodicalTrainPathSlot.getName()); } }
From source file:ch.swissbytes.Service.business.Spreadsheet.ToCSV.java
License:Apache License
/** * Called to convert the contents of the currently opened workbook into * a CSV file./*from www. j av a2 s .c o m*/ */ private void convertToCSV() { Sheet sheet = null; Row row = null; int lastRowNum = 0; this.csvData = new ArrayList<ArrayList<String>>(); System.out.println("Converting files contents to CSV format."); // Discover how many sheets there are in the workbook.... int numSheets = this.workbook.getNumberOfSheets(); // and then iterate through them. for (int i = 0; i < numSheets; i++) { // Get a reference to a sheet and check to see if it contains // any rows. sheet = this.workbook.getSheetAt(i); if (sheet.getPhysicalNumberOfRows() > 0) { // Note down the index number of the bottom-most row and // then iterate through all of the rows on the sheet starting // from the very first row - number 1 - even if it is missing. // Recover a reference to the row and then call another method // which will strip the data from the cells and build lines // for inclusion in the resylting CSV file. lastRowNum = sheet.getLastRowNum(); for (int j = 0; j <= lastRowNum; j++) { row = sheet.getRow(j); this.rowToCSV(row); } } } }
From source file:cn.lhfei.fu.poi.HomeworkDataFactory.java
License:Apache License
@Test public void read() throws IOException, InvalidFormatException { InputStream inp = new FileInputStream( "E:\\Webapp_workspace\\webapps_agent\\forestry-university-app\\src\\test\\resource\\excel\\2014-2015.xlsx"); //InputStream inp = new FileInputStream("workbook.xlsx"); Workbook wb = WorkbookFactory.create(inp); Sheet sheet = wb.getSheetAt(0); int totalRows = sheet.getPhysicalNumberOfRows(); Cell teacherCell = null;/*from ww w.java 2s . c om*/ Cell courseCell = null; Cell academicYearCell = null; Cell semesterCell = null; Cell classCell = null; String teacherName = null; String courseName = null; String academicYear = null; String semester = null; String classNames = null; HomeworkBaseModel model = null; Date currentDate = new Date(); for (int i = 0; i < totalRows; i++) { Row row = sheet.getRow(i); teacherCell = row.getCell(2); // courseCell = row.getCell(3); // academicYearCell = row.getCell(4); // semesterCell = row.getCell(5); // classCell = row.getCell(10); // ? if (teacherCell != null) { teacherName = teacherCell.getStringCellValue().trim(); } if (courseCell != null) { courseName = courseCell.getStringCellValue().trim(); } if (academicYearCell != null) { academicYear = academicYearCell.getStringCellValue().trim(); } if (semesterCell != null) { semester = semesterCell.getStringCellValue().trim(); } if (classCell != null) { classNames = classCell.getStringCellValue().trim(); String[] names = classNames.split(","); if (names != null && names.length > 0) { for (String className : names) { model = new HomeworkBaseModel(); model.setAcademicYear(academicYear); model.setSemester(semester); model.setActionType(OperationTypeEnum.SC.getCode().toString()); model.setClassName(className); model.setCourseName(courseName); model.setCreateTime(currentDate); model.setTeacherName(teacherName); } } } log.info("teacher={}, course={}, xn={}, xq={}, homework={}", teacherName, courseName, academicYear, semester, classNames); } }
From source file:cn.lhfei.fu.service.impl.ExcelServiceImpl.java
License:Apache License
/** * <tt> ? ?? ? </tt>/*from w w w . j a va 2 s. c o m*/ * <tt> ? ?? </tt> * @param file * @param degreeEnum * @return * @throws IOException * @throws InvalidFormatException */ public void importStudent(InputStream file, DegreeEnum degreeEnum) throws InvalidFormatException, IOException { Date currentDate = new Date(); List<StudentBaseModel> studentList = new ArrayList<StudentBaseModel>(); List<UserModel> userList = new ArrayList<UserModel>(); Workbook wb = WorkbookFactory.create(file); Sheet sheet = wb.getSheetAt(0); int totalRows = sheet.getPhysicalNumberOfRows(); Cell studentIdCell = null; // ? Cell studentNameCell = null; // ?? Cell classCell = null; // ? Cell genderCell = null; // Integer degree = degreeEnum.getCode(); int size = 0; for (int i = 1; i < totalRows; i++) { String studentId = ""; String studentName = ""; int gender = 0; // (0)|(1) String genderStr = ""; String className = ""; String grade = ""; String major = ""; String desc = "?"; Row row = sheet.getRow(i); StudentBaseModel model = new StudentBaseModel(); UserModel userModel = new UserModel(); if (degreeEnum.equals(DegreeEnum.BK)) { // ? studentIdCell = row.getCell(0); studentNameCell = row.getCell(1); classCell = row.getCell(2); genderCell = row.getCell(3); className = classCell.getStringCellValue(); } else if (degreeEnum.equals(DegreeEnum.SS)) { Cell gradeCell = null; // Cell majorCell = null; // gradeCell = row.getCell(0); majorCell = row.getCell(1); studentIdCell = row.getCell(2); studentNameCell = row.getCell(3); genderCell = row.getCell(4); grade = gradeCell.getStringCellValue(); major = majorCell.getStringCellValue(); } studentIdCell.setCellType(Cell.CELL_TYPE_STRING); studentId = studentIdCell.getStringCellValue(); studentName = studentNameCell.getStringCellValue(); genderStr = genderCell.getStringCellValue(); if ("".equals(genderStr)) { gender = 1; } else { gender = 0; } model.setClassName(className); model.setGrade(grade); model.setMajorName(major); model.setMajorCode(major); model.setStudentId(studentId); model.setName(studentName); model.setDegree(degree); model.setGender(gender); model.setCreateTime(currentDate); model.setModifyTime(currentDate); model.setBirthday(currentDate); model.setUserType(UserTypeEnum.STUDENT.getCode()); model.setAliasName(studentName); model.setEmail(studentId + "@fu.com"); model.setExtend(desc); model.setExtend1(desc); log.info("Total Rows: {}", totalRows); userModel.setBirthday(currentDate); userModel.setCreateTime(currentDate); userModel.setGender(gender); userModel.setModifyTime(currentDate); userModel.setPassWord(SecurityUtils.toMd5("123456")); userModel.setRoleId(24); userModel.setSignTime(currentDate); userModel.setUserId(studentId); userModel.setUserName(studentName); userModel.setAliasName(studentName); userModel.setEmail(studentId + "@fu.com"); userModel.setUserType(UserTypeEnum.STUDENT.getCode()); size++; userList.add(userModel); studentList.add(model); if (size % MAX_BATCH_SIZE == 0) { excelMapper.importStudent(studentList); excelMapper.importSysUser(userList); studentList = new ArrayList<StudentBaseModel>(); userList = new ArrayList<UserModel>(); } } if (studentList.size() > 0) { excelMapper.importStudent(studentList); excelMapper.importSysUser(userList); } }
From source file:cn.lhfei.fu.service.impl.ExcelServiceImpl.java
License:Apache License
/** * /*w w w . j a v a2 s . c o m*/ * -?-?-??-()-()-??--?-??-?? * * @param file * @param degreeEnum * @return * @throws IOException * @throws InvalidFormatException */ public void importThesis(InputStream file, DegreeEnum degreeEnum) throws InvalidFormatException, IOException { Date currentDate = new Date(); List<ThesisBaseModel> thesisList = new ArrayList<ThesisBaseModel>(); Workbook wb = WorkbookFactory.create(file); Sheet sheet = wb.getSheetAt(0); int totalRows = sheet.getPhysicalNumberOfRows(); Cell academicYearCell = null; Cell classCell = null; Cell studentIdCell = null; Cell studentNameCell = null; Cell titleCell = null; Cell enTitleCell = null; Cell originCell = null; Cell thesisTypeCell = null; Cell teacherIdCell = null; Cell teacherNameCell = null; Cell teacherTitleCell = null; String desc = "?"; Integer degree = degreeEnum.getCode(); int size = 0; for (int i = 1; i < totalRows; i++) { String academicYear = ""; String className = ""; String studentId = ""; String studentName = ""; String title = ""; String enTitle = ""; String origin = ""; String thesisType = ""; String teacherId = ""; String teacherName = ""; String teacherTitle = ""; Row row = sheet.getRow(i); academicYearCell = row.getCell(0); classCell = row.getCell(1); studentIdCell = row.getCell(2); studentNameCell = row.getCell(3); titleCell = row.getCell(4); enTitleCell = row.getCell(5); originCell = row.getCell(6); thesisTypeCell = row.getCell(7); teacherIdCell = row.getCell(8); teacherNameCell = row.getCell(9); teacherTitleCell = row.getCell(10); studentIdCell.setCellType(Cell.CELL_TYPE_STRING); teacherIdCell.setCellType(Cell.CELL_TYPE_STRING); academicYearCell.setCellType(Cell.CELL_TYPE_STRING); academicYear = academicYearCell.getStringCellValue(); className = classCell.getStringCellValue(); studentId = studentIdCell.getStringCellValue(); studentName = studentNameCell.getStringCellValue(); title = titleCell.getStringCellValue(); enTitle = enTitleCell.getStringCellValue(); origin = originCell.getStringCellValue(); thesisType = thesisTypeCell.getStringCellValue(); teacherId = teacherIdCell.getStringCellValue(); teacherName = teacherNameCell.getStringCellValue(); teacherTitle = teacherTitleCell.getStringCellValue(); ThesisBaseModel model = new ThesisBaseModel(); model.setAcademicYear(academicYear); model.setClassName(className); model.setStudentId(studentId); model.setStudentName(studentName); model.setThesisTitle(title); model.setThesisEnTitle(enTitle); model.setOrigin(origin); model.setThesisType(thesisType); model.setTeacherId(teacherId); model.setTeacherName(teacherName); model.setTeacherTitle(teacherTitle); model.setDescription(desc); model.setDegree(degree); model.setActionType("" + OperationTypeEnum.PLSC.getCode()); model.setOperationTime(currentDate); model.setCreateTime(currentDate); model.setModifyTime(currentDate); thesisList.add(model); size++; if (size % 50 == 0) { excelMapper.importThesis(thesisList); thesisList = new ArrayList<ThesisBaseModel>(); } } if (thesisList.size() > 0) { excelMapper.importThesis(thesisList); } }
From source file:cn.lhfei.fu.service.impl.HomeworkBaseServiceImpl.java
License:Apache License
@Override public boolean importHomework(String filePath) throws Exception { InputStream inp = new FileInputStream(filePath); Workbook wb = WorkbookFactory.create(inp); Sheet sheet = wb.getSheetAt(0); int totalRows = sheet.getPhysicalNumberOfRows(); Cell teacherCell = null;// ww w . j ava2 s. com Cell courseCell = null; Cell academicYearCell = null; Cell semesterCell = null; Cell classCell = null; String teacherName = null; String courseName = null; String academicYear = null; String semester = null; String classNames = null; HomeworkBaseModel model = null; Date currentDate = new Date(); List<HomeworkBaseModel> homeworkList = new ArrayList<HomeworkBaseModel>(); for (int i = 0; i < totalRows; i++) { Row row = sheet.getRow(i); teacherCell = row.getCell(2); // courseCell = row.getCell(3); // academicYearCell = row.getCell(4); // semesterCell = row.getCell(5); // classCell = row.getCell(10); // ? if (teacherCell != null) { teacherName = teacherCell.getStringCellValue().trim(); } if (courseCell != null) { courseName = courseCell.getStringCellValue().trim(); } if (academicYearCell != null) { academicYear = academicYearCell.getStringCellValue().trim(); } if (semesterCell != null) { semester = semesterCell.getStringCellValue().trim(); } if (classCell != null) { classNames = classCell.getStringCellValue().trim(); String[] names = classNames.split(","); if (names != null && names.length > 0) { for (String className : names) { model = new HomeworkBaseModel(); model.setAcademicYear(academicYear); model.setSemester(semester); model.setActionType(OperationTypeEnum.SC.getCode().toString()); model.setClassName(className); model.setCourseName(courseName); model.setTeacherName(teacherName); model.setOperationTime(currentDate); model.setCreateTime(currentDate); model.setModifyTime(currentDate); model.setName(""); model.setTeacherId(""); model.setCourseCode("0"); homeworkList.add(model); } } } log.info("teacher={}, course={}, xn={}, xq={}, homework={}", teacherName, courseName, academicYear, semester, classNames); } for (HomeworkBaseModel baseModel : homeworkList) { excelFactoryMapper.importHomework(baseModel); } return false; }
From source file:cn.lhfei.fu.service.impl.HomeworkDataBuildFactory.java
License:Apache License
@Override public boolean importDataByExcel(String filePath, Map<String, Object> params) throws Exception { InputStream inp = new FileInputStream(filePath); Workbook wb = WorkbookFactory.create(inp); Sheet sheet = wb.getSheetAt(0); int totalRows = sheet.getPhysicalNumberOfRows(); Cell homeworkNameCell = null; // ?? Cell academicYearCell = null; // Cell semesterCell = null; // Cell teacherIdCell = null; // ? Cell teacherNameCell = null; // ?? Cell classCell = null; // ??? Cell courseCodeCell = null; // ? Cell courseNameCell = null; // ?? String homeworkName = null;/* w ww .ja va 2s.c om*/ String teacherId = null; String teacherName = null; String courseName = null; String courseCode = null; String academicYear = null; String semester = null; String className = null; HomeworkBaseModel model = null; Date currentDate = new Date(); List<HomeworkBaseModel> homeworkList = new ArrayList<HomeworkBaseModel>(); for (int i = 1; i < totalRows; i++) { Row row = sheet.getRow(i); homeworkNameCell = row.getCell(0); // ?? academicYearCell = row.getCell(1); // semesterCell = row.getCell(2); // teacherIdCell = row.getCell(3); // ? teacherNameCell = row.getCell(4); // ?? classCell = row.getCell(5); // ??? courseCodeCell = row.getCell(6); // ? courseNameCell = row.getCell(7); // ?? if (homeworkNameCell != null) { homeworkName = homeworkNameCell.getStringCellValue().trim(); } if (academicYearCell != null) { academicYear = academicYearCell.getStringCellValue().trim(); } if (semesterCell != null) { semester = semesterCell.getStringCellValue().trim(); } if (teacherIdCell != null) { teacherId = teacherIdCell.getStringCellValue().trim(); } if (teacherNameCell != null) { teacherName = teacherNameCell.getStringCellValue().trim(); } if (courseCodeCell != null) { courseCode = courseCodeCell.getStringCellValue().trim(); } if (courseNameCell != null) { courseName = courseNameCell.getStringCellValue().trim(); } if (classCell != null) { className = classCell.getStringCellValue().trim(); model = new HomeworkBaseModel(); model.setName(homeworkName); model.setAcademicYear(academicYear); model.setSemester(semester); model.setTeacherId(teacherId); model.setTeacherName(teacherName); model.setClassName(className); model.setCourseCode(courseCode); model.setCourseName(courseName); model.setActionType(OperationTypeEnum.SC.getCode().toString()); model.setOperationTime(currentDate); model.setCreateTime(currentDate); model.setModifyTime(currentDate); homeworkList.add(model); } log.info("teacher={}, course={}, xn={}, xq={}, homework={}", teacherName, courseName, academicYear, semester, className); } for (HomeworkBaseModel baseModel : homeworkList) { excelFactoryMapper.importHomework(baseModel); } return false; }
From source file:cn.lhfei.fu.service.impl.TeacherServiceImplTest.java
License:Apache License
@Test public void updateTitle() throws Exception { String filePath = "src\\test\\resource\\excel\\??? - 2014-10-31???.xlsx"; String teacherId = ""; String teacherTitle = ""; InputStream inp = new FileInputStream(filePath); Workbook wb = WorkbookFactory.create(inp); Sheet sheet = wb.getSheetAt(0); int totalRows = sheet.getPhysicalNumberOfRows(); Cell teacherIdCell = null;/*from w w w. j a v a 2 s. c o m*/ Cell teacherTitleCell = null; for (int i = 1; i < totalRows; i++) { Row row = sheet.getRow(i); teacherIdCell = row.getCell(1); teacherTitleCell = row.getCell(8); teacherId = teacherIdCell.getStringCellValue(); if (teacherId != null && teacherId.startsWith("S")) { teacherId = teacherId.replaceAll("S", ""); } teacherTitle = teacherTitleCell.getStringCellValue(); log.info("ID: {}, Title: {}", teacherId, teacherTitle); teacherService.updateTeacherTitle(teacherId, teacherTitle); } }