输出到EXCEL供打印 Private Sub Command1_Click() Dim i As Integer, j As Integer Set xlsapp = CreateObject("Excel.application") xlsapp.Visible = True '调试完成后改为false Set xlsbook = xlsapp.workbooks.Add Set xlsSheet = xlsbook.worksheets(1)
Adodc1.Recordset.MoveFirst Adodc1.Recordset.MoveLast zs1 = Adodc1.Recordset.RecordCount Adodc1.Recordset.MoveFirst i = 0 Do While Not Adodc1.Recordset.EOF For j = 0 To Adodc1.Recordset.Fields.Count - 1 If Not IsNull(DataGrid1.Text) Then xlsSheet.cells(i + 1, j + 1) = Adodc1.Recordset(j) End If Next Adodc1.Recordset.MoveNext i = i + 1 Loop xlsbook.Saveas App.Path & "\report.xls" xlsbook.Close xlsapp.quit End Sub
http://microinfo.top263.net/Zip/DRPSP5.zip
///要用dataGrid里边的内容去生成一个报表的,哦
生成EXCEL或水晶报表都可以的
http://microinfo.top263.net/Zip/DatGrdRpt.ziphttp://www.codeproject.com/useritems/datagridex.asp
http://www.4046.com/nnsrc/netdown.asp?id=357
Private Sub Command1_Click()
Dim i As Integer, j As Integer
Set xlsapp = CreateObject("Excel.application")
xlsapp.Visible = True '调试完成后改为false
Set xlsbook = xlsapp.workbooks.Add
Set xlsSheet = xlsbook.worksheets(1)
Adodc1.Recordset.MoveFirst
Adodc1.Recordset.MoveLast
zs1 = Adodc1.Recordset.RecordCount
Adodc1.Recordset.MoveFirst
i = 0
Do While Not Adodc1.Recordset.EOF
For j = 0 To Adodc1.Recordset.Fields.Count - 1
If Not IsNull(DataGrid1.Text) Then
xlsSheet.cells(i + 1, j + 1) = Adodc1.Recordset(j)
End If
Next
Adodc1.Recordset.MoveNext
i = i + 1
Loop
xlsbook.Saveas App.Path & "\report.xls"
xlsbook.Close
xlsapp.quit
End Sub
http://www.csdn.net/expert/topic/725/725834.xml?temp=.3093073
直接用datareort就可以了。
做一个数据环境,在其下建一个command,然后从command中拖字段到datareport中,然后将datareport与ado相连,改变command的commandtext的sql与ado的sql语句一样属性然后对datareport进行刷新即可。
具体刷新:
dt.数据环境.rscommand1.close
dt.数据环境.rscommands(1).commandtext = SQL
dt.数据环境.rscommand1.open
http://www.yxjr.com/cp/yxprint.html
DataGrid只是用来浏览数据的控件,不是用来打印的哦