标题:datagrid 的问题
只看楼主
guyan1009
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2006-5-15
 问题点数:0 回复次数:0 
datagrid 的问题

写了个小程序,VB6+2000环境,数据库用到了ADO 和DATAGRID,datagrid查询结果配合一个command按钮加了段输出到EXCEL的代码,可是只能输出当前datagrid显示的一页,超出页部份不输出,手动翻到datagrid下一页再次运行才行,而且是又输出到一个新文件,看看怎么样把datagrid里所有的查询结果全部一次输出到excel,帮帮忙啦,调试可行的话另外加分~~

代码如下:

Private Sub Command1_Click()
Dim i, j As Integer
Dim xlApplication As Excel.Application, xlWorkbook As Excel.Workbook, xlSheet
On Error Resume Next
Set xlApplication = GetObject(, "Excel.Application")
If Err.Number <> 0 Then Set xlApplication = CreateObject("Excel.Application")
Set xlWorkbook = xlApplication.Workbooks.Add
Set xlSheet = xlWorkbook.ActiveSheet
For i = 1 To DataGrid1.Columns.Count
xlSheet.Cells(1, i) = DataGrid1.Columns(i - 1).Caption
For j = 0 To DataGrid1.VisibleRows - 1
xlSheet.Cells(j + 2, i) = DataGrid1.Columns(i - 1).CellText(DataGrid1.RowBookmark(j))
Next j
Next i

xlApplication.Visible = True
Set xlSheet = Nothing
Set xlWorkbook = Nothing
Set xlApplication = Nothing
End Sub

搜索更多相关主题的帖子: datagrid 
2007-04-21 22:17



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-133879-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 1.188078 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved