0

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);
    }
  });
}
tompen78
  • 3
  • 2

1 Answers1

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.

Rick Kirkham
  • 9,038
  • 1
  • 14
  • 32
  • 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. – tompen78 Apr 17 '23 at 07:48
  • 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! – tompen78 Apr 17 '23 at 07:49
  • 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. – Rick Kirkham Apr 17 '23 at 20:27
  • 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! https://gist.github.com/ThomasHeron/038f463c41e095d1da11a4f3c56c0c0c – tompen78 Apr 18 '23 at 06:52
  • ScriptLab is telling me that that is not a valid gist URL. `https://gist.github.com/ThomasHeron/038f463c41e095d1da11a4f3c56c0c0c` – Rick Kirkham Apr 18 '23 at 19:09
  • Strange. I put the link in the ScriptLab import dialogue and it worked for me. I went to github --> Share --> Copy shareable link for this gist. Not sure how else to do it. BTW ScriptLab is also saying that the coersion type (XmlSvg) is not supported. https://gist.github.com/ThomasHeron/038f463c41e095d1da11a4f3c56c0c0c – tompen78 Apr 19 '23 at 07:00
  • According to this, https://learn.microsoft.com/javascript/api/requirement-sets/common/image-coercion-requirement-sets?view=excel-js-preview#imagecoercion-12, PowerPoint does support XmlSvg. Can you add a screenshot of the coercion type error to your question? – Rick Kirkham Apr 19 '23 at 16:56
  • Exactly that's what I expect... I posted the code for the function in the original question along with a screenshot of the error I receive. Thanks! – tompen78 Apr 20 '23 at 07:01
  • I was able to open your gist in a browser and block copy it to Script Lab. I also get the "undefined" error, but I don't get the error about coercion type. Consider raising this as a a bug on the [office-js](https://github.com/OfficeDev/office-js/issues/new/choose) repo. – Rick Kirkham Apr 20 '23 at 16:56
  • Thanks Rick! I just reported this to the office-js repo as you suggested. The number is #3309 for anyone that might come across the same issue. https://github.com/OfficeDev/office-js/issues/3309 – tompen78 Apr 21 '23 at 07:10