我做了一个excel到出的程序,导出的数据如果没有为空的话可以正常导出.但是如果导出的数据中,只要有一个单元格为空的话,就会出现:时实错误13,类型不匹配
代码如下:
Dim i As Integer
     Dim j As Integer
     Dim m As Integer
     Dim n As Integer
     Dim k As Integer
     Set xlApp = CreateObject("excel.application")
     Dim xlBook As Object
     Dim xlSheet As Object
     xlApp.Visible = True
     '建立excel对象的工作薄对象
     Set xlBook = xlApp.Workbooks.Add
      '建立excel对象的工作表对象
     Set xlSheet = xlBook.Worksheets(1)
     j = DataGrid1.Columns.Count
     i = 0
     
     For n = 0 To j - 1
        '如果DataGrid1表格中第n列可见,则将其该列的列标题输出至excel表
        If DataGrid1.Columns(n).Visible = True Then
            '在excel表中的第2行,第i列对应的单元格中显示DataGrid1表格中第n列的列标题
            xlSheet.Cells(1, i + 1) = DataGrid1.Columns(n).Caption
            i = i + 1
        End If
     Next n
    Adodc1.Recordset.MoveFirst
    m = 0
     Do While Not Adodc1.Recordset.EOF
         
        i = 1
        For n = 0 To j - 1
           '如果ataGrid1表格中第n列可见,则将其该列的值输出至excel表
          If DataGrid1.Columns(n).Visible = True Then
             If DataGrid1.Columns(n) = Null Then
               xlSheet.Cells(m + 2, i) = ""
              Else
              '在excel表中的第m+3行,第i列对应的单元格中显示DataGrid1表格中第n列的值
              xlSheet.Cells(m + 2, i) = DataGrid1.Columns(n).Value--调试的时候这里错
              i = i + 1
              End If
           End If
        Next n
       Adodc1.Recordset.MoveNext
        m = m + 1
       Loop
  xlApp.Visible = True       '显示Excel
  Set xlApp = Nothing        '交还控制给Excel
  Set xlBook = Nothing
  Set xlSheet = Nothing
请大家帮帮我