Example usage for org.apache.poi.ss.usermodel Cell getNumericCellValue

List of usage examples for org.apache.poi.ss.usermodel Cell getNumericCellValue

Introduction

In this page you can find the example usage for org.apache.poi.ss.usermodel Cell getNumericCellValue.

Prototype

double getNumericCellValue();

Source Link

Document

Get the value of the cell as a number.

Usage

From source file:coolmap.application.io.external.ImportDataFromXLS.java

@Override
public void configure(File... file) {
    //need to popup a secondary dialog; this must be done differently

    try {//  w  w w  .  j av a  2  s .c o m
        File inFile = file[0];
        String fileNameString = inFile.getName().toLowerCase();

        FileInputStream inStream = new FileInputStream(inFile);

        Workbook workbook = null;
        if (fileNameString.endsWith("xls")) {
            workbook = new HSSFWorkbook(inStream);
        } else if (fileNameString.toLowerCase().endsWith("xlsx")) {
            workbook = new XSSFWorkbook(inStream);
        }

        int sheetCount = workbook.getNumberOfSheets();

        String[] sheetNames = new String[sheetCount];

        for (int i = 0; i < sheetNames.length; i++) {
            String sheetName = workbook.getSheetAt(i).getSheetName();

            sheetNames[i] = sheetName == null || sheetName.length() == 0 ? "Untitled" : sheetName;
        }

        //also need to get the top 100 rows + all columns
        DefaultTableModel tableModels[] = new DefaultTableModel[sheetCount];
        Cell cell;
        Row row;

        ArrayList<ArrayList<ArrayList<Object>>> previewData = new ArrayList();
        for (int si = 0; si < sheetCount; si++) {

            //The row iterator automatically skips the blank rows
            //so only need to figure out how many rows to skip; which is nice
            //columns, not the same though
            Sheet sheet = workbook.getSheetAt(si);
            Iterator<Row> rowIterator = sheet.rowIterator();

            int ri = 0;

            ArrayList<ArrayList<Object>> data = new ArrayList<ArrayList<Object>>();

            while (rowIterator.hasNext()) {

                row = rowIterator.next();
                ArrayList<Object> rowData = new ArrayList<>();

                for (int j = 0; j < row.getLastCellNum(); j++) {
                    cell = row.getCell(j);

                    try {
                        if (cell == null) {
                            rowData.add(null);
                        } else if (cell.getCellType() == Cell.CELL_TYPE_BLANK) {
                            rowData.add(null);
                        } else if (cell.getCellType() == Cell.CELL_TYPE_STRING) {
                            rowData.add(cell.getStringCellValue());
                        } else if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
                            rowData.add(cell.getNumericCellValue());
                        } else if (cell.getCellType() == Cell.CELL_TYPE_BOOLEAN) {
                            rowData.add(cell.getBooleanCellValue());
                        } else {
                            rowData.add(cell.toString());
                        }
                    } catch (Exception e) {
                        //
                        CMConsole.logError(" error parsing excel cell: " + cell + ", [" + ri + "," + j + "]");
                        rowData.add(null);
                    }

                }

                data.add(rowData);

                ri++;

                if (ri == previewNum) {
                    break;
                }
            } //end 

            //                System.out.println(data);
            //                now the data is the data
            //                ugh-> this is not a generic importer
            previewData.add(data);

        } //end of iterating all sheets

        ConfigPanel configPanel = new ConfigPanel(sheetNames, previewData);

        //int returnVal = JOptionPane.showMessageDialog(CoolMapMaster.getCMainFrame(), configPanel);
        int returnVal = JOptionPane.showConfirmDialog(CoolMapMaster.getCMainFrame(), configPanel,
                "Import from Excel: " + inFile.getAbsolutePath(), JOptionPane.OK_CANCEL_OPTION,
                JOptionPane.PLAIN_MESSAGE, null);

        if (returnVal == JOptionPane.OK_OPTION) {
            proceed = true;

            inStream.close();
            workbook = null;

            //set parameters
            inFile = file[0];
            importOntology = configPanel.getImportOntology();
            rowStart = configPanel.getRowStart();
            columnStart = configPanel.getColumnStart();
            sheetIndex = configPanel.getSheetIndex();

        } else {
            //mark operation cancelled
            proceed = false;
        }

    } catch (Exception e) {
        CMConsole.logError(" failed to import numeric matrix data from: " + file);
        e.printStackTrace();
    }
}

