3

In visual Studio 2010 Console application, I added a reference to Microsoft.Office.Interop.Excel.dll from C:\Program Files (x86)\Microsoft Visual Studio 10.0\Visual Studio Tools for Office\PIA\Office14\Microsoft.Office.Interop.Excel.dll and my program to open and write into an excel file works fine. But when I run this .exe on another machine that doesn't have Microsoft Office or visual studio, it throws.

One option is to install PIA on the machines I want my program to run but I want it to be self contained. What is the best way?

Jai
  • 319
  • 2
  • 9
  • 30
  • VS2010 has the "Embed interop types" option. You don't need the PIA anymore. Use it. – Hans Passant Dec 07 '11 at 20:18
  • yes that is already set to true within VS2010. Following tips from other posts, I tried to install PIA on the other machine running Win 7, x64 but I don't think it installed anything since Office 2010 was not already installed on it. So, I tried a hack - I created C:\Program Files (x86)\Microsoft Visual Studio 10.0\Visual Studio Tools for Office\PIA\Office14 on the other machine and copied all of the contents from my dev machine over and then ran my exe, but it still doesn't work... – Jai Dec 07 '11 at 21:48
  • You cannot interop with Excel if Excel is not installed on the machine. – Hans Passant Dec 07 '11 at 21:56

1 Answers1

2

If you only need to open and write to excel files, use any public source libraries for working with xls / xlsx files and do not use Microsoft.Office.Interop.Excel.dll at all.

See Reading Excel files from C# or http://koogra.sourceforge.net/.

Community
  • 1
  • 1
Alpha01
  • 838
  • 6
  • 13
  • use any public source libraries - I am unclear on that, Can you please give an example? – Jai Dec 07 '11 at 20:35