迟绑定错误

所以我最近把我的当前项目中的选项严格打开,并修复了所有的选项抛出我碰到这个小错误后。

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 

这两行(从开始到“边界”)都抛出了一个晚期绑定错误,我不知道哪个是适当的演员或修复这些行。

根据我find的文档(这里: http : //msdn.microsoft.com/en-us/library/office/ff822605.aspx ,和在这里: http : //msdn.microsoft.com/en-us/library/ office / aa612949(v = office.10).aspx ), Borders属性返回一个集合,用常量索引,表示你想要的边界(上,下,左,右等)

你的线应该看起来像这样,

 sheet.Cells(1, i).Borders(xlEdgeBottom).LineStyle = Excel.XlLineStyle.xlContinuous 

你可以使用sheet.Cells(i, j).Text = cell.Valuesheet.Cells(i, j).Value = cell.Value (这可能是Value2)