關(guān)于在ASP程序頁面中插入excel文件的實例代碼分享
下面提供的大家分享的是關(guān)于在ASP程序頁面中插入excel文件的實例代碼,希望能夠?qū)Υ蠹矣杏谩?/p>
<%
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
%>