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
674 stars 95 forks source link

Powerpoint office-js fails to read shapes in desktop version #2754

Open praveenbattula opened 2 years ago

praveenbattula commented 2 years ago

I have implemented the solution using Typescript, React, OfficeJS for PowerPoint. I have success in reading slides, but while reading shapes and textframes in each slide I see generic error: image

Update 08/22/2022 I have enabled full statements using command to see where exactly it fails to load: OfficeExtension.config.extendedErrorLogging = true; and below is the result: image

The code is failing at sync() method when reading textframes in a slide. The same works very fine in online version. OfficeExtension.config.extendedErrorLogging = true; return PowerPoint.run(async (context) => { var slides = context.presentation.slides; context.load(slides); await context.sync(); var shapesArray: any[] = []; for (var j = 0; j < slides.items.length; j++) { var s = slides.items[j]; var shapes = s.shapes; s.load("shapes"); shapesArray.push(shapes); } await context.sync(); var textFrames: any[] = []; for (var i = 0; i < shapesArray.length; i++) { for (var k = 0; k < shapesArray[i].items.length; k++) { var item = shapesArray[i].items[k]; if (item.type == "Image" || item.type == "Unsupported") continue; item.load("textFrame"); textFrames.push(item.textFrame); } await context.sync(); } var textRanges: any[] = []; for (var jk = 0; jk < textFrames.length; jk++) { var textFrame = textFrames[jk]; if (textFrames[jk].hasText) { textFrame.load("textRange"); textRanges.push(textFrame.textRange); } } await context.sync(); **//fails here...** var textArray: string[] = []; if (textRanges && textRanges.length > 0) for (var kj = 0; kj < textRanges.length; kj++) { if (textRanges[kj].text) textArray.push(textRanges[kj].text); } return textArray.join(" "); });

Your Environment

Expected behavior

The code if it works in office online then expect it to work on desktop version as well. This is simple text reading in a textFrame. So not sure reason for failure....

Current behavior

It just fails to execute sync() on reading text frames in a given slide.

Steps to reproduce

Any given presentation, just create taskpane add-in. Try to read slides from presentation and read shapes. Then try to read text frames. I have no success till date.

Link to live example(s)

There is no live example available.

Context

We have the implementation of add-in is completed. Works well in online but not in desktop. This is blocking us to go live as planned.

Please let me know if additional information is required. Thanks for looking into this.

ononder commented 2 years ago

Hello Praveen, I tried this code on Desktop PowerPoint, and didn't had any issues. Given that you mention this works on web, I have theory that this might be dependent on the content on the presentation.

Would you be able to isolate the issue that causes the problem? i.e. you can try to delete slides and shapes on a slide, until the error disappears. And whenever it works, we can try to understand the shape you deleted. That can give us better information on how to repro this issue.

praveenbattula commented 2 years ago

Thanks for the reply @ononder. I have tested with new powerpoint presentation which has 1 slide with a text box with text "test". And it fails to read textFrame property. I can read slides and metadata and shapes. When try to read textFrame it fails no matter what. Please make sure the version you have is same as ours "Microsoft 365 MSO (16.0.14326.21008) 32-bit Version 2108". Please let me know if you need more information.

praveenbattula commented 2 years ago

I have updated original post with additional things I have found by enabling logging. Please verify new code and image added.

Also, I have got new version of office installed on my laptop for testing. The new version is "Microsoft® PowerPoint® for Microsoft 365 MSO (Version 2202 Build 16.0.14931.20648) 32-bit" - Semi annual enterprise channel. Can someone throw some ideas or ways to fix it as it is a blocker to our production deployment. Thank you.

praveenbattula commented 2 years ago

Hi, any help on this? what else information you may need to investigate? This is a blocker and if any help would be greatly appreciated. Thank you.

sergeyhayrapetyan commented 11 months ago

Hello. I have the same problem and have not been able to find a solution for a long time. Did you manage to find a solution to the problem? If yes, please let me know.