当前位置:编程学习 > asp >>

在ASP页面中插入excel文件(转)

答案:<%
set xlApp = Server.CreateObject("Excel.Application")
'使服务端不出现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)
'关闭Excel
myWorkbook.Close
xlApp.Quit
set myWorksheet = Nothing
set myWorkbook = Nothing
set myxlApp = Nothing
'写出到浏览器中
Response.Redirect strFileName
%>

上一个:在ASP中用程序控制弹出NTLM验证窗口
下一个:ASP页面内VBScript和JScript的交互(转)

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,