データ テーブルをサブ プロシージャに渡そうとしています。エラーが発生しましたが、エラーが発生した理由がわかりません。列/行のインデックスが 0 に設定されていますか?
私のコードの67行目は....
wBook.SaveAs(strFName)
Private Sub DataTableToExcel(ByVal dtTemp As DataTable)
Try
Dim _excel As New Microsoft.Office.Interop.Excel.Application
Dim wBook As Microsoft.Office.Interop.Excel.Workbook
Dim wSheet As Microsoft.Office.Interop.Excel.Worksheet
wBook = _excel.Workbooks.Add()
wSheet = wBook.ActiveSheet()
Dim dt As System.Data.DataTable = dtTemp
Dim dc As System.Data.DataColumn
Dim dr As System.Data.DataRow
Dim cIndex As Integer = 0
Dim rIndex As Integer = 0
For Each dc In dt.Columns
cIndex = cIndex + 1
_excel.Cells(1, cIndex) = dc.ColumnName
Next
For Each dr In dt.Rows
rIndex = rIndex + 1
cIndex = 0
For Each dc In dt.Columns
cIndex = cIndex + 1
_excel.Cells(rIndex + 1, cIndex) = dr(dc.ColumnName)
Next
Next
wSheet.Columns.AutoFit()
Dim strFName As String = "H:\RawDataReport\" & txtGPSystemNum.Text & dtpInvoiceDate.Text & _
".xlsx"
If System.IO.File.Exists(strFName) Then
System.IO.File.Delete(strFName)
End If
wBook.SaveAs(strFName)
wBook.Close()
_excel.Quit()
Catch ex As Exception
MessageBox.Show(ex.ToString())
End Try
End Sub