OneNote JavaScript API access element

507 Views Asked by At

I have tried to create my first One Note Add In using the JavaScript API. I have tried the example in the MS documentaion (Build your first OneNote task pane add-in). This one works.

Now I want to try to change the formatting of an element in the document. For example I want to change the font colour of a text. However, I have not yet found a way to access the elements in a document.

Can I access elements in a document via a JS Add In to change their "style" property? How can I do that?

Thanks Micheal

1

There are 1 best solutions below

1
On

Finally, I found a way to access the OneNote page content from the JS Add In. You can load the page content using

var page = context.application.getActivePage();
var pageContents = page.contents;

context.load(pageContents);

Now you have access to the page content in the qued commands.

return context.sync().then( function() {

  var outline = pageContents.items[0].outline;    
  outline.appendHtml("<p>new paragraph</p>");

  var p = outline.paragraphs;
  context.load(p);
  ...
});

So consequently you can access element by element in document the hirarchy.