private void openExcelFile()
{
try
{
//ExcelApp,用来读取Sheet名
Excel.Application myApp=new Excel.ApplicationClass();
//Excel表
Excel.Sheets sheets; //Excel工作簿
Excel.Workbook xBook; this.cboExcelSheet.Items.Clear();
xBook = myApp.Workbooks._Open(@strOpenFilePath,Missing.Value,Missing.Value,Missing.Value,Missing.Value
,Missing.Value,Missing.Value,Missing.Value,Missing.Value
,Missing.Value,Missing.Value,Missing.Value,Missing.Value);
sheets = xBook.Worksheets; foreach(Excel.Worksheet item in sheets)
{
this.cboExcelSheet.Items.Add(item.Name.ToString());
System.Runtime.InteropServices.Marshal.ReleaseComObject(item);
} //System.Windows.Forms.Application.Exit(); if(sheets != null && xBook != null)
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(sheets);
System.Runtime.InteropServices.Marshal.ReleaseComObject(xBook);
System.Runtime.InteropServices.Marshal.ReleaseComObject(myApp); sheets = null;
xBook = null;
myApp = null;
GC.Collect();
this.Cursor = Cursors.Default;
}
// KillProcess("EXCEL.EXE");
// this.Cursor = Cursors.Default;
}
catch(Exception err)
{
MessageBox.Show(err.Message,this.Text,MessageBoxButtons.OK,MessageBoxIcon.Information);
this.Cursor = Cursors.Default;
}
}
在线等
{
try
{
//ExcelApp,用来读取Sheet名
Excel.Application myApp=new Excel.ApplicationClass();
//Excel表
Excel.Sheets sheets; //Excel工作簿
Excel.Workbook xBook; this.cboExcelSheet.Items.Clear();
xBook = myApp.Workbooks._Open(@strOpenFilePath,Missing.Value,Missing.Value,Missing.Value,Missing.Value
,Missing.Value,Missing.Value,Missing.Value,Missing.Value
,Missing.Value,Missing.Value,Missing.Value,Missing.Value);
sheets = xBook.Worksheets; foreach(Excel.Worksheet item in sheets)
{
this.cboExcelSheet.Items.Add(item.Name.ToString());
System.Runtime.InteropServices.Marshal.ReleaseComObject(item);
} //System.Windows.Forms.Application.Exit(); if(sheets != null && xBook != null)
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(sheets);
System.Runtime.InteropServices.Marshal.ReleaseComObject(xBook);
System.Runtime.InteropServices.Marshal.ReleaseComObject(myApp); sheets = null;
xBook = null;
myApp = null;
GC.Collect();
this.Cursor = Cursors.Default;
}
// KillProcess("EXCEL.EXE");
// this.Cursor = Cursors.Default;
}
catch(Exception err)
{
MessageBox.Show(err.Message,this.Text,MessageBoxButtons.OK,MessageBoxIcon.Information);
this.Cursor = Cursors.Default;
}
}
在线等
放在其他地方没有用
{
System.Diagnostics.Process myproc= new System.Diagnostics.Process();
//得到所有打开的进程
try
{
foreach (Process thisproc in Process.GetProcessesByName(processName))
{
if(!thisproc.CloseMainWindow())
{
thisproc.Kill();
}
//MessageBox.Show("杀死" + processName + "成功!");
}
}
catch(Exception Ex)
{
//MessageBox.Show("杀死" + processName + "失败!");
}
}
比如我要杀的是EXCEL,那我上面调用的时候是不是KillProcess("EXCEL.EXE");这样?
这个方法也不好啊,会把其他EXCEL进程都杀死的
下载地址:http://www.eudev.net简介
ExcelQuicker是为了提高报表产出率和功能而诞生的一款高效、强大的Excel报表控件,它虽然也要通过COM操作VBA完成Excel报表,但是在它的内部,我进行了专门的优化,使其运行期效率大大的高过了通常普通的操作VBA接口。更为重要的是,通过对Excel VBA接口的二次封装,使其开发变得更加简便、易懂。并且结合实际应用,为开发人员提供了更为简便的开发途经,使得Excel报表的开发易如反掌,并且,将Excel报表具有的更多的功能呈现出来。同时,提高了运行效率、开发效率、强化了功能...主要技术特征:
以抽象工厂为主要涉及模式,另有Composite、Strategy等;
通过FxCop代码警察检测,全项开启,仅21项报警;
支持OLAP透视表,以及所有类型的透视图Chart;
可跨应用程序域访问,支持.NET Remoting技术;
支持列表,并支持列表对应的8种Chart图形,现在主要是饼图和柱图,其他类型图待扩展;
优化批量数据导出;
模板化编程,ExcelQuicker中的所有涉及都围绕这一主旨,大大减少了你的开发负担;
……
{
if(!thisproc.CloseMainWindow())
{
thisproc.Kill();
}
}