Share via

How to use Graph API to edit Word or PowerPoint content

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

Microsoft 365 and Office | Word | For business | Windows
Microsoft 365 and Office | PowerPoint | For business | Windows
Microsoft Security | Microsoft Graph
0 comments No comments

3 answers

Sort by: Most helpful
  1. Sourabh Gupta 805 Reputation points Microsoft External Staff
    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".

    Was this answer helpful?

    1 person found this answer helpful.

  2. Mallipeddi, Haritha 0 Reputation points
    2024-12-16T14:10:33.0866667+00:00

    test test test setset sets tset set setsetsets t

    Was this answer helpful?

    0 comments No comments

  3. Ross Cullen 46 Reputation points
    2024-05-28T12:52:45.7766667+00:00

    Do you know what kind of stream this is?

    I have several suggestions from copilot/chatGPT to deal with the "stream" but it is unclear whether its a binary stream, a byte stream or something else...

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.