[FIELDSET][LEGEND]引自:1楼[/LEGEND]
读者您好:
很抱歉我们不能帮你修改程序,只能给你开发思路:
首先引用EXCEL对象,并使用ADO数据库控件绑定Datagrid 控件,然后按照如下代码操作:
Dim i As Integer, r As Integer, c As Integer
Dim newxls As Excel.Application
Dim newbook As Excel.Workbook
Dim newsheet As Excel.Worksheet
Set newxls = CreateObject("Excel.Application") '创建excel应用程序,打开excel2000
Set newbook = newxls.Workbooks.Add '创建工作簿
Set newsheet = newbook.Worksheets(1) '创建工作表
If Adodc1.Recordset.RecordCount > 0 Then
For i = 0 To DataGrid1.Columns.Count - 1
newsheet.Cells(1, i + 1) = DataGrid1.Columns(i).Caption
Next i
'指定表格内容
Adodc1.Recordset.MoveFirst
Do Until Adodc1.Recordset.EOF
r = Adodc1.Recordset.AbsolutePosition
For c = 0 To DataGrid1.Columns.Count - 1
DataGrid1.Col = c
newsheet.Cells(r + 1, c + 1) = DataGrid1.Columns(c)
Next c
Adodc1.Recordset.MoveNext
Loop
end if
大概思路是这样的,细节还需要您自己慢慢研究。
[/FIELDSET]
回复:
我现在是ADO与datagrid捆绑就有问题了。
记录源里面(命令文本SQL)该怎么填写?
还有个问题:
你上面给出的代码,放在什么下面呢?窗体下面,还是ADODC控件下面呢?