ASP输出生成Word 、Excel、Txt文件的方法
在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文件的方法的更多相关文章
- word和.txt文件转html 及pdf文件, 使用poi jsoup itext心得
word和.txt文件转html 及pdf文件, 使用poi jsoup itext心得本人第一次写博客,有上面不足的或者需要改正的希望大家指出来,一起学习交流讨论.由于在项目中遇到了这一个问题,在 ...
- asp.net生成word文档服务器配置
一.asp.net生成word文档,布署到正式的服务器上就出现 错误:System.Runtime.InteropServices.COMException (0x800A1098 ...
- ASP.NET生成WORD文档,服务器部署注意事项
网上转的,留查备用,我服务器装的office2007所以修改的是Microsoft Office word97 - 2003 文档这一个. ASP.NET生成WORD文档服务器部署注意事项 1.Asp ...
- Asp.net读取和写入txt文件方法(实例)!
Asp.NET读取和写入txt文件方法(实例)! [程序第一行的引入命名空间文件 - 参考] System; using System.Collections; using System.Config ...
- python的OS模块生成100个txt文件
#!/user/bin/env/python35 # -*-coding:utf-8-*- # author:Keekuun """ 问题:生成一个文件夹,文件夹下面生成 ...
- ASP输出JSON数据及客户端jQuery处理方法
首先ASP处理JSON需要json官方提供的JSON For ASP 封装类文件,下载地址:http://code.google.com/p/aspjson/downloads/list 下载最新的J ...
- Javascript写入txt和读取txt文件的方法
文章主要介绍了Javascript写入txt和读取txt文件的方法,需要的朋友可以参考下1. 写入 FileSystemObject可以将文件翻译成文件流. 第一步: 例: 复制代码 代码如下: Va ...
- 导出OpenID为txt文件的方法
导出OpenID为txt文件的方法 public function export(){ $shop = M("Shop"); $arr = $shop->field('ope ...
- 2、Python djang 框架下的word Excel TXT Image 等文件的下载
2.python实现文件下载 (1)方法一.直接用a标签的href+数据库中文件地址,即可下载.缺点:word excel是直接弹框下载,对于image txt 等文件的下载方式是直接在新页面打开. ...
- php 备份数据库代码(生成word,excel,json,xml,sql)
单表备份代码: 复制代码代码如下: <?php class Db { var $conn; function Db($host="localhost",$user=" ...
随机推荐
- day06-功能实现05
家居网购项目实现05 以下皆为部分代码,详见 https://github.com/liyuelian/furniture_mall.git 12.功能11-后台分页(分页显示家居) 12.1需求分析 ...
- (已转)Linux基础第六章 信号
6.1 前言 本章简单描述信号.信号是Linux系统中,内核和进程通信的一种方式.如果内核希望打断进程的顺序执行,那么内核会在进程的PCB中记录信号.而当这个进程被分配到CPU,进入执行状态时,首先会 ...
- 教你用JavaScript实现乘法游戏
案例介绍 欢迎来的我的小院,我是霍大侠,恭喜你今天又要进步一点点了!我们来用JavaScript编程实战案例,做一个乘法积分游戏.乘法游戏主要通过用户输入的数值和程序计算的数值进行对比,正确积一分,错 ...
- drf快速使用 CBV源码分析 drf之APIView分析 drf之Request对象分析
目录 序列化和反序列化 drf介绍和安装 使用原生django写接口 django DRF安装 drf快速使用 模型 序列化类 视图 路由 datagrip 使用postman测试接口 CBV源码分析 ...
- mysql基础命令语法
删除空格 update 表名 set 字段名 = replace(字段名 ,' ','') ; 临时表创建与删除 -- 创建临时表 create temporary table if not exis ...
- 连号区间数【第四届蓝桥杯省赛C++B组,第四届蓝桥杯省赛JAVAB组】
连号区间数 小明这些天一直在思考这样一个奇怪而有趣的问题: 在 \(1∼N\) 的某个排列中有多少个连号区间呢? 这里所说的连号区间的定义是: 如果区间 \([L,R]\) 里的所有元素(即此排列的第 ...
- [C++]C++11:Function与Bind
std::function 它是函数.函数对象.函数指针.和成员函数的包装器,可以容纳任何类型的函数对象,函数指针,引用函数,成员函数的指针. 以统一的方式处理函数.函数对象.函数指针.和成员函数. ...
- [cocos2d-x]我发现的内存管理机制的一些问题
之前看过的一些文章中关于内存的管理机制讲的非常好,但是我发现它们在谈到每一帧都会创建一个新的内存池的时候,我发现源码并不是这样: PoolManager* PoolManager::getInstan ...
- [BUUCTF]洞拐洞拐洞洞拐
[BUUCTF] 洞拐洞拐洞洞拐 问题链接:https://buuoj.cn/challenges#洞拐洞拐洞洞拐 问题附件是一张图片. 一. 图片分析 查看图片,发现是由有规律的黑白像素构成的PNG ...
- 动力节点——day07
什么是异常? 异常是指在程序的运行过程中所发生的不正常的事件,它会中断正在运行的程序 Java中异常的存在形式? 异常在java中以类的形式存在,每一个异常类都可以创建异常对象 异常的继承结构图 编译 ...