List of usage examples for org.apache.poi.ss.usermodel Cell getColumnIndex
int getColumnIndex();
From source file:javaapp.ParseDebtorData.java
public static ArrayList<String> parseReport(String name, int c1, int c2, int c3, int c4, int c5, int c6, String tbl) throws IOException { String excelFilePath = "S9/GBRCNCOR.xlsx"; FileInputStream inputStream = new FileInputStream(new File(excelFilePath)); ArrayList<String> ar = new ArrayList<String>(); String sqlstr = ""; Workbook workbook = new XSSFWorkbook(inputStream); //Sheet uninv_open = workbook.getSheetAt(sno); Sheet uninv_open = workbook.getSheet(name); //String sname = workbook.getSheetName(sno); System.out.println("Parsing Sheet Name : " + name + " ---> " + tbl); Iterator<Row> iterator = uninv_open.iterator(); String rec = ""; String pay = ""; String per = ""; String svc = ""; double dval = 0; double cval = 0; String rpps = ""; while (iterator.hasNext()) { Row nextRow = iterator.next();/* ww w. ja v a 2 s.c o m*/ Iterator<Cell> cellIterator = nextRow.cellIterator(); dval = 0; cval = 0; while (cellIterator.hasNext()) { Cell cell = cellIterator.next(); if (cell.getColumnIndex() == c1 || cell.getColumnIndex() == c2 || cell.getColumnIndex() == c3 || cell.getColumnIndex() == c4 || cell.getColumnIndex() == c5 || cell.getColumnIndex() == c6) { switch (cell.getCellType()) { case Cell.CELL_TYPE_STRING: if (cell.getColumnIndex() == c1) { rec = cell.getStringCellValue(); } if (cell.getColumnIndex() == c2) { pay = cell.getStringCellValue(); } if (cell.getColumnIndex() == c3) { svc = cell.getStringCellValue(); } if (cell.getColumnIndex() == c4) { per = cell.getStringCellValue(); } break; case Cell.CELL_TYPE_BOOLEAN: //System.out.print(cell.getBooleanCellValue()); break; case Cell.CELL_TYPE_NUMERIC: //System.out.print(cell.getNumericCellValue()); if (cell.getColumnIndex() == c5) { dval = cell.getNumericCellValue(); } if (cell.getColumnIndex() == c6) { cval = cell.getNumericCellValue(); } break; } } } if (rec.length() == 5 || rec.length() == 8) { rpps = rec + "-" + pay + "-" + per + "-" + svc; //System.out.print(rpps+"|"+dval+"|"+cval); //System.out.println("insert into "+tbl+" (rpps,sdrval) values(\""+rpps+"\","+dval+")"); //System.out.println(); // ADD insert Query to Array sqlstr = "insert into " + tbl + " (rpps,sdrval) values(\"" + rpps + "\"," + dval + ")"; ar.add(sqlstr); //stmt.executeUpdate("insert into "+tbl+" (rpps,sdrval) values(\""+rpps+"\","+dval+")"); } } workbook.close(); inputStream.close(); return ar; }
From source file:javaapp.ParseDebtorTransactionsData.java
public static ArrayList<String> parseReport(String name, int c1, int c2, int c3, int c4, int c5, int c6, String tbl) throws IOException { String excelFilePath = "S9/GBRCNCOR.xlsx"; FileInputStream inputStream = new FileInputStream(new File(excelFilePath)); ArrayList<String> ar = new ArrayList<String>(); String sqlstr = ""; Workbook workbook = new XSSFWorkbook(inputStream); //Sheet uninv_open = workbook.getSheetAt(sno); Sheet uninv_open = workbook.getSheet(name); //String sname = workbook.getSheetName(sno); System.out.println("Parsing Sheet Name : " + name + " ---> " + tbl); Iterator<Row> iterator = uninv_open.iterator(); String rec = ""; String pay = ""; String per = ""; String svc = ""; double dval = 0; double cval = 0; String rpps = ""; String filter = ""; while (iterator.hasNext()) { Row nextRow = iterator.next();/*from w ww . j a va 2s . com*/ Iterator<Cell> cellIterator = nextRow.cellIterator(); dval = 0; cval = 0; while (cellIterator.hasNext()) { Cell cell = cellIterator.next(); if (cell.getColumnIndex() == 23 || cell.getColumnIndex() == c1 || cell.getColumnIndex() == c2 || cell.getColumnIndex() == c3 || cell.getColumnIndex() == c4 || cell.getColumnIndex() == c5 || cell.getColumnIndex() == c6) { switch (cell.getCellType()) { case Cell.CELL_TYPE_STRING: if (cell.getColumnIndex() == c1) { rec = cell.getStringCellValue(); } if (cell.getColumnIndex() == c2) { pay = cell.getStringCellValue(); } if (cell.getColumnIndex() == c3) { svc = cell.getStringCellValue(); } if (cell.getColumnIndex() == c4) { per = cell.getStringCellValue(); } if (cell.getColumnIndex() == 23) { filter = cell.getStringCellValue(); } break; case Cell.CELL_TYPE_BOOLEAN: //System.out.print(cell.getBooleanCellValue()); break; case Cell.CELL_TYPE_NUMERIC: //System.out.print(cell.getNumericCellValue()); if (cell.getColumnIndex() == c5) { dval = cell.getNumericCellValue(); } if (cell.getColumnIndex() == c6) { cval = cell.getNumericCellValue(); } break; } } } if (rec.length() == 5 || rec.length() == 8) { rpps = rec + "-" + pay + "-" + per + "-" + svc; if (tbl.equalsIgnoreCase("open") || tbl.equalsIgnoreCase("close")) { if (filter.equalsIgnoreCase("Missing Invoice") || filter.equalsIgnoreCase("Unreconciled") || filter.equalsIgnoreCase("")) { continue; } } // if(name.equalsIgnoreCase("Settled Transactions-Funds-Paid")){ //System.out.println(rpps+"|"+dval+"|"+cval); //} //System.out.println("insert into "+tbl+" (rpps,sdrval) values(\""+rpps+"\","+dval+")"); //System.out.println(); // ADD insert Query to Array sqlstr = "insert into " + tbl + " (rpps,sdrval) values(\"" + rpps + "\"," + dval + ")"; ar.add(sqlstr); //stmt.executeUpdate("insert into "+tbl+" (rpps,sdrval) values(\""+rpps+"\","+dval+")"); } } workbook.close(); inputStream.close(); return ar; }
From source file:javaapp.SimpleExcelReaderExample.java
public static ArrayList<String> parseReport(int sno, int c1, int c2, int c3, int c4, int c5, int c6, String tbl) throws IOException { String excelFilePath = "GBRCNCOR.xlsx"; FileInputStream inputStream = new FileInputStream(new File(excelFilePath)); ArrayList<String> ar = new ArrayList<String>(); String sqlstr = ""; Workbook workbook = new XSSFWorkbook(inputStream); //Sheet uninv_open = workbook.getSheetAt(sno); Sheet uninv_open = workbook.getSheetAt(sno); String sname = workbook.getSheetName(sno); System.out.println("Parsing Sheet Number ---> " + sno + "---> Name : " + sname + " ---> " + tbl); Iterator<Row> iterator = uninv_open.iterator(); String rec = ""; String pay = ""; String per = ""; String svc = ""; double dval = 0; double cval = 0; String rpps = ""; while (iterator.hasNext()) { Row nextRow = iterator.next();/*from w w w .ja va 2 s . c o m*/ Iterator<Cell> cellIterator = nextRow.cellIterator(); dval = 0; cval = 0; while (cellIterator.hasNext()) { Cell cell = cellIterator.next(); if (cell.getColumnIndex() == c1 || cell.getColumnIndex() == c2 || cell.getColumnIndex() == c3 || cell.getColumnIndex() == c4 || cell.getColumnIndex() == c5 || cell.getColumnIndex() == c6) { switch (cell.getCellType()) { case Cell.CELL_TYPE_STRING: if (cell.getColumnIndex() == c1) { rec = cell.getStringCellValue(); } if (cell.getColumnIndex() == c2) { pay = cell.getStringCellValue(); } if (cell.getColumnIndex() == c3) { svc = cell.getStringCellValue(); } if (cell.getColumnIndex() == c4) { per = cell.getStringCellValue(); } break; case Cell.CELL_TYPE_BOOLEAN: //System.out.print(cell.getBooleanCellValue()); break; case Cell.CELL_TYPE_NUMERIC: //System.out.print(cell.getNumericCellValue()); if (cell.getColumnIndex() == c5) { dval = cell.getNumericCellValue(); } if (cell.getColumnIndex() == c6) { cval = cell.getNumericCellValue(); } break; } } } if (rec.length() == 5 || rec.length() == 8) { rpps = rec + "-" + pay + "-" + per + "-" + svc; //System.out.print(rpps+"|"+dval+"|"+cval); //System.out.println("insert into "+tbl+" (rpps,sdrval) values(\""+rpps+"\","+dval+")"); //System.out.println(); // ADD insert Query to Array sqlstr = "insert into " + tbl + " (rpps,sdrval) values(\"" + rpps + "\"," + dval + ")"; ar.add(sqlstr); //stmt.executeUpdate("insert into "+tbl+" (rpps,sdrval) values(\""+rpps+"\","+dval+")"); } } workbook.close(); inputStream.close(); return ar; }
From source file:kupkb_experiments.ExperimentSpreadSheetParser.java
License:Open Source License
public IRI lookupId(Cell cell, String value) { int colIndex = cell.getColumnIndex(); int rowIndex = cell.getRowIndex(); Collection<OntologyTermValidation> validations = validationManager.getContainingValidations( new Range(workbook.getSheet(0), colIndex + 1, rowIndex, colIndex + 1, rowIndex)); for (OntologyTermValidation v : validations) { OntologyTermValidationDescriptor desc = v.getValidationDescriptor(); for (Term t : desc.getTerms()) { if (t.getName().toLowerCase().equals(value.toLowerCase())) { if (t.getIRI().toString().contains("e-lico.eu")) { return IRI.create(t.getIRI().toString().replace("e-lico.eu", "kupkb.org")); }/* w w w . j a v a 2s . co m*/ return t.getIRI(); } } } return null; }
From source file:kupkb_experiments.ExperimentSpreadSheetParser.java
License:Open Source License
private String getValueForKey(Cell cell) { int colIndex = cell.getColumnIndex(); int rowIndex = cell.getRowIndex(); // System.err.println(cell.getStringCellValue() + " col" + colIndex + " row " + rowIndex); Cell nextCell = sheet.getRow(rowIndex).getCell(colIndex + 1); if (nextCell != null) { return nextCell.getStringCellValue(); }/*w w w .ja va 2 s . com*/ return ""; }
From source file:kupkb_experiments.ExperimentSpreadSheetParser.java
License:Open Source License
private void firstPass(HSSFRow row) { // first pass, looking for experiment ID and where the role and compound list are located Iterator i = row.cellIterator(); while (i.hasNext()) { Cell cell = (Cell) i.next(); // System.out.println(cell.getCellType()); cell.setCellType(HSSFCell.CELL_TYPE_STRING); // if (cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC) { ///*from w ww . j a va 2 s . c o m*/ // } if (SpreadhseetVocabulary.isValid(cell.getStringCellValue())) { // put this in the map, and the value of the next cell if (keyValue.get(cell.getStringCellValue().toLowerCase()) == null) { keyValue.put(cell.getStringCellValue().toLowerCase(), new ArrayList<Cell>()); } keyValue.get(cell.getStringCellValue().toLowerCase()).add(cell); if (cell.getStringCellValue().toLowerCase().equals(SpreadhseetVocabulary.ROLE.getKeyName())) { roleCell.add(cell); } else if (cell.getStringCellValue().toLowerCase() .equals(SpreadhseetVocabulary.GENE_SYMBOL.getKeyName())) { compoundListStart = row.getRowNum() + 1; compoundAttributeToColumn.put(SpreadhseetVocabulary.GENE_SYMBOL.getKeyName(), cell.getColumnIndex()); } // else if (cell.getStringCellValue().toLowerCase().equals(SpreadhseetVocabulary.GENE_SYMBOL.getKeyName()) && cell.getColumnIndex() != 9) { // compoundAttributeToColumn.put(SpreadhseetVocabulary.GENE_SYMBOL.getKeyName(), cell.getColumnIndex()); // } else if (cell.getStringCellValue().toLowerCase().equals(SpreadhseetVocabulary.GENE_ID.getKeyName()) && cell.getColumnIndex() != 9) { compoundAttributeToColumn.put(SpreadhseetVocabulary.GENE_ID.getKeyName(), cell.getColumnIndex()); } else if (cell.getStringCellValue().toLowerCase() .equals(SpreadhseetVocabulary.ENTREZ_GENE_ID.getKeyName()) && cell.getColumnIndex() != 9) { compoundAttributeToColumn.put(SpreadhseetVocabulary.ENTREZ_GENE_ID.getKeyName(), cell.getColumnIndex()); } else if (cell.getStringCellValue().toLowerCase() .equals(SpreadhseetVocabulary.UNIPROT_ID.getKeyName()) && cell.getColumnIndex() != 9) { compoundAttributeToColumn.put(SpreadhseetVocabulary.UNIPROT_ID.getKeyName(), cell.getColumnIndex()); } else if (cell.getStringCellValue().toLowerCase() .equals(SpreadhseetVocabulary.UNIPROT_ACC.getKeyName()) && cell.getColumnIndex() != 9) { compoundAttributeToColumn.put(SpreadhseetVocabulary.UNIPROT_ACC.getKeyName(), cell.getColumnIndex()); } else if (cell.getStringCellValue().toLowerCase() .equals(SpreadhseetVocabulary.HMDB_ID.getKeyName()) && cell.getColumnIndex() != 9) { compoundAttributeToColumn.put(SpreadhseetVocabulary.HMDB_ID.getKeyName(), cell.getColumnIndex()); } else if (cell.getStringCellValue().toLowerCase() .equals(SpreadhseetVocabulary.MICROCOSM.getKeyName())) { compoundAttributeToColumn.put(SpreadhseetVocabulary.MICROCOSM.getKeyName(), cell.getColumnIndex()); } else if (cell.getStringCellValue().toLowerCase() .equals(SpreadhseetVocabulary.EXPRESSION_STRENGTH.getKeyName())) { compoundAttributeToColumn.put(SpreadhseetVocabulary.EXPRESSION_STRENGTH.getKeyName(), cell.getColumnIndex()); } else if (cell.getStringCellValue().toLowerCase() .equals(SpreadhseetVocabulary.DIFFERENTIAL.getKeyName())) { compoundAttributeToColumn.put(SpreadhseetVocabulary.DIFFERENTIAL.getKeyName(), cell.getColumnIndex()); } else if (cell.getStringCellValue().toLowerCase() .equals(SpreadhseetVocabulary.RATIO.getKeyName())) { compoundAttributeToColumn.put(SpreadhseetVocabulary.RATIO.getKeyName(), cell.getColumnIndex()); } else if (cell.getStringCellValue().toLowerCase() .equals(SpreadhseetVocabulary.P_VALUE.getKeyName())) { compoundAttributeToColumn.put(SpreadhseetVocabulary.P_VALUE.getKeyName(), cell.getColumnIndex()); } else if (cell.getStringCellValue().toLowerCase().equals(SpreadhseetVocabulary.FDR.getKeyName())) { compoundAttributeToColumn.put(SpreadhseetVocabulary.FDR.getKeyName(), cell.getColumnIndex()); } } } }
From source file:Loader.LoadDataset.java
/** * * Load the dataset where the attribute loaded * is determined by @param idx1 and @param idx2 * and put them in @attribute dataset//w w w .j a va2s. c o m * */ public void setData(Set<Integer> excluded, int idx1, int idx2) { // Create @attribute rowIterator to iterate every rows Iterator<Row> rowIterator = spreadsheet.iterator(); // Assign @attribute row with the first row row = (XSSFRow) rowIterator.next(); // Iterate as long as rowIterator isn't // the last row while (rowIterator.hasNext()) { // Attribute that will be used to contain the atttribute // in a data (row) List<Double> data_row = new ArrayList<>(); // Assign @attribute row with next row row = (XSSFRow) rowIterator.next(); // Create @attribute cellIterator to iterate every // cells in a row Iterator<Cell> cellIterator = row.cellIterator(); // Iterate as long as cellIterator isn't // the last cell while (cellIterator.hasNext()) { // Create @attribute cell and assign it with // next cell Cell cell = cellIterator.next(); // Just take the selected attributes (determined // by column @param attr1 and column @param attr2) if (excluded.contains(cell.getColumnIndex())) { continue; } else if (cell.getColumnIndex() == row.getLastCellNum() - 1) { if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) { Double res = cell.getNumericCellValue(); datalabel.add(String.valueOf(res.intValue())); } else { datalabel.add(cell.getStringCellValue()); } } else if ((cell.getColumnIndex() == idx1) || (cell.getColumnIndex() == idx2)) { data_row.add(cell.getNumericCellValue()); } } // Insert the data into @attribute dataset dataset.add(data_row); } }
From source file:Logic.ReadDoctorsFromExcel.java
public void readFromExcel(String file, JTable table) throws IOException { XSSFWorkbook wb = new XSSFWorkbook(new FileInputStream(file)); XSSFSheet sheet = wb.getSheetAt(0);/*from w w w.j a va 2 s . com*/ Iterator<Row> it = sheet.iterator(); while (it.hasNext()) { Row row = it.next(); Iterator<Cell> cells = row.iterator(); while (cells.hasNext()) { Cell cell = cells.next(); int cellIndex = cell.getColumnIndex(); switch (cellIndex) { case 0: name = cell.getStringCellValue(); break; case 1: if (Cell.CELL_TYPE_NUMERIC == cell.getCellType()) { snils = String.valueOf((int) cell.getNumericCellValue()); break; } if (Cell.CELL_TYPE_STRING == cell.getCellType()) { snils = cell.getStringCellValue(); break; } break; case 2: if (Cell.CELL_TYPE_NUMERIC == cell.getCellType()) { v002 = String.valueOf((int) cell.getNumericCellValue()); break; } if (Cell.CELL_TYPE_STRING == cell.getCellType()) { v002 = cell.getStringCellValue(); break; } break; case 3: if (Cell.CELL_TYPE_NUMERIC == cell.getCellType()) { v015 = String.valueOf((int) cell.getNumericCellValue()); break; } if (Cell.CELL_TYPE_STRING == cell.getCellType()) { v015 = cell.getStringCellValue(); break; } break; default: System.out.print("|"); break; } } DefaultTableModel model = (DefaultTableModel) table.getModel(); String[] data = { name, snils, v002, v015 }; model.addRow(data); removeAllFields(); } }
From source file:mongodbutils.Filehandler.java
public boolean processFile(String filePath, MongodbConnection mc, String strdbName, String strCollName) throws IOException { this.mc = mc; FileInputStream fileIn = null; try {/*from ww w .j a v a2 s .co m*/ fileIn = new FileInputStream(filePath); POIFSFileSystem fs = new POIFSFileSystem(fileIn); HSSFWorkbook wb = new HSSFWorkbook(fs); HSSFSheet sheet = wb.getSheetAt(0); Object objReturn = null; //Read in first row as field names Row rowH = sheet.getRow(sheet.getFirstRowNum()); String fields[] = new String[sheet.getRow(0).getLastCellNum()]; for (Cell cell : rowH) { objReturn = null; objReturn = getCellValue(cell); fields[cell.getColumnIndex()] = objReturn.toString(); } //loop thru all cells with values int rowcount = 0; for (Row row : sheet) { if (row.getRowNum() == 0) { continue; //skip first row } JSONObject obj = new JSONObject(); for (Cell cell : row) { if (fields.length < cell.getColumnIndex()) { continue; //only export column if we have header set } objReturn = null; objReturn = getCellValue(cell); if (!objReturn.toString().equals("")) { if (objReturn instanceof Double) { obj.put(fields[cell.getColumnIndex()], objReturn); } else if (objReturn instanceof String) { if (objReturn.toString().contains("$date")) { JSONParser parser = new JSONParser(); try { obj.put(fields[cell.getColumnIndex()], parser.parse(objReturn.toString())); } catch (ParseException ex) { Logger.getLogger(Filehandler.class.getName()).log(Level.SEVERE, null, ex); } } else { obj.put(fields[cell.getColumnIndex()], objReturn); } } } } rowcount += 1; mc.insertJSON(strdbName, strCollName, obj.toJSONString()); } return true; } catch (FileNotFoundException ex) { Logger.getLogger(Filehandler.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(Filehandler.class.getName()).log(Level.SEVERE, null, ex); } catch (Exception e) { Logger.getLogger(Filehandler.class.getName()).log(Level.SEVERE, null, e); } finally { if (fileIn != null) { fileIn.close(); } } return false; }
From source file:mpqq.MPQQ.java
private static XSSFWorkbook procTab1(XSSFWorkbook referenceWB, XSSFWorkbook mpqqWB, int referenceFirstRow) { XSSFSheet trackerTab = referenceWB.getSheetAt(USE_FOR_TAB1); XSSFSheet tab1 = mpqqWB.getSheetAt(1); //Iterator<Row> rowIterator = trackerTab.iterator(); DataFormatter df = new DataFormatter(); //MPQQ first row int rowIdx = 11; for (int refCurRow = referenceFirstRow; refCurRow <= trackerTab.getLastRowNum(); refCurRow++) { Row row = trackerTab.getRow(refCurRow); //Check if row is visible if (!row.getZeroHeight() || (row.isFormatted() && row.getRowStyle().getHidden())) { int colIdx = 1; //Iterate trough the Columns Iterator<Cell> cellIterator = row.cellIterator(); while (cellIterator.hasNext()) { Cell cell = cellIterator.next(); switch (cell.getColumnIndex()) { case 3: Cell currentCell = checkRowCellExists(tab1, rowIdx, colIdx); currentCell.setCellValue(df.formatCellValue(row.getCell(T2PEPSICO_STOCK_CODE))); //Go to next Column colIdx++;//w ww. ja v a2 s. c o m break; case 4: break; default: } } //Jump Next Row rowIdx++; } } return mpqqWB; }