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:functions.excels.RowCheck.java

License:Apache License

/**
 * Vrifie que la ligne donne est juste./* w  w w. java2  s  . c om*/
 * @param rowNumber
 */
public void checkRow() {
    Cell cell = row.getCell(0);
    if (cell == null)
        addError("Pas d'espce.");
    else {
        espece_nom = cell.getStringCellValue();
        if ((espece = Espece.find.where().eq("espece_nom", espece_nom).findUnique()) == null) {
            try {
                EspeceSynonyme syn = EspeceSynonyme.find.where().eq("synonyme_nom", espece_nom).findUnique();
                if (syn != null)
                    espece = syn.synonyme_espece;
                else
                    addError("L'espce " + espece_nom + " n'existe pas.");
            } catch (PersistenceException e) {
                addError("Deux espces synonymes ont le mme nom : " + espece_nom);
            }
        }
    }
    cell = row.getCell(1);
    if (cell != null) {
        sexe = cell.getStringCellValue();
        if (sexe != null && !sexe.equals("")) {
            if (sexe.equals("oeuf") || sexe.equals("OEuf") || sexe.equals("Oeuf"))
                stade_sexe = StadeSexe.find.byId(6);
            else {
                if ((stade_sexe = StadeSexe.find.where().eq("stade_sexe_intitule", sexe).findUnique()) == null)
                    addError("Le stade/sexe " + sexe + " n'existe pas.");
                if (stade_sexe != null && espece != null
                        && !espece.getGroupe().getStadesSexes().contains(stade_sexe)) {
                    addError("Le stade/sexe " + stade_sexe + " n'est pas valable pour le groupe "
                            + espece.getGroupe());
                }
            }
        }
    }
    cell = row.getCell(2);
    if (cell != null) {
        try {
            nombre_dbl = cell.getNumericCellValue();
            if (nombre_dbl != 0) {
                nombre = (int) nombre_dbl;
            }
        } catch (IllegalStateException | NumberFormatException e) {
            addError(nombre_dbl + " n'est pas un entier.");
        }
    }
    cell = row.getCell(3);//Dpartement, on s'en fout.
    cell = row.getCell(4);
    if (cell != null) {
        commune_nom = cell.getStringCellValue();
        if (commune_nom != null && !commune_nom.equals("")) {
            commune = Commune.findFromNomApproximatif(commune_nom);
            if (commune == null)
                addError("La commune " + commune_nom + " n'est pas rfrence.");
        }
    }
    cell = row.getCell(5);
    lieu_dit = cell.getStringCellValue();
    cell = row.getCell(6);
    if (cell == null)
        addError("Maille UTM non spcifie.");
    else {
        utm_str = cell.getStringCellValue();
        utm = UTMS.find.byId(utm_str);
        if (utm == null)
            addError("Maille UTM " + utm_str + " non existante.");
    }
    cell = row.getCell(7);
    if (cell != null) {
        try {
            date_min_date = cell.getDateCellValue();
            if (date_min_date != null) {
                date_min = Calendar.getInstance();
                date_min.setTime(date_min_date);
            }
        } catch (IllegalStateException e) {
            addError("Date minimum spcifie invalide.");
        }
    }
    cell = row.getCell(8);
    if (cell == null)
        addError("Date non spcifie.");
    else {
        try {
            date_date = cell.getDateCellValue();
            date.setTime(date_date);
            if (date_date == null)
                addError("La date n'est pas spcifie.");
            if (date_min != null && date != null && date_min.compareTo(date) >= 0)
                addError("La date min est suprieure au gale  la date.");
        } catch (IllegalStateException e) {
            addError("Date invalide.");
        }
    }
    cell = row.getCell(9);
    if (cell == null)
        addError("Tmoin non spcifie.");
    else {
        String temoins_str = cell.getStringCellValue();
        if (temoins_str == null)
            addError("Tmoin non spcifie.");
        else {
            temoins = temoins_str.split(",");
            membres = new Membre[temoins.length];
            for (int i = 0; i < temoins.length; i++) {
                temoins[i] = temoins[i].trim();
                membres[i] = Membre.find.where().eq("membre_nom", temoins[i]).findUnique();
                if (membres[i] == null)
                    addError("Le membre '" + temoins[i] + "' n'est pas rfrenc.");
            }
        }
    }
    cell = row.getCell(10);
    if (cell != null)
        determinateur = cell.getStringCellValue();
    cell = row.getCell(11);
    if (cell != null)
        methodeCapture = cell.getStringCellValue();
    else
        methodeCapture = null;
    cell = row.getCell(12);
    if (cell != null)
        milieu = cell.getStringCellValue();
    else
        milieu = null;
    cell = row.getCell(13);
    if (cell != null)
        essence = cell.getStringCellValue();
    else
        essence = null;
    cell = row.getCell(14);
    if (cell != null)
        remarque = cell.getStringCellValue();
    else
        remarque = null;
    cell = row.getCell(15);
    if (cell != null)
        collection = cell.getStringCellValue();
    else
        collection = null;

    StringBuilder memo_sb = new StringBuilder();
    boolean started = false;
    if (remarque != null && !remarque.equals("")) {
        if (!started) {
            started = true;
            memo_sb.append(remarque);
        } else
            memo_sb.append(" ; " + remarque);
    }
    if (methodeCapture != null && !methodeCapture.equals("")) {
        if (!started) {
            started = true;
            memo_sb.append("Mthode de capture : " + methodeCapture);
        } else
            memo_sb.append(" ; Mthode de capture : " + methodeCapture);
    }
    if (milieu != null && !milieu.equals("")) {
        if (!started) {
            started = true;
            memo_sb.append("Milieu : " + milieu);
        } else
            memo_sb.append(" ; Milieu : " + milieu);
    }
    if (essence != null && !essence.equals("")) {
        if (!started) {
            started = true;
            memo_sb.append("Essence : " + essence);
        } else
            memo_sb.append(" ; Essence : " + essence);
    }
    if (collection != null && !collection.equals("")) {
        if (!started) {
            started = true;
            memo_sb.append("Collection : " + collection);
        } else
            memo_sb.append(" ; Collection : " + collection);
    }
    memo = memo_sb.toString();
}

