在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. Flutter和Rust如何优雅的交互

    前言 文章的图片链接都是在github上,可能需要...你懂得:本文含有大量关键步骤配置图片,强烈建议在合适环境下阅读 Flutter直接调用C层还是蛮有魅力,想想你练习C++,然后直接能用flutt ...

  2. UVA439 Knight Moves

    原题Vjudge 题目大意 有一个骑士,他可以骑马日字型跳跃,问他从A点到B点最少要几步 解题思路 这题就是一个特别裸的广搜板子 它的主要问题在于输入输出 输入的数据我们可以用\(pair\)读入,第 ...

  3. [深度学习] ubuntu18.04配置深度学习环境笔记

    最近装过很多ubuntu18.04系统的nvidia驱动,cuda10.2,cudnn7.6.5,发现每次都会出现一些小问题.总结了具体步骤,做个记录.主要分为三个步骤:驱动安装,cuda安装,cud ...

  4. [python] 基于chardet识别字符编码

    对于人类能够识别的字符,计算机会根据某一对应关系将其转换为二进制形式进行保存.这个对应关系就是字符编码表,即什么样的字符对应什么样的二进制编码.这种字符编码表往往是多种多样的,因此,如果我们想要将一个 ...

  5. [C++标准模板库:自修教程与参考手册]关于deque

    Deque的基本概念 deque和vector很相似,也提供随机存取的能力,将元素都动态地存储在一个数组中,最大的区别就是:deque的头和尾都是开放的,非常方便在头尾两端进行一些操作.(重点在于:d ...

  6. 洛谷P1048 典型01背包问题

    写在前面的话 蒟蒻在学习诸多图论算法之前,实际上没学过dp! 强说是学过也是只学了01背包,今天就来温习一下-- DP是啥? 动态规划(Dynamic Programming,DP)是运筹学的一个分支 ...

  7. win32com操作word 第三集:Range精讲(一)

    本课程<win32com操作word API精讲&项目实战>,本公众号以文字分享为主,B站与视频号则发布视频分享,ID均为:一灯编程 本集开始,将会深入Document接口.打开或 ...

  8. continue语句-死循环

    continue语句 continue 使用场景:结束本次循环,继续下一次的循环 public static void main(String[] args) { for (int i = 1; i ...

  9. 面试必问:说一下 Java 虚拟机的内存布局?

    我们通常所说的 Java 虚拟机(JVM)的内存布局,一般是指 Java 虚拟机的运行时数据区(Runtime Data Area),也就是当字节码被类加载器加载之后的执行区域划分.当然它通常是 JV ...

  10. 【Python】bytes和hex字符串之间的相互转换

    十六进制字符串:a="CC DD 01 61 F6 01 00 64 A4 81 00 00 00 8B" b=bytes.fromhex(a) 转为字节 from socket ...