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=" ...
随机推荐
- Spring之后置处理器
Spring的后置处理器是Spring对外开发的重要扩展点,允许我们接入Bean的实例化流程中,以达到动态注册BeanDefinition.动态修改BeanDefinition.动态修改Bean的 ...
- Flask 终端启动运行
在终端启动 1.首先创建xxxx.py文件(xxxx表示创建的文件名)写入一个小app实例,例如: # 在hello.py文件下创建一个小的FLask app from flask import Fl ...
- VSCode运行C/C++配置
将MinGw安装目录下的 1.安装 VSCode 2.安装 MinGW 链接:点击跳转 3.MinGW 内安装两个模块 1.右键 Mark for Installation 勾选 (此处已安装好,所以 ...
- python之路52 ORM查询、ORM事务、查询优化、常用字段及参数、ajax方法
Q查询进阶操作 from django.db.models import Q q_obj = Q() # 1.产生q对象 q_obj.connector = 'or' # 默认多个条件的连接是and可 ...
- MSIC总结取证分析——日志分析
MSIC总结取证分析 一.日志分析: 1.常见日志分析类型: 2.常见一些考点: (1)还原特定IP攻击手段(SQL注入.暴力破解.命令执行等),或还原最初攻击时间: (2)寻找flag或者特定文件解 ...
- Educational Codeforces Round 33 (Rated for Div. 2) 虚拟赛体验
前言 就只做出了 \(A,B,C,D\) 是不是很弱? A.Chess For Three A,B,C 三人下棋,A和B先下,每次下完棋之后由现在观战的人(例如第一局就由C)代替下输的人. 每次输入一 ...
- 浅谈LCA问题(最近公共祖先)(四种做法)
[模板]最近公共祖先(LCA) \(update \ 2023.1.3\) 新增了树链剖分 题目描述 如题,给定一棵有根多叉树,请求出指定两个点直接最近的公共祖先. 输入格式 第一行包含三个正整数 \ ...
- 华为运动健康服务Health Kit 6.9.0版本新增功能揭秘!
华为运动健康服务(HUAWEI Health Kit)6.9.0版本新鲜出炉啦! 一文了解新增功能,快来一起加入Health Kit生态大家庭! 一.更丰富:睡眠呼吸记录健康数据开放 呼吸机是用于为患 ...
- Linux C 打印变量数组内容到一个文件中的方法。
思路: 1.以追加的方式新建打开一个文件 2.将buf 按字节,先将整型转换为字符串,之后写入到文件中. memset(tmp_buf, 0, sizeof(tmp_buf)); sprintf(tm ...
- API 网关的功能用途及实现方式
1. API 网关诞生背景 前言 API 经济生态链已经在全球范围覆盖, 绝大多数企业都已经走在数字化转型的道路上,API 成为企业连接业务的核心载体, 并产生巨大的盈利空间.快速增长的 API 规模 ...