Private Sub Button14_Click(sender As Object, e As EventArgs) Handles Button14.Click
Dim result_array() As Double = {5.5, 6.3, 7.5, 5, 8.2, 5.5}
Dim stCurrentDir As String = System.IO.Directory.GetCurrentDirectory()
Dim read_excel As String = "成績表_原紙.xlsx"
Dim write_excel As String = "成績表_" & Now.ToString("yyyymmddHHmmss") & "xlsx"
Dim read_path, write_path As String
Dim r As Integer
Dim okng_flag As String = "良"
read_path = stCurrentDir & "\" & read_excel
write_path = stCurrentDir & "\" & write_excel
'EXCEL変数
Dim excelApp As New Excel.Application()
Dim excelBooks As Excel.Workbooks = excelApp.Workbooks
Dim excelBook As Excel.Workbook
Dim sheet As Excel.Worksheet
Try
excelApp.Visible = False '非表示
excelBook = excelApp.Workbooks.Open(read_path)
sheet = excelApp.Worksheets(1)
For r = 0 To 5 Step 1
sheet.Cells(4, r + 3) = result_array(r)
If result_array(r) < 5 Then
okng_flag = "否"
End If
Next
sheet.Cells(4, 9) = okng_flag
excelBook.SaveAs(write_path) '名前をつけて保存
Catch ex As Exception
Throw '例外スルー
Finally
excelApp.Quit()
sheet = Nothing
excelBook = Nothing
excelApp = Nothing
Call System.Runtime.InteropServices.Marshal.ReleaseComObject(sheet)
Call System.Runtime.InteropServices.Marshal.ReleaseComObject(excelBook)
Call System.Runtime.InteropServices.Marshal.ReleaseComObject(excelApp)
End Try
End Sub