按键精灵如何调用函数调用EXCEL数据后,总残留多个EXCEL.EXE进程,如何解决

如何解决打开多个excel文件建立多个进程的问题_百度文库
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
如何解决打开多个excel文件建立多个进程的问题
&&如何解决打开多个excel文件建立多个进程的问题
阅读已结束,下载文档到电脑
想免费下载更多文档?
定制HR最喜欢的简历
下载文档到电脑,方便使用
还剩1页未读,继续阅读
定制HR最喜欢的简历
你可能喜欢用户名:kaliking
文章数:34
评论数:79
访问量:160107
注册日期:
阅读量:1297
阅读量:3317
阅读量:583154
阅读量:468219
[匿名]51cto游客:
[匿名]darkblue:
51CTO推荐博文
不废话, 开门见山...
将 调用 Excel 的操作单独写成方法 / 函数,& 再写一个方法 / 函数 调用它, 并强制垃圾回收
//Excel 操作
public void DoSomething()&&&&&&& {
&&&&&&&&&&& Missing missing = Missing.V
&&&&&&&&&&& Excel.Application excel = new Excel.Application();
&&&&&&&&&&& if (excel == null)&&&&&&&&&&& {&&&&&&&&&&&&&&& MessageBox.Show("打开 Excel 时出错", "");&&&&&&&&&&&&&&&&&&&&&&&&&& }&&&&&&&&&&& excel.Visible =&&&&&&&&&&& excel.AlertBeforeOverwriting =&&&&&&&&&&& excel.DisplayAlerts =&&&&&&&&&&& Excel.Workbook book = excel.Workbooks.Open(TemplateFile,&&&&&&&&&&&&&&&&&&&&&&&&&&& missing, missing, missing, missing, missing, missing, missing,&&&&&&&&&&&&&&&&&&&&&&&&&&& missing, missing, missing, missing, missing, missing, missing);
&&&&&&&&&&& if (book == null)&&&&&&&&&&& {&&&&&&&&&&&&&&& MessageBox.Show("打开 Excel 时出错", "");&&&&&&&&&&&&&&&&&&&&&&&&&& }
&&&&&&&&&&& Excel.Worksheet sheet = book.Sheets[1] as Excel.W
&&&&&&&&&&& if (sheet == null)&&&&&&&&&&& {&&&&&&&&&&&&&&& MessageBox.Show("打开 Excel 时出错", "");&&&&&&&&&&&&&&&&&&&&&&&&&& }&&&&&&&&&&& try&&&&&&&&&&& {
&&&&&&&&&&&&&&&&//do something
&&&&&&&&&&& }&&&&&&&&&&& catch (Exception ex)&&&&&&&&&&& {&&&&&&&&&&&&&&& MessageBox.Show(ex.Message, "意外");
&&&&&&&&&&& }&&&&&&&&&&& finally&&&&&&&&&&& {&&&&&&&&&&&&&&&&sheet.SaveAs("c:\1.xls", missing, missing, missing, missing, missing, missing, missing, missing, missing);&&&&&&&&&&&&&&& book.Save();&&&&&&&&&&&&&&& excel.Workbooks.Close();&&&&&&&&&&&&&&& excel.Quit();&&&&&&&&&&&&&&& sheet =&&&&&&&&&&&&&&& book =&&&&&&&&&&&&&&& excel =
&&&&&&&&&&& }
//调用 DoSomething()
public void ExportData()&&&&&&& {&&&&&&&&&&& try&&&&&&&&&&& {&&&&&&&&&&&&&&& DoSomething();
&&&&&&&&&&& }&&&&&&&&&&& catch (Exception)&&&&&&&&&&& {&&&&&&&&&&&&&&&&//Error
&&&&&&&&&&& }&&&&&&&&&&& finally&&&&&&&&&&& {
&&&&&&&&&&&&&&& //垃圾回收&&&&&&&&&&&&&&& GC.Collect();&&&&&&&&&&& }&&&&&&& }
了这篇文章
类别:┆阅读(0)┆评论(0)
21:01:57 07:47:37 17:37:04 12:40:13 00:10:58随笔 - 28&
&&&&&&&&&&&
使用.net 调用Excel 生成Excel 报表 的时候 会出现 Excel.exe的进程不能关闭. 反复打开几次就会多几次Excel.exe的问题.
网上使用的关闭此进程的方法.
GC.Collect();
可是这样的方法有时不起作用.
直被一个问题困扰就是导出excel时如何关闭excel进程,我使用过oExcelApp.Quit(); 也用过GC回收,结果都不理想,后来发现可以kill进程,但是问题是kill进程 时不好解决多人并发的使用,比如一个人在导表然后kill所以的excel但是如果同时又有人在导表那么这就把另外一个excel结束了,现在我们要办的 是如何kill当前这个进程,这里我们先看一下代码:
Public Function CloseExcel(ByRef _xl As Excel.Application) As Boolean
If _xlApp Is Nothing Then
Return True
If _xlSheet Is Nothing Then
Return True
Dim PreocessExcelId As Integer = 0
BringWindowToTop(_xlApp.Hwnd)
If _xlBook IsNot Nothing Then
_xlBook.Close()
Catch ex As Exception
If Not (TypeOf (ex) Is COMException) Then
_xlApp.Quit()
GetWindowThreadProcessId(_xlApp.Hwnd, PreocessExcelId)
If PreocessExcelId & 0 Then
Dim pExcel = Process.GetProcessById(PreocessExcelId)
If pExcel IsNot Nothing Then
pExcel.Kill()
Return True
Catch ex As Exception
'_xlBook.Close()
'_xlApp.Quit()
_xlSheet = Nothing
_xlBook = Nothing
_xlApp = Nothing
End Function
&DllImport(&User32.dll&)& _
Private Shared Function GetWindowThreadProcessId(ByVal hWnd As IntPtr, ByRef OutPresId As Integer) As Integer
End Function
'BringWindowToTop
&DllImport(&User32.dll&)& _
Private Shared Function BringWindowToTop(ByVal hWnd As IntPtr) As Boolean
End Function
阅读(...) 评论()温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!&&|&&
LOFTER精选
网易考拉推荐
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
阅读(850)|
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
历史上的今天
在LOFTER的更多文章
loftPermalink:'',
id:'fks_',
blogTitle:'VB调用excel打印完后,任务管理器中的excel.exe进程无法退出',
blogAbstract:'问题现象描述:\r\nVB调用一个excel模板,往模板里填充数据,填好数据之后打印,打印完成后关闭excel对象,关闭代码如下:\r\n&exclBook.Close (True)&exclApp.Quit&Set exclSheet = Nothing&Set exclBook = Nothing&Set exclApp = Nothing但是单步调试执行了这些语句以后,能看到打开的excel被关闭了,但是任务管理器中的excel.exe 进程却没有退出,只有把程序退出了任务管理器中的excel.exe进程才会退出。\r\n在网上找答案,发现很多人都遇到了这个问题,并且大部分的回答都是说ex',
blogTag:'',
blogUrl:'blog/static/',
isPublished:1,
istop:false,
modifyTime:1,
publishTime:0,
permalink:'blog/static/',
commentCount:0,
mainCommentCount:0,
recommendCount:0,
bsrk:-100,
publisherId:0,
recomBlogHome:false,
currentRecomBlog:false,
attachmentsFileIds:[],
groupInfo:{},
friendstatus:'none',
followstatus:'unFollow',
pubSucc:'',
visitorProvince:'',
visitorCity:'',
visitorNewUser:false,
postAddInfo:{},
mset:'000',
remindgoodnightblog:false,
isBlackVisitor:false,
isShowYodaoAd:false,
hostIntro:'',
hmcon:'0',
selfRecomBlogCount:'0',
lofter_single:''
{list a as x}
{if x.moveFrom=='wap'}
{elseif x.moveFrom=='iphone'}
{elseif x.moveFrom=='android'}
{elseif x.moveFrom=='mobile'}
${a.selfIntro|escape}{if great260}${suplement}{/if}
{list a as x}
推荐过这篇日志的人:
{list a as x}
{if !!b&&b.length>0}
他们还推荐了:
{list b as y}
转载记录:
{list d as x}
{list a as x}
{list a as x}
{list a as x}
{list a as x}
{if x_index>4}{break}{/if}
${fn2(x.publishTime,'yyyy-MM-dd HH:mm:ss')}
{list a as x}
{if !!(blogDetail.preBlogPermalink)}
{if !!(blogDetail.nextBlogPermalink)}
{list a as x}
{if defined('newslist')&&newslist.length>0}
{list newslist as x}
{if x_index>7}{break}{/if}
{list a as x}
{var first_option =}
{list x.voteDetailList as voteToOption}
{if voteToOption==1}
{if first_option==false},{/if}&&“${b[voteToOption_index]}”&&
{if (x.role!="-1") },“我是${c[x.role]}”&&{/if}
&&&&&&&&${fn1(x.voteTime)}
{if x.userName==''}{/if}
网易公司版权所有&&
{list x.l as y}
{if defined('wl')}
{list wl as x}{/list}

我要回帖

更多关于 按键精灵调用cmd 的文章

 

随机推荐