0

Need to work with Excel automation using C#.
There is no Visual Studio installation, and can't be done. But Ms-Office 2007 is installed at workstation.
While using csc.exe for compilation, getting errors, because of Microsoft.Office assembly. I tried searching at general locations, but could not locate dll file.

using Microsoft.Office.Interop.Excel;
using Excel = Microsoft.Office.Interop.Excel;

/// no files found
/// assembly paths ; C:\Windows\assembly\Microsoft.Office.Interop.Excel
/// C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.5


class Program
{
    static void Main(string[] args)
    {
        var excelApp = new Excel.Application();
        excelApp.Workbooks.Add();

        // Insert VBA code here.

        excelApp.Visible = true;
    }
}
msinfo
  • 1,147
  • 6
  • 21
  • 39
  • you should reference the dll as you call csc with the /r parameter – fixagon Sep 12 '14 at 08:57
  • Yes, I am using E:\csharp>C:\Windows\Microsoft.NET\Framework\v3.5\csc.exe /r:C:\Windows\assembly\Microsoft.Office.Interop.Excel.dll helloworld.cs [But it fails because of reference problem.] – msinfo Sep 12 '14 at 09:52
  • Not an answer to your question but something you should know when working with the Excel Introp: http://stackoverflow.com/a/158752/2594742 – AeroX Sep 12 '14 at 11:43
  • I don't understand why you don't reference the interop DLL? Add Reference > Microsoft Office 12/14. [Here is more information](http://stackoverflow.com/a/13328392/495455). BTW VS2012 doesn't have the Setup/Deployment Wizard thats included with VS2010 you need to use something else to deploy the VSTO add-in or COM component like WIX with recent versions of Visual Studio (ie versions > VS2010). – Jeremy Thompson Sep 14 '14 at 01:10

1 Answers1

2

you can reference the DLL which is located in the GAC csc /recurse:* /r:"C:\windows\assembly\GAC_MSIL\Microsoft.Office.Inte 5.0.0.0__71e9bce111e9429c\Microsoft.Office.Interop.Excel.dll"

Depending on you office version you have eventually to change the path a bit

fixagon
  • 5,506
  • 22
  • 26
  • path - C:\windows\assembly\ doesn't have any folder or dll of above name. It cotains list of assemblies only. And right click gives option to Uninstall them and see their properties. – msinfo Sep 12 '14 at 09:36
  • 1
    it is hidden --> make Windows key + r --> paste "C:\windows\assembly\GAC_MSIL" --> enter – fixagon Sep 12 '14 at 10:43
  • I found dll @ locaiton: C:\windows\assembly\GAC_MSIL\Microsoft.Office.Tools.Excel.v9.0\9.0.0.0__b03f5f7f11d50a3a\Microsoft.Office.Tools.Excel.v9.0.dll.So while compiling I added reference as per your instructions. Now error comes like this : The type or namespace name 'Interop' does not exist in the namespace 'Microsoft.Office' (are you missing an assembly reference?) and The type or namespace name 'Excel' could not be found (are you missing a using directive or an assembly reference?). – msinfo Sep 15 '14 at 05:20
  • If I try writing < using Microsoft.Office.Tools.Excel.v9.0; > its not legal to write. – msinfo Sep 15 '14 at 05:22