Excel JavaScript API Part 5: The large numbers bug

There is currently (JavaScript Excel API set 1.4) a rather nasty bug when writing large integer numbers (anything larger than int32) back to a range.

30 January 2018 – API set 1.7 – this bug is still there!

The JS can correctly read these large numbers – it just silently gets the wrong answer when writing them back.

Testing what works and what does not work

I ran 5 tests:

  1. 9876543210 – a large integer
  2. 9876543210.0 – a large double that can convert to an integer
  3. 9876543210.1 – a large non-integer double
  4. ‘9876543210’ – a large number as a string
  5. “‘9876543210” – a large number as a string prefixed with ‘

The results were:

  1. 1286608618 – wrong
  2. 1286608618 – wrong
  3. 9876543210.1 – correct
  4. 9876543210 – gives a number but the string type has been ignored by Excel
  5. ‘9876543210 – correct – Excel treats this as string because of the ‘

Here is the test code:

async function run() {
try {
await Excel.run(async (context) => {
let sheet = context.workbook.worksheets.getActiveWorksheet();
let rng1 = sheet.getRange("A3");
rng1.values = [[9876543210]];
let rng2 = sheet.getRange("A5");
rng2.values = [[9876543210.0]];
let rng3 = sheet.getRange("A7");
rng3.values = [[9876543210.1]];
let rng4 = sheet.getRange("A9");
rng4.values = [['9876543210']];
let rng5 = sheet.getRange("A11");
rng5.values = [["'9876543210"]];

await context.sync();
catch (error) {

The Hacky Bypass

The real problem of course comes when you use JS to read a range and write it back but you don’t know what the range contains. If it’s a large integer your code is FUBAR.

The only current bypass is to loop through the range values, test for large integers and convert them to string by surrounding with ‘.


I sure hope this gets fixed soon!

This entry was posted in Excel, JS-API and tagged , . Bookmark the permalink.

4 Responses to Excel JavaScript API Part 5: The large numbers bug

  1. dougaj4 says:

    Charles – are you still working with JavaScript?

    I have been experimenting with the “Insider” JavaScript UDFs. It seems that the large number bug is fixed (at least in the UDF version), but I’d say it is very much a work in progress. I was not able to get the MS tutorials working for some reason, but I bought a guide from Mr Excel “JavaScript, Straight to the Point” (cost about $5.00), and got it working with that (except using Onedrive, which I still can’t get to work).
    The main problem I have had is using largeish arrays (i.e. more than about 200,000 rows x 1 column) return #NA (even if the return value is a single value), and you have to re-load the add-in to get it working again.

  2. fastexcel says:

    Glad the JS UDF book worked for you: I did the Tech Edit on it a few months ago. Yes – I noticed the problem with large arrays and JS UDFs, and IIRC I passed it on to MS. The problem is made worse by the fact that you cannot pass a range (everything arrives as arrays) and do intersect with used range. So full column refs are a big no-no at the moment. My recommendation (as well as fixing the bug) was to consider automatically truncating arrays either to the used range or to the last array cell actually containing data.

    Are you coming to our Develop Excel conference in October?

    • dougaj4 says:

      Not being able to find the end of an array passed from a UDF does seem like a pretty big drawback!
      London is a bit of a hike from Sydney for one day for the conference (and we’ll be enjoying a trip to the Barrier Reef anyway:))

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s