三九宝宝网宝宝绘画黑板报

在VB SQL2000中创建一个EXCEL模板报表问题

12月30日 编辑 39baobao.com

把此代码放到你的”EXCEL”的按纽代码下面就能实现.

Dim 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) \'创建工作表

Adodc1.RecordSource = \"select * from individual order by 编号\"

Adodc1.Refresh

If Adodc1.Recordset.RecordCount > 0 Then

newxls.Visible = True

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

newsheet.Cells(r + 1, c + 1) = DataGrid1.Columns(c)

Next c

Adodc1.Recordset.MoveNext

Loop

End If

标注:\'“individual” 为你想生成报表的表名称。编号为表中的字段。

Adodc1为连接的数据库控件。

推荐阅读
图文推荐