Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
'エクセルに出力
If Me.ListView1.Items.Count = 0 Then
MessageBox.Show("リンクはありません。", "データなし", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Exit Sub
End If
Dim oEx As Object
Dim book As Object
Dim i As Integer = 1
Try
'エクセルオブジェクト作成
oEx = CreateObject("Excel.Application")
'ワークブック作成
book = oEx.workbooks.add
Do Until i = Me.ListView1.Items.Count + 1
oEx.cells(i, 1).value = Me.ListView1.Items(i - 1).SubItems(0).Text
oEx.cells(i, 2).value = Me.ListView1.Items(i - 1).SubItems(1).Text
oEx.cells(i, 3).value = Me.ListView1.Items(i - 1).SubItems(2).Text
i = i + 1
Loop
'エクセル表示
oEx.visible = True
Catch ex As Exception
MessageBox.Show(ex.Message.ToString, "エラー", MessageBoxButtons.OK, MessageBoxIcon.Error)
Finally
'後始末
book = Nothing
oEx = Nothing
End Try
End Sub
|