Wednesday, November 4, 2015

Office Word add-ins: Insert template base on Word, Part 1

This is a three-part blog series to introduce Word Add-in and how to use Open XML SDK for JavaScript. The goal of these blog posts is to create an Office add-in that can insert a Word base template into another Word file. By describe how to create a Word add-in that can read a Word file and use the file as a template. This allow an user to choice and insert a prepare template and the templates is easy created in Word.

User case:

  1. An user starts Word with the add-in.
  2. The user presses a button in the add-in.
  3. The add-in call a services for the template.
  4. The add-in insert the template in the current Word file.

Steps, Create the project and setup API services to return a template:

  1. Create a Word add-in project base on the “App for Office”.clip_image002clip_image004clip_image006
  2. Add a WebAPI webservice to the project.
    Add a Web API Controller Class to the project. N.B.! remember to post-fixet the filename with Controller!
    clip_image008Edit the ApiController to return a base64 string.
    This example read a docx file from a sub folder “Documetns” in the website that host the Add-in.
    clip_image010Add a Global.asax to the project to allow ApiController to be start and call.

    Add the folder “Documents” file to the project and create a Word file named template1.docx. And the project structure and Word file shout look something like this.clip_image015

Related blog posts

No comments:

Post a Comment