在ASP中生成Word文件、Excel文件和Txt文件,参考了微软的官方文档,自己简单弄了下,基本可以实现了,不足之处,望指导!下面言归正传。

1、用ASP生成Word文档,代码示例:

01

<%

02

Response.ContentType = "application/msword"

03

Response.AddHeader "Content-Disposition", "attachment;filename=NAME.doc"

04

Response.Write("欢迎来到源码爱好者!<br>" & vbnewline)

05

Response.Write("<h1>用ASP生成Word文档的示例</h1>")

06

response.write "<table width=""100%"" border=""1"" >"

07

response.write "<tr>"

08

response.write "<th width=""40%""><b>Name</b></th>"

09

response.write "<th width=""30%""><b>Username</b></th>"

10

response.write "<th width=""30%""><b>Password</b></th>"

11

response.write "</tr>"

12

response.write "<tr>"

13

response.write "<td width=""40%"">源码爱好者</td>"

14

response.write "<td width=""30%"">user</td>"

15

response.write "<td width=""30%"">mypassword</td>"

16

response.write "</tr>"

17

response.write "</table>"

18

%>

用这种方法生成的Word文档,有时候会出现一个提示:“Microsoft Office Word 需要转换器以正确显示该文件。这项功能目前尚未安装,是否现在安装?”,这时候重新安装SKU011.CAB就可以了,原因不明。

2、ASP生成Excel文档:

01

<%

02

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

03

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

04

response.write "<table width=""100%"" border=""1"" >"

05

response.write "<tr>"

06

response.write "<th width=""40%""><b>教程文章</b></th>"

07

response.write "<th width=""30%""><b>Username</b></th>"

08

response.write "<th width=""30%""><b>Password</b></th>"

09

response.write "</tr>"

10

response.write "<tr>"

11

response.write "<td width=""40%"">源码爱好者</td>"

12

response.write "<td width=""30%"">user</td>"

13

response.write "<td width=""30%"">mypassword</td>"

14

response.write "</tr>"

15

response.write "</table>"

16

%>

3、ASP生成Txt文档,这个最简单,用Fso就可以:

view sourceprint?

1

<%

2

set objFso = server.createobject("scripting.filesystemobject")

3

set objFile = objFso.CreateTextFile("sample.txt", false)

4

objFile.write "这是一个生成txt文本的演示文档"

5

objFile.close

6

set objFile = nothing

7

objFso = nothing

8

%>

在ASP中生成Word文件、Excel文件和Txt文件,参考了微软的官方文档,自己简单弄了下,基本可以实现了,不足之处,望指导!下面言归正传。

1、用ASP生成Word文档,代码示例:

01 <%
02 Response.ContentType = "application/msword"
03 Response.AddHeader "Content-Disposition""attachment;filename=NAME.doc"
04 Response.Write("欢迎来到源码爱好者!<br>" & vbnewline)
05 Response.Write("<h1>用ASP生成Word文档的示例</h1>")
06 response.write "<table width=""100%"" border=""1"" >"
07 response.write "<tr>"
08 response.write "<th width=""40%""><b>Name</b></th>"
09 response.write "<th width=""30%""><b>Username</b></th>"
10 response.write "<th width=""30%""><b>Password</b></th>"
11 response.write "</tr>"
12 response.write "<tr>"
13 response.write "<td width=""40%"">源码爱好者</td>"
14 response.write "<td width=""30%"">user</td>"
15 response.write "<td width=""30%"">mypassword</td>"
16 response.write "</tr>"
17 response.write "</table>"
18 %>

用这种方法生成的Word文档,有时候会出现一个提示:“Microsoft Office Word 需要转换器以正确显示该文件。这项功能目前尚未安装,是否现在安装?”,这时候重新安装SKU011.CAB就可以了,原因不明。

2、ASP生成Excel文档:

01 <%
02 Response.AddHeader "Content-Disposition""attachment;filename=members.xls"
03 Response.ContentType = "application/vnd.ms-excel"
04 response.write "<table width=""100%"" border=""1"" >"
05 response.write "<tr>"
06 response.write "<th width=""40%""><b>教程文章</b></th>"
07 response.write "<th width=""30%""><b>Username</b></th>"
08 response.write "<th width=""30%""><b>Password</b></th>"
09 response.write "</tr>"
10 response.write "<tr>"
11 response.write "<td width=""40%"">源码爱好者</td>"
12 response.write "<td width=""30%"">user</td>"
13 response.write "<td width=""30%"">mypassword</td>"
14 response.write "</tr>"
15 response.write "</table>"
16 %>

3、ASP生成Txt文档,这个最简单,用Fso就可以:

1 <%
2 set objFso = server.createobject("scripting.filesystemobject")
3 set objFile = objFso.CreateTextFile("sample.txt", false)
4 objFile.write "这是一个生成txt文本的演示文档"
5 objFile.close
6 set objFile = nothing
7 objFso = nothing
8 %>

