asp.net生成xls文件完成后自动关闭excel进程代码

asp教程.net生成xls文件完成后自动关闭excel进程代码
//方法一

gc.collect();
        applicationclass excel;
        _workbook xbk;
        _worksheet xst;
        excel = new applicationclass();
        xbk = excel.workbooks.add(true);
        xst = (_worksheet)xbk.activesheet;
           //自定义代码...
        //结束时
        xbk.close(false, null, null);
        excel.quit();
        system.runtime.interops教程ervices.marshal.releasecomobject(xbk);
        system.runtime.interopservices.marshal.releasecomobject(excel);
        system.runtime.interopservices.marshal.releasecomobject(xst);
        xbk = null;
        excel = null;
        xst = null;

//方法二

 

finally
            {
                ((microexcel._application)tempapp).workbooks.close();
                int32 tempgeneration = gc.getgeneration(tempapp);
                ((microexcel._application)tempapp).quit();
                gc.collect(tempgeneration);
                //上面部分在winform中就已经干掉excel进程了,但是在asp.net教程中还不行          
                process[] myprocesses;
                myprocesses = process.getprocessesbyname("excel");

                //得不到excel进程id,暂时只能判断进程启动时间
                foreach (process myprocess in myprocesses)
                {
                    try
                    {
                        datetime starttime = myprocess.starttime;

                        if (starttime >= tempstart && starttime <= tempend)
                        {
                            myprocess.kill();
                        }
                    }//直接在vs中运行网页就不会有取不到starttime的问题
                    catch//有一些核心进程是不允许访问的,因此而引起的异常可以捕获并放弃处理
                    { }
                }
                    
            }

时间: 2024-08-26 09:07:15

asp.net生成xls文件完成后自动关闭excel进程代码的相关文章

通过文件结构直接生成xls文件

以下代码演示了直接通过excel可以识别的文件结构生成xls文件的方法,这样就可以不引用麻烦的ole了. 1.using System;2.using System.Collections.Generic;3.using System.Text;4.namespace ConsoleApplication165.{6. class Program7. {8. static void Main( string [] args)9. {10. //不通过OLE生成excel文件的方法11. Exce

通过excel可识别的xml结构直接生成xls文件

上一片文章演示了如何根据简单的excel文件结构直接生成xls文件,如果涉及到合并,公式之类的复 杂操作,可以使用xml结构来直接构造xls文件,比如生成如下所示文件 上图中D列和E列为 公式,第4行为公式合计,7.8行为合并过的单元格.完整代码如下: using System;using System.Collections.Generic;using System.Text;using System.Xml;namespace ConsoleApplication17{ class Prog

C# 请问如何把asp.net生成shtml文件(急,在线等)

问题描述 C#请问如何把asp.net生成shtml文件 解决方案 解决方案二:http://blog.csdn.net/jyk/archive/2006/03/07/617376.aspxhttp://www.cnblogs.com/T_98Dsky/archive/2005/08/25/222992.html解决方案三:http://blog.csdn.net/chestnuts/archive/2006/12/08/1435061.aspx解决方案四:请问您的意思是生成一个纯的静态页还是使

Linux下按照时间和大小生成新文件的程序流程及其C代码实现

一.概述 在实际的软件开发项目中,会出现按照时间和大小生成新文件的需求.例如,某软件需求的描述如下: 按照如下两个条件之一生成新的文件: 第一,新的一天到来. 第二,文件的大小超过阈值. 本文详细介绍了根据时间和大小生成新文件的程序流程,并给出了C程序实现. 二.算法设计 对于这个按照不同的条件生成新文件的需求,在编写代码之前,我们要认真考虑以下问题: 1.如何知道当前写文件的时间与上次时间相比,是新的一天? 对于这个问题,最简单的做法是将上次写完文件之后的时间保存在内存中,等下次写文件之前读取

vs2013 asp.net 生成网站文件太多了,如何精简?

问题描述 做个小网站,生成后感觉好臃肿,bin.packages.Scripts,这几个文件夹就有60多兆,里面文件多如牛毛,ftp上传半天都传不完,感觉好痛苦难道里面的文件没有可以精简的吗?如何让网站文件数量减少,体积减小呢?感谢各位大虾指教,^_^ 解决方案 解决方案二:除了bin文件之外,那些诸如样式啊.脚本啊之类的文件夹内的文件如果没用到的,可以一律干掉啊.不过我觉得这些文件夹不会太大!!可能是生成项目时,VS自动添加了很多dll(有些实际却没用到的)!!底子好的就可以把那些干掉解决方案

用ASP+FSO生成JS文件

asp+|fso|js <!--#include file="conn.asp"-->  <%  set js = server.CreateObject("ADODB.RecordSet")  sql="select top 10 * from article order by id desc"  set js = conn.Execute (Sql)  do while not js.eof      title=js(&q

用ASP+FSO生成JS文件_FSO专题

复制代码 代码如下: <!--#include file="conn.asp"-->  <%  set js = server.CreateObject("ADODB.RecordSet")  sql="select top 10 * from article order by id desc"  set js = conn.Execute (Sql)  do while not js.eof      title=js(&qu

如何用Asp动态生成xml文件

xml|动态|生成xml 相关代码如下:FunctionReplaceChar(FstrSource)dimstrRetifIsNull(FstrSource)then FstrSource=""endifstrRet=Replace(FstrSource,"&","&")strRet=Replace(strRet,"<","<")strRet=Replace(strRet,&q

asp.net生成csv文件代码

using system.web; public class sdsavecsv {         /// <summary>         /// 构造函数         /// </summary>         /// <param name="response">httpresponse对象</param>         public sdsavecsv(httpresponse response)         {