成人午夜激情影院,小视频免费在线观看,国产精品夜夜嗨,欧美日韩精品一区二区在线播放

用ASP生成Word文檔(還有Excel和Txt文檔)

2010-08-28 10:52:45來源:西部e網(wǎng)作者:

網(wǎng)上很多用ASP生成(創(chuàng)建)Word文檔的方法都已經(jīng)隨著Word和Excel的版本變更而失效了,在dotnetindex上看到了幾篇老外寫的文章,簡(jiǎn)介而且好用,試驗(yàn)了一下還確實(shí)不錯(cuò),放上來保存一下:

1、用ASP生成Word文檔

ASP has the ability to dynamically output any kind of office application format. Before to start coding, The first thing we need to do is set correct file type. Becase the browser needs to know what to do with the file. Second step is to edit file name. You can use HTML and CSS to create styles in your word document.

Here is a comple source code :

<%
Response.ContentType = "application/msword"
Response.AddHeader "Content-Disposition", "attachment;filename=NAME.doc"   
Response.Write("Weste.net : <a href=""http://weste.net"">歡迎您訪問西部e網(wǎng)!</a><br>" & vbnewline)
Response.Write("<h1>We can use HTML codes for word documents</h1>")
response.write "<table width=""100%"" border=""1"" >"
response.write "<tr>"
response.write "<th width=""40%""><b>Name</b></th>"
response.write "<th width=""30%""><b>Username</b></th>"
response.write "<th width=""30%""><b>Password</b></th>"
response.write "</tr>"
response.write "<tr>"
response.write "<td width=""40%"">Weste.net</td>"
response.write "<td width=""30%"">admin@weste.net</td>"
response.write "<td width=""30%"">mypassword</td>"
response.write "</tr>"
response.write "</table>"
%>
說明:用這種方式生成Word文檔的時(shí)候,出現(xiàn)過一個(gè)問題。就是有的時(shí)候會(huì)顯示W(wǎng)ord的格式不對(duì)。當(dāng)打開生成的文檔時(shí),Word會(huì)提示:“Microsoft Office Word 需要轉(zhuǎn)換器以正確顯示該文件。這項(xiàng)功能目前尚未安裝,是否現(xiàn)在安裝?”,需要重新安裝SKU011.CAB文件才行。問題我沒搞明白,等過幾天我真正使用的時(shí)候再進(jìn)行測(cè)試。
原文:http://www.dotnetindex.com/articles/3892_Creating_Word_Files_Online.asp

2、用ASP生成Excel文檔

ASP has the ability to dynamically output any kind of office application format. Before to start coding, The first thing we need to do is set correct file type. Becase the browser needs to know what to do with the file. Second step is to edit file name. You can use HTML and CSS to create styles in your word document.

<%
Response.AddHeader "Content-Disposition", "attachment;filename=members.xls"

Response.ContentType = "application/vnd.ms-excel"

response.write "<table width=""100%"" border=""1"" >"
response.write "<tr>"
response.write "<th width=""40%""><b>Name</b></th>"
response.write "<th width=""30%""><b>Username</b></th>"
response.write "<th width=""30%""><b>Password</b></th>"
response.write "</tr>"
response.write "<tr>"
response.write "<td width=""40%"">Weste.net</td>"
response.write "<td width=""30%"">admin@weste.net</td>"
response.write "<td width=""30%"">mypassword</td>"
response.write "</tr>"
response.write "</table>"
%>

原文:http://www.dotnetindex.com/articles/3893_Creating_Excel_Files_Online.asp

3、用ASP生成Txt文檔

In VBScript language there is no any function for Input/Output on hard disk. But you may use FileSystem Object to create and edit files on server. This is an indirect technics to create any file on server.

Here some examples for creating files on server :

<%
set objFso = server.createobject("scripting.filesystemobject")
set objFile = objFso.CreateTextFile("sample.txt", true)
objFile.write "An example creating a file"
objFile.close
set objFile = nothing
objFso = nothing
%>

In this example, server create everytime a new file on same file. If you do not want to create any file with same name, change file mode to false

<%
set objFso = server.createobject("scripting.filesystemobject")
set objFile = objFso.CreateTextFile("sample.txt", false)
objFile.write "An example creating a file"
objFile.close
set objFile = nothing
objFso = nothing
%>

You can not create file, because, you've already create same file.

原文:http://www.dotnetindex.com/articles/5539_Creating_Text_files_on_server.asp

關(guān)鍵詞:ASP
主站蜘蛛池模板: 新晃| 新巴尔虎右旗| 甘孜县| 东丰县| 玛纳斯县| 安庆市| 丹凤县| 和林格尔县| 甘洛县| 寻乌县| 马边| 西城区| 紫阳县| 从江县| 寻甸| 霍城县| 象山县| 彭州市| 阳新县| 贞丰县| 朝阳县| 金乡县| 金乡县| 伊金霍洛旗| 桃源县| 克拉玛依市| 东安县| 溧阳市| 日照市| 区。| 株洲市| 曲周县| 墨竹工卡县| 将乐县| 河池市| 阳山县| 西和县| 沛县| 余江县| 丹巴县| 赫章县|