null values #7

Closed
opened 2016-05-10 18:43:07 +00:00 by SysProfile · 1 comment
SysProfile commented 2016-05-10 18:43:07 +00:00 (Migrated from github.com)

Hello !, please excuse the translation into English. The translation is by Google Translate from Spanish

I am using the following example https://github.com/SheetJSDev/js-xlsx-demo. Everything works fine but when I send a null value, fails.
I made a small change in function "sheet_from_array_of_arrays" but it would be good that the script can solve it.

function sheet_from_array_of_arrays(data) {
  var row_num = data.length;
  var keys = Object.keys(data[0])
  var col_num = keys.length;

  var ws = {};
  var range = { s: { c: 0, r: 0 }, e: { c: col_num, r: row_num } };
  ws['!ref'] = XLSX.utils.encode_range(range);

  for (var R = 0; R < row_num; R++) {
    for (var C = 0; C < col_num; C++) {
      var cell_ref = XLSX.utils.encode_cell({ c: C, r: R });
      var cell = { v: data[R][keys[C]] };
      cell.t = 's';
      // My two cents (start)
      if (cell.v == null) {
        cell.v = '';
      }
      // My two cents (end)
      ws[cell_ref] = cell;
    }
  }
  return ws;
}
Hello !, please excuse the translation into English. The translation is by Google Translate from Spanish I am using the following example https://github.com/SheetJSDev/js-xlsx-demo. Everything works fine but when I send a null value, fails. I made a small change in function "sheet_from_array_of_arrays" but it would be good that the script can solve it. ``` function sheet_from_array_of_arrays(data) { var row_num = data.length; var keys = Object.keys(data[0]) var col_num = keys.length; var ws = {}; var range = { s: { c: 0, r: 0 }, e: { c: col_num, r: row_num } }; ws['!ref'] = XLSX.utils.encode_range(range); for (var R = 0; R < row_num; R++) { for (var C = 0; C < col_num; C++) { var cell_ref = XLSX.utils.encode_cell({ c: C, r: R }); var cell = { v: data[R][keys[C]] }; cell.t = 's'; // My two cents (start) if (cell.v == null) { cell.v = ''; } // My two cents (end) ws[cell_ref] = cell; } } return ws; } ```
SysProfile commented 2016-05-10 18:44:53 +00:00 (Migrated from github.com)

This is not the right place for this comment

This is not the right place for this comment
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: sheetjs/js-crc32#7
No description provided.