none
Why do I get Internal Error 5001 from setFormatsAsync in one case but not another? RRS feed

  • Question

  • I am developing a simple web add-in for Excel 2013 (desktop).  I have the Office.js v1.1 framework installed. I have searched this forum and read the other posts about error 5001 w/setFormatsAsync and: a) I am using a Table binding, b) desktop Excel 2013 not Excel Online, and c) have the v1.1 of the Office.js framework. 

    I observe that depending on how I construct the "cells" object in the arguments I pass to setFormatsAsync, in one case it works as expected and in another case it fails with Internal Error 5001.  Here's the pertinent code:

            // pretend these values came from the UI as strings ...
            var row = "2";
            var col = "2";
            var target;
            var flag = 1; // 1 succeeds, 0 fails!
            if (flag === 0)
                target = { cells: { row: Number(row), column: Number(col) }, format: { backgroundColor: "gray" } };
            else
                target = { cells: { row: 2, column: 2 }, format: { backgroundColor: "gray" } };
            var targets = [];
            targets.push(target);
            binding.setFormatsAsync(targets,
                function (result) {
                    if (result.status === Office.AsyncResultStatus.Failed) {
                        var failed = 1;
                    }
                    else {
                        var succeeded = 1;
                    }
                }
            );

    In the code fork where the object that is set as the "cells" property contains its row and column properties converted from string to Number, the call fails (flag=0). But when I hard wire the values (flag=1) as row: 2, column: 2 then the setFormatsAsync call succeeds.

    I am not a javascript expert, but this seems like both code paths should behave the same. Any explanation for this?  Thanks.


    Shaun Logan - Oracle

    Monday, October 26, 2015 3:33 PM

Answers

  • >>>In the code fork where the object that is set as the "cells" property contains its row and column properties converted from string to Number, the call fails (flag=0). But when I hard wire the values (flag=1) as row: 2, column: 2 then the setFormatsAsync call succeeds.

    According to your description, I have made a sample and reproduced this issue.
    Base on my testing, I suggest that you could modify your code like below:

    target = { cells: { row: parseInt(row), column: parseInt(col) }, format: { backgroundColor: "gray" } };


    • Edited by David_JunFeng Tuesday, November 3, 2015 9:15 AM
    • Proposed as answer by David_JunFeng Friday, November 6, 2015 8:12 AM
    • Marked as answer by Shaun Logan Friday, November 6, 2015 1:55 PM
    Tuesday, October 27, 2015 9:39 AM

All replies

  • >>>In the code fork where the object that is set as the "cells" property contains its row and column properties converted from string to Number, the call fails (flag=0). But when I hard wire the values (flag=1) as row: 2, column: 2 then the setFormatsAsync call succeeds.

    According to your description, I have made a sample and reproduced this issue.
    Base on my testing, I suggest that you could modify your code like below:

    target = { cells: { row: parseInt(row), column: parseInt(col) }, format: { backgroundColor: "gray" } };


    • Edited by David_JunFeng Tuesday, November 3, 2015 9:15 AM
    • Proposed as answer by David_JunFeng Friday, November 6, 2015 8:12 AM
    • Marked as answer by Shaun Logan Friday, November 6, 2015 1:55 PM
    Tuesday, October 27, 2015 9:39 AM
  • Thanks! using parseInt(x) instead of Number(x) makes setFormatsAsync() work as expected.

    Shaun Logan - Oracle

    Friday, November 6, 2015 1:56 PM