From source file:coverageqc.data.DoNotCall.java

public static DoNotCall populate(Row xslxHeadingRow, Row xslxDataRow, Integer calltype) {
    DoNotCall donotcall = new DoNotCall();
    int columnNumber;
    int cellIndex;
    String[] headerArray;/*from  w w w .  j a  va 2  s  .  co m*/
    HashMap<String, Integer> headings = new HashMap<String, Integer>();

    columnNumber = xslxHeadingRow.getLastCellNum();
    headerArray = new String[columnNumber];

    Iterator<Cell> cellIterator = xslxHeadingRow.cellIterator();
    while (cellIterator.hasNext()) {
        Cell cell = cellIterator.next();
        cellIndex = cell.getColumnIndex();
        switch (cell.getCellType()) {
        case Cell.CELL_TYPE_BOOLEAN:
            headerArray[cellIndex] = Boolean.toString(cell.getBooleanCellValue());
            break;
        case Cell.CELL_TYPE_NUMERIC:
            headerArray[cellIndex] = Double.toString(cell.getNumericCellValue());
            break;
        case Cell.CELL_TYPE_STRING:
            headerArray[cellIndex] = cell.getStringCellValue();
            break;
        default:
            headerArray[cellIndex] = "";
        }

    } //end while celliterator

    for (int x = 0; x < headerArray.length; x++) {
        headings.put(headerArray[x].substring(0, headerArray[x].indexOf("_")), x);
    }

    //String[] dataArray = xslxDataLine.split("\t");
    if (xslxDataRow.getCell(headings.get("HGVSc")) != null) {
        donotcall.hgvsc = xslxDataRow.getCell(headings.get("HGVSc").intValue()).getStringCellValue();

    }
    //donotcall.hgvsp = xslxDataRow.getCell(headings.get("HGVSp").intValue()).getStringCellValue();
    if (xslxDataRow.getCell(headings.get("ENSP")) != null) {
        donotcall.ensp = xslxDataRow.getCell(headings.get("ENSP").intValue()).getStringCellValue();
    }
    if (xslxDataRow.getCell(headings.get("Transcript")) != null) {
        donotcall.transcript = xslxDataRow.getCell(headings.get("Transcript").intValue()).getStringCellValue();
    } else {
        System.out.println(
                "Transcript_27 column entry is negative!  This is essential to do not call! Do not call list needs to be fixed!  Crashing to prevent abnormal behavior!");
        System.exit(1);
    }
    donotcall.coordinate = (long) xslxDataRow.getCell(headings.get("Coordinate").intValue())
            .getNumericCellValue();

    // CallType is the page of the xlsx :
    // 1 => Always_Not_Real
    // 2 => Not_Real_When_Percentage_Low
    // 3 => Undetermined_Importance
    if (calltype == 1) {
        donotcall.callType = "Don't call, always";
    } else if (calltype == 2) {
        donotcall.callType = "If percentage low, don't call";

    } else {
        donotcall.callType = "On lab list, Unknown significance";
    }

    return donotcall;
}

From source file:csv.impl.ExcelReader.java

License:Open Source License

/**
 * Returns the value of the specified cell.
 * If the cell contained/*from   w  w w  . j a  v  a 2s. c  om*/
 * a formula, the formula is evaluated before returning the row.
 * @param cell cell object
 * @return value of cell
 */
public Object getValue(Cell cell) {
    if (cell == null)
        return null;

    int cellType = cell.getCellType();
    if (cellType == Cell.CELL_TYPE_FORMULA && !isEvaluateFormulas()) {
        cellType = cell.getCachedFormulaResultType();
    }

    switch (cellType) {
    case Cell.CELL_TYPE_STRING:
        return cell.getStringCellValue();
    case Cell.CELL_TYPE_NUMERIC:
        if (DateUtil.isCellDateFormatted(cell)) {
            return cell.getDateCellValue();
        } else {
            return cell.getNumericCellValue();
        }
    case Cell.CELL_TYPE_BLANK:
        return null;
    case Cell.CELL_TYPE_BOOLEAN:
        return cell.getBooleanCellValue();
    case Cell.CELL_TYPE_FORMULA:
        return evaluateCellValue(cell);
    case Cell.CELL_TYPE_ERROR:
        return cell.getErrorCellValue();
    }
    return null;
}

From source file:Dao.XlsBillDao.java

