在ASP页面中插入excel文件(转)
发表于:2007-06-30来源:作者:点击数:
标签:
% set xlApp = Server.CreateObject(Excel.Application) ‘’使服务端不出现Excel窗口 xlApp.Visible = false ‘’建立一个worksheet set myWorkbook = xlApp.Workbooks.Add set myWorksheet = myWorkbook.Worksheets(1) ‘’建立表头 myWorksheet.Range(A1).
<%
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
%>
原文转自:http://www.ltesting.net