明輝手游網(wǎng)中心:是一個免費提供流行視頻軟件教程、在線學(xué)習分享的學(xué)習平臺!

在ASP頁面中插入excel文件(轉(zhuǎn))

[摘要]<%set xlApp = Server.CreateObject("Excel.Application")'使服務(wù)端不出現(xiàn)Excel窗口xlApp.Visible = false'建立一個worksheetset myWorkbook = xlApp.W...

<%
set xlApp = Server.CreateObject("Excel.Application")
'使服務(wù)端不出現(xiàn)Excel窗口
xlApp.Visible = false
'建立一個worksheet
set myWorkbook = xlApp.Workbooks.Add
set myWorksheet = myWorkbook.Worksheets(1)
'建立表頭
myWorksheet.Range("A1").Value = '電話薄'
myWorksheet.Range("A1").Font.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(strAppPath, InstrRev(strAppPath, "\"))
strFullPath = strAppPath & strFileName
'保存文件
myWorkbook.SaveAs(strFullPath)
'關(guān)閉Excel
myWorkbook.Close
xlApp.Quit
set myWorksheet = Nothing
set myWorkbook = Nothing
set myxlApp = Nothing
'寫出到瀏覽器中
Response.Redirect strFileName
%>