List of usage examples for org.apache.poi.ss.usermodel Row cellIterator
Iterator<Cell> cellIterator();
From source file:org.pharmgkb.ItpcSheet.java
License:LGPL
protected void parseColumnIndexes() throws Exception { if (sf_logger.isDebugEnabled()) { sf_logger.debug("Parsing column indexes and headings"); }// w w w .j a va 2 s. c o m Row headerRow = m_dataSheet.getRow(0); Iterator<Cell> headerCells = headerRow.cellIterator(); while (headerCells.hasNext()) { Cell headerCell = headerCells.next(); String header = headerCell.getStringCellValue(); int idx = headerCell.getColumnIndex(); for (Pattern pattern : sf_medPatterns.keySet()) { if (pattern.matcher(header).matches()) { medIdx.put(sf_medPatterns.get(pattern), idx); } } if (StringUtils.isNotEmpty(header)) { header = header.trim().toLowerCase(); } if (header.contains("subject id")) { subjectId = idx; } else if (header.equalsIgnoreCase("project site")) { projectSiteIdx = idx; } else if (header.contains("gender")) { genderIdx = idx; } else if (header.contains("age at diagnosis")) { ageIdx = idx; } else if (header.contains("race") && header.contains("omb")) { raceIdx = idx; } else if (header.equalsIgnoreCase("Metastatic Disease at Primary Disease")) { metastaticIdx = idx; } else if (header.contains("maximum dimension of tumor")) { tumorDimensionIdx = idx; } else if (header.equalsIgnoreCase("Number of Positive Nodes")) { numPositiveNodesIdx = idx; } else if (header.equalsIgnoreCase("Nottingham Grade")) { tumorGradingIdx = idx; } else if (header.equalsIgnoreCase("Progesterone Receptor")) { pgrStatusIdx = idx; } else if (header.equalsIgnoreCase("Radiation Treatment")) { radioIdx = idx; } else if (header.contains("menopause status at diagnosis")) { menoStatusIdx = idx; } else if (header.equals("estrogen receptor")) { erStatusIdx = idx; } else if (header.contains("intended tamoxifen duration")) { durationIdx = idx; } else if (header.contains("intended tamoxifen dose")) { tamoxDoseIdx = idx; } else if (header.contains("if tumor or tissue was dna source")) { tumorSourceIdx = idx; } else if (header.contains("blood or buccal cells")) { bloodSourceIdx = idx; } else if (header.contains("prior history of cancer")) { priorHistoryIdx = idx; } else if (header.contains("sites of prior cancer")) { priorSitesIdx = idx; } else if (header.contains("prior invasive breast cancer or dcis")) { priorDcisIdx = idx; } else if (header.equalsIgnoreCase("chemotherapy")) { chemoIdx = idx; } else if (header.contains("additional hormone or other treatment after breast surgery?")) { hormoneIdx = idx; } else if (header.contains("systemic therapy prior to surgery?")) { systemicTherIdx = idx; } else if (header.contains("annual physical exam after breast cancer surgery")) { followupIdx = idx; } else if (header.contains("time between definitive breast cancer surgery")) { timeBtwSurgTamoxIdx = idx; } else if (header.contains("first adjuvant endocrine therapy")) { firstAdjEndoTherIdx = idx; } else if (header.contains("project notes")) { projectNotesIdx = idx; } else if (header.equalsIgnoreCase("other cyp2d6 genotyping")) { otherGenoIdx = idx; } else if (header.contains("rs4986774") && !header.contains("source")) { rs4986774idx = idx; } else if (header.contains("rs1065852") && !header.contains("source")) { rs1065852idx = idx; } else if (header.contains("rs3892097") && !header.contains("source")) { rs3892097idx = idx; } else if (header.contains("rs5030655") && !header.contains("source")) { rs5030655idx = idx; } else if (header.contains("rs16947") && !header.contains("source")) { rs16947idx = idx; } else if (header.contains("rs28371706") && !header.contains("source")) { rs28371706idx = idx; } else if (header.contains("rs28371725") && !header.contains("source")) { rs28371725idx = idx; } else if (genotypeSourceHeaderTitles.contains(header)) { sampleSourceIdxs.add(idx); } else if (header.contains("cyp2d6 *5") && !header.contains("source")) { star5idx = idx; } else if (header.contains("fluoxetine")) { fluoxetineCol = idx; } else if (header.contains("paroxetine")) { paroxetineCol = idx; } else if (header.contains("quinidine")) { quinidienCol = idx; } else if (header.contains("buproprion")) { buproprionCol = idx; } else if (header.contains("duloxetine")) { duloxetineCol = idx; } else if (header.contains("cimetidine")) { cimetidineCol = idx; } else if (header.contains("sertraline")) { sertralineCol = idx; } else if (header.equals("citalopram")) { citalopramCol = idx; } else if (header.contains("amplichip call")) { amplichipidx = idx; } else if (header.equalsIgnoreCase("Additional cancer?")) { // column BP additionalCancerIdx = idx; } else if (header.contains("time from diagnosis to ipsilateral local or regional recurrence")) { // column BR addCxIpsilateralIdx = idx; } else if (header.contains("time from diagnosis to distant recurrence")) { // column BS addCxDistantRecurIdx = idx; } else if (header.contains("time from diagnosis to contralateral breast cancer")) { // column BT addCxContralateralIdx = idx; } else if (header.contains("time from diagnosis to second primary invasive cancer")) { // column BU addCxSecondInvasiveIdx = idx; } else if (header.contains("time from diagnosis to date of last disease evaluation")) { // column BX addCxLastEvalIdx = idx; } else if (header.equalsIgnoreCase("Time from diagnosis until death if the patient has died")) { // column CE daysDiagToDeathIdx = idx; } else if (header.equalsIgnoreCase("Has the patient died?")) { // column CD patientDiedIdx = idx; } else if (header.contains("enter disease-free survival time")) { // column BO diseaseFreeSurvivalTimeIdx = idx; } else if (header.contains("survival time if patient has not died")) { // column CI survivalNotDiedIdx = idx; } else if (header.equalsIgnoreCase("Cause of death if the patient has died")) { causeOfDeathIdx = idx; } } // new columns to add to the end of the template int startPgkbColsIdx = projectNotesIdx + 1; newFirstDiseaseEventIdx = startPgkbColsIdx; diagToEventCalcIdx = startPgkbColsIdx + 1; allele1finalIdx = startPgkbColsIdx + 2; allele2finalIdx = startPgkbColsIdx + 3; genotypeIdx = startPgkbColsIdx + 4; genoMetabStatusIdx = startPgkbColsIdx + 5; weakIdx = startPgkbColsIdx + 6; potentIdx = startPgkbColsIdx + 7; scoreIdx = startPgkbColsIdx + 8; metabStatusIdx = startPgkbColsIdx + 9; incAgeIdx = startPgkbColsIdx + 10; incNonmetaIdx = startPgkbColsIdx + 11; incPriorHistIdx = startPgkbColsIdx + 12; incErPosIdx = startPgkbColsIdx + 13; incSysTherIdx = startPgkbColsIdx + 14; incAdjTamoxIdx = startPgkbColsIdx + 15; incDurationIdx = startPgkbColsIdx + 16; incTamoxDoseIdx = startPgkbColsIdx + 17; incChemoIdx = startPgkbColsIdx + 18; incHormoneIdx = startPgkbColsIdx + 19; incDnaCollectionIdx = startPgkbColsIdx + 20; incFollowupIdx = startPgkbColsIdx + 21; incGenoDataAvailIdx = startPgkbColsIdx + 22; exclude1Idx = startPgkbColsIdx + 23; exclude2Idx = startPgkbColsIdx + 24; exclude3Idx = startPgkbColsIdx + 25; exclude4Idx = startPgkbColsIdx + 26; includeCrit1Idx = startPgkbColsIdx + 27; includeCrit2Idx = startPgkbColsIdx + 28; includeCrit3Idx = startPgkbColsIdx + 29; bfciIdx = startPgkbColsIdx + 30; genoSourceIdx = startPgkbColsIdx + 31; writeCellTitles(headerRow); styleCells(headerRow, startPgkbColsIdx, headerRow.getCell(0).getCellStyle()); // write the description row Row descrRow = m_dataSheet.getRow(1); writeCellDescr(descrRow); styleCells(descrRow, startPgkbColsIdx, descrRow.getCell(0).getCellStyle()); }
From source file:org.pharmgkb.ItpcSheet.java
License:LGPL
/** * Styles the given row with the Title Style specified in <code>getTitleStyle</code>. The <code>startIndex</code> * parameter specifies which column column to start applying the style on (0 = all columns) inclusively. * @param row an Excel Row//ww w .j a v a 2 s . c o m * @param startIndex the index of the column to start applying the style on * @param style the CellStyle to apply */ public void styleCells(Row row, int startIndex, CellStyle style) { Iterator<Cell> headerCells = row.cellIterator(); while (headerCells.hasNext()) { Cell headerCell = headerCells.next(); if (headerCell.getColumnIndex() >= startIndex) { headerCell.setCellStyle(style); } } }
From source file:org.project.utilities.readExcel.java
public ArrayList readExcel2(File exfile, String exfilename) { ArrayList col = new ArrayList(); ArrayList cellArrayLisstHolder = new ArrayList(); File file2 = new File(filepath); try {/*from w w w. ja v a2 s . co m*/ FileInputStream file = new FileInputStream(exfile); //Workbook workbook = null; // String name = file2.getName(); // System.out.println("path " + exfile.getName()); String name = exfilename; Workbook workbook = null; Sheet sheet2 = null; if (name.toLowerCase().endsWith("xlsx")) { workbook = new XSSFWorkbook(file); } else if (name.toLowerCase().endsWith("xls")) { workbook = new HSSFWorkbook(file); } Sheet sheet = workbook.getSheetAt(0); Row firstrow = sheet.getRow(0); for (Cell cell : firstrow) { } Iterator<Row> rowiterator = sheet.iterator(); while (rowiterator.hasNext()) { Row row = rowiterator.next(); Iterator<Cell> celliterator = row.cellIterator(); ArrayList cellStoreArrayList = new ArrayList(); while (celliterator.hasNext()) { Cell cell = celliterator.next(); // while(celliterator.hasNext()){ cellStoreArrayList.add(cell); } cellArrayLisstHolder.add(cellStoreArrayList); System.out.println(""); } file.close(); } catch (Exception e) { e.printStackTrace(); } return cellArrayLisstHolder; }
From source file:org.project.utilities.readExcel.java
public ArrayList readExcel() { ArrayList col = new ArrayList(); ArrayList cellArrayLisstHolder = new ArrayList(); File file2 = new File("/home/asl/Desktop/html work/ProgramFile/programdata.xls"); try {// w w w . j a v a 2s. co m FileInputStream file = new FileInputStream(file2); //Workbook workbook = null; String name = file2.getName(); Workbook workbook = null; Sheet sheet2 = null; if (name.toLowerCase().endsWith("xlsx")) { workbook = new XSSFWorkbook(file); } else if (name.toLowerCase().endsWith("xls")) { workbook = new HSSFWorkbook(file); } Sheet sheet = workbook.getSheetAt(0); Row firstrow = sheet.getRow(0); for (Cell cell : firstrow) { } Iterator<Row> rowiterator = sheet.iterator(); while (rowiterator.hasNext()) { Row row = rowiterator.next(); Iterator<Cell> celliterator = row.cellIterator(); ArrayList cellStoreArrayList = new ArrayList(); while (celliterator.hasNext()) { Cell cell = celliterator.next(); // while(celliterator.hasNext()){ cellStoreArrayList.add(cell); // } /* switch (cell.getCellType()) { case Cell.CELL_TYPE_NUMERIC: // System.out.print(cell.getNumericCellValue() + "\t"); case Cell.CELL_TYPE_STRING: // System.out.print(cell.getStringCellValue() + "\t"); }*/ } cellArrayLisstHolder.add(cellStoreArrayList); System.out.println(""); } file.close(); } catch (Exception e) { e.printStackTrace(); } return cellArrayLisstHolder; }
From source file:org.sakaiproject.gradebook.gwt.server.ImportExportUtilityImpl.java
License:Educational Community License
private boolean poiRowContainsString(Row row, String text) { if (null == text) return false; text = text.trim().toLowerCase();/*from w ww . ja va2 s . c o m*/ if (row != null && row.cellIterator().hasNext()) for (org.apache.poi.ss.usermodel.Cell cell : row) { if (cell.getCellType() == org.apache.poi.ss.usermodel.Cell.CELL_TYPE_STRING && cell.getStringCellValue().trim().toLowerCase().equals(text)) { return true; } } return false; }
From source file:org.sakaiproject.gradebook.gwt.server.ImportExportUtilityImpl.java
License:Educational Community License
private int readHeaderRow(Row curRow) { int ret = -1; Iterator<org.apache.poi.ss.usermodel.Cell> cellIterator = curRow.cellIterator(); // FIXME - need to decide to take this out into the institutional adviser while (cellIterator.hasNext()) { org.apache.poi.ss.usermodel.Cell cl = cellIterator.next(); String cellData = new org.apache.poi.ss.usermodel.DataFormatter().formatCellValue(cl).toLowerCase(); if ("student id".equals(cellData)) { return cl.getColumnIndex(); }//from w ww. j ava2 s .c o m } return ret; }
From source file:org.sakaiproject.gradebook.gwt.server.ImportExportUtilityImpl.java
License:Educational Community License
private org.apache.poi.ss.usermodel.Cell findCellWithTextonSheetForPoi(org.apache.poi.ss.usermodel.Sheet cur, String searchText) {/* ww w. ja v a 2s . c om*/ if (searchText == null || cur == null) { return null; } Iterator<Row> rIter = cur.rowIterator(); while (rIter.hasNext()) { Row curRow = rIter.next(); Iterator<org.apache.poi.ss.usermodel.Cell> cIter = curRow.cellIterator(); while (cIter.hasNext()) { org.apache.poi.ss.usermodel.Cell curCell = cIter.next(); if (curCell.getCellType() == HSSFCell.CELL_TYPE_STRING) { if (searchText.equals(curCell.getRichStringCellValue().getString())) { return curCell; } } } } return null; }
From source file:org.semtix.gui.auszahlung.auszahlungsmodul.Datenabgleich.java
License:Open Source License
/** * Liest eine XLS Datei ein und gleicht sie mit der Datenbank ab * * @param path /Pfad/angabe/zur/Datei.xyz *//*from w ww. j av a 2 s .c om*/ public void einlesen(String path) { try { FileInputStream file = new FileInputStream(new File(path)); // Get the workbook instance for XLS file HSSFWorkbook workbook = new HSSFWorkbook(file); // Get first sheet from the workbook HSSFSheet sheet = workbook.getSheetAt(0); // Iterate through each rows from first sheet Iterator<Row> rowIterator = sheet.iterator(); while (rowIterator.hasNext()) { Row row = rowIterator.next(); // For each row, iterate through each columns Iterator<Cell> cellIterator = row.cellIterator(); Cell[] cells = new Cell[row.getLastCellNum()]; int i = 0; boolean exmatrikuliert = false; while (cellIterator.hasNext()) { Cell cell = cellIterator.next(); cells[i] = cell; i++; if (i == 5 && cell.getCellType() == Cell.CELL_TYPE_STRING) { if (cell.getStringCellValue().equalsIgnoreCase("X")) { // if this cell contains an X we have to see if a) // Antrag is invalid b) Person is Teilimmatrikuliert // c) How many months Teilimmatrikuliert exmatrikuliert = true; } } } // we have to see if a) Antrag is invalid b) Person is // Teilimmatrikuliert c) How many months Teilimmatrikuliert if (exmatrikuliert) { Cell semesterCell = cells[6]; // Semester aufschlsseln nach Jahr und Typ String semesterJahrPerson = null; String semesterTypPerson = null; if (semesterCell.getCellType() == Cell.CELL_TYPE_NUMERIC) { String semester = "" + semesterCell.getNumericCellValue(); semesterJahrPerson = semester.substring(0, 4).trim(); semesterTypPerson = semester.substring(4, 5).trim(); if (semesterTypPerson.equals("1")) { semesterTypPerson = "S"; } else if (semesterTypPerson.equals("2")) { semesterTypPerson = "W"; } } // get current selected Semester String semesterTypAktuell = SemesterConf.getSemester().getSemesterArt().getBuchstabe().trim(); String semesterJahrAktuell = SemesterConf.getSemester().getSemesterJahr().trim(); // if its really the same semester get the date of // exmatriculation and check how many months if (semesterJahrAktuell.equalsIgnoreCase(semesterJahrPerson) && semesterTypAktuell.equalsIgnoreCase(semesterTypPerson)) { // get cell with exmatriculation date Cell exmatriculationDateCell = cells[5]; // Find out date of exmatriculation / round up date to next month int exmatriculationmonth = 0; if (HSSFDateUtil.isCellDateFormatted(exmatriculationDateCell)) { Date date = exmatriculationDateCell.getDateCellValue(); // Calendar cal = Calendar.getInstance(); // cal.setTime(date); // int monat = cal.get(Calendar.MONTH); SimpleDateFormat df = new SimpleDateFormat("MM"); exmatriculationmonth = Integer.parseInt(df.format(date)); exmatriculationmonth++; } int monateZuschuss = 0; // Sommersemester if (semesterTypAktuell.equals("S")) { monateZuschuss = 6 - (10 - exmatriculationmonth); // Wintersemester } else if (semesterTypAktuell.equals("W")) { if (exmatriculationmonth > 4) { monateZuschuss = 6 - (16 - exmatriculationmonth); } else { monateZuschuss = 6 - (4 - exmatriculationmonth); } } if (monateZuschuss < 6) { Cell manrCell = cells[0]; Cell nachnameCell = cells[2]; Cell vornameCell = cells[3]; String matrikelnummer = "" + manrCell.getNumericCellValue(); matrikelnummer = matrikelnummer.substring(0, matrikelnummer.indexOf('.')); String nachname = getStringFromCell(nachnameCell); String vorname = getStringFromCell(vornameCell); // write Teilzuschuss to DB dbhandler.setAntragToTeilzuschuss(monateZuschuss, matrikelnummer); } } else { Cell manrCell = cells[0]; Cell nachnameCell = cells[2]; Cell vornameCell = cells[3]; String matrikelnummer = "" + manrCell.getNumericCellValue(); matrikelnummer = matrikelnummer.substring(0, matrikelnummer.indexOf('.')); String nachname = getStringFromCell(nachnameCell); String vorname = getStringFromCell(vornameCell); // dbhandler.denyAntrag(AntragAblehnungsgrund.EXMATRIKULIERT.getBegruendung(), matrikelnummer); } } } file.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:org.shareok.data.documentProcessor.ExcelHandler.java
/** * Reads out the data in an excel file and stores data in a hashmap<p> * The cell data has the ending of "--type" to label the data type * //from ww w . j ava2 s . co m * @throws Exception */ @Override public void readData() { String name = fileName; Sheet sheet = null; try { if (null == name || "".equals(name)) { throw new FileNameException("File name is not specified!"); } FileInputStream file = new FileInputStream(new File(name)); String extension = DocumentProcessorUtil.getFileExtension(name); String[] excelTypes = router.loadOfficeFileType("excel"); if (null == excelTypes || excelTypes.length == 0) { throw new FileTypeException("The file types are empty!"); } HashMap<String, String> typeMap = new HashMap<>(); for (String s : excelTypes) { typeMap.put(s, s); } if (typeMap.containsKey(extension)) { if (extension.equals("xlsx")) { } } sheet = getWorkbookSheet(extension, file); int maxNumOfCells = sheet.getRow(0).getLastCellNum(); Iterator<Row> rowIterator = sheet.iterator(); DateFormat df = new SimpleDateFormat("MM/dd/yyyy"); int rowCount = 0; //int colCount = 0; while (rowIterator.hasNext()) { Row row = rowIterator.next(); Iterator<Cell> cellIterator = row.cellIterator(); //while(cellIterator.hasNext()) { for (int colCount = 0; colCount < maxNumOfCells; colCount++) { //Cell cell = cellIterator.next(); Cell cell = row.getCell(colCount); if (null == cell) { cell = row.createCell(colCount); } String key = Integer.toString(rowCount) + "-" + Integer.toString(colCount); switch (cell.getCellType()) { case Cell.CELL_TYPE_BOOLEAN: data.put(key, Boolean.toString(cell.getBooleanCellValue()) + "---bool"); break; case Cell.CELL_TYPE_NUMERIC: if (isCellDateFormatted(cell)) { data.put(key, df.format(cell.getDateCellValue()) + "---dat"); } else { data.put(key, Double.toString(cell.getNumericCellValue()) + "---num"); } break; case Cell.CELL_TYPE_STRING: data.put(key, cell.getStringCellValue() + "---str"); break; case Cell.CELL_TYPE_BLANK: data.put(key, ""); break; case Cell.CELL_TYPE_ERROR: data.put(key, "ERROR_VALUE"); break; case Cell.CELL_TYPE_FORMULA: FormulaEvaluator evaluator = sheet.getWorkbook().getCreationHelper() .createFormulaEvaluator(); //handleCell(cell.getCachedFormulaResultType(), cell, evaluator); data.put(key, String.valueOf(cell.getCachedFormulaResultType())); break; default: data.put(key, cell.getRichStringCellValue() + "---def"); break; } // colCount++; } rowCount++; //colCount = 0; } file.close(); } catch (FileNotFoundException ex) { Logger.getLogger(ExcelHandler.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(ExcelHandler.class.getName()).log(Level.SEVERE, null, ex); } catch (Exception ex) { Logger.getLogger(ExcelHandler.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:org.shareok.data.msofficedata.ExcelHandler.java
/** * * @throws Exception//w w w . j a v a2 s .c om */ @Override public void readData() { String name = fileName; Sheet sheet = null; try { if (null == name || "".equals(name)) { throw new Exception("File name is not specified!"); } FileInputStream file = new FileInputStream(new File(name)); String extension = FileUtil.getFileExtension(name); String[] excelTypes = router.loadOfficeFileType("excel"); if (null == excelTypes || excelTypes.length == 0) { throw new Exception("The file types are empty!"); } HashMap<String, String> typeMap = new HashMap<>(); for (String s : excelTypes) { typeMap.put(s, s); } if (typeMap.containsKey(extension)) { if (extension.equals("xlsx")) { } } sheet = getWorkbookSheet(extension, file); Iterator<Row> rowIterator = sheet.iterator(); DateFormat df = new SimpleDateFormat("MM/dd/yyyy"); int rowCount = 0; int colCount = 0; while (rowIterator.hasNext()) { Row row = rowIterator.next(); Iterator<Cell> cellIterator = row.cellIterator(); while (cellIterator.hasNext()) { Cell cell = cellIterator.next(); String key = Integer.toString(rowCount) + "-" + Integer.toString(colCount); switch (cell.getCellType()) { case Cell.CELL_TYPE_BOOLEAN: data.put(key, Boolean.toString(cell.getBooleanCellValue()) + "---bool"); break; case Cell.CELL_TYPE_NUMERIC: if (isCellDateFormatted(cell)) { data.put(key, df.format(cell.getDateCellValue()) + "---dat"); } else { data.put(key, Double.toString(cell.getNumericCellValue()) + "---num"); } break; case Cell.CELL_TYPE_STRING: data.put(key, cell.getStringCellValue() + "---str"); break; default: data.put(key, cell.getRichStringCellValue() + "---def"); break; } colCount++; } rowCount++; colCount = 0; } file.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException ex) { Logger.getLogger(ExcelHandler.class.getName()).log(Level.SEVERE, null, ex); } catch (Exception ex) { Logger.getLogger(ExcelHandler.class.getName()).log(Level.SEVERE, null, ex); } }