Search code examples
printingoffice-jsoffice-addinsexcel-addinsexcel-web-addins

How to add a print functionality to Office Add-in?


I am building an Excel Add-in with the Office JS API. Is there a way to handle printing with the Add-in or open a printing window?

I have been going through the documentation but can't find any methods for this. Am I missing something?

Edit: To be more specific, I want to open the Excel print dialog with the Add-in.


Solution

  • There is no API in Office.js to invoke the Excel print dialog. If you know that all the users of your add-in will be working on Windows machines, using desktop Excel, you might look into whether a VSTO/VBA add-in has this feature. But if some users will be using Excel on the web or Excel on Mac, you'll have to stick to an Office.js add-in. In the later case, the best you can do is have your add-in prompt and/or instruct users to print from the Excel UI. You can have some control over the layout of the worksheet when it prints. See Work with worksheets - Page layout and print settings for more information.

    You can suggest that Office add-ins be given access to the print UI at Microsoft 365 Developer Platform Ideas, but I suspect that security concerns would make it unlikely that Office.js-based add-ins, which are web applications, would be given that feature. The JavaScript/HTML that is hosted by a web application can be changed by its creator after the add-in has been installed by a user and/or approved by an administrator. This makes it possible for a rogue add-in creator to change the behavior of the add-in post-installation.