So i recently turned Option Strict On in my current project and after fixing all of the small errors that option throws i bumped into this one.
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
Those two lines (from the start to “Borders.”) are throwing a late binding error and i’m not sure which is the proper cast or fix for those lines.
According to the documentation I found (here: http://msdn.microsoft.com/en-us/library/office/ff822605.aspx, and here: http://msdn.microsoft.com/en-us/library/office/aa612949(v=office.10).aspx), the
Bordersproperty returns a collection, indexed by constant that represents which border you want (top, bottom, left, right, etc.)Your line should maybe look like this,