ASP输出生成Word 、Excel、Txt文件的方法的更多相关文章

  1. word和.txt文件转html 及pdf文件, 使用poi jsoup itext心得

    word和.txt文件转html 及pdf文件, 使用poi jsoup  itext心得本人第一次写博客,有上面不足的或者需要改正的希望大家指出来,一起学习交流讨论.由于在项目中遇到了这一个问题,在 ...

  2. asp.net生成word文档服务器配置

    一.asp.net生成word文档,布署到正式的服务器上就出现           错误:System.Runtime.InteropServices.COMException (0x800A1098 ...

  3. ASP.NET生成WORD文档,服务器部署注意事项

    网上转的,留查备用,我服务器装的office2007所以修改的是Microsoft Office word97 - 2003 文档这一个. ASP.NET生成WORD文档服务器部署注意事项 1.Asp ...

  4. Asp.net读取和写入txt文件方法(实例)!

    Asp.NET读取和写入txt文件方法(实例)! [程序第一行的引入命名空间文件 - 参考] System; using System.Collections; using System.Config ...

  5. python的OS模块生成100个txt文件

    #!/user/bin/env/python35 # -*-coding:utf-8-*- # author:Keekuun """ 问题:生成一个文件夹,文件夹下面生成 ...

  6. ASP输出JSON数据及客户端jQuery处理方法

    首先ASP处理JSON需要json官方提供的JSON For ASP 封装类文件,下载地址:http://code.google.com/p/aspjson/downloads/list 下载最新的J ...

  7. Javascript写入txt和读取txt文件的方法

    文章主要介绍了Javascript写入txt和读取txt文件的方法,需要的朋友可以参考下1. 写入 FileSystemObject可以将文件翻译成文件流. 第一步: 例: 复制代码 代码如下: Va ...

  8. 导出OpenID为txt文件的方法

    导出OpenID为txt文件的方法 public function export(){ $shop = M("Shop"); $arr = $shop->field('ope ...

  9. 2、Python djang 框架下的word Excel TXT Image 等文件的下载

    2.python实现文件下载 (1)方法一.直接用a标签的href+数据库中文件地址,即可下载.缺点:word excel是直接弹框下载,对于image txt 等文件的下载方式是直接在新页面打开. ...

  10. php 备份数据库代码(生成word,excel,json,xml,sql)

    单表备份代码: 复制代码代码如下: <?php class Db { var $conn; function Db($host="localhost",$user=" ...

随机推荐

  1. 彻底理解Python中的闭包和装饰器(下)

    上篇讲了Python中的闭包,本篇要讲的装饰器就是闭包的一个重要应用. 如果你还不知道什么是闭包,猛戳这里阅读:彻底理解Python中的闭包和装饰器(上) 什么是装饰器 装饰器的作用是在不修改函数定义 ...

  2. Mattermost 笔记

    目录 部署 配置 客户端 桌面程序 Android 使用 扩展 Jenkins Hubot 机器人 Jira GitHub Mattermost 是一个开源.可私有化部署的在线通讯平台,可以和Gith ...

  3. 学习.NET MAUI Blazor(一)、Blazor是个啥?

    先把Blazor放一边,先来看看目前Web开发的技术栈. 注:上图只是为了说明问题,没有任何语言歧视! 这是目前最常用的前后端分离开发模式,这个开发模式需要配备前端工程师和后端工程师.当然了,全栈工程 ...

  4. Python启动HTTP服务进行文件传输

    有时候局域网共享个东西不方便,尤其在服务器上的时候,总不能先下载下来,再上传上去吧,于是经常在这台机器用python起个http服务,然后去另一台机器直接访问,一来二去,妥试不爽,特进行一下分离 py ...

  5. M.2 SSD固态硬盘上安装windows问题

    近来M2硬盘大降价,笔记就趁便宜买了一个2T的M.2固态硬盘,插在笔记本上,接下来安装win11,本想以前安装多次,也是老手了,没想到遇到很多问题,一度陷入僵局,不过最终还是安装成功了,下面记录下安装 ...

  6. .NET周报【1月第1期 2023-01-06】

    国内文章 [开源]基于.net6+gtksharp实现的Linux下的图形界面串口调试工具 https://www.cnblogs.com/flykai/p/17007554.html 由于公司的上位 ...

  7. ArcGIS Python判断数据是否存在

    判断是程序编写的一个基本的操作,也是增强程序稳定性的重要方式.在ArcPy处理数据时,要保证数据存在才能做后续的操作,为源GIS提示使用arcpy自带的Exists函数可判断要素类.表.数据集.sha ...

  8. ArcGIS工具 - 按要素裁切数据库

    在GIS处理数据中,经常需要分图,将整个任务区划分成若干块,由不同的人协作完成.为了节省分图裁切时间,减少人员操作失误,为源GIS专门制作了按要素裁切数据库工具,以提高数据生产效率. 需求描述 裁切单 ...

  9. 从最简单的线性DP开始

    导读 ^ _ ^ 线性DP可以说是最常见的DP问题. 从本期开始,我们将从最简单的线性DP开始学起. 后面同时更新一些经典的面试题带大家更加深入的学习线性DP 如何计算动态规划的时间复杂度? 状态数 ...

  10. 微服务框架——MybatisPlus

    MybatisPlus 一.快速入门 1.mybatisPlus特性 无侵入:只增强,不改变. 损耗小:启动的时候直接注入基本CRUD 强大的CRUD操作:提供通用Mapper,通用service,条 ...