From source file:functions.excels.RowCheckEdit.java

License:Apache License

/**
 * Vrifie que la ligne donne est juste.//  ww  w.  j  a  v a2s .c  om
 */
public void checkRow() {
    //ID
    Cell cell = row.getCell(0);
    double info_id = -1;
    if (cell != null && (info_id = cell.getNumericCellValue()) > 0)
        complement = InformationsComplementaires.find.byId((long) info_id);
    if (info_id != 0 && complement == null)
        addError("ID information complmentaire inexistante " + info_id);
    //ID observation
    cell = row.getCell(1);
    if (cell != null && (info_id = cell.getNumericCellValue()) > 0)
        observation = Observation.find.byId((long) info_id);
    if (observation == null && complement == null)
        addError("ID observation inexistante " + info_id);
    //UTM
    cell = row.getCell(3);
    String utm_str = null;
    if (cell != null) {
        utm_str = cell.getStringCellValue();
        utm = UTMS.find.byId(utm_str);
    }
    if (utm == null)
        addError("Maille UTM inexistante : " + utm_str);
    //Lieu-dit
    cell = row.getCell(4);
    if (cell != null)
        this.lieu_dit = cell.getStringCellValue();
    //Commune
    cell = row.getCell(5);
    if (cell != null) {
        String commune_nom = cell.getStringCellValue();
        if (!commune_nom.isEmpty()) {
            commune = Commune.findFromNomApproximatif(commune_nom);
            if (commune == null)
                addError("La commune '" + commune_nom + "' n'est pas rfrence.");
        }
    }
    //Date_min
    cell = row.getCell(6);
    if (cell != null) {
        try {
            String date_min_str = cell.getStringCellValue();
            if (date_min_str != null && !date_min_str.isEmpty()) {
                date_min = DateUtil.toCalendarExcel(date_min_str);
            }
        } catch (ParseException e) {
            addError("Date min invalide");
        }
    }
    //Date
    cell = row.getCell(7);
    if (cell != null) {
        try {
            String date_str = cell.getStringCellValue();
            if (date_str != null) {
                date = DateUtil.toCalendarExcel(date_str);
            }
        } catch (ParseException e) {
            addError("Date invalide");
        }
    }
    if (date == null)
        addError("La date est vide !");
    //Espce
    cell = row.getCell(8);
    if (cell == null)
        addError("Pas d'espce.");
    else {
        String espece_nom = cell.getStringCellValue();
        if ((espece = Espece.find.where().eq("espece_nom", espece_nom).findUnique()) == null) {
            try {
                EspeceSynonyme syn = EspeceSynonyme.find.where().eq("synonyme_nom", espece_nom).findUnique();
                if (syn != null)
                    espece = syn.synonyme_espece;
                else
                    addError("L'espce " + espece_nom + " n'existe pas.");
            } catch (PersistenceException e) {
                addError("Deux espces synonymes ont le mme nom : " + espece_nom);
            }
        }
    }
    //Nombre
    cell = row.getCell(9);
    if (cell != null) {
        try {
            this.nombre = (int) cell.getNumericCellValue();
        } catch (IllegalStateException | NumberFormatException e) {
            this.nombre = null;
        }
        this.nombre = (this.nombre != null && this.nombre == 0) ? null : nombre;
    }
    //Stade
    cell = row.getCell(10);
    if (cell != null) {
        String sexe = cell.getStringCellValue();
        if (sexe != null && !sexe.equals("")) {
            if (sexe.equals("oeuf") || sexe.equals("OEuf") || sexe.equals("Oeuf"))
                stade_sexe = StadeSexe.find.byId(6);
            else {
                if ((stade_sexe = StadeSexe.find.where().eq("stade_sexe_intitule", sexe).findUnique()) == null)
                    addError("Le stade/sexe " + sexe + " n'existe pas.");
                if (stade_sexe != null && espece != null
                        && !espece.getGroupe().getStadesSexes().contains(stade_sexe)) {
                    addError("Le stade/sexe " + stade_sexe + " n'est pas valable pour le groupe "
                            + espece.getGroupe());
                }
            }
        }
    }
    //Tmoin(s)
    cell = row.getCell(11);
    if (cell == null)
        addError("Tmoin non spcifi.");
    else {
        String temoins_str = cell.getStringCellValue();
        if (temoins_str == null)
            addError("Tmoin non spcifi.");
        else {
            String[] temoins_str_tab = temoins_str.split(",");
            temoins = new Membre[temoins_str_tab.length];
            for (int i = 0; i < temoins_str_tab.length; i++) {
                temoins_str_tab[i] = temoins_str_tab[i].trim();
                temoins[i] = Membre.find.where().eq("membre_nom", temoins_str_tab[i]).findUnique();
                if (temoins[i] == null)
                    addError("Le membre '" + temoins_str_tab[i] + "' n'est pas rfrenc.");
            }
        }
    }
    //Dterminateur
    cell = row.getCell(12);
    if (cell != null)
        determinateur = cell.getStringCellValue();
    //Mmo
    cell = row.getCell(13);
    try {
        if (cell != null)
            memo = cell.getStringCellValue();
    } catch (IllegalStateException e) {
        addError("Le champ mmo n'est pas une chane de caractres");
    }
}