public ArrayList<WorkItemBean> ReadXLS(File f) {
    WorkDao wdao = new WorkDao();
    FileInputStream fis = null;/*from   www.j a  v  a2  s .c  om*/
    ArrayList<WorkItemBean> itm = new ArrayList<WorkItemBean>();
    try {
        String pono = null;
        XSSFRow row = null;
        //fis = new FileInputStream(new File("D:\\WO-2015-2008.xlsx"));
        fis = new FileInputStream(f);
        XSSFWorkbook workbook = new XSSFWorkbook(fis);
        XSSFSheet spreadsheet = workbook.getSheetAt(0);
        Iterator<Row> rowIterator = spreadsheet.iterator();
        int i = 0;
        while (rowIterator.hasNext()) {
            i++;
            row = (XSSFRow) rowIterator.next();
            if (i == 1) {
                Iterator<Cell> cellIterator = row.cellIterator();
                while (cellIterator.hasNext()) {
                    Cell cell = cellIterator.next();
                    if (cell.getColumnIndex() == 0) {
                        pono = cell.getStringCellValue();
                        pono = pono.substring((pono.indexOf(":") + 1));
                    }
                }
            }
            if (i > 2) {
                WorkItemBean bean = new WorkItemBean();
                //                    System.out.println("ROW" + i);
                Iterator<Cell> cellIterator = row.cellIterator();
                while (cellIterator.hasNext()) {

                    Cell cell = cellIterator.next();
                    if (cell.getColumnIndex() >= 0) {
                        //System.out.print("COLUMN");
                        if (cell.getColumnIndex() == 1) {
                            //System.out.print(cell.getColumnIndex() + ":" + cell.getStringCellValue() + " \t ");
                            if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
                                bean.setITEM_ID(String.valueOf(cell.getNumericCellValue()));
                            } else {
                                bean.setITEM_ID(cell.getStringCellValue());
                            }
                        } else if (cell.getColumnIndex() == 2) {
                            //System.out.print(cell.getColumnIndex() + ":" + cell.getStringCellValue() + " \t ");
                            bean.setITEM_DESC(cell.getStringCellValue());
                        } else if (cell.getColumnIndex() == 3) {
                            //System.out.print(cell.getColumnIndex() + ":" + cell.getStringCellValue() + " \t ");
                            bean.setUOM(cell.getStringCellValue());
                        } else if (cell.getColumnIndex() == 4) {
                            if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
                                bean.setQTY((float) cell.getNumericCellValue());
                                //System.out.print(cell.getColumnIndex() + ":" + cell.getNumericCellValue() + " \t ");
                            } else {
                                bean.setQTY(Float.parseFloat(cell.getStringCellValue()));
                                //System.out.print(cell.getColumnIndex() + ":" + cell.getStringCellValue() + " \t ");
                            }
                        } else if (cell.getColumnIndex() == 5) {
                            //System.out.print(cell.getColumnIndex() + ":" + cell.getNumericCellValue() + " \t ");
                            if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
                                bean.setRATE((float) cell.getNumericCellValue());
                            } else {
                                bean.setRATE(Float.parseFloat(cell.getStringCellValue()));
                            }

                        } else if (cell.getColumnIndex() == 7) {

                            if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
                                bean.setPLANT(Integer.toString((int) cell.getNumericCellValue()));
                                //System.out.print(cell.getColumnIndex() + ":" + cell.getNumericCellValue() + " \t ");
                            } else {
                                bean.setPLANT(cell.getStringCellValue());
                                //System.out.print(cell.getColumnIndex() + ":" + cell.getStringCellValue() + " \t ");
                            }
                        } else if (cell.getColumnIndex() == 8) {

                            if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
                                bean.setCC(Integer.toString((int) cell.getNumericCellValue()));
                                //System.out.print(cell.getColumnIndex() + ":" + cell.getNumericCellValue() + " \t ");
                            } else {
                                bean.setCC(cell.getStringCellValue());
                                //System.out.print(cell.getColumnIndex() + ":" + cell.getStringCellValue() + " \t ");
                            }
                        } else if (cell.getColumnIndex() == 9) {
                            if (wdao.isProjWO(pono)) {
                                if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
                                    bean.setPROJ(Integer.toString((int) cell.getNumericCellValue()));
                                    //System.out.print(cell.getColumnIndex() + ":" + cell.getNumericCellValue() + " \t ");
                                } else {
                                    bean.setPROJ(cell.getStringCellValue());
                                    //System.out.print(cell.getColumnIndex() + ":" + cell.getStringCellValue() + " \t ");
                                }
                            } else {
                                bean.setPROJ("-");

                            }
                        } else if (cell.getColumnIndex() == 10) {
                            if (wdao.isProjWO(pono)) {
                                if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
                                    bean.setTASK(Integer.toString((int) cell.getNumericCellValue()));
                                    //System.out.print(cell.getColumnIndex() + ":" + cell.getNumericCellValue() + " \t ");
                                } else {
                                    bean.setTASK(cell.getStringCellValue());
                                    //System.out.print(cell.getColumnIndex() + ":" + cell.getStringCellValue() + " \t ");
                                }
                            } else {
                                bean.setTASK("-");

                            }
                        } else if (cell.getColumnIndex() == 11) {

                            if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
                                bean.setCMT(Integer.toString((int) cell.getNumericCellValue()));
                                //System.out.print(cell.getColumnIndex() + ":" + cell.getNumericCellValue() + " \t ");
                            } else {
                                bean.setCMT(cell.getStringCellValue());
                                //System.out.print(cell.getColumnIndex() + ":" + cell.getStringCellValue() + " \t ");
                            }
                        } else {

                        }
                    }
                }
                //System.out.println();
                itm.add(bean);
            }
        }
        Logger.getLogger(XlsBillDao.class.getName()).log(Level.SEVERE, "READ DONE !!");
        fis.close();
    } catch (FileNotFoundException ex) {
        Logger.getLogger(XlsBillDao.class.getName()).log(Level.SEVERE, "Exception : {0}", ex);
    } catch (IOException ex) {
        Logger.getLogger(XlsBillDao.class.getName()).log(Level.SEVERE, "Exception : {0}", ex);
    } finally {
        try {
            fis.close();
        } catch (IOException ex) {
            Logger.getLogger(XlsBillDao.class.getName()).log(Level.SEVERE, "Exception : {0}", ex);
        }

    }
    for (WorkItemBean i : itm) {
        if (i.getQTY() != 0) {
            Logger.getLogger(XlsBillDao.class.getName()).log(Level.INFO,
                    "ITEM_ID : {0} QTY:{1} PLANT:{2} CC:{3}",
                    new Object[] { i.getITEM_ID(), i.getQTY(), i.getPLANT(), i.getCC() });
        }
    }
    return itm;
}

