简体   繁体   English

C#命令行添加对Microsoft.Office.Interop.Excel的引用

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

Need to work with Excel automation using C#. 需要使用C#使用Excel自动化。
There is no Visual Studio installation, and can't be done. 没有安装Visual Studio,无法完成。 But Ms-Office 2007 is installed at workstation. 但是Ms-Office 2007安装在工作站上。
While using csc.exe for compilation, getting errors, because of Microsoft.Office assembly. 使用csc.exe进行编译时,由于Microsoft.Office程序集而出现错误。 I tried searching at general locations, but could not locate dll file. 我尝试在常规位置搜索,但找不到dll文件。

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" 您可以引用位于GAC csc / recurse:* / r中的DLL:“ 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 根据您的Office版本,您最终必须更改路径

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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