1

I'm creating a WPF application in Visual Studio 2015 that uses Microsoft.Office.Interop.Word for create Word document.When I create setup file for my project and run it in my PC everything is good but when I install and run it on a different PC it doesn't work.

How can i add Microsoft.Office.Interop.Word to setup file?

vasil oreshenski
  • 2,788
  • 1
  • 14
  • 21
omid naghipoor
  • 178
  • 1
  • 2
  • 12
  • I think the problem is that Office needs to be installed on the target PC. The interop just allows you to access the installed version of Office. – Steve Feb 20 '18 at 15:04
  • 1
    It's also worth looking at OpenXml, which can create a Word document without running an instance of the Word application. It's not the easiest thing to work with, but neither is Interop. If you download the OpenXml SDK there is an app that will take an existing Word document and generate code that creates the equivalent OpenXml files. If all you're doing is some content that might change then quite possibly you could create your document, generate the code, and then modify the code to work with some inputs. Or try building it from scratch. – Scott Hannen Feb 20 '18 at 15:10
  • 2
    An alternative is to use something like NPOI. https://github.com/tonyqus/npoi – Steve Feb 20 '18 at 15:10
  • 3
    @Steve - I forgot about NPOI. That's a wrapper for OpenXML. I think it's the closest thing to EPPlus for Word. (EPPlus is an OpenXML library for Excel.) Also, take a look at [this sample code](https://stackoverflow.com/questions/16194646/create-word-document-with-open-xml). If you're already doing the work with interop, this might not be too bad. – Scott Hannen Feb 20 '18 at 15:13
  • 1
    @ScottHannen Don't forget about [DocX](https://github.com/xceedsoftware/DocX). I've used it in a couple of projects. Much easier than Open XML SDK, though I haven't used NPOI. – mason Feb 20 '18 at 15:23
  • @mason Thanks - I'm clearly way out of touch when it comes to Word. – Scott Hannen Feb 20 '18 at 15:25

2 Answers2

1

This interop is registered in the GAC after office / msword install on the PC. (which means you don't need to distribute the dll)

Check here for more info about PIAs. It states the following:

To perform certain development tasks, the PIAs must be installed and registered in the global assembly cache on the development computer. Typically, the PIAs are installed automatically when you install Office on the development computer. For more information, see Configuring a Computer to Develop Office Solutions.

The Office PIAs are not required on end-user computers to run Office solutions. For more information, see Designing and Creating Office Solutions.

Best option is to use some alternative of MsWord (check comments) or you can check on startup in the registry for the office install if available and if not you need to notify the user which functionalities won't work (or disallow usage of the application if more appropriate).

vasil oreshenski
  • 2,788
  • 1
  • 14
  • 21
0

You don't need to explicitly include PIA as part of your set up (from C#4 onward)

In your local - right click assembly properties and make Embed Interop Type to true. Relevant types required to communicate to office com type will get embedded to your assembly.

enter image description here

rahulaga-msft
  • 3,964
  • 6
  • 26
  • 44