From source file:Dao.XlsWoDao.java

public ArrayList<WorkItemBean> ReadXLS(File f) {
    Logger.getLogger(XlsWoDao.class.getName()).log(Level.SEVERE, "READ XLS CALLED");
    FileInputStream fis = null;/*from  www.j  a v a  2  s .  com*/
    ArrayList<WorkItemBean> itm = new ArrayList<WorkItemBean>();
    try {
        XSSFRow row = null;
        //  fis = new FileInputStream(new File("D:\\CreateWO_Tmp.xlsx"));
        fis = new FileInputStream(f);
        XSSFWorkbook workbook = new XSSFWorkbook(fis);
        XSSFSheet spreadsheet = workbook.getSheetAt(0);
        Iterator<Row> rowIterator = spreadsheet.iterator();
        int i = 0;
        while (rowIterator.hasNext()) {
            //                System.out.println("NEW ROW");
            i++;
            row = (XSSFRow) rowIterator.next();
            if (i == 1) {
                Iterator<Cell> cellIterator = row.cellIterator();
                while (cellIterator.hasNext()) {
                    Cell cell = cellIterator.next();
                    if (cell.getColumnIndex() == 0) {
                    }
                }
            }
            if (i > 3) {
                WorkItemBean bean = new WorkItemBean();
                // System.out.println("ROW" + i);
                Iterator<Cell> cellIterator = row.cellIterator();
                while (cellIterator.hasNext()) {
                    //                        System.out.println("NEW COLUMN");
                    Cell cell = cellIterator.next();
                    if (cell.getColumnIndex() >= 0) {
                        //   System.out.print("COLUMN");
                        if (cell.getColumnIndex() == 0) {
                            if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
                                int t = (int) cell.getNumericCellValue();
                                bean.setITEM_ID(String.valueOf(t));
                            } else {
                                bean.setITEM_ID(cell.getStringCellValue());
                            }

                        } else if (cell.getColumnIndex() == 1) {
                            if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
                                bean.setRATE((float) cell.getNumericCellValue());
                            } else {
                                bean.setRATE(Float.parseFloat(cell.getStringCellValue()));
                            }
                        } else if (cell.getColumnIndex() == 2) {
                            if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
                                int t = (int) cell.getNumericCellValue();
                                bean.setPLANT(String.valueOf(t));
                            } else {
                                bean.setPLANT(cell.getStringCellValue());
                            }
                        } else if (cell.getColumnIndex() == 3) {
                            if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
                                int t = (int) cell.getNumericCellValue();
                                bean.setPROJ(String.valueOf(t));
                            } else {
                                bean.setPROJ(cell.getStringCellValue());
                            }

                        } else if (cell.getColumnIndex() == 4) {
                            if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
                                int t = (int) cell.getNumericCellValue();
                                bean.setTASK(String.valueOf(t));
                            } else {
                                bean.setTASK(cell.getStringCellValue());
                            }
                        } else if (cell.getColumnIndex() == 5) {
                            if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
                                int t = (int) cell.getNumericCellValue();
                                bean.setCMT(String.valueOf(t));
                            } else {
                                bean.setCMT(cell.getStringCellValue());
                            }
                        }
                    }
                }
                // if (bean.getITEM_ID() != null || !"".equals(bean.getITEM_ID())) {
                itm.add(bean);
                // }
            }
        }

    } catch (FileNotFoundException ex) {
        Logger.getLogger(XlsWoDao.class.getName()).log(Level.SEVERE, "Exception : {0}", ex);
    } catch (IOException ex) {
        Logger.getLogger(XlsWoDao.class.getName()).log(Level.SEVERE, "Exception : {0}", ex);
    } finally {
        try {
            fis.close();
        } catch (IOException ex) {
            Logger.getLogger(XlsWoDao.class.getName()).log(Level.SEVERE, "Exception : {0}", ex);
        }
    }
    return itm;
}

