如何从在word.interop c#中运行进程的任务管理器中完全终止打开的excel.exe?

问题描述 投票:0回答:1

我必须打开一个excel文件,并希望将数据获取到word文档中。我以前经常拥有此代码。

    private Excel.Application excelapp;
    Type ExcelType = Type.GetTypeFromProgID("Excel.Application");
    dynamic ExcelInst = Activator.CreateInstance(ExcelType);
    this.excelapp = ExcelInst;

    this.workbook = this.excelapp.Workbooks.Open(Filename : this.filePath, ReadOnly: true);

因此,我使用了所有技术来关闭/退出/处理打开的进程。 (不要杀)。那些行不通。找不到解决方案。

c# excel office-interop word
1个回答
0
投票

我使用以下命令打开excel并阅读/更新。

Excel.Application app;
Excel.Workbook wb;
private void openAndRead()
{

 app = new Excel.Application();
 wb = app.Workbooks.Open(YourFileHere);

//do stuff here read or write
//app.ActiveSheet.Cells[1, "A"] = "write this in cell A1";
//string read= app.ActiveSheet.Cells[1, "A"]; 

}

private void closeExcel ()
{
 app.DisplayAlerts = false; //this will stop popup questions from excel
 wb.Close();
 app.Quit();
}
© www.soinside.com 2019 - 2024. All rights reserved.