From source file:gda.hrpd.data.ExcelReader.java

License:Open Source License

/**
 * load data from spreadsheet to the map, or initialise the multimap
 *///from  w w w  . j  av a2 s .c  om
public void readData() {
    mvm.clear();

    int i = 0;
    for (Iterator<Row> rit = sheet.rowIterator(); rit.hasNext();) {
        Row row = rit.next();
        for (Iterator<Cell> cit = row.cellIterator(); cit.hasNext();) {
            Cell cell = cit.next();
            if (cell.getCellType() == Cell.CELL_TYPE_STRING) {
                mvm.put(i, cell.getRichStringCellValue().toString());
            } else if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
                mvm.put(i, String.valueOf(cell.getNumericCellValue()));
            } else if (cell.getCellType() == Cell.CELL_TYPE_BLANK) {
                mvm.put(i, "");
            }
        }
        i++;
    }
    logger.debug("Read row {}", i);
}

From source file:gov.anl.cue.arcane.engine.Util.java

License:Open Source License

/**
 * Gets the spreadsheet string./*www  . j  av  a2 s.  com*/
 *
 * @param sheet the sheet
 * @param rowIndex the row index
 * @param columnIndex the column index
 * @return the spreadsheet string
 */
public static String getSpreadsheetString(XSSFSheet sheet, int rowIndex, int columnIndex) {

    // Prepare the results storage.
    String cellContents = "";

    // Get the next value.
    Cell cell = sheet.getRow(rowIndex).getCell(columnIndex, Row.RETURN_BLANK_AS_NULL);

    // Check the next value.
    if (cell != null) {

        // Convert the next value, as needed.
        if (cell.getCellType() == Cell.CELL_TYPE_STRING) {
            cellContents = cell.getStringCellValue();
        } else {
            cellContents = "" + cell.getNumericCellValue();
        }

    }

    // Return the results.
    return cellContents;

}

