01.
<%
02.
Set
xlApp = Server.CreateObject(
"Excel.Application"
)
03.
Set
xlBook = xlApp.Workbooks.Add
04.
Set
xlSheet = xlBook.Worksheets(1)
05.
06.
07.
xlApp.Application.Visible =
False
08.
09.
With
xlApp.ActiveSheet.Cells(1,1)
10.
.Value =
"Overall Product Sales 2000"
11.
.Font.Bold =
True
12.
.Font.Name =
"Tahoma"
13.
.Font.Size = 16
14.
End
With
15.
16.
With
xlApp.ActiveSheet.Cells(3,1)
17.
.Value =
"Product Name"
18.
.Font.Italic =
True
19.
.Font.Name =
"Tahoma"
20.
.Font.Size = 13
21.
.MergeCells =
True
22.
End
With
23.
24.
With
xlApp.ActiveSheet.Cells(3,2)
25.
.Value =
"Product Income"
26.
.Font.Italic =
True
27.
.Font.Name =
"Tahoma"
28.
.Font.Size = 13
29.
.MergeCells =
True
30.
End
With
31.
32.
Set
objConn = Server.CreateObject(
"ADODB.Connection"
)
33.
Set
objRS = Server.CreateObject(
"ADODB.Recordset"
)
34.
35.
strConn =
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
36.
strConn = strConn & Server.MapPath(
"Sales00.mdb"
)
37.
strQuery =
"SELECT ProductName,ProductIncome FROM ProductSales"
38.
39.
40.
While
Not
objRS.EOF
41.
xlApp.ActiveSheet.Cells(iRow,1).Value = objRS(
"ProductName"
)
42.
xlApp.ActiveSheet.Cells(iRow,2).Value = objRS(
"ProductIncome"
)
43.
xlApp.ActiveSheet.Cells(iRow,2).NumberFormat =
"$#,##0.00"
44.
iRow = iRow + 1
45.
objRS.MoveNext
46.
Wend
47.
48.
49.
xlSheet.SaveAs Server.MapPath(
"MyExcelBook.xls"
)
50.
51.
52.
xlApp.Application.Quit
53.
54.
objRS.Close
55.
objConn.Close
56.
Set
objRS =
Nothing
57.
Set
objConn =
Nothing
58.
Set
xlSheet =
Nothing
59.
Set
xlBook =
Nothing
60.
Set
xlApp =
Nothing
61.
%>