Search code examples
javascriptexcelggplot2bokehoffice-js

Creating embedded web browser or iframe in Excel Javascript API


I'm trying to create an Office-JS project which will take some form data, which i've created inside a Excel Taskpane Form. Then when they submit it will send a request to my website which will process the form and spit back some HTML/JS as strings for Bokeh or ggplot.

Thus my question: Is there a way to create an "embedded" iframe or Microsoft web browser that I can put html/js into and send the "left side" with context.sync() using the Excel JS API?

I've found documentation about using the built in graphs, but I was hoping to pass back more complex graphs: https://learn.microsoft.com/en-us/office/dev/add-ins/excel/excel-add-ins-charts

Something like this: enter image description here

To put it into code, this is where i'm stuck:

function getData(){
     return Excel.run( function (context) {
         return context.sync().then( function () {

         .ajax({
             <my url and form data>

         }).done( function(data, status, xhr) {
             var browser = create_browser(); // I do not know what this would be

             // Bokeh route returns data["script"] & data["div"]
             // (\n<script type="text/javascript">\n ... <div class="bk-plotdiv" id="30d5b5cf-da07-4382-9b93-09ac605ba96d"></div>\n</div>)

             browser.render(data["script"], data["div"])
             sheet.getRange().values = browser
         })
    })
})

Solution

  • I think what you might want is a Content add-in. This is an example of one: Excel Content Add-in Humongous-Insurance. Some more information at Create new objects in Office documents. But you can't have both a browser in a task pane and one in the Excel document. These are different add-in types and the add-in manifest specifies the type. You will need to have the form as well as the resulting graphic in the content window.