From source file:gov.anl.cue.arcane.engine.Util.java

License:Open Source License

/**
 * Gets the spreadsheet number.//from   ww  w. j  a  va 2s .  c o  m
 *
 * @param sheet the sheet
 * @param rowIndex the row index
 * @param columnIndex the column index
 * @return the spreadsheet number
 */
public static double getSpreadsheetNumber(XSSFSheet sheet, int rowIndex, int columnIndex) {

    // Prepare the results storage.
    Double cellContents = Double.NaN;

    // Get the next value.
    Cell cell = sheet.getRow(rowIndex).getCell(columnIndex, Row.RETURN_BLANK_AS_NULL);

    // Check the next value.
    if (cell != null) {

        // Convert the next value, as needed.
        if (cell.getCellType() == Cell.CELL_TYPE_STRING) {
            cellContents = Double.parseDouble(cell.getStringCellValue());
        } else {
            cellContents = cell.getNumericCellValue();
        }

    }

    // Return the results.
    return cellContents;

}

From source file:gov.nih.nci.cananolab.util.ExcelParser.java

License:BSD License

/**
 * Vertically parse the Excel file into a 2-D matrix represented as a map of map.
 * Key is Column header, value is a map, whose key is Row header and value is
 * the cell./*from w w w . jav  a  2 s. co  m*/
 * 
 * @return
 * @throws IOException
 */
public SortedMap<String, SortedMap<String, Double>> verticalParse(String fileName) throws IOException {
    InputStream inputStream = null;
    SortedMap<String, SortedMap<String, Double>> dataMatrix = new TreeMap<String, SortedMap<String, Double>>();
    try {
        inputStream = new BufferedInputStream(new FileInputStream(fileName));
        POIFSFileSystem fs = new POIFSFileSystem(inputStream);
        Workbook wb = new HSSFWorkbook(fs);
        Sheet sheet1 = wb.getSheetAt(0);
        //printSheet(sheet1);
        Row firstRow = sheet1.getRow(0);
        int rowIndex = 0;
        for (Row row : sheet1) {
            int colIndex = 0;
            String rowHeader = row.getCell(0).getStringCellValue();
            for (Cell cell : row) {
                if (rowIndex > 0 && colIndex > 0) { //skipping first row/column
                    String columnHeader = firstRow.getCell(colIndex).getStringCellValue();
                    SortedMap<String, Double> columnData = null;
                    if (dataMatrix.get(columnHeader) != null) {
                        columnData = dataMatrix.get(columnHeader);
                    } else {
                        columnData = new TreeMap<String, Double>();
                    }
                    if (cell != null) {
                        columnData.put(rowHeader, cell.getNumericCellValue());
                        dataMatrix.put(columnHeader, columnData);
                    }
                }
                colIndex++;
            }
            rowIndex++;
        }
    } finally {
        if (inputStream != null) {
            try {
                inputStream.close();
            } catch (Exception e) {
            }
        }
    }
    return dataMatrix;
}

From source file:gov.nih.nci.cananolab.util.ExcelParser.java

License:BSD License

/**
 * Horizontally parse the Excel file into a 2-D matrix represented as a map of map.
 * Key is Row header, value is a map, whose key is Column header and value is
 * the cell.//  w w w  . j a  va 2  s . co m
 * 
 * @return
 * @throws IOException
 */
