Microsoft Graph support for editing open PowerPoint files
Asked Answered
D

0

8

I have a scenario where the user's open PowerPoint presentation needs to be modified by a custom solution. I'm looking at using a PowerPoint web add-in in conjunction with the Graph API's support for OneDrive/SharePoint files.

However, PowerPoint has nothing specifically available in the JavaScript for Office API yet for replacing the contents of the actively edited presentation. As a proof of concept, I've tried using Graph to overwrite a specific PowerPoint file in OneDrive using the upload command, but it throws an error because the file is open in PowerPoint for Windows:

Status Code: 423 Microsoft.Graph.ServiceException: Code: resourceLocked 
Message: The resource you are attempting to access is locked 
Inner error:    AdditionalData:     
                date: 2020-10-05T21:06:53   
                request-id: 5e3c2604-382d-4139-a433-8b95ef4f619e    
                client-request-id: 5e3c2604-382d-4139-a433-8b95ef4f619e 
ClientRequestId: 5e3c2604-382d-4139-a433-8b95ef4f619e

I note that if I open that same file in PowerPoint Online, the sharing icon indicator triggers and I'm able to make changes in either editor that are nearly immediately updated in the other editor. So a protocol exists for making live changes. I'm guessing this is through WOPI??. Is there another Graph method available I can use that can support this scenario? Or do I have to build a full WOPI client and/or server solution to do this (which looks insane, if it's possible)?

Descombes answered 5/10, 2020 at 21:38 Comment(8)
I have a use case very similar to this. What do you mean by "both" editors? I am assuming you called the upload API end point in OneDrive using something like python-pptx to edit the file and update it? How would changes you make in PowerPoint Web update automatically without another download REST API call from One Drive?Minoru
Have you tried the OneDrive API with a different Authenticated user than the one who's currently signed in with PowerPoint Web?Minoru
Graph API does not support PowerPoint (or any other office application) explicitly, as far as I know. It's not about that. If you want to edit PowerPoint file in the office PowerPoint application, you probably want to build a PowerPoint add-in. Why are you saying there is no API? It looks like there is, you can start over here: learn.microsoft.com/en-us/office/dev/add-ins/reference/overview/… If you want to allow the user to securely edit a file that is hosted by you using the PP, then you want WOPI, yes.Molehill
@GauravRamanan it's not clear what you want to achieve - do you want to allow a user to edit some PP files using MS PowerPoint, but improve the editing experience by adding some functions (add-in scenario) or you want to generate some PowerPoint files yourself and upload them somewhere.Molehill
@Molehill Take a look at Python - PPTX It can manipulate almost anything in PowerPoint by changing its XML. However, I cannot run it on a file that is currently open in the same system. The OP has tried to solve this problem by "fetching the file contents" of the file via OneDrive and feeding the contents into something like python-pptx. That way. if this is possible, the file can be simultaneously edited by the current system user as well as through this tool simultaneously. Almost working like an Add In. JS / VBA is not applicable for me.Minoru
The JS API is woefully inadequate (especially for PPT) try making any serious Add In and you'll hit a wall. The DX is too bad for VBA and more advanced stuff (like Network Requests) doesn't even work on MacOS. The Solution needs to be Cross Platform.Minoru
@GauravRamanan As far as I know, it is not possible to use python library from a browser JavaScript (i.e. from an office JavaScript add-in). You need some backend (server) where you run your python scripts. Am Iissing thd point?Molehill
You could consider using web assembly to process office files to be able to use advanced libraries from Javascript (still no python though, as far as I can tell). The file locking is controlled by the application that edits it. This is to prevent editing conflicts. Javascript add-in API allows you to update document XML content, in the already opened file. Check out my article on using openxml (default library for processing office docs) from Javascript: medium.com/@nbelyh/…Molehill

© 2022 - 2024 — McMap. All rights reserved.