How to use Graph API to edit Word or PowerPoint content

Satya Revanth Kumar Majji (AU) 0 Reputation points
2024-03-13T06:12:31.9233333+00:00

How can I use the Microsoft Graph API to extract content from a Word or PowerPoint document, find and replace specific text, and then update the existing document? I have attempted to use https://graph.microsoft.com/v1.0/me/drive/items/{drive-item-id}/content, but the content is in a non-readable format.

Screen Shot 2024-03-13 at 5.10.53 pm

Word
Word
A family of Microsoft word processing software products for creating web, email, and print documents.
687 questions
Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,796 questions
PowerPoint
PowerPoint
A family of Microsoft presentation graphics products that offer tools for creating presentations and adding graphic effects like multimedia objects and special effects with text.
227 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Sourabh Gupta 795 Reputation points Microsoft Vendor
    2024-03-16T10:46:22.15+00:00

    Hi @Satya Revanth Kumar Majji (AU) ,Thanks for reaching out.

    The content endpoint on drive item returns a stream. In order to edit a word or PowerPoint document you need to use some library to get the document from a stream. one such popular third party library is Aspose. You can load the document using aspose and edit it programmatically.

    Once the document is edited you can save it and upload it by using graph api (in the upload api of the graph use conflict behavior as replace)

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".