From source file:das.pf.io.IOExcel.java

License:Open Source License

/**
 * Este metodo se encarga de escribir todos los valores correspondientes a las 
 * unidades en dolares, estandares y de valores.
 * //  ww w  . j  ava  2 s .  co m
 * @param target
 *          Instancia que modela la fila sobre la cual se escribiran en la celdas.
 * 
 * @param source
 *          Instancia que modela la fila que contiene las celdas con los datos a escribir.
 * 
 * @param startValues
 *          Indice que marca la primer celda a escribir
 * 
 * @param endValues
 *          Indice que indica la ultima celda sobre la que se debe escribir.
 * 
 * @param indexValuesSource 
 *          Indice que indica la primer celda que contiene los datos a escribir dentro de la fila fuente.
 */
private void writeUnitValues(Row target, Row source, int startValues, int endValues, int indexValuesSource) {
    try {
        for (int indexCell = startValues; indexCell < endValues; indexCell++) {
            if (indexValuesSource == 62 || indexValuesSource == 111)
                indexValuesSource++;

            Cell value = target.createCell(indexCell);
            Cell valueSource = source.getCell(indexValuesSource++);

            if (valueSource != null) {
                if (valueSource.getCellType() == Cell.CELL_TYPE_NUMERIC)
                    value.setCellValue(valueSource.getNumericCellValue());
                else if (valueSource.getCellType() == Cell.CELL_TYPE_STRING)
                    value.setCellValue(Double.parseDouble(valueSource.getRichStringCellValue().getString()));

                value.setCellType(Cell.CELL_TYPE_NUMERIC);
            }

            value = null;
            valueSource = null;
        }
    } catch (NumberFormatException ex) {
        Logger.getLogger(IOExcel.class.getName()).log(Level.SEVERE, ex.getMessage(), ex);

        Util.showException("Ocurrio un error procensado los valores de las unidades", ex);
    }
}

From source file:data.control.dataSheet.java

