1

I must be missing something, but I cannot seem to figure out how to build a simple function to copy and paste a shape in my Office Addin for PowerPoint. Seems there is no support for this. At least not what I can find in the APIs for PowerPoint. Really hope I am missing something obvious here...

The work around I use at the moment is to copy all available attributes of the shapes I want to copy and then add a new shape with the same attributes. This would be fine (even though cumbersome), but only some attributes are accessible (like height, width etc.). Many text / paragraph formatting attributes are still missing.

Hope someone knows a better way to do this! Any support will be greatly appreciated!

error message I receive in ScriptLab:

$("#run").click(run);

function run() {
  Office.context.document.getSelectedDataAsync(Office.CoercionType.XmlSvg, {}, (asyncResult) => {
    if (asyncResult.status === Office.AsyncResultStatus.Failed) {
      //await context.sync();
      console.error(asyncResult);
    } else {
      //await context.sync();
      console.log(asyncResult);
    }
  });
}

1 Answer 1

0

I think this can be done with the Common APIs. Try using document.getSelectedDataAsync and setSelectedDataAsync. The reference for the Common APIs is office package.

Sign up to request clarification or add additional context in comments.

10 Comments

I was hoping for a better solution, but I think you are right that this is the only way available for now. The drawback with the setSelectedDataAsynch for SVGs is that it is not a "real" shape (it is obviously a SVG). Which means that adjustment points and other shape specific attributes are lost in the process. For the getSelectedDataAsynch part I have not been successful in getting the function to return a value. I only get "undefined" returned.
This is my function as it is written now; getSelectedSVG = async () => { await PowerPoint.run(async (context) => { Office.context.document.getSelectedDataAsync( Office.CoercionType.XmlSvg, function (result) { const dataValue = result.asyncContext as string; console.log(dataValue); return dataValue as any; } ); await context.sync(); }); }; My understanding is it should return a string for the XML, but I get only undefined. Any ideas where I go wrong? Thanks!
It would be great if you could reproduce this in the Script Lab tool. If you can, create a gist and provide the URL to the gist.
Good idea. I get the same issue in ScriptLab as well. Hope you can access the gist the way I provided it! Many thanks for your support! <script src="gist.github.com/ThomasHeron/…> gist.github.com/ThomasHeron/038f463c41e095d1da11a4f3c56c0c0c
ScriptLab is telling me that that is not a valid gist URL. https://gist.github.com/ThomasHeron/038f463c41e095d1da11a4f3c56c0c0c
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.