List of usage examples for org.apache.poi.xssf.usermodel XSSFCell getStringCellValue
@Override
public String getStringCellValue()
For numeric cells we throw an exception.
From source file:in.expertsoftware.colorcheck.Reporting_Qtr_Verification.java
private boolean operation_Standard_Workingsection_Verification(int SORQ_tokenLocation, int first_Occurance_Of_Financial_Comparision, XSSFSheet Sheet, ArrayList<String> opeartion_standard_workingSectionList, ArrayList<ErrorModel> errorModelList, XSSFWorkbook workbook) {// w w w .jav a 2 s . co m int reporting_Qtr_OS_Working_SectionCount = 0; String reporting_Qtr_Formula_Cell_Formula; String reporting_Qtr_Formula_Cell_Value; boolean isError = false; XSSFRow row; XSSFCell cell; for (int start = (SORQ_tokenLocation - 1); start < (first_Occurance_Of_Financial_Comparision - 1); start++) { try { row = Sheet.getRow(start); cell = row.getCell(1); reporting_Qtr_Formula_Cell_Value = cell.getStringCellValue(); if (reporting_Qtr_Formula_Cell_Value.equalsIgnoreCase("Operational Comparison")) { start = start + 1; } else if (reporting_Qtr_OS_Working_SectionCount < opeartion_standard_workingSectionList.size()) { switch (cell.getCellType()) { case Cell.CELL_TYPE_FORMULA: reporting_Qtr_Formula_Cell_Formula = cell.getCellFormula(); if (reporting_Qtr_Formula_Cell_Formula.contains("$")) { reporting_Qtr_Formula_Cell_Formula = reporting_Qtr_Formula_Cell_Formula .replaceAll("\\$", "").replaceAll(" ", ""); } String retrive_Formula = opeartion_standard_workingSectionList .get(reporting_Qtr_OS_Working_SectionCount); if (reporting_Qtr_Formula_Cell_Formula.equals(retrive_Formula)) { reporting_Qtr_OS_Working_SectionCount++; } else { ErrorModel errorModel = new ErrorModel(); CellReference cellRef = new CellReference(cell); errorModel.setCell_ref(cellRef.formatAsString()); errorModel.setSheet_name("Reporting_Qtr"); errorModel.setError_desc( "Sequence does not match Actual Sequence should be" + retrive_Formula); errorModel.setError_level("Error"); errorModel.setRow((cell.getRowIndex() + 1)); errorModelList.add(errorModel); reporting_Qtr_OS_Working_SectionCount++; isError = true; } break; case Cell.CELL_TYPE_BLANK: break; default: { ErrorModel errorModel = new ErrorModel(); CellReference cellRef = new CellReference(cell); errorModel.setCell_ref(cellRef.formatAsString()); errorModel.setSheet_name("Reporting_Qtr"); errorModel.setError_desc("Cell does not contain formula"); errorModel.setError_level("Error"); errorModel.setRow((cell.getRowIndex() + 1)); errorModelList.add(errorModel); reporting_Qtr_OS_Working_SectionCount++; isError = true; } break; } } else { reporting_Qtr_OS_Working_SectionCount++; } } catch (NullPointerException nullexcp) { continue; } catch (Exception e) { e.printStackTrace(); } } if (reporting_Qtr_OS_Working_SectionCount != opeartion_standard_workingSectionList.size()) { ErrorModel errorModel = new ErrorModel(); errorModel.setSheet_name("Reporting_Qtr"); errorModel.setError_desc("Reporting_Qtr have " + Math.abs(reporting_Qtr_OS_Working_SectionCount - opeartion_standard_workingSectionList.size()) + " extra rows from Operation_Standard"); errorModel.setError_level("Error"); errorModelList.add(errorModel); isError = true; } return isError; }
From source file:in.expertsoftware.colorcheck.Reporting_Qtr_Verification.java
private boolean financial_Standard_Workingsection_Verification(int first_Occurance_Of_Financial_Comparision, int EORQ_tokenLocation, XSSFSheet Sheet, ArrayList<String> financial_standard_workingSectionList, ArrayList<ErrorModel> errorModelList, XSSFWorkbook workbook) { int reporting_Qtr_FS_Working_SectionCount = 0; String reporting_Qtr_Formula_Cell_Formula = null; String reporting_Qtr_Formula_Cell_Value; XSSFRow row;/*w ww . j av a 2s . co m*/ XSSFCell cell; boolean isError = false; for (int start = (first_Occurance_Of_Financial_Comparision - 1); start < EORQ_tokenLocation; start++) { try { row = Sheet.getRow(start); cell = row.getCell(1); reporting_Qtr_Formula_Cell_Value = cell.getStringCellValue(); if (reporting_Qtr_Formula_Cell_Value.equals("Financial Comparison")) { start = start + 3; } else if (reporting_Qtr_FS_Working_SectionCount < financial_standard_workingSectionList.size()) { switch (cell.getCellType()) { case Cell.CELL_TYPE_FORMULA: reporting_Qtr_Formula_Cell_Formula = cell.getCellFormula(); if (reporting_Qtr_Formula_Cell_Formula.contains("$")) { reporting_Qtr_Formula_Cell_Formula = reporting_Qtr_Formula_Cell_Formula .replaceAll("\\$", "").replaceAll(" ", ""); } String retrive_Formula = financial_standard_workingSectionList .get(reporting_Qtr_FS_Working_SectionCount); if (reporting_Qtr_Formula_Cell_Formula.equals(retrive_Formula)) { reporting_Qtr_FS_Working_SectionCount++; } else { ErrorModel errorModel = new ErrorModel(); CellReference cellRef = new CellReference(cell); errorModel.setCell_ref(cellRef.formatAsString()); errorModel.setSheet_name("Reporting_Qtr"); errorModel.setError_desc( "Sequence does not match Actual Sequence should be" + retrive_Formula); errorModel.setError_level("Error"); errorModel.setRow((cell.getRowIndex() + 1)); errorModelList.add(errorModel); reporting_Qtr_FS_Working_SectionCount++; isError = true; } break; case Cell.CELL_TYPE_BLANK: break; default: { ErrorModel errorModel = new ErrorModel(); CellReference cellRef = new CellReference(cell); errorModel.setCell_ref(cellRef.formatAsString()); errorModel.setSheet_name("Reporting_Qtr"); errorModel.setError_desc("Cell does not contain formula "); errorModel.setError_level("Error"); errorModel.setRow((cell.getRowIndex() + 1)); errorModelList.add(errorModel); reporting_Qtr_FS_Working_SectionCount++; isError = true; } break; } } else { reporting_Qtr_FS_Working_SectionCount++; } } catch (NullPointerException nullexcp) { continue; } catch (Exception e) { e.printStackTrace(); } } if (reporting_Qtr_FS_Working_SectionCount != financial_standard_workingSectionList.size()) { ErrorModel errorModel = new ErrorModel(); errorModel.setSheet_name("Reporting_Qtr"); errorModel.setError_desc("Reporting_Qtr have " + Math.abs(reporting_Qtr_FS_Working_SectionCount - financial_standard_workingSectionList.size()) + " extra rows from Operation_Standard"); errorModel.setError_level("Error"); errorModelList.add(errorModel); isError = true; } return isError; }
From source file:in.expertsoftware.colorcheck.Reporting_Year_Verification.java
private boolean operation_Standard_Workingsection_Verification(int SORY_tokenLocation, int first_Occurance_Of_Financial_Comparision, XSSFSheet Sheet, ArrayList<String> opeartion_standard_workingSectionList, ArrayList<ErrorModel> errorModelList, XSSFWorkbook workbook) {/*ww w . j av a 2s .c o m*/ int reporting_Year_OS_Working_SectionCount = 0; String reporting_Year_Formula_Cell_Formula; String reporting_Year_Formula_Cell_Value; boolean isError = false; XSSFRow row; XSSFCell cell; for (int start = (SORY_tokenLocation - 1); start < (first_Occurance_Of_Financial_Comparision - 1); start++) { try { row = Sheet.getRow(start); cell = row.getCell(1); reporting_Year_Formula_Cell_Value = cell.getStringCellValue(); if (reporting_Year_Formula_Cell_Value.equalsIgnoreCase("Operational Comparison")) { start = start + 1; } else if (reporting_Year_OS_Working_SectionCount < opeartion_standard_workingSectionList.size()) { switch (cell.getCellType()) { case Cell.CELL_TYPE_FORMULA: reporting_Year_Formula_Cell_Formula = cell.getCellFormula(); if (reporting_Year_Formula_Cell_Formula.contains("$")) { reporting_Year_Formula_Cell_Formula = reporting_Year_Formula_Cell_Formula .replaceAll("\\$", "").replaceAll(" ", ""); } String retrive_Formula = opeartion_standard_workingSectionList .get(reporting_Year_OS_Working_SectionCount); if (reporting_Year_Formula_Cell_Formula.equals(retrive_Formula)) { reporting_Year_OS_Working_SectionCount++; } else { ErrorModel errorModel = new ErrorModel(); CellReference cellRef = new CellReference(cell); errorModel.setCell_ref(cellRef.formatAsString()); errorModel.setSheet_name("Reporting_Year"); errorModel.setError_desc( "Sequence does not match Actual Sequence should be" + retrive_Formula); errorModel.setError_level("Error"); errorModel.setRow((cell.getRowIndex() + 1)); errorModelList.add(errorModel); reporting_Year_OS_Working_SectionCount++; isError = true; } break; case Cell.CELL_TYPE_BLANK: break; default: { ErrorModel errorModel = new ErrorModel(); CellReference cellRef = new CellReference(cell); errorModel.setCell_ref(cellRef.formatAsString()); errorModel.setSheet_name("Reporting_Year"); errorModel.setError_desc("Cell does not contain formula"); errorModel.setError_level("Error"); errorModel.setRow((cell.getRowIndex() + 1)); errorModelList.add(errorModel); reporting_Year_OS_Working_SectionCount++; isError = true; } break; } } else { reporting_Year_OS_Working_SectionCount++; } } catch (NullPointerException nullexcp) { continue; } catch (Exception e) { e.printStackTrace(); } } if (reporting_Year_OS_Working_SectionCount != opeartion_standard_workingSectionList.size()) { ErrorModel errorModel = new ErrorModel(); errorModel.setSheet_name("Reporting_Year"); errorModel.setError_desc("Reporting_Year have " + Math.abs( reporting_Year_OS_Working_SectionCount - opeartion_standard_workingSectionList.size()) + " extra rows from Operation_Standard"); errorModel.setError_level("Error"); errorModelList.add(errorModel); isError = true; } return isError; }
From source file:in.expertsoftware.colorcheck.Reporting_Year_Verification.java
private boolean financial_Standard_Workingsection_Verification(int first_Occurance_Of_Financial_Comparision, int EORY_tokenLocation, XSSFSheet Sheet, ArrayList<String> financial_standard_workingSectionList, ArrayList<ErrorModel> errorModelList, XSSFWorkbook workbook) { int reporting_Year_FS_Working_SectionCount = 0; String reporting_Year_Formula_Cell_Formula = null; String reporting_Year_Formula_Cell_Value; XSSFRow row;// w ww. j a v a2 s . com XSSFCell cell; boolean isError = false; for (int start = (first_Occurance_Of_Financial_Comparision - 1); start < EORY_tokenLocation; start++) { try { row = Sheet.getRow(start); cell = row.getCell(1); reporting_Year_Formula_Cell_Value = cell.getStringCellValue(); if (reporting_Year_Formula_Cell_Value.equalsIgnoreCase("Financial Comparison")) { start = start + 3; } else if (reporting_Year_FS_Working_SectionCount < financial_standard_workingSectionList.size()) { switch (cell.getCellType()) { case Cell.CELL_TYPE_FORMULA: reporting_Year_Formula_Cell_Formula = cell.getCellFormula(); if (reporting_Year_Formula_Cell_Formula.contains("$")) { reporting_Year_Formula_Cell_Formula = reporting_Year_Formula_Cell_Formula .replaceAll("\\$", "").replaceAll(" ", ""); } String retrive_Formula = financial_standard_workingSectionList .get(reporting_Year_FS_Working_SectionCount); if (reporting_Year_Formula_Cell_Formula.equals(retrive_Formula)) { reporting_Year_FS_Working_SectionCount++; } else { ErrorModel errorModel = new ErrorModel(); CellReference cellRef = new CellReference(cell); errorModel.setCell_ref(cellRef.formatAsString()); errorModel.setSheet_name("Reporting_Year"); errorModel.setError_desc( "Sequence does not match Actual Sequence should be" + retrive_Formula); errorModel.setError_level("Error"); errorModel.setRow((cell.getRowIndex() + 1)); errorModelList.add(errorModel); reporting_Year_FS_Working_SectionCount++; isError = true; } break; case Cell.CELL_TYPE_BLANK: break; default: { ErrorModel errorModel = new ErrorModel(); CellReference cellRef = new CellReference(cell); errorModel.setCell_ref(cellRef.formatAsString()); errorModel.setSheet_name("Reporting_Year"); errorModel.setError_desc("Cell does not contain formula "); errorModel.setError_level("Error"); errorModel.setRow((cell.getRowIndex() + 1)); errorModelList.add(errorModel); reporting_Year_FS_Working_SectionCount++; isError = true; } break; } } else { reporting_Year_FS_Working_SectionCount++; } } catch (NullPointerException nullexcp) { continue; } catch (Exception e) { e.printStackTrace(); } } if (reporting_Year_FS_Working_SectionCount != financial_standard_workingSectionList.size()) { ErrorModel errorModel = new ErrorModel(); errorModel.setSheet_name("Reporting_Year"); errorModel.setError_desc("Reporting_Year have " + Math.abs( reporting_Year_FS_Working_SectionCount - financial_standard_workingSectionList.size()) + " extra rows from Operation_Standard"); errorModel.setError_level("Error"); errorModelList.add(errorModel); isError = true; } return isError; }
From source file:info.toegepaste.controller.UploadController.java
public void fileUploadListener(FileUploadEvent e) { // Get uploaded file from the FileUploadEvent to use with primefaces this.file = e.getFile(); // Get uploaded file to use with Apache POI InputStream POIFile;//from w w w.jav a2 s.c om XSSFWorkbook workbook = null; try { POIFile = e.getFile().getInputstream(); //Create workbook workbook = new XSSFWorkbook(POIFile); } catch (IOException ex) { } // Print out the information of the file System.out.println( "Uploaded File Name Is :: " + file.getFileName() + " :: Uploaded File Size :: " + file.getSize()); //Create a worksheet (needed to get rows) XSSFSheet worksheet = workbook.getSheetAt(0); //Divide worksheet into rows Iterator<Row> rowIterator = worksheet.iterator(); //Get Classgroup from line 1 cell 2 XSSFRow currentRow = (XSSFRow) rowIterator.next(); Iterator<Cell> klasIter = currentRow.cellIterator(); XSSFCell klasCell = currentRow.getCell(1); //Get Course from line 2 cell 2 currentRow = (XSSFRow) rowIterator.next(); Iterator<Cell> courseIter = currentRow.cellIterator(); XSSFCell courseCell = currentRow.getCell(1); //Get subject from line 3 cell 2 System.out.println("Stuff"); currentRow = (XSSFRow) rowIterator.next(); Iterator<Cell> subjectIter = currentRow.cellIterator(); XSSFCell subjectCell = currentRow.getCell(1); System.out.println("Subject:" + subjectCell.toString()); System.out.println("Subject:" + subjectCell.getStringCellValue()); //Get total possible score from line 4 cell 2 currentRow = (XSSFRow) rowIterator.next(); Iterator<Cell> totalScoreIter = currentRow.cellIterator(); XSSFCell totalScoreCell = currentRow.getCell(1); //Skip line 5 & 6 currentRow = (XSSFRow) rowIterator.next(); currentRow = (XSSFRow) rowIterator.next(); currentRow = (XSSFRow) rowIterator.next(); List<Classgroup> group = classgroupService.getWithName(klasCell.getStringCellValue()); //Persist new exam to database Exam newExam = new Exam(); Classgroup newGroup = new Classgroup(); //Check if classgroup already exists, create if it doesnt if (group.isEmpty()) { newGroup.setName(klasCell.getStringCellValue()); newGroup.setCourses(null); classgroupService.insert(newGroup); } else { newGroup = group.get(0); } newExam.setClassgroup(newGroup); List<Course> course = courseService.getWithName(courseCell.getStringCellValue()); Course newCourse = new Course(); //Check if course exists, if not create if (course.isEmpty()) { newCourse.setName(courseCell.getStringCellValue()); int year = Calendar.getInstance().get(Calendar.YEAR); newCourse.setYear(year); newCourse.setClassgroup(newGroup); int maand = Calendar.getInstance().get(Calendar.MONTH); if (maand <= 6 && maand >= 1) { newCourse.setSemester(2); } else { newCourse.setSemester(1); } courseService.insert(newCourse); } else { newCourse = course.get(0); } newExam.setCourse(newCourse); newExam.setName(subjectCell.getStringCellValue()); // double totalScoreValue = ; // String totalScoreWorkaround =String.valueOf(totalScoreValue); newExam.setTotal((int) totalScoreCell.getNumericCellValue()); examService.insert(newExam); //Read file to end, cell 0 student number, cell 1 name, cell 2 score while (rowIterator.hasNext()) { XSSFCell userNrCell = currentRow.getCell(0); System.out.println(userNrCell.toString()); int StudentNumber = 0; // String StudentNumberWorkaround =userNrCell.getStringCellValue(); StudentNumber = (int) userNrCell.getNumericCellValue(); List<Student> currentStudent = studentsService.getStudentInListByNumber(StudentNumber); Student newStudent = new Student(); XSSFCell userNameCell = currentRow.getCell(1); //Check if student exists, else create if (currentStudent.isEmpty()) { String fullName = userNameCell.getStringCellValue(); String nameArray[] = fullName.split(" "); newStudent.setFirstname(nameArray[0]); newStudent.setLastname(nameArray[1]); newStudent.setNumber(StudentNumber); newStudent.setEmail("r0" + StudentNumber + "@student.thomasmore.be"); newStudent.setClassgroup(newGroup); newStudent.setPassword(null); studentsService.insert(newStudent); } else { newStudent = currentStudent.get(0); } //Add score to student List<Score> currentScore = scoreService.checkIfScoreExists(newStudent, newExam); XSSFCell scoreCell = currentRow.getCell(2); Score scoreEntry = new Score(); if (currentScore.isEmpty()) { scoreEntry.setExam(newExam); scoreEntry.setScore((int) scoreCell.getNumericCellValue()); if (currentStudent.isEmpty()) { scoreEntry.setStudent(newStudent); } else { scoreEntry.setStudent(currentStudent.get(0)); } scoreService.insert(scoreEntry); } else { scoreEntry = currentScore.get(0); } currentRow = (XSSFRow) rowIterator.next(); } }
From source file:javafxapplication3.FXMLDocumentController.java
public static void readXLSXFile() throws IOException { InputStream ExcelFileToRead;/*w w w . j a v a2 s .c o m*/ ExcelFileToRead = new FileInputStream("C:\\Users\\IBM_ADMIN\\Desktop\\reimbursement.xlsx"); XSSFWorkbook wb = new XSSFWorkbook(ExcelFileToRead); System.out.println(wb); XSSFWorkbook test = new XSSFWorkbook(); XSSFSheet sheet = wb.getSheetAt(0); XSSFRow row; XSSFCell cell; Iterator rows = sheet.rowIterator(); ObservableList<ObservableList> csvData = FXCollections.observableArrayList(); while (rows.hasNext()) { ObservableList<String> amzrow = FXCollections.observableArrayList(); row = (XSSFRow) rows.next(); Iterator cells = row.cellIterator(); while (cells.hasNext()) { cell = (XSSFCell) cells.next(); if (cell.getCellType() == XSSFCell.CELL_TYPE_STRING) { amzrow.add(cell.getStringCellValue()); //System.out.print(cell.getStringCellValue()+" "); } else if (cell.getCellType() == XSSFCell.CELL_TYPE_NUMERIC) { //amzrow.add(cell.getNumericCellValue()); //System.out.print(cell.getNumericCellValue()+" "); } else { //U Can Handel Boolean, Formula, Errors } } csvData.add(amzrow); } //tableview.getItems().add(csvData); }
From source file:mil.tatrc.physiology.datamodel.dataset.DataSetReader.java
License:Apache License
protected static List<SEPatient> readPatients(XSSFSheet xlSheet) { String property, value, unit; List<SEPatient> patients = new ArrayList<SEPatient>(); try {// ww w . j a v a 2s. c om int rows = xlSheet.getPhysicalNumberOfRows(); for (int r = 0; r < rows; r++) { XSSFRow row = xlSheet.getRow(r); if (row == null) continue; int cells = row.getPhysicalNumberOfCells(); if (r == 0) {// Allocate the number of patients we have for (int i = 1; i < cells; i++) patients.add(new SEPatient()); } property = row.getCell(0).getStringCellValue(); if (property == null || property.isEmpty()) continue; Log.info("Processing Patient Field : " + property); for (int c = 1; c < cells; c++) { String cellValue = null; XSSFCell cell = row.getCell(c); switch (cell.getCellType()) { case XSSFCell.CELL_TYPE_NUMERIC: cellValue = Double.toString(cell.getNumericCellValue()); break; case XSSFCell.CELL_TYPE_STRING: cellValue = cell.getStringCellValue(); break; } if (cellValue == null || cellValue.isEmpty()) continue; int split = cellValue.indexOf(" "); // Pull The Value if (split == -1) { value = cellValue; unit = ""; } else { value = cellValue.substring(0, split); unit = cellValue.substring(split + 1); } if (value.equals("INF")) value = "Infinity"; if (!setProperty(patients.get(c - 1), property, value, unit)) { Log.error("Error pulling" + property + " from " + cellValue); break; } } } } catch (Exception ex) { Log.error("Error reading XLS", ex); return null; } return patients; }
From source file:mil.tatrc.physiology.datamodel.dataset.DataSetReader.java
License:Apache License
protected static Map<String, SESubstance> readSubstances(XSSFSheet xlSheet) { EnumAnatomy currCmpt = null;//from ww w . java 2 s . c om String property, value, unit; SESubstance substance = null; SESubstanceAnatomyEffect afx = null; List<SESubstance> substances = new ArrayList<SESubstance>(); Set<Integer> skipColumns = new HashSet<Integer>(); try { int rows = xlSheet.getPhysicalNumberOfRows(); for (int r = 0; r < rows; r++) { XSSFRow row = xlSheet.getRow(r); if (row == null) continue; int cells = row.getPhysicalNumberOfCells(); if (r == 0) { for (int c = 1; c < cells; c++) { property = row.getCell(c).getStringCellValue().trim(); if (property.equals("Reference Value") || property.equals("Reference Source") || property.equals("Notes/Page")) skipColumns.add(c); } } property = row.getCell(0).getStringCellValue().trim(); if (property == null || property.isEmpty()) continue; Log.info("Processing Substance Field : " + property); if (property.indexOf("Compartment Effects") > -1) { if (property.indexOf("Myocardium") > -1) currCmpt = EnumAnatomy.MYOCARDIUM; else if (property.indexOf("Fat") > -1) currCmpt = EnumAnatomy.FAT; else if (property.indexOf("Kidneys") > -1) currCmpt = EnumAnatomy.KIDNEYS; else if (property.indexOf("Brain") > -1) currCmpt = EnumAnatomy.BRAIN; else if (property.indexOf("Muscle") > -1) currCmpt = EnumAnatomy.MUSCLE; else if (property.indexOf("Skin") > -1) currCmpt = EnumAnatomy.SKIN; else if (property.indexOf("Bone") > -1) currCmpt = EnumAnatomy.BONE; else if (property.indexOf("Gut") > -1) currCmpt = EnumAnatomy.GUT; else if (property.indexOf("Splanchnic") > -1) currCmpt = EnumAnatomy.SPLANCHNIC; else if (property.indexOf("Spleen") > -1) currCmpt = EnumAnatomy.SPLEEN; else if (property.indexOf("Large Intestine") > -1) currCmpt = EnumAnatomy.LARGE_INTESTINE; else if (property.indexOf("Small Intestine") > -1) currCmpt = EnumAnatomy.SMALL_INTESTINE; else if (property.indexOf("Liver") > -1) currCmpt = EnumAnatomy.LIVER; else if (property.indexOf("Right Lung") > -1) currCmpt = EnumAnatomy.RIGHT_LUNG; else if (property.indexOf("Left Lung") > -1) currCmpt = EnumAnatomy.LEFT_LUNG; else { Log.error("Unsupported Anatomy Compartment : " + property); break; } } int s = -1; for (int c = 1; c < cells; c++) { if (skipColumns.contains(c)) continue; s++; String cellValue = null; XSSFCell cell = row.getCell(c); switch (cell.getCellType()) { case XSSFCell.CELL_TYPE_NUMERIC: cellValue = Double.toString(cell.getNumericCellValue()); break; case XSSFCell.CELL_TYPE_STRING: cellValue = cell.getStringCellValue(); break; case XSSFCell.CELL_TYPE_FORMULA: switch (evaluator.evaluateFormulaCell(cell)) { case XSSFCell.CELL_TYPE_NUMERIC: cellValue = Double.toString(cell.getNumericCellValue()); break; case XSSFCell.CELL_TYPE_STRING: cellValue = cell.getStringCellValue(); break; } } if (cellValue == null) continue; cellValue = cellValue.trim(); if (cellValue.isEmpty()) continue; if (property.equals("Name")) { substance = new SESubstance(); substances.add(substance); } int split = cellValue.indexOf(" "); // Pull The Value if (split == -1) { value = cellValue; unit = ""; } else { value = cellValue.substring(0, split); unit = cellValue.substring(split + 1); } if (value.equals("INF")) value = "Infinity"; substance = substances.get(c - (3 * s) - 1); if (currCmpt == null) afx = null; else afx = substance.getAnatomyEffect(currCmpt); if (!setProperty(substance, afx, property, value, unit)) { Log.error("Error pulling" + property + " from " + cellValue); break; } } } } catch (Exception ex) { Log.error("Error reading XLS", ex); return null; } Map<String, SESubstance> map = new HashMap<String, SESubstance>(); for (SESubstance sub : substances) map.put(sub.getName(), sub); return map; }
From source file:mil.tatrc.physiology.datamodel.dataset.DataSetReader.java
License:Apache License
protected static List<SESubstanceCompound> readCompounds(XSSFSheet xlSheet, Map<String, SESubstance> substances) { String property, value, unit; SESubstance s;//from w w w . ja v a2 s .c o m SESubstanceCompound compound = null; SESubstanceCompoundComponent component = null; List<SESubstanceCompound> compounds = new ArrayList<SESubstanceCompound>(); try { int rows = xlSheet.getPhysicalNumberOfRows(); for (int r = 0; r < rows; r++) { XSSFRow row = xlSheet.getRow(r); if (row == null) continue; int cells = row.getPhysicalNumberOfCells(); if (r == 0) {// Allocate the number of patients we have for (int i = 1; i < cells; i++) compounds.add(new SESubstanceCompound()); } property = row.getCell(0).getStringCellValue(); if (property == null || property.isEmpty()) continue; Log.info("Processing Patient Field : " + property); if (property.equals("Data Type")) continue;// Only one type at this point for (int c = 1; c < cells; c++) { String cellValue = null; XSSFCell cell = row.getCell(c); switch (cell.getCellType()) { case XSSFCell.CELL_TYPE_NUMERIC: cellValue = Double.toString(cell.getNumericCellValue()); break; case XSSFCell.CELL_TYPE_STRING: cellValue = cell.getStringCellValue(); break; } if (cellValue == null || cellValue.isEmpty()) continue; int split = cellValue.indexOf(" "); // Pull The Value if (split == -1) { value = cellValue; unit = ""; } else { value = cellValue.substring(0, split); unit = cellValue.substring(split + 1); } compound = compounds.get(c - 1); if (property.equals("Compound Name")) { compound.setName(value); continue; } if (property.equals("Component Name")) { s = substances.get(value); component = compound.getComponent(s); continue; } if (!setProperty(component, property, value, unit)) { Log.error("Error setting property"); break; } } } } catch (Exception ex) { Log.error("Error reading XLS", ex); return null; } return compounds; }
From source file:mil.tatrc.physiology.datamodel.dataset.DataSetReader.java
License:Apache License
protected static Map<String, SEEnvironmentalConditions> readEnvironments(XSSFSheet xlSheet, Map<String, SESubstance> substances) { String property, value, unit; SESubstance substance = null;// w ww.ja va2s. c o m SEEnvironmentalConditions environment; SESubstanceFraction subFrac = null; Map<String, SEEnvironmentalConditions> map = new HashMap<String, SEEnvironmentalConditions>(); List<SEEnvironmentalConditions> environments = new ArrayList<SEEnvironmentalConditions>(); try { int rows = xlSheet.getPhysicalNumberOfRows(); for (int r = 0; r < rows; r++) { XSSFRow row = xlSheet.getRow(r); if (row == null) continue; int cells = row.getPhysicalNumberOfCells(); if (r == 0) {// Allocate the number of environments we have for (int i = 1; i < cells; i++) environments.add(new SEEnvironmentalConditions()); } property = row.getCell(0).getStringCellValue(); if (property == null || property.isEmpty()) continue; if (property.equals("AmbientSubstanceData")) continue; Log.info("Processing Environment Field : " + property); for (int c = 1; c < cells; c++) { String cellValue = null; XSSFCell cell = row.getCell(c); switch (cell.getCellType()) { case XSSFCell.CELL_TYPE_NUMERIC: cellValue = Double.toString(cell.getNumericCellValue()); break; case XSSFCell.CELL_TYPE_STRING: cellValue = cell.getStringCellValue(); break; } if (cellValue == null || cellValue.isEmpty()) continue; int split = cellValue.indexOf(" "); // Pull The Value if (split == -1) { value = cellValue; unit = ""; } else { value = cellValue.substring(0, split); unit = cellValue.substring(split + 1); } environment = environments.get(c - 1); if (property.equals("Name")) { map.put(cellValue, environment); continue; } if (property.equals("Substance")) {// NOTE THIS ASSUMES THAT A ROW IS ALL ASSOCIATED WITH THE SAME SUBSTANCE substance = substances.get(value); continue; } if (substance == null) subFrac = null; else subFrac = environment.getAmbientSubstance(substance, null); if (!setProperty(environment, subFrac, property, value, unit)) { Log.error("Error pulling" + property + " from " + cellValue); break; } } } } catch (Exception ex) { Log.error("Error reading XLS", ex); return null; } return map; }