所以我最近在我当前的项目中打开了 Option Strict On,在修复了选项引发的所有小错误之后,我碰到了这个。
Public Sub ExportarExcel(ByVal grilla As DataGridView)
Dim excelApp As Excel.Application
Dim workbook As Excel.Workbook
Dim sheet As Excel.Worksheet
Dim i As Integer = 1
Dim j As Integer = 1
excelApp = CType(CreateObject("Excel.Application"), Excel.Application)
workbook = excelApp.Workbooks.Add
sheet = CType(workbook.Worksheets.Add, Excel.Worksheet)
For Each col As DataGridViewColumn In grilla.Columns
sheet.Cells(1, i).Borders.LineStyle = Excel.XlLineStyle.xlContinuous 'Problematic line
sheet.Cells(1, i) = col.HeaderText
i = i + 1
Next
i = 2
For Each row As DataGridViewRow In grilla.Rows
j = 1
For Each cell As DataGridViewCell In row.Cells
sheet.Cells(i, j).Borders.LineStyle = Excel.XlLineStyle.xlContinuous 'Problematic line
sheet.Cells(i, j) = cell.Value
j = j + 1
Next
i = i + 1
Next
sheet.Columns.AutoFit()
excelApp.Visible = True
End Sub
这两行(从开头到“边界”)引发了后期绑定错误,我不确定哪些是这些行的正确转换或修复。