excel icon indicating copy to clipboard operation
excel copied to clipboard

Cell with null value

Open gjmg2303 opened this issue 2 years ago • 1 comments

Hello good day, I am working with the api, and I love it. but I have a problem. the excel may contain cells with null values in the same row as in the column if it has values. My question is, how can I control or override that null value by assigning a default value. Thank you very much for your time. Kind regards, John

error:

 Error: Unexpected null value.

output each cell:

, Data(nam1, 1, 1, null, Hoja1), Data(surname1, 2, 1, null, Hoja1), null, Data(country1, 2, 1, null, Hoja1)

to get the differents cell value:

  some row have some cell with null value: 

   final row = excel.tables[excel.tables.keys.first]!.rows.map((e) => e.map((e) => e!.value).toList()).toList();

    print(row);

    row.forEach((e) {
      int index = row.indexOf(e);

      if (index > 0)
      {
          name:        row[index][0],
          surname:          row[index][1],
          age:  row[index][2], //VALUE NULL 
          country: row[index][3]
      }
    }

gjmg2303 avatar Jun 01 '22 18:06 gjmg2303

Had similar issue, appears people like to leave empty columns and rows in there excel files... very basic workaround was to check if cell was null in my loop through rows and cells, and then if null set to empty strings or other defaults...

      for (var cell in row ) {
          Map cellObj = {};

          //print('cell No. $cellNo');

          //print('cell raw: ${cell.toString()}');

          if(cell != null) {
            cellObj['cell-type'] = cell.cellType.toString();
            cellObj['cell-value'] = cell.value.toString();
            cellObj['cell-props'] = [];
            for(var prop in cell.props) {
              cellObj['cell-props'].add(prop.toString());     
            }
            cellObj['cell-is-formula'] = cell.isFormula;
            if(cell.isFormula) {
              Formula f = cell.value;
              cellObj['cell-formula'] = f.formula.toString();
            }
          }
          else { // set defaults for null cells
            cellObj['cell-type'] = "";
            cellObj['cell-value'] = "";
            cellObj['cell-props'] = [];
            cellObj['cell-is-formula'] = false;
          }
          cells.add(cellObj);
        }

Hope this helps. By the way, great work by JustKawal !

d3ndesign avatar Jul 03 '22 23:07 d3ndesign