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
导出Excel是杀进程
最新推荐文章于 2024-09-10 14:15:01 发布