导出Excel是杀进程

Public Sub OutExcFile(ByVal strUserId As String, ByVal objControl As System.Web.UI.Control)

        Dim objExcel As Excel.Application
        Dim objWorkBooks As Excel.Workbooks = Nothing
        Dim objBook As Excel.Workbook = Nothing
        Dim objSheets As Excel.Sheets = Nothing
        Dim objWorkSheet As Excel.Worksheet = Nothing

        objExcel = New Excel.Application

        Try
            Dim strOutFileName As String = CopyModel("SkillMap.xls", strUserId)

            objWorkBooks = objExcel.Workbooks

            '文件打开
            objBook = objWorkBooks.Open(strOutFileName)
            objSheets = objBook.Worksheets
            objWorkSheet = objSheets(1)

            ' 基本信息输出
            SetBaseInfo(strUserId, objWorkSheet)

            ' 技术语言信息输出
            SetLangItemStatus(strUserId, objWorkSheet)

            ' 外语能力信息输出
            SetForLanInfo(strUserId, objWorkSheet)

            ' 资格/培训,海外工作经历,业务经历,管理经历的取得设定
            SetGridView(strUserId, objWorkSheet, objExcel)

            objWorkSheet.Range("A1").Select()

            objBook.Save()

            ' 作成的文件输出
            Dim strWebFilePath As String = Web.Configuration.WebConfigurationManager.AppSettings("OutFileWebPath")
            Dim strSkillFileName = strOutFileName.Substring(strOutFileName.LastIndexOf("/") + 1)
            Dim strURL As String = "<script LANGUAGE='JavaScript'>" & "window.open('" & objControl.ResolveUrl("/" & strWebFilePath & strSkillFileName) & "')" & "</script>"
            objControl.Page.ClientScript.RegisterStartupScript(Me.GetType(), "", strURL)

        Catch ex As Exception
            Throw ex
        Finally
            If Not IsNothing(objWorkSheet) Then
                ReleaseComObject(objWorkSheet)
            End If
            If Not IsNothing(objBook) Then
                ReleaseComObject(objBook)
            End If
            If Not IsNothing(objSheets) Then
                ReleaseComObject(objSheets)
            End If
            If Not IsNothing(objWorkBooks) Then
                ReleaseComObject(objWorkBooks)
            End If

            If objExcel IsNot Nothing Then
                objExcel.UserControl = False
                'Excel退出
                objExcel.Quit()
                '对像释放
                ReleaseComObject(objExcel)
                Dim intgeneration As Integer = 0
                intgeneration = System.GC.GetGeneration(objExcel)
                objExcel = Nothing
                System.GC.Collect(intgeneration)
                System.GC.Collect()
            End If
        End Try
    End Sub

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值