|
分類:[ASP.NET (VB)]
はじめまして。EXCELが開放されなくて困っています。
色々なサイトを見て調べましたが原因がわかりません。
どなたかご教授お願いします。
以下ソース
Dim Script As String
Dim oExcel As New Excel.Application
'WorkBookオブジェクト
Dim oBook As Excel.Workbook
Dim oBooks As Excel.Workbooks
Dim oSheet As Excel.Worksheet
Dim xlRange As Excel.Range
If FileUpload.HasFile = False Then
Exit Sub
End If
Try
If Path.GetExtension(FileUpload.FileName) = ".xls" Or _
Path.GetExtension(FileUpload.FileName) = ".Xls" Then
'Excelを非表示にする
oExcel.Application.Visible = False
'エクセルのファイル名
oBooks = oExcel.Workbooks
oBook = oBooks.Open(FileUpload.PostedFile.FileName)
oSheet = oBook.Worksheets(1)
xlRange = oSheet.Cells
txtJyuchuSaki.Text = xlRange.Range("E19").Value
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlRange)
xlRange = oSheet.Cells
txtJyuchuSaki.Text &= xlRange.Range("F19").Value
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlRange)
xlRange = oSheet.Cells
txtJyuchuSaki.Text &= xlRange.Range("G19").Value
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlRange)
xlRange = oSheet.Cells
txtJyuchuSaki.Text &= xlRange.Range("H19").Value
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlRange)
xlRange = oSheet.Cells
txtKoujiMei.Text = xlRange.Range("E21").Value
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlRange)
xlRange = oSheet.Cells
txtKoujiBasyo.Text = xlRange.Range("E22").Value
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlRange)
xlRange = oSheet.Cells
txtKouki_S.Text = xlRange.Range("E27").Value & "/"
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlRange)
xlRange = oSheet.Cells
txtKouki_S.Text &= xlRange.Range("G27").Value
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlRange)
xlRange = oSheet.Cells
txtKouki_S.Text &= xlRange.Range("H27").Value & "/"
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlRange)
xlRange = oSheet.Cells
txtKouki_S.Text &= xlRange.Range("I27").Value
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlRange)
xlRange = oSheet.Cells
txtKouki_S.Text &= xlRange.Range("J27").Value
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlRange)
xlRange = oSheet.Cells
txtKouki_E.Text = xlRange.Range("L27").Value & "/"
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlRange)
xlRange = oSheet.Cells
txtKouki_E.Text &= xlRange.Range("N27").Value
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlRange)
xlRange = oSheet.Cells
txtKouki_E.Text &= xlRange.Range("O27").Value & "/"
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlRange)
xlRange = oSheet.Cells
txtKouki_E.Text &= xlRange.Range("P27").Value
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlRange)
xlRange = oSheet.Cells
txtKouki_E.Text &= xlRange.Range("Q27").Value
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlRange)
xlRange = oSheet.Cells
txtJyuChuKin.Text = ConvDec(xlRange.Range("E28").Value).ToString("#,##0")
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlRange)
xlRange = oSheet.Cells
txtJyuChuGenka.Text = ConvDec(xlRange.Range("E29").Value).ToString("#,##0")
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlRange)
xlRange = oSheet.Cells
txtYoteiGenka.Text = ConvDec(xlRange.Range("E30").Value).ToString("#,##0")
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlRange)
xlRange = oSheet.Cells
txtSyohizei.Text = ConvDec(xlRange.Range("R28").Value).ToString("#,##0")
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlRange)
xlRange = oSheet.Cells
txtMituMoriNo.Text = xlRange.Range("AE28").Value
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlRange)
xlRange = oSheet.Cells
txtZairyo.Text = ConvDec(xlRange.Range("E31").Value).ToString("#,##0")
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlRange)
xlRange = oSheet.Cells
txtGaichuHi.Text = ConvDec(xlRange.Range("E33").Value).ToString("#,##0")
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlRange)
xlRange = oSheet.Cells
txtRoumuHi.Text = ConvDec(xlRange.Range("E34").Value).ToString("#,##0")
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlRange)
xlRange = oSheet.Cells
txtKeihi.Text = ConvDec(xlRange.Range("E35").Value).ToString("#,##0")
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlRange)
xlRange = oSheet.Cells
txtBF.Text = xlRange.Range("E41").Value
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlRange)
xlRange = oSheet.Cells
txtBF.Text &= xlRange.Range("F41").Value
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlRange)
xlRange = oSheet.Cells
txtF.Text = xlRange.Range("G41").Value
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlRange)
xlRange = oSheet.Cells
txtF.Text &= xlRange.Range("H41").Value
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlRange)
xlRange = oSheet.Cells
txtRF.Text = xlRange.Range("I41").Value
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlRange)
xlRange = oSheet.Cells
txtRF.Text &= xlRange.Range("J41").Value
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlRange)
xlRange = oSheet.Cells
txtTatemono.Text = ConvDec(xlRange.Range("E42").Value).ToString("#,##0")
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlRange)
lblView()
Else
Script = "<script language=javascript>" + "window.alert('EXCELファイルではありません。')" + "</script>"
Response.Write(Script)
End If
Catch ex As Exception
Finally
If Not (xlRange Is Nothing) Then
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlRange)
xlRange = Nothing
End If
If Not (oSheet Is Nothing) Then
System.Runtime.InteropServices.Marshal.ReleaseComObject(oSheet)
oSheet = Nothing
End If
If Not (oBook Is Nothing) Then
oBook.Close()
System.Runtime.InteropServices.Marshal.ReleaseComObject(oBook)
oBook = Nothing
End If
If Not (oBooks Is Nothing) Then
oBooks.Close()
System.Runtime.InteropServices.Marshal.ReleaseComObject(oBooks)
oBooks = Nothing
End If
If Not (oExcel Is Nothing) Then
oExcel.Quit()
System.Runtime.InteropServices.Marshal.ReleaseComObject(oExcel)
oExcel = Nothing
End If
GC.Collect()
End Try
End Sub
|