visual studio2012 でwindowsフォームアプリを作成します。
データグリッドビューのデータをExcelに出力するようにしています。
ですが、Excelを閉じてもタスクが残ってしまいます。
調べながら色々と試してみましたが、全然だめでした。
ソースは以下の通りです。
'出力ボタン Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Dim app As Excel.Application = Nothing Dim book As Excel.Workbook = Nothing Dim sheet As Excel.Worksheet = Nothing Dim books As Excel.Workbooks = Nothing Try 'Excelを開く app = New Excel.Application() 'Bookを開く books = app.Workbooks book = books.Open("C:\form3\Book1.xlsx") 'シートの指定 sheet = book.Worksheets(1) 'Excelに出力する For i As Integer = 0 To DataGridView1.Rows.Count - 1 sheet.Range("A" & i + 2 & "").Value = DataGridView1.Rows(i).Cells(1).Value sheet.Range("B" & i + 2 & "").Value = DataGridView1.Rows(i).Cells(4).Value sheet.Range("C" & i + 2 & "").Value = DataGridView1.Rows(i).Cells(5).Value sheet.Range("D" & i + 2 & "").Value = DataGridView1.Rows(i).Cells(6).Value sheet.Range("E" & i + 2 & "").Value = DataGridView1.Rows(i).Cells(7).Value Next 'Excelの表示 app.Visible = True '5秒だけ表示する System.Threading.Thread.Sleep(5000) '保存する book.Save() '閉じる app.Quit() Catch ex As Exception Throw ex Finally Marshal.ReleaseComObject(sheet) Marshal.ReleaseComObject(books) Marshal.ReleaseComObject(book) Marshal.ReleaseComObject(app) End Try End Sub
「Excelを閉じてもタスクが残ってしまいます。」 とありますが、ここでいう「タスク」って何ですか?

回答5件
あなたの回答
tips
プレビュー