Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. //Function to get ooxmldocument via XMLHttpRequest
  2.  
  3. function getTemplate(fileName) {
  4.  
  5. var myOOXMLRequest = new XMLHttpRequest();
  6.  
  7. var myXML;
  8.  
  9. myOOXMLRequest.open('GET', fileName, false);
  10.  
  11. myOOXMLRequest.send();
  12.  
  13. if (myOOXMLRequest.status === 200) {
  14.  
  15. myXML = myOOXMLRequest.responseText;
  16. console.log('myXML VariabelData: ', myXML);
  17. return myXML;
  18. }
  19. return "" ;
  20. }
  21.  
  22. // Insert a 'default' template with logo and contentControllers in header and footer of the xml
  23. function insertDefaultTemplate() {
  24.  
  25. Word.run(function (context) {
  26. var body = context.document.body;
  27.  
  28. // Synchronize the document state by executing the queued commands, and return a promise to indicate task completion.
  29. return context.sync().then(function () {
  30.  
  31. var t = getTemplate('/Content/Templates/BrevmallMD.xml', 'Replace');
  32.  
  33. body.insertText("Formaterar dokument...", Word.InsertLocation.start);
  34.  
  35. return context.sync().then(function () {
  36.  
  37. body.insertOoxml(t, Word.InsertLocation.replace);
  38.  
  39.  
  40. return context.sync().then(function () {
  41. showNotification("Standardmallen är införd!", "Välj användaruppgifter.");
  42. });
  43. });
  44. })
  45. }).catch(function (error) {
  46. errorHandler();
  47. })
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement