1
votes

rangeObject.GetImage() works great in Excel for Windows, partially works in Excel Online, and returns an upside-down image in Excel for Mac 16.16.1.

I use range.getImage() to get a picture of exactly what is in a range. This is then used in other Office applications.

  • In Excel for Windows (version 1806), it works perfectly as I had hoped. It gets anything put on the range, including cell content, images, shapes, etc. pasted in the range.

  • In Excel Online, it simply gets the cell content, including text, borders, background color, and conditional formatting, but not other things pasted on top of the range.

  • In Excel for Mac (version 16.15), it only returns a black image (with the correct dimensions).

  • In Excel for Mac (version 16.16.1 and 16.18), it returns an upside-down image that does not have the correct colors (blue instead of black). It also does not have shapes/images inserted on top of the range.

To duplicate the issue in Script Lab: select a range with some content, then run this code:

$("#run").click(run);
function run() {
    Excel.run(function (ctx) {
        var rng = ctx.workbook.getSelectedRange();
        var image = rng.getImage();
        return ctx.sync().then(function () {
            var srcImage = "data:image/png;base64, " + image.value;
            $("#img").attr("src", srcImage);
        });
    }).catch(function (error) {
        console.log("Error: " + error);
        if (error instanceof OfficeExtension.Error) {
            console.log("Debug info: " + JSON.stringify(error.debugInfo));
        }
    });
}
<p class="ms-font-m">Shows the range image below</p>
<button id="run" class="ms-Button">
    <span class="ms-Button-label">Run code</span>
</button><br/>
<img id="img" src="" alt="" />

Is this a known issue? Will the method (new in API 1.7) become consistent across platforms? If so, when?

Also added here: https://github.com/OfficeDev/office-js/issues/235

1

1 Answers

0
votes

Yes, This is a known issue. our team has tried to fix the issue, however, the code didn't check-in, because based on team's investigation, this is a not bug level fix, it would lead to other potential issues. 2585831 is the workitem that we are tracking.