|
<!--#include file= "conn.asp"-->
<%
Set xlapplication = Server.CreateObject ("Excel.Application") ' calls the Excel object
xlapplication.visible = False ' Do not need to open Excel
Xlapplication.sheetsinnewworkbook=1 ' to specify the number of tables in Excel
XlApplication.Workbooks.Add ' Add Workbook
Set Xlworksheet = xlapplication.worksheets (1) ' generates child objects for worksheet 1th
xlworksheet.name= Statistics ' specified sheet name
' Specifies the width of the column and alignment 1 left-aligned 2-aligned 3 Centered
XlApplication.ActiveSheet.Columns (1). columnwidth=5
XlApplication.ActiveSheet.Columns (1). horizontalalignment=3
XlApplication.ActiveSheet.Columns (2). columnwidth=10
XlApplication.ActiveSheet.Columns (2). Horizontalalignment=3
XlApplication.ActiveSheet.Columns (3). Columnwidth=20
XlApplication.ActiveSheet.Columns (3). Horizontalalignment=3
' XlApplication.ActiveSheet.Rows (i). Height of RowHeight = 30 ' line
' Specify the height of the column and the specific column
Xlworksheet.range (Xlworksheet.cells (1,1), Xlworksheet.cells (1,3)). MergeCells =true ' Merge columns
Xlworksheet.range ("A1"). Value= "2005 Statistics"
Xlworksheet.range ("A1"). Font. Size=14 ' font size
Xlworksheet.range ("A1"). Font.bold=true ' Bold
Xlworksheet.range ("A1"). Horizontalalignment=3 ' Horizontal alignment
Xlworksheet.range ("A1"). Verticalalignment=3 ' Vertical alignment
Xlworksheet.cells (2,1). Value = "Number"
Xlworksheet.cells (2,2). Value = "Name"
Xlworksheet.cells (2,3). Value = "unit"
' Xlworksheet.range ("A1:c1"). Borders.linestyle=1 ' Set row style
'--------------------------------------------------can do loop i=i+1 (database data)
I=1
strSQL = "SELECT * from Excel"
Set rs =conn.execute (strSQL)
If not rs.eof then
Do as not rs.eof
Xlworksheet.cells (2+i,1). Value = RS (0)
Xlworksheet.cells (2+i,2). Value = RS (1)
Xlworksheet.cells (2+i,3). Value = RS (2)
I=i+1
Rs.movenext
Loop
End If
'--------------------------------------------------
Set fs = CreateObject ("Scripting.FileSystemObject")
Tfile=server.mappath ("Test.xls")
If Fs. FileExists (Tfile) Then
Set f = fs. GetFile (Tfile)
F.delete true
Set F = Nothing
End If
Set fs = Nothing
Xlworksheet.saveas tfile ' Save file
Xlapplication.quit ' Release object
Set xlworksheet = Nothing
Set xlapplication = Nothing
%>
|