简体   繁体   中英

C# command line add reference to Microsoft.Office.Interop.Excel

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;
    }
}

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM