关闭Excel的应用程序在C#中的数据访问后, [英] Closing Excel Application Process in C# after Data Access

查看:255
本文介绍了关闭Excel的应用程序在C#中的数据访问后,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写在C#中打开一个Excel模板文件进行读/写操作的应用程序。我想,当用户关闭应用程序,Excel应用程序进程已被关闭,但不保存Excel文件。看到我的任务管理器应用程序的多个运行后。

I'm writing an application in C# that opens an Excel template file for read/write operations. I want to when user closes the application, excel application process has been closed, without saving excel file. See my Task Manager after multiple runs of the app.

我用这个code打开Excel文件:

I use this code to open the excel file :

public Excel.Application excelApp = new Excel.Application();
public Excel.Workbook excelBook;
excelBook = excelApp.Workbooks.Add(@"C:/pape.xltx");

和数据访问我用这个code:

and for data access I use this code :

Excel.Worksheet excelSheet = (Worksheet)(excelBook.Worksheets[1]);
excelSheet.DisplayRightToLeft = true;
Range rng;
rng = excelSheet.get_Range("C2");
rng.Value2 = txtName.Text;

我看到计算器类似的问题,如<一个href=\"http://stackoverflow.com/questions/12530303/close-excel-application-process-after-data-has-been-fetched\">this问题和和考试答案,但它不工作

I see similar questions in stackoverflow such as this question and this, and test answers, but it doesn't works.

推荐答案

试试这个:

excelBook.Close(0); 
excelApp.Quit();

在关闭工作簿,你有三个可选参数:

When closing the work-book, you have three optional parameters:

Workbook.close SaveChanges, filename, routeworkbook 

Workbook.Close(假)或者如果你正在做后期绑定,有时更容易使用零
Workbook.Close(0)
这是一种自动的工作簿的结束当我是怎么做到的。

Workbook.Close(false) or if you are doing late binding, it sometimes is easier to use zero Workbook.Close(0) That is how I've done it when automating closing of workbooks.

我也去了,抬头一看对应的文档,并在这里找到:
<一href=\"http://office.microsoft.com/client/help$p$pview.aspx?AssetId=HV805549059990&lcid=1033&NS=EXCEL.DEV&Version=12&CTT=4\">Excel工作簿关闭

Also I went and looked up the documentation for it, and found it here: Excel Workbook Close

谢谢,

这篇关于关闭Excel的应用程序在C#中的数据访问后,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