将数据库的内容输出到EXCEL为什么不好使?

将数据库的内容输出到EXCEL为什么不好使?? 输出几行就报错,错误提示"Invalid row number"
Private Sub Command1_Click()
Dim i As Integer, j As Integer
Dim newxls As New Excel.Application
Dim newbook As Excel.Workbook
Dim newsheet As Excel.Worksheet
Set newxls = CreateObject("Excel.Application")
newxls.Visible = True
Set newbook = newxls.Workbooks.Add
Set newsheet = newbook.Worksheets(1) For i = 0 To Data1.Recordset.RecordCount - 1
For j = 0 To Data1.Recordset.Fields.Count - 1
DBGrid1.Row = i
DBGrid1.Col = j
newsheet.Cells(i + 1, j + 1) = DBGrid1.Text
Next j
Next i
End Sub
[640 byte] By [longbao] at [2008-1-9]
# 1
还有一个 For 在哪里?

--------------------------------------------------------------
程序,犹如人生。
cangwu_lee-橙子 at 2007-10-18 > top of Msdn China Tech,visual basic,非技术类...
# 2
Sorry,原来躲在后面了。

For i = 0 To Data1.Recordset.RecordCount - 1
For j = 0 To Data1.Recordset.Fields.Count - 1
if Not isNull(Data1.Recordset.Fields(j).value) then
newsheet.Cells(i + 1, j + 1) = Data1.Recordset.Fields(j).value
end if
Next j
Next i

--------------------------------------------------------------
程序,犹如人生。
cangwu_lee-橙子 at 2007-10-18 > top of Msdn China Tech,visual basic,非技术类...
# 3
问题出在哪里啊??
longbao at 2007-10-18 > top of Msdn China Tech,visual basic,非技术类...