Search code examples
reporting-servicesms-word

Using a Word template in SSRS


I have a word document currently used in a mail merge. My product owner wants it setup to use SSRS so we can take advantage of internally generated data in addition to the stock data our vendor's platform provides. The platform integrates with SSRS so options that are not SSRS are not available to me. I found this question but it's been inactive for 9 years and didn't get a lot of traffic and the linked blog post appears to be gone.

Using a Word document as a template for an SSRS report?

Is there any way to use the word doc as a template, or some kind of starting point in SSRS?


Solution

  • Unfortunately this is not possible without a lot of work. I had the same issue several years ago and ended up writing an application in C# to do all the work. This was not something that we could achieve in a few days.

    Just in case you considered going that route, here are some of the issues you might face and what we did to get round them.

    1. Font/Styles: We wanted to apply certain styles to sections such as the contents page, numeric tables, blocks of text. Within the SSRS report was an option to 'use tags' (via a report parameter). This allowed us to add tags that could be used to search/replace or style anything within them. The app would look for these tags style according to the template
    2. Nested tables: Our reports were mainly tables of data interspersed with blocks of text. SSRS tries to gets things to physically align with what you see on screen so it tends to put everything in tables. This causes problems when you want to find blocks of text etc (as above) so I had to write a routine that would look for the innermost table and extract that. Sometimes this would select the wrong table such as if column are merged, SSRS will create yet another table to contain just that one piece of text so I had to add tags to the report to tell the app what to expect. All very messy.

    The basic principle was to get SSRS to dump out a word file then our app would read thru it and extract the content, pasting it into a new document which was based on our Word Template.

    If I had to repeat the process avoid doing what I did and I would concentrate on getting SSRS to output exactly what was required, matching the template design but this is only good if you don't have things like form fields etc as SSRS cannot produce these.

    Word Automation is another option but that is slow or maybe look at some of the Apose renderers and see if they are of any use. ( https://www.aspose.com/ )

    Sorry its not the answer you wanted but hopefully it will save you some time trying to figure it out.