androidxlsxapache-poi-4

setCellType(CellType.STRING) is deprecated


Issue: setCellType is deprecated.

 row.getCell(0, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK).setCellType(CellType.STRING);

So far tried:

Searched for replacement. No useful sources for setting a cell type as STRING. Appreciate help!


Solution

  • Before:

           row.getCell(0, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK).setCellType(                                
           contentValues.put(ITEMCODE, row.getCell(0, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK).getStringCellValue());
    

    After:

    InputStream strm =getClass().getResourceAsStream("Sample.xls"));
    Workbook wb = WorkbookFactory.create(strm);
    DataFormatter Stringform = new DataFormatter();
    FormulaEvaluator Formeval = new HSSFFormulaEvaluator((HSSFWorkbook) wb);
    
    Sheet sheet= wb.getSheetAt(0);
    Iterator<Row> rit = sheet.rowIterator();
    
    while(rit.hasNext()){
    
        Row row = rit.next();
        Cell cellValue = row.getCell(0);
        Formeval.evaluate(row.getCell(0)); // Returns string
        String cellValueStr = Stringform.formatCellValue(row.getCell(0),Formeval);
        
        ContentValues contentValues = new ContentValues();
    
        contentValues.put(DNNO, Stringform.formatCellValue(row.getCell(0, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK),Formeval));
                                                                     
    }