public ArrayList<Patient> getPatients() {
    ArrayList<XSSFRow> theRows;
    ArrayList<Patient> thePatients = new ArrayList();
    boolean firstRowSkipped = false;

    connect();//from w ww  .j a  va2 s  .  c  om
    theRows = fetchRows();

    // looping through the rows
    Iterator<XSSFRow> rowIterator = theRows.iterator();

    while (rowIterator.hasNext()) {

        // reading the row
        Row aRow = rowIterator.next();

        if (!firstRowSkipped) {
            firstRowSkipped = true;
            continue;
        }

        Patient aPatient = new Patient();

        // loading the cells
        Iterator<Cell> cellIterator = aRow.cellIterator();

        // looping through the cells
        while (cellIterator.hasNext()) {
            // reading the cell
            Cell cell = cellIterator.next();

            if (cell != null) {
                switch (cell.getColumnIndex()) {

                case 0:
                    // ID
                    aPatient.setID((int) cell.getNumericCellValue());
                    break;
                case 1:
                    // Name
                    aPatient.setName(cell.getStringCellValue());
                    break;
                case 2: // heart rate
                case 3: // heart rate
                case 4: // heart rate
                case 5: // heart rate
                case 6: // heart rate
                    //aPatient.addHeartRate(cell.getNumericCellValue());
                    break;
                case 7: // tempreature
                case 8: // tempreature
                case 9: // tempreature
                case 10:// tempreature
                case 11:// tempreature
                    //aPatient.addTempreature(cell.getNumericCellValue());
                    break;
                case 12:
                    // blood_type
                    aPatient.setBloodType(cell.getStringCellValue());

                    break;
                case 13:
                    // sex
                    aPatient.setSex(cell.getStringCellValue());
                    break;
                case 14:
                    // age
                    aPatient.setAge((int) cell.getNumericCellValue());
                    break;
                case 15:
                    // date_added
                    aPatient.setDateAdded(cell.getDateCellValue());
                    break;
                case 16:
                    // last_updated
                    aPatient.setLastUpdated(cell.getDateCellValue());
                    break;
                case 17:
                    // last_alarmed
                    aPatient.setLastAlarm(cell.getDateCellValue());
                default:
                    break;
                }
            }
        }
        // adding patient to the collection
        if (aPatient.getName() != null) {
            thePatients.add(aPatient);
        }
        //aPatient.printAll();
    }

    //closeConnection();
    return thePatients;
}

From source file:de.chott.jfreechartsample.reader.FileReaderService.java

/**
 * Liest mit Hilfe der Apache-Poi-Library ein XLS-File aus und gibt die Daten darin als Liste von PieChartData-Objekten zurck. 
 * //from ww w.j  a  v  a  2  s  .co  m
 * @param stream Das File als Resource-InputStream
 * @return eine Liste der PieChartData
 * @throws IOException 
 */
public List<PieChartData> readPieChartDataFromXls(InputStream stream) throws IOException {
    List<PieChartData> retVal = new ArrayList<>();
    HSSFWorkbook workbook = new HSSFWorkbook(stream);

    HSSFSheet sheet = workbook.getSheetAt(0);

    Iterator<Row> rowIterator = sheet.iterator();
    rowIterator.next();

    while (rowIterator.hasNext()) {
        Row row = rowIterator.next();
        PieChartData data = new PieChartData();

        Cell countryCell = row.getCell(0);
        Cell weightCell = row.getCell(1);

        if (countryCell != null && weightCell != null) {
            data.setCountry(countryCell.getStringCellValue());
            data.setWeight(weightCell.getNumericCellValue());

            retVal.add(data);
        }
    }

    return retVal;
}

From source file:de.enerko.reports2.engine.CellDefinition.java

License:Apache License

protected CellValue parse_number(Cell in) {
    CellValue rv = null;/* w w  w .j a  v  a  2s.co  m*/

    try {
        if (HSSFDateUtil.isCellDateFormatted(in)) {
            rv = new CellValue("datetime", Report.DATEFORMAT_OUT.format(in.getDateCellValue()));
        } else {
            rv = new CellValue("number", Double.toString(in.getNumericCellValue()));
        }
    } catch (IllegalStateException e) {
        // Siehe Dokumentation getNumericCellValue
        rv = new CellValue("string", in.getStringCellValue());
    }

    return rv;
}

From source file:de.fhg.fokus.odp.portal.uploaddata.service.Worker.java

/**
 * This method handles integer or double values and adds them as a correct
 * String to our map.//ww  w .j av a  2  s  .co  m
 * 
 * @param map
 *            HashMap which stores the (key,value)-pairs
 * @param parameter
 *            this is the name of this column
 * @param cell
 * @param extrasStringBuilder
 *            intermediate extrasString
 */
private void handleNumber(HashMap<String, String> map, String parameter, Cell cell,
        StringBuilder extrasStringBuilder) {
    String val;
    val = String.valueOf(cell.getNumericCellValue());

    if (parameter.startsWith("extras:")) {
        String[] tmp = parameter.split(":");
        parseExtras(extrasStringBuilder, tmp[1], val);
    } else {
        map.put(parameter, "\"" + val + "\"");
    }
}