This resolved the issue for me. Your code becomes:

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

  

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

And then release all those objects, (Note: All the com object should be release, othewise the excel process won't be closed.)

System.Runtime.InteropServices.Marshal.ReleaseComObject(rng);
System.Runtime.InteropServices.Marshal.ReleaseComObject(excelSheet);
System.Runtime.InteropServices.Marshal.ReleaseComObject(sheets);
excelBook .Save();
excelBook .Close(true);
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlBook);
System.Runtime.InteropServices.Marshal.ReleaseComObject(workbooks);
excelApp.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp);

I wrap this in a try {} finally {} to ensure everything gets released even if something goes wrong (what could possibly go wrong?) e.g.

public Excel.Application excelApp = null;
public Excel.Workbooks workbooks = null;
...
try
{
excelApp = new Excel.Application();
workbooks = excelApp.Workbooks;
...
}
finally
{
...
if (workbooks != null) System.Runtime.InteropServices.Marshal.ReleaseComObject(workbooks);
excelApp.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp);
}

解决C#使用Microsoft.Office.Interop.Excel操作Excel后进程一直存在的问题的更多相关文章

  1. C# Microsoft.Office.Interop.Owc11 导出excel文件

    C# Microsoft.Office.Interop.Owc11 导出excel文件 1.新建项SupremeWindowsForms窗体应用项目(项目平台设置称X86) 注意:因为大多数第三方写的 ...

  2. Microsoft.Office.Interop.Excel, Version=12.0.0.0版本高于引用的程序集(已解决)

    Microsoft.Office.Interop.Excel, Version=12.0.0.0版本高于引用的程序集(已解决) 论坛里的帮助:http://bbs.csdn.net/topics/39 ...

  3. Excel操作 Microsoft.Office.Interop.Excel.dll的使用

    ----转载: http://www.cnblogs.com/lanjun/archive/2012/06/17/2552920.html 先说说题外话,前段时间近一个月,我一直在做单据导入功能,其中 ...

  4. C# 使用自带Microsoft.Office.Interop.Excel简单操作Excel文件

    项目添加应用 Microsoft.Office.Interop.Excel.dll 文件 引用命名空间: using Excel = Microsoft.Office.Interop.Excel; 简 ...

  5. Microsoft.Office.Interop.Excel操作Excel文件时出现的问题及解决方案

    问题描述: Microsoft.Office.Interop.Excel.Worksheet 打不开文件 Microsoft Office Excel 不能访问文件"a.xls". ...

  6. 解决方法:未能加载文件或程序集“Microsoft.Office.Interop.Excel。。

    .NET错误提示:未能加载文件或程序集“Microsoft.Office.Interop.Excel, Version=11.0.0.0, Culture=neutral, PublicKeyToke ...

  7. c#操作excel方式三:使用Microsoft.Office.Interop.Excel.dll读取Excel文件

    1.引用Microsoft.Office.Interop.Excel.dll 2.引用命名空间.使用别名 using System.Reflection; using Excel = Microsof ...

  8. Microsoft.Office.Interop.Excel Find 操作

    public void SearchLoactions(string filepath, int start, int end ,string expectvalue) { if (end >= ...

  9. 引用Microsoft.Office.Interop.Excel出现的问题

    引用Microsoft.Office.Interop.Excel出现的问题   转自:http://www.hccar.com/Content,2008,6,11,75.aspx,作者:方继祥 操作背 ...

随机推荐

  1. Selenium2+python自动化69-PhantomJS使用【转载】

    前言 PhantomJS是一个没有界面的浏览器,本质上是它其实也就是一个浏览器,只是不在界面上展示. PhantomJS非常适合爬虫方面,很多玩爬虫的都喜欢用这个浏览器. 一.PhantomJS环境准 ...

  2. 《锋利的JQuery》读书要点笔记4——表格表单的操作

    第五章 jQuery对表单,表格的操作以及更多应用 这章主要以一些具体案例讲解了jQuery对表单,表格的常用操作,以及一些常见的jQuery应用,用到的都是上几章说的东西.下面就以具体的案例来展开. ...

  3. C#实现DES加密解密,AES加密解密

    DES算法描述简介: DES是Data Encryption Standard(数据加密标准)的缩写.它是由IBM公司研制的一种加密算法,美国国家标准局于1977年公布把它作为非机要部门使用的数据加密 ...

  4. Codeforces 1023 B.Pair of Toys (Codeforces Round #504 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Fi)

    B. Pair of Toys 智障题目(嘤嘤嘤~) 代码: 1 //B 2 #include<iostream> 3 #include<cstdio> 4 #include& ...

  5. COW

    COW 时间限制: 1 Sec  内存限制: 64 MB提交: 41  解决: 18[提交][状态][讨论版] 题目描述 Bessie the cow has stumbled across an i ...

  6. UVA548 Tree (二叉树的遍历)

    You are to determine the value of the leaf node in a given binary tree that is the terminal node of ...

  7. 传统路径导出 VS 直接路径导出(oracle exp direct=y)

    Oracle 传统的Export与Import依旧被保留到11g,而且9i与10g有很多依旧使用Export与Import方式进行备份与恢复的企业.从Oracle 7.3开始,传统的exp导出程序提供 ...

  8. py thon 多线程(转一篇好文章)

    http://www.cnblogs.com/fnng/p/3670789.html

  9. TZOJ 5347: 数据结构实验:删除链表元素

    描述 完成链表的创建.元素查找和删除等操作. 部分代码已经给出,请补充完整,提交时请勿包含已经给出的代码. void PrintLinkList(Node *head) { int flag = 0; ...

  10. IntelliJ IDEA字符串常量长度太长的问题解决:constant string too long

    Java compiler下的Use compiler为Eclipse: