1

所以我最近在我当前的项目中打开了 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

这两行(从开头到“边界”)引发了后期绑定错误,我不确定哪些是这些行的正确转换或修复。

4

2 回答 2

1

根据我找到的文档(这里: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
于 2012-11-14T22:41:19.900 回答
0

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

于 2012-11-14T21:29:25.063 回答