public SortedMap<String, SortedMap<String, Double>> horizontalParse(String fileName) throws IOException {
    InputStream inputStream = null;
    SortedMap<String, SortedMap<String, Double>> dataMatrix = new TreeMap<String, SortedMap<String, Double>>();
    try {
        inputStream = new BufferedInputStream(new FileInputStream(fileName));
        POIFSFileSystem fs = new POIFSFileSystem(inputStream);
        Workbook wb = new HSSFWorkbook(fs);
        Sheet sheet1 = wb.getSheetAt(0);
        //printSheet(sheet1);
        Row firstRow = sheet1.getRow(0);
        int rowIndex = 0;
        for (Row row : sheet1) {
            int colIndex = 0;
            String rowHeader = row.getCell(0).getStringCellValue();
            for (Cell cell : row) {
                if (rowIndex > 0 && colIndex > 0) { //skipping first row/column
                    String columnHeader = firstRow.getCell(colIndex).getStringCellValue();
                    SortedMap<String, Double> rowData = null;
                    if (dataMatrix.get(rowHeader) != null) {
                        rowData = dataMatrix.get(rowHeader);
                    } else {
                        rowData = new TreeMap<String, Double>();
                    }
                    if (cell != null) {
                        rowData.put(columnHeader, cell.getNumericCellValue());
                        dataMatrix.put(rowHeader, rowData);
                    }
                }
                colIndex++;
            }
            rowIndex++;
        }
    } finally {
        if (inputStream != null) {
            try {
                inputStream.close();
            } catch (Exception e) {
            }
        }
    }
    return dataMatrix;
}

From source file:gov.nih.nci.cananolab.util.ExcelParser.java

License:BSD License

/**
 * Parse secondary StanShaw Excel spreadsheet and store data in a 3-layer map.
 * 1st layer: sample map, key is sample name (261-13-4), value is the 2nd layer map.
 * 2nd layer: assay map, key is assay name (Aorta 1), value is the 3rd layer map.
 * 3rd layer: datum map, there are always 3 entries in this map, for example,  
 *            key is datum name Median (M), value is 9.02194E-08.
 *            key is datum name Mean (M), value is 7.96025E-08.
 *            key is datum name SEM (M), value is 6.12968E-09.
 *  /*from ww  w  . ja v a 2  s . c o m*/
 * @param fileName
 * @return a 3-layer map
 * @throws IOException
 */
public SortedMap<String, SortedMap<String, SortedMap<String, Double>>> twoWayParse(String fileName)
        throws IOException {
    InputStream inputStream = null;
    SortedMap<String, SortedMap<String, SortedMap<String, Double>>> dataMatrix = new TreeMap<String, SortedMap<String, SortedMap<String, Double>>>();
    try {
        inputStream = new BufferedInputStream(new FileInputStream(fileName));
        POIFSFileSystem fs = new POIFSFileSystem(inputStream);
        Workbook wb = new HSSFWorkbook(fs);
        Sheet sheet1 = wb.getSheetAt(0);
        //printSheet(sheet1);
        // Sheet must contain >= 2 rows (header + data).
        if (sheet1.getLastRowNum() < 1) {
            return dataMatrix;
        }
        // Sheet must contain >= 5 columns (assay, sample + 3 datums).   
        Row firstRow = sheet1.getRow(0);
        if (firstRow.getLastCellNum() < 4) {
            return dataMatrix;
        }
        // Iterate sheet from 2nd row and populate the data matrix.
        for (int rowIndex = 1; rowIndex <= sheet1.getLastRowNum(); rowIndex++) {
            Row row = sheet1.getRow(rowIndex);

            //1.get sampleName key for 1st layer map, assayName key for 2 layer map.
            String sampleName = row.getCell(1).getStringCellValue();
            String assayName = row.getCell(0).getStringCellValue();

            //2.find sampleMap in dataMatrix, if null create & store new sampleMap.
            SortedMap<String, SortedMap<String, Double>> sampleMap = dataMatrix.get(sampleName);
            if (sampleMap == null) {
                sampleMap = new TreeMap<String, SortedMap<String, Double>>();
                dataMatrix.put(sampleName, sampleMap);
            }

            //3.find assayMap in sampleMap, if null create & store new assayMap.
            SortedMap<String, Double> assayMap = sampleMap.get(assayName);
            if (assayMap == null) {
                assayMap = new TreeMap<String, Double>();
                sampleMap.put(assayName, assayMap);
            }

            //4.iterate row from col-2 to last column, store datum value.
            for (int colIndex = 2; colIndex <= row.getLastCellNum(); colIndex++) {
                Cell cell = row.getCell(colIndex);
                if (cell != null && cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
                    String datumName = firstRow.getCell(colIndex).getStringCellValue();
                    assayMap.put(datumName, cell.getNumericCellValue());
                }
            }
        }
    } finally {
        if (inputStream != null) {
            try {
                inputStream.close();
            } catch (Exception e) {
            }
        }
        //this.print2ndMatrix(dataMatrix);
    }
    return dataMatrix;
}

