Execel文件插入到ASP页面
发布时间:2006-10-14 2:59:30   收集提供:gaoqian
<%
Set Xlapp=Server.Createobject("Execel.Application")
Xlapp.Visible=false
'使服务端不出现Execel窗口
Set myWorkbook=xlapp.Wordbooks.Add
Set myWorksheet=myWorkbook.Worksheets(1)
'建立一个WorkSheet
myWorkSheet.Range("A1").Value=''
myWorkSheet.Range("A1").Vont.size=18
myWorkSheet.Range("A1").Font.Bold=True
myWorkSheet.Range("A2").Value='姓名'
myWorkSheet.Range("B2").Value='住址'
myWorkSheet.Range("C2").Value='电话'
myWorkSheet.Range("D2").Value='传真'
'建立表头
myWorkSheet.Range("A2:D2").Font.Bold=True
StrFileName=Session.SessionID&".xls"
'确保文件名唯一
strAppPath=Request.ServerVariables("PATH_TRANSLATED")
strAppPath=Left(strAppPth,InstrRev(strAppPath,"\"))
strFullPath=strAppPath&strFileName
myWorkBook.SaveAs(StrFullPath)
'保存文件
myWorkbook.Close
'关闭Excel
xlApp.Quit
Set myWorkSheet=Nothing
Set myWorkBook=Nothing
Set myxlApp=Nothing
Response.Redirect strFileName
'发到浏览器中去
%>
 
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50