我有这个C#程序永远不会关闭Excel进程.基本上,它查找字符串在Excel中的范围中出现的实例数.我尝试了各种各样的东西,但它没有用.有一个Form调用此方法,但这不应该更改进程未关闭的原因.我看看Hans Passant的建议,但都没有.
编辑:我尝试了提到的东西,它仍然不会关闭.这是我更新的代码.编辑:尝试整个Process.Kill(),它的工作原理,但它似乎是一个应该工作的东西的黑客攻击.
public class CompareHelper
{
// Define Variables
Excel.Application excelApp = null;
Excel.Workbooks wkbks = null;
Excel.Workbook wkbk = null;
Excel.Worksheet wksht = null;
Dictionary<String, int> map = new Dictionary<String, int>();
// Compare columns
public void GetCounts(string startrow, string endrow, string columnsin, System.Windows.Forms.TextBox results, string excelFile)
{
results.Text = "";
try
{
// Create an instance of Microsoft Excel and make it invisible
excelApp = new Excel.Application();
excelApp.Visible = false;
// open a Workbook and get the active …Run Code Online (Sandbox Code Playgroud)