Dim strSource, strDestination As String
strSource = App.Path & "\Excels\RegisterFee.xls"
‘RegisterFee.xls就是一个模版文件
strDestination = App.Path & "\Excels\Temp.xls"
FileCopy strSource, strDestination
‘将模版文件拷贝到一个临时文件
---- 三. 生成工作表内容
---- 有了上述两步工作的铺垫,我们下面接着就只要根据(表一)的格式给各单元格赋值了。如:
datPrimaryRS.Recordset.MoveFirst
‘datPrimaryRS为Data控件
If IsNull(datPrimaryRS.Recordset!姓名) = False Then
xlSheet.Cells(4, 2) = datPrimaryRS.Recordset!姓名
End If
If IsNull(datPrimaryRS.Recordset!性别) = False Then
xlSheet.Cells(4, 4) = datPrimaryRS.Recordset!性别
End If
If IsNull(datPrimaryRS.Recordset!民族) = False Then
xlSheet.Cells(4, 6) = datPrimaryRS.Recordset!民族
End If
………………
1. 创建数据环境设计器
(1)创建一个新的标准EXE工程文件。
(2)在工程菜单上,选择添加数据环境。如果在工程菜单中没有列出这一项,那么选择组件—设计器标签—选中数据环境,选择确定。
(3)在数据连接属性对话框中,选择Microsoft Jet 3.51 OLE DB Provider。
(4)选择“下一步”按钮,这样就进入了Connection标签。
(5)选择第一个文本框旁的“...”按钮。
(6)在存取数据库对话框中浏览并选择数据库文件Nwind.mdb。
(7)选择“确定”关闭该对话框。
(8)用鼠标右击Connection1图标,然后选择Rename,将名字改为Northwind。
(9)用鼠标右击Northwind图标,然后选择Add Command,再用鼠标右击Command1,选择“属性”命令,弹出属性对话框,在对话框中,按下表所示设置属性值。
Command Name
Customers
Connection
Northwind
DataBase Object
Table
Object Name
Customers
(10)选择“确定”关闭该对话框。
(11)用鼠标右击Customers命令,选择Add Child Command,再用鼠标右击Command1,选择“属性”命令,弹出属性对话框,在对话框中,按下表所示设置属性值。
Command Name
Orders
Connection
Northwind
DataBase Object
Table
Object Name
Orders
(12)选择Relation标签,选中Relate to a Parent Command Object检查框。在Parent下拉框中选中Customers;Parent域和Child域中均已包含了CustomerID。
(13)选择添加,按“确定”关闭对话框。
(14)在属性窗口中按下表设置工程文件和设计器的属性值,然后保存工程文件。
Project Name
prjNwind
DataEnvironment Name
deNwind
Form Name
frmShowReport
3. 用Show方法预览数据报表
现在数据环境和数据报表对象都已建立,可以准备运行程序了。我们要做的最后一件事情就是编写代码以显示数据报表。
(1)在工程浏览器窗口中,用鼠标双击frmShowReport以显示表单设计器。
(2)在工具箱上,点击General标签。
(3)点击CommandButton图标,然后在表单上画一个命令按钮。
(4)在属性窗口中按下表设置命令按钮控件的属性。
Name
cmdShow
Caption
Show Report
(5)在按钮事件中,键入以下代码:
Private Sub cmdShow_Click()
rptNwind.Show
End Sub
(6)保存并运行工程文件。
点击Show Report以打印预览模式显示报表。