<%
set xlApp = Server.CreateObject("Excel.Application")
xlApp.Visible = false
' 使服務端不出現Excel視窗.
set myWorkbook = xlApp.Workbooks.Add
' 建立一個worksheet.
set myWorksheet = myWorkbook.Worksheets(1)
myWorksheet.Range("A1").Value = '精彩春風通訊錄'
myWorksheet.Range("A1").Font.Size = 12
myWorksheet.Range("A1").Font.Bold = true
myWorksheet.Range("A2").Value = '姓名'
myWorksheet.Range("B2").Value = '地址'
myWorksheet.Range("C2").Value = '電話'
myWorksheet.Range("D2").Value = '手機'
' 以上7行建立表頭.
myWorksheet.Range("A2:D2").Font.Bold = true
strFileName = Session.SessionID & ".xls"
' 確保檔案名稱唯一.
strAppPath = Request.ServerVariables("PATH_trANSLATED")
strAppPath = Left(strAppPath, 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
' 寫到ASP頁面,即瀏覽器中.
%>
[1]