List of usage examples for org.apache.poi.ss.usermodel Cell getNumericCellValue
double getNumericCellValue();
From source file:jexcel4py.Jexcel4py.java
private void copyCell(Cell rdCell, Cell wrCell) { // wrCell.setCellStyle(rdCell.getCellStyle()); // wrCell.setCellType(rdCell.getCellType()); int cellStyle = rdCell.getCellType(); String rdCellValue = rdCell.getStringCellValue(); switch (cellStyle) { case Cell.CELL_TYPE_BLANK: wrCell.setCellValue("heys"); break;/*from w w w .ja v a2 s . co m*/ case Cell.CELL_TYPE_BOOLEAN: wrCell.setCellValue(rdCell.getBooleanCellValue()); break; case Cell.CELL_TYPE_ERROR: wrCell.setCellValue(rdCell.getErrorCellValue()); break; case Cell.CELL_TYPE_FORMULA: wrCell.setCellValue(rdCell.getCellFormula()); break; case Cell.CELL_TYPE_NUMERIC: wrCell.setCellValue(rdCell.getNumericCellValue()); break; case Cell.CELL_TYPE_STRING: wrCell.setCellValue(rdCell.getStringCellValue()); break; default: wrCell.setCellValue("heys"); break; } }
From source file:jexcelcompi.JExcelCompi.java
public void ejemplo() throws FileNotFoundException, IOException { FileInputStream fis = new FileInputStream(new File("hoja2.xls")); HSSFWorkbook wb = new HSSFWorkbook(fis); HSSFSheet sheet = wb.getSheetAt(0);//from ww w.j av a 2 s . c o m FormulaEvaluator formulaEvaluator = wb.getCreationHelper().createFormulaEvaluator(); int x = 0; for (Row row : sheet) { for (Cell cell : row) { switch (formulaEvaluator.evaluateInCell(cell).getCellType()) { case Cell.CELL_TYPE_NUMERIC: { System.out.println(cell.getNumericCellValue() + "\t\t"); } //case Cell.CELL_TYPE_STRING: //System.out.println(cell.getStringCellValue()+"\t\tcadena"); x++; } } System.out.println(); } }
From source file:joinery.impl.Serialization.java
License:Open Source License
private static final Object readCell(final Cell cell) { switch (cell.getCellType()) { case Cell.CELL_TYPE_NUMERIC: if (DateUtil.isCellDateFormatted(cell)) { return DateUtil.getJavaDate(cell.getNumericCellValue()); }// w ww .j a v a 2s. c o m return cell.getNumericCellValue(); case Cell.CELL_TYPE_BOOLEAN: return cell.getBooleanCellValue(); default: return cell.getStringCellValue(); } }
From source file:jp.co.orangeright.crossheadofficesample2.jsf.ItemFileInterfaceContoroller.java
private String getTodenExcelCellValue(Cell cell) { int cellType = cell.getCellType(); switch (cellType) { case Cell.CELL_TYPE_BLANK: return ""; case Cell.CELL_TYPE_NUMERIC: return Integer.toString(Double.valueOf(cell.getNumericCellValue()).intValue()); default:/*from w w w . j a va2s .c om*/ return cell.getStringCellValue(); } }
From source file:jp.qpg.Tool.java
License:Apache License
/** * get cell value//from w w w. j ava 2 s. c om * * @param cell cell * @return cell value */ public static Optional<String> cellValue(Cell cell) { String text = null; try { text = formatter.formatAsString(cell, Locale.JAPAN); } catch (IllegalStateException e) { switch (cell.getCellType()) { case BOOLEAN: text = String.valueOf(cell.getBooleanCellValue()); break; case STRING: text = cell.getStringCellValue(); break; case NUMERIC: text = String.valueOf(cell.getNumericCellValue()); break; case ERROR: text = String.valueOf(cell.getErrorCellValue()); break; case BLANK: break; case FORMULA: break; case _NONE: break; } } return Optional.ofNullable(text).filter(((Predicate<String>) String::isEmpty).negate()); }
From source file:jp.ryoyamamoto.poiutils.Cells.java
License:Apache License
private static void copyCellValue(Cell source, Cell target) { switch (source.getCellType()) { case Cell.CELL_TYPE_NUMERIC: target.setCellValue(source.getNumericCellValue()); break;/*from ww w .j a v a 2s. co m*/ case Cell.CELL_TYPE_STRING: target.setCellValue(source.getRichStringCellValue()); break; case Cell.CELL_TYPE_FORMULA: target.setCellFormula(source.getCellFormula()); break; case Cell.CELL_TYPE_BLANK: break; case Cell.CELL_TYPE_BOOLEAN: target.setCellValue(source.getBooleanCellValue()); break; case Cell.CELL_TYPE_ERROR: target.setCellErrorValue(source.getErrorCellValue()); break; } }
From source file:jschsftp.JSCHsftp.java
private static String getCellValue(Cell cell) { String strCellValue = ""; if (cell == null) return ""; switch (cell.getCellType()) { case Cell.CELL_TYPE_STRING: strCellValue = cell.getStringCellValue(); break;//w w w. ja v a2 s. c om case Cell.CELL_TYPE_NUMERIC: strCellValue = "" + cell.getNumericCellValue(); break; case Cell.CELL_TYPE_BOOLEAN: strCellValue = "" + cell.getBooleanCellValue(); break; default: break; } return strCellValue; }
From source file:jst.DataSet.java
public void addDataSetExcel(String fileLearning, String fileTesting) throws IOException { FileInputStream file = new FileInputStream(new File(fileLearning)); XSSFWorkbook workbook = new XSSFWorkbook(file); XSSFSheet sheet = workbook.getSheetAt(0); Iterator<Row> rowIterator = sheet.iterator(); while (rowIterator.hasNext()) { Row row = rowIterator.next();/* w w w . j a va2 s . c o m*/ Iterator<Cell> cellIterator = row.cellIterator(); String data[] = new String[7]; int w = 0; while (cellIterator.hasNext()) { Cell cell = cellIterator.next(); switch (cell.getCellType()) { case Cell.CELL_TYPE_NUMERIC: data[w] = String.valueOf(cell.getNumericCellValue()); break; case Cell.CELL_TYPE_STRING: data[w] = cell.getStringCellValue(); break; } w++; } CarEvaluation ce = new CarEvaluation(data[0], data[1], data[2], data[3], data[4], data[5], data[6]); dataSetLearning.add(ce); } file.close(); file = new FileInputStream(new File(fileTesting)); workbook = new XSSFWorkbook(file); sheet = workbook.getSheetAt(0); rowIterator = sheet.iterator(); while (rowIterator.hasNext()) { Row row = rowIterator.next(); Iterator<Cell> cellIterator = row.cellIterator(); String data[] = new String[7]; int w = 0; while (cellIterator.hasNext()) { Cell cell = cellIterator.next(); switch (cell.getCellType()) { case Cell.CELL_TYPE_NUMERIC: data[w] = String.valueOf((int) cell.getNumericCellValue()); break; case Cell.CELL_TYPE_STRING: data[w] = cell.getStringCellValue(); break; } w++; } CarEvaluation ce = new CarEvaluation(data[0], data[1], data[2], data[3], data[4], data[5], data[6]); dataSetTesting.add(ce); } }
From source file:KTCNPM.MainForm.java
private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton9ActionPerformed try {// w ww . j ava2s . c o m JFileChooser chooser = new JFileChooser(); chooser.showOpenDialog(null); chooser.setSize(50, 5000); File file = chooser.getSelectedFile(); FileInputStream in = new FileInputStream(file); try { XSSFWorkbook workbook = new XSSFWorkbook(in); XSSFSheet mySheet = workbook.getSheetAt(0); Iterator<Row> rowIterator = mySheet.iterator(); while (rowIterator.hasNext()) { Row row = rowIterator.next(); Iterator<Cell> cellIterator = row.cellIterator(); while (cellIterator.hasNext()) { Cell cell = cellIterator.next(); switch (cell.getCellType()) { case Cell.CELL_TYPE_STRING: // b? qua khi xu break; case Cell.CELL_TYPE_NUMERIC: // ly khi data l s arraylist.add((int) cell.getNumericCellValue()); break; } } } } catch (IOException ex) { Logger.getLogger(MainForm.class.getName()).log(Level.SEVERE, null, ex); } } catch (FileNotFoundException ex) { Logger.getLogger(MainForm.class.getName()).log(Level.SEVERE, null, ex); } System.out.println(arraylist.size()); for (int i = 0; i < arraylist.size(); i++) { System.out.println(arraylist.get(i)); } if (arraylist.size() == 34) { // taw int num1 = arraylist.get(0); int num2 = arraylist.get(1); int num3 = arraylist.get(2); int sum_taw = num1 * 1 + num2 * 2 + num3 * 3; this.taw.setText(Integer.toString(sum_taw)); this.listTAW = new ArrayList<>(); listTAW.add("STT"); listTAW.add("Loi tc nhn"); listTAW.add("S tc nhn"); listTAW.add("Tr?ng s"); listTAW.add("Tng"); listTAW.add("1"); listTAW.add("?n gin"); listTAW.add(Integer.toString(num1)); listTAW.add("1"); listTAW.add(Integer.toString(num1)); listTAW.add("2"); listTAW.add("Trung bnh"); listTAW.add(Integer.toString(num2)); listTAW.add("2"); listTAW.add(Integer.toString(num2 * 2)); listTAW.add("3"); listTAW.add("Phc tp"); listTAW.add(Integer.toString(num3)); listTAW.add("3"); listTAW.add(Integer.toString(num3 * 3)); listTAW.add(" "); listTAW.add("Cng (1+2+3)"); listTAW.add("TAW"); listTAW.add(""); listTAW.add(Integer.toString(sum_taw)); // tbf int tbf1 = arraylist.get(3); int tbf2 = arraylist.get(4); int tbf3 = arraylist.get(5); float tbf_sum1 = tbf1 * 5 + tbf2 * 10 + tbf3 * 15; int tbf4 = arraylist.get(6); int tbf5 = arraylist.get(7); int tbf6 = arraylist.get(8); float tbf_sum2 = (float) ((tbf4 * 5 + tbf5 * 10 + tbf6 * 15) * 1.2); int tbf7 = arraylist.get(9); int tbf8 = arraylist.get(10); int tbf9 = arraylist.get(11); float tbf_sum3 = (float) ((tbf7 * 5 + tbf8 * 10 + tbf9 * 15) * 1.5); this.tbf.setText(Float.toString(tbf_sum1 + tbf_sum2 + tbf_sum3)); this.listTBF = new ArrayList<>(); listTBF.add("STT"); listTBF.add("Loi"); listTBF.add("S tr?ng hp s dng"); listTBF.add("?im ca tng loi tr?ng hp s dng"); listTBF.add("1"); listTBF.add("B"); listTBF.add(""); listTBF.add(""); listTBF.add(""); listTBF.add("?n gin"); listTBF.add(Integer.toString(tbf1)); listTBF.add(Integer.toString(tbf1 * 5)); listTBF.add(""); listTBF.add("Trung bnh"); listTBF.add(Integer.toString(tbf2)); listTBF.add(Integer.toString(tbf2 * 10)); listTBF.add(""); listTBF.add("Phc tp"); listTBF.add(Integer.toString(tbf3)); listTBF.add(Integer.toString(tbf3 * 15)); listTBF.add("2"); listTBF.add("M"); listTBF.add(" "); listTBF.add(" "); listTBF.add(""); listTBF.add("?n gin"); listTBF.add(Integer.toString(tbf4)); listTBF.add(Float.toString((float) (tbf4 * 5 * 1.2))); listTBF.add(""); listTBF.add("Trung bnh"); listTBF.add(Integer.toString(tbf5)); listTBF.add(Float.toString((float) (tbf5 * 10 * 1.2))); listTBF.add(""); listTBF.add("Phc tp"); listTBF.add(Integer.toString(tbf6)); listTBF.add(Float.toString((float) (tbf6 * 15 * 1.2))); listTBF.add("3"); listTBF.add("T"); listTBF.add(" "); listTBF.add(" "); listTBF.add(""); listTBF.add("?n gin"); listTBF.add(Integer.toString(tbf7)); listTBF.add(Float.toString((float) (tbf7 * 5 * 1.5))); listTBF.add(""); listTBF.add("Trung bnh"); listTBF.add(Integer.toString(tbf8)); listTBF.add(Float.toString((float) (tbf8 * 10 * 1.5))); listTBF.add(""); listTBF.add("Phc tp"); listTBF.add(Integer.toString(tbf9)); listTBF.add(Float.toString((float) (tbf9 * 15 * 1.5))); listTBF.add(""); listTBF.add("Cng 1+2+3"); listTBF.add("TBF"); listTBF.add(Float.toString(tbf_sum1 + tbf_sum2 + tbf_sum3)); // tcf int f1 = arraylist.get(12); int f2 = arraylist.get(13); int f3 = arraylist.get(14); int f4 = arraylist.get(15); int f5 = arraylist.get(16); int f6 = arraylist.get(17); int f7 = arraylist.get(18); int f8 = arraylist.get(19); int f9 = arraylist.get(20); int f10 = arraylist.get(21); int f11 = arraylist.get(22); int f12 = arraylist.get(23); int f13 = arraylist.get(24); float tfw = (float) (f1 * 2 + f2 + f3 + f4 + f5 + f6 * 0.5 + f7 * 0.5 + f8 * 2 + f9 + f10 + f11 + f12 + f13); float TCF = (float) (0.6 + (0.01 * tfw)); this.tcf.setText(Float.toString(TCF)); ArrayList<String> l = new ArrayList<>(); l.add("TT"); l.add("Cc h s"); l.add("Tr?ng s"); l.add("Gi tr xp hng"); l.add("Kt qu"); l.add("I"); l.add("H s k thut - cng ngh (TFW)"); l.add(""); l.add(""); l.add(Float.toString(tfw)); l.add("1"); l.add("H thng phn tn"); l.add("2"); l.add(Integer.toString(f1)); l.add(Integer.toString(f1 * 2)); l.add("2"); l.add("Tnh cht p ng tc th?i hoc yu cu m bo cht lng"); l.add("1"); l.add(Integer.toString(f2)); l.add(Integer.toString(f2)); l.add("3"); l.add("Hiu qu s dng trc tuyn"); l.add("1"); l.add(Integer.toString(f3)); l.add(Integer.toString(f3)); l.add("4"); l.add("? phc tp ca x l bn trong"); l.add("1"); l.add(Integer.toString(f4)); l.add(Integer.toString(f4)); l.add("5"); l.add("M ngun phi ti s dng c"); l.add("1"); l.add(Integer.toString(f5)); l.add(Integer.toString(f5)); l.add("6"); l.add("D ci t"); l.add("0.5"); l.add(Integer.toString(f6)); l.add(Float.toString((float) (f6 * 0.5))); l.add("7"); l.add("D s dng"); l.add("0.5"); l.add(Integer.toString(f7)); l.add(Float.toString((float) (f7 * 0.5))); l.add("8"); l.add("Kh nng chuyn i"); l.add("2"); l.add(Integer.toString(f8)); l.add(Integer.toString(f8 * 2)); l.add("9"); l.add("Kh nng d thay i"); l.add("1"); l.add(Integer.toString(f9)); l.add(Integer.toString(f9)); l.add("10"); l.add("S dng ng th?i"); l.add("1"); l.add(Integer.toString(f10)); l.add(Integer.toString(f10)); l.add("11"); l.add("C cc tnh nng bo mt c bit"); l.add("1"); l.add(Integer.toString(f11)); l.add(Integer.toString(f11)); l.add("12"); l.add("Cung cp truy nhp trc tip ti cc phn m?m ca cc hng th ba"); l.add("1"); l.add(Integer.toString(f12)); l.add(Integer.toString(f12)); l.add("13"); l.add("Yu cu phng tin o to c bit cho ng?i s dng"); l.add("1"); l.add(Integer.toString(f13)); l.add(Integer.toString(f13)); l.add("II"); l.add("H s phc tp v? k thut - cng ngh (TCF)"); l.add(""); l.add(""); l.add(Float.toString(TCF)); this.listTCF = new ArrayList<>(); this.listTCF = l; // EF int f111 = arraylist.get(25); int f21 = arraylist.get(26); int f31 = arraylist.get(27); int f41 = arraylist.get(28); int f51 = arraylist.get(29); int f61 = arraylist.get(30); int f71 = arraylist.get(31); int f81 = arraylist.get(32); ArrayList<Integer> list1 = new ArrayList<>(); list1.add(f111); list1.add(f21); list1.add(f31); list1.add(f41); list1.add(f51); list1.add(f61); list1.add(f71); list1.add(f81); ArrayList<Double> trongso = new ArrayList<>(); trongso.add(1.5); trongso.add(0.5); trongso.add(1.0); trongso.add(0.5); trongso.add(1.0); trongso.add(2.0); trongso.add(-1.0); trongso.add(-1.); float es = 0; for (int i = 0; i < 8; i++) { float s = (float) (list1.get(i) * trongso.get(i)); if (s <= 0) { es += 0; } else if (s > 0 && s <= 1) { es += 0.05; } else if (s > 1 && s <= 2) { es += 0.1; } else if (s > 2 && s <= 3) { es += 0.6; } else { es += 1; } } float P; if (es < 1) { P = 48; } else if (es >= 1 && es < 3) { P = 32; } else { P = 20; } float efw = (float) (f111 * 1.5 + f21 * 0.5 + f31 + f41 * 0.5 + f51 + f61 * 2 - f71 - f81); float EF = (float) (1.4 + (-0.03 * efw)); this.ef.setText(Float.toString(EF)); this.p.setText(Float.toString(P)); this.listEF = new ArrayList<>(); listEF.add("TT"); listEF.add("Cc h s tc ng mi tr?ng"); listEF.add("Tr?ng s"); listEF.add("Gi tr xp hng"); listEF.add("Kt qu"); listEF.add("? n nh, kinh nghim"); listEF.add("I"); listEF.add("H s tc ng mi tr?ng v nhm lm vic (EFW)"); listEF.add(""); listEF.add(""); listEF.add(Float.toString(efw)); listEF.add(""); listEF.add(""); listEF.add("?nh gi cho tng thnh vin"); listEF.add(""); listEF.add(""); listEF.add(""); listEF.add(""); listEF.add("1"); listEF.add( "C p dng qui trnh pht trin phn m?m theo mu RUP v c hiu bit v? RUP hoc quy trnh pht trin phn m?m tng ng"); listEF.add("1.5"); listEF.add(Integer.toString(f111)); listEF.add(Float.toString((float) (f111 * 1.5))); listEF.add(Float.toString(giaTriNoiSuy((float) (f111 * 1.5)))); listEF.add("2"); listEF.add("C kinh nghim v? ng dng tng t"); listEF.add("0.5"); listEF.add(Integer.toString(f21)); listEF.add(Float.toString((float) (f21 * 0.5))); listEF.add(Float.toString(giaTriNoiSuy((float) (f21 * 0.5)))); listEF.add("3"); listEF.add("C kinh nghim v? hng i tng"); listEF.add("1"); listEF.add(Integer.toString(f31)); listEF.add(Float.toString((float) (f31))); listEF.add(Float.toString(giaTriNoiSuy((float) (f31)))); listEF.add("4"); listEF.add("C kh nng lnh o Nhm"); listEF.add("0.5"); listEF.add(Integer.toString(f41)); listEF.add(Float.toString((float) (f41 * 0.5))); listEF.add(Float.toString(giaTriNoiSuy((float) (f41 * 0.5)))); listEF.add("5"); listEF.add("Tnh cht nng ng"); listEF.add("1"); listEF.add(Integer.toString(f51)); listEF.add(Float.toString((float) (f51))); listEF.add(Float.toString(giaTriNoiSuy((float) (f51)))); listEF.add(""); listEF.add("?nh gi chung cho D n"); listEF.add(""); listEF.add(""); listEF.add(""); listEF.add(""); listEF.add("6"); listEF.add("? n nh ca cc yu cu"); listEF.add("2"); listEF.add(Integer.toString(f61)); listEF.add(Float.toString((float) (f61 * 2))); listEF.add(Float.toString(giaTriNoiSuy((float) (f61 * 2)))); listEF.add("7"); listEF.add("S dng cc nhn vin lm bn th?i gian"); listEF.add("-1"); listEF.add(Integer.toString(f71)); listEF.add(Float.toString((float) (f71 * -1))); listEF.add("0"); listEF.add("8"); listEF.add("Dng ngn ng lp trnh loi kh"); listEF.add("-1"); listEF.add(Integer.toString(f81)); listEF.add(Float.toString((float) (f81 * -1))); listEF.add("0"); listEF.add("II"); listEF.add("H s phc tp v? mi tr?ng (EF)"); listEF.add(""); listEF.add(""); listEF.add(Float.toString(EF)); listEF.add(""); listEF.add("III"); listEF.add("? n nh kinh nghim (ES)"); listEF.add(""); listEF.add(""); listEF.add(Float.toString(es)); listEF.add(""); listEF.add("IV"); listEF.add("Ni suy th?i gian lao ng (P)"); listEF.add(""); listEF.add(""); listEF.add(Float.toString(P)); listEF.add(""); //H float H; int heso = arraylist.get(33); switch (heso) { case 2: H = (float) (2.65 * 2350000 / (22 * 8)); break; case 3: H = (float) (2.96 * 2350000 / (22 * 8)); break; default: H = (float) (3.27 * 2350000 / (22 * 8)); break; } this.h.setText(Float.toString(H)); // thuc hien tnh ton this.again(); } }
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//from w w w . j a va 2s . 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); } }