Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 后期绑定错误_.net_Vb.net_Visual Studio 2010_Excel - Fatal编程技术网

.net 后期绑定错误

.net 后期绑定错误,.net,vb.net,visual-studio-2010,excel,.net,Vb.net,Visual Studio 2010,Excel,所以我最近在我当前的项目中启用了Option Strict,在修复Option抛出的所有小错误后,我遇到了这个错误 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 D

所以我最近在我当前的项目中启用了Option Strict,在修复Option抛出的所有小错误后,我遇到了这个错误

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

这两行(从开始到“Borders.”都出现了延迟绑定错误,我不确定哪一行是正确的转换或修复。你可以使用
sheet.Cells(i,j)。Text=cell.Value
sheet.Cells(i,j)。Value=cell.Value
(这可能是Value2)

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

根据我找到的文档(此处:,此处:),属性
Borders
返回一个集合,由表示所需边框(顶部、底部、左侧、右侧等)的常量索引

你的线路应该是这样的

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

根据我找到的文档(此处:,此处:),属性
Borders
返回一个集合,由表示所需边框(顶部、底部、左侧、右侧等)的常量索引

你的线路应该是这样的

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

您是否尝试使用值1而不是
Excel.XlLineStyle.xlContinuous
?@Steve尝试过,但错误指向“sheet.Cells(1,i).Borders”行的左侧您是否尝试使用值1而不是
Excel.XlLineStyle.xlContinuous
?@Steve尝试过,但错误指向“sheet.Cells”行的左侧(一)边界”