Unable to get property 'encode_cell' of undefined or null reference in IE11 compatibility View #952

Closed
opened 2018-01-10 12:17:15 +00:00 by Suncatcher · 6 comments
Suncatcher commented 2018-01-10 12:17:15 +00:00 (Migrated from github.com)

The XLSX write script doesn't work in IE11 Compatibility Mode, whilst in standards mode it works fine. It throws Unable to get property 'encode_cell' of undefined or null reference for function sheet_from_array_of_arrays()

image

Here is my code:

function sheet_from_array_of_arrays(data, sheet) {
  var ws = {};
  var merged = ['One', 'Two', 'Three', 'Four'];
  var mline = 0;
  if(merged.indexOf(sheet) >= 0) mline++;
  var range = {s: {c:10000000, r:10000000}, e: {c:0, r:0 }};
  for(var R = 0; R != data.length; ++R) {
    for(var C = 0; C != data[R].length; ++C) {
      if(range.s.r > R) range.s.r = R;
      if(range.s.c > C) range.s.c = C;
      if(range.e.r < R) range.e.r = R;
      if(range.e.c < C) range.e.c = C;
      var cell = {v: data[R][C] };
      if(cell.v == null) continue;
      var cell_ref = XLSX.utils.encode_cell({c:C,r:R});

      if(typeof cell.v === 'number') cell.t = 'n';
      else if(typeof cell.v === 'boolean') cell.t = 'b';
      else if(cell.v instanceof Date) {
        cell.t = 'n'; cell.z = XLSX.SSF._table[14];
        cell.v = datenum(cell.v);
      }
      else cell.t = 's';
      ws[cell_ref] = cell;
    }
  }
  if(range.s.c < 10000000) ws['!ref'] = XLSX.utils.encode_range(range);
  return ws;
}

As I see in Debugger, XLSX object is created normally, whilst utils property is showed as undefined for some reason.

2018-01-10 2

How can I fix this? Compatibility View is a must for my use-case.

The XLSX write script doesn't work in IE11 Compatibility Mode, whilst in standards mode it works fine. It throws **Unable to get property 'encode_cell' of undefined or null reference** for function _sheet_from_array_of_arrays()_ ![image](https://user-images.githubusercontent.com/6388034/34772383-73218014-f610-11e7-95d0-758d9bcebb08.png) Here is my code: function sheet_from_array_of_arrays(data, sheet) { var ws = {}; var merged = ['One', 'Two', 'Three', 'Four']; var mline = 0; if(merged.indexOf(sheet) >= 0) mline++; var range = {s: {c:10000000, r:10000000}, e: {c:0, r:0 }}; for(var R = 0; R != data.length; ++R) { for(var C = 0; C != data[R].length; ++C) { if(range.s.r > R) range.s.r = R; if(range.s.c > C) range.s.c = C; if(range.e.r < R) range.e.r = R; if(range.e.c < C) range.e.c = C; var cell = {v: data[R][C] }; if(cell.v == null) continue; var cell_ref = XLSX.utils.encode_cell({c:C,r:R}); if(typeof cell.v === 'number') cell.t = 'n'; else if(typeof cell.v === 'boolean') cell.t = 'b'; else if(cell.v instanceof Date) { cell.t = 'n'; cell.z = XLSX.SSF._table[14]; cell.v = datenum(cell.v); } else cell.t = 's'; ws[cell_ref] = cell; } } if(range.s.c < 10000000) ws['!ref'] = XLSX.utils.encode_range(range); return ws; } As I see in Debugger, **XLSX** object is created normally, whilst **utils** property is showed as _undefined_ for some reason. ![2018-01-10 2](https://user-images.githubusercontent.com/6388034/34772673-888f4750-f611-11e7-876f-e22b4ad466ad.png) How can I fix this? Compatibility View is a must for my use-case.
reviewher commented 2018-01-11 00:21:30 +00:00 (Migrated from github.com)

Can you make that page available publicly to reproduce? The browser test suite works for some round trip tests but bombs out because of some missing JSON typeof guards, so the issue is likely in your HTML Also see if adding a JSON shim, like https://github.com/douglascrockford/JSON-js, helps -- compatibility mode 7 has no default JSON object

Can you make that page available publicly to reproduce? The [browser test suite](http://oss.sheetjs.com/js-xlsx/tests) works for some round trip tests but bombs out because of some missing JSON typeof guards, so the issue is likely in your HTML Also see if adding a JSON shim, like https://github.com/douglascrockford/JSON-js, helps -- compatibility mode 7 has no default JSON object
reviewher commented 2018-01-11 08:10:50 +00:00 (Migrated from github.com)

Here's the situation: The test suite loads using the 0.11.17 version of the script. It fails on a few BIFF5 tests, which I just fixed in the comment. Locally the tests pass in IE11 with compatibility view level 5 as well as level 7, so I'm fairly confident in saying that any issues are likely coming with your HTML. Are you loading the shim.js script?

Here's the situation: The test suite loads using the 0.11.17 version of the script. It fails on a few BIFF5 tests, which I just fixed in the comment. Locally the tests pass in IE11 with compatibility view level 5 as well as level 7, so I'm fairly confident in saying that any issues are likely coming with your HTML. Are you loading the shim.js script?
Suncatcher commented 2018-01-11 08:42:00 +00:00 (Migrated from github.com)

Can you make that page available publicly to reproduce?

Unfortunately no. This page works in enterprise network and I cannot reproduce it.

Are you loading the shim.js script?

I wasn't, but just now I added shim, and the error didn't disappear. Still the same error.
Any suggestions?

>> Can you make that page available publicly to reproduce? Unfortunately no. This page works in enterprise network and I cannot reproduce it. >> Are you loading the shim.js script? I wasn't, but just now I added shim, and the error didn't disappear. Still the same error. Any suggestions?
Suncatcher commented 2018-01-11 08:43:10 +00:00 (Migrated from github.com)

image

![image](https://user-images.githubusercontent.com/6388034/34816019-357c07be-f6bc-11e7-8456-189fa0a01697.png)
Suncatcher commented 2018-01-12 11:50:43 +00:00 (Migrated from github.com)

Can you please, comment smth?

Can you please, comment smth?
reviewher commented 2018-01-12 16:31:02 +00:00 (Migrated from github.com)

The test suite http://oss.sheetjs.com/js-xlsx/tests/ loads and runs in all of the IE11 compatibility modes (including mode 5 and mode 7). Almost every test uses XLSX.utils.encode_cell, so your issue is not reproducible in the public site. The problem almost certainly lies in your code. Since you can't share the containing HTML, drop an email to support@sheetjs.com for more assistance.

The test suite http://oss.sheetjs.com/js-xlsx/tests/ loads and runs in all of the IE11 compatibility modes (including mode 5 and mode 7). Almost every test uses `XLSX.utils.encode_cell`, so your issue is not reproducible in the public site. The problem almost certainly lies in your code. Since you can't share the containing HTML, drop an email to support@sheetjs.com for more assistance.
Sign in to join this conversation.
No Milestone
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/sheetjs#952
No description provided.