OfficeDev / office-js

A repo and NPM package for Office.js, corresponding to a copy of what gets published to the official "evergreen" Office.js CDN, at https://appsforoffice.microsoft.com/lib/1/hosted/office.js.
https://learn.microsoft.com/javascript/api/overview
Other
687 stars 94 forks source link

range.getImage() returns unknown response on Excel Mac #4921

Closed sahil-shubham closed 2 weeks ago

sahil-shubham commented 1 month ago

Your Environment

Expected behavior

Using the Range.getImage() on the above mentioned excel desktop on mac returns an unknown string. Ideally, this should have been a base64 string.

Current behavior

The current behaviour results in the following output. The same code running on the excel web returns this instead. I don't see any console errors.

Steps to reproduce

  1. Try range.getImage() for say the used range

Context

Trying to get an image of the excel sheet and identify different table boundaries using a model in the backend.

Useful logs

shanshanzheng-dev commented 1 month ago

Hi @sahil-shubham Thanks for reporting this issue. Could you share us your test code, that will help us repro your issue better. Thanks.

sahil-shubham commented 1 month ago

@shanshanzheng-dev Here you go. Thanks for the quick response on the issue.

Let me know if you need anything else from my side.

shanshanzheng-dev commented 1 month ago

Hi @sahil-shubham Thanks, I can repro, we'll take a look this and report back if we have a suggestion for you, but unfortunately, we can't share the timeline.

XuanZhouMSFT commented 1 month ago

Hi @sahil-shubham, thanks for reporting this issue. I see the base64 string in MAC, Win43 and online are different. But they are all valid to use. You can try it with sample code like "context.workbook.worksheets.getActiveWorksheet().shapes.addImage(mybase64.value)" to have a try.

sahil-shubham commented 1 month ago

@XuanZhouMSFT Thank you for the quick reply.

You are right about the image string being valid to the extent that one can add the image back in the sheet. Although I am unable to decode this string to image anywhere else (including making a data URI of it), what image type would this be? And why are the strings different in the first place?

XuanZhouMSFT commented 1 month ago

@sahil-shubham Could you help to share what do you want to do with the base64 string? And if possible, could you help to share some sample code about why the base64 string not work in your way? It could help me better understand your problems and provide suggestion.

sahil-shubham commented 1 month ago

The main goal is to use the sheet image for doing object detection. Before doing this we load the image and do some resizing operations using node-canvas, this process works well for when testing on browser but on desktops the resulting data URI formed with the base64 string is unable to load.

To make the data URI, I just append data:image/png;base64, at the start of the base64 string. It's weird how I am unable to see or load this desktop base64 string anywhere, except in the case when you put it back into the sheet as a shape.

You can see with the two output gists I linked in the issue description, one image is valid to be loaded and another isn't. That is how I came to conclusion of this being an unknown string.

XuanZhouMSFT commented 1 month ago

@sahil-shubham Thanks for waiting. I can reproduce your problem locally. Recently we release a fix for this issue. Please help to update your version to be 16.90.24100615 or later, and then try again. Please let me know if your problem still exists.

sahil-shubham commented 1 month ago

Updated and tested on the above version, it works. Thank you for your time, this issue can be closed now.

RuizhiSunMS commented 2 weeks ago

Close this case since the customer confirmed.