From source file:gov.nih.nci.cananolab.util.ExcelParser.java

License:BSD License

public void printSheet(Sheet sheet) {
    for (Row row : sheet) {
        for (Cell cell : row) {
            CellReference cellRef = new CellReference(cell.getRowIndex(), cell.getColumnIndex());
            System.out.print(cellRef.formatAsString());
            System.out.print(" - ");

            switch (cell.getCellType()) {
            case Cell.CELL_TYPE_STRING:
                System.out.println(cell.getRichStringCellValue().getString());
                break;
            case Cell.CELL_TYPE_NUMERIC:
                if (DateUtil.isCellDateFormatted(cell)) {
                    System.out.println(cell.getDateCellValue());
                } else {
                    System.out.println(cell.getNumericCellValue());
                }/*w  w w.  ja va2s  . com*/
                break;
            case Cell.CELL_TYPE_BOOLEAN:
                System.out.println(cell.getBooleanCellValue());
                break;
            case Cell.CELL_TYPE_FORMULA:
                System.out.println(cell.getCellFormula());
                break;
            default:
                System.out.println();
            }
        }
    }
}

From source file:gov.nih.nci.evs.app.neopl.XLStoXLSX.java

License:Open Source License

/**
 * @param args// w  ww .j  a va  2s.c o m
 * @throws InvalidFormatException
 * @throws IOException
 */

public static void run(String inputfile, String outputfile) throws IOException {
    InputStream in = new BufferedInputStream(new FileInputStream(inputfile));
    try {
        Workbook wbIn = new HSSFWorkbook(in);
        File outFn = new File(outputfile);
        if (outFn.exists()) {
            outFn.delete();
        }

        Workbook wbOut = new XSSFWorkbook();
        int sheetCnt = wbIn.getNumberOfSheets();
        for (int i = 0; i < sheetCnt; i++) {
            Sheet sIn = wbIn.getSheetAt(0);
            Sheet sOut = wbOut.createSheet(sIn.getSheetName());
            Iterator<Row> rowIt = sIn.rowIterator();
            while (rowIt.hasNext()) {
                Row rowIn = rowIt.next();
                Row rowOut = sOut.createRow(rowIn.getRowNum());

                Iterator<Cell> cellIt = rowIn.cellIterator();
                while (cellIt.hasNext()) {
                    Cell cellIn = cellIt.next();
                    Cell cellOut = rowOut.createCell(cellIn.getColumnIndex(), cellIn.getCellType());

                    switch (cellIn.getCellType()) {
                    case Cell.CELL_TYPE_BLANK:
                        break;

                    case Cell.CELL_TYPE_BOOLEAN:
                        cellOut.setCellValue(cellIn.getBooleanCellValue());
                        break;

                    case Cell.CELL_TYPE_ERROR:
                        cellOut.setCellValue(cellIn.getErrorCellValue());
                        break;

                    case Cell.CELL_TYPE_FORMULA:
                        cellOut.setCellFormula(cellIn.getCellFormula());
                        break;

                    case Cell.CELL_TYPE_NUMERIC:
                        cellOut.setCellValue(cellIn.getNumericCellValue());
                        break;

                    case Cell.CELL_TYPE_STRING:
                        cellOut.setCellValue(cellIn.getStringCellValue());
                        break;
                    }

                    {
                        CellStyle styleIn = cellIn.getCellStyle();
                        CellStyle styleOut = cellOut.getCellStyle();
                        styleOut.setDataFormat(styleIn.getDataFormat());
                    }
                    cellOut.setCellComment(cellIn.getCellComment());

                    // HSSFCellStyle cannot be cast to XSSFCellStyle
                    // cellOut.setCellStyle(cellIn.getCellStyle());
                }
            }
        }
        OutputStream out = new BufferedOutputStream(new FileOutputStream(outFn));
        try {
            wbOut.write(out);
        } finally {
            out.close();
        }
    } finally {
        in.close();
    }
}