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=" ...
随机推荐
- PTA散列表平方探测法解决冲突
PTA散列表平方探测法解决冲突 核心问题 当所有的位置都被填上了,且不能插入关键词,要进入死循环了怎么办? 题目 本题的任务很简单:将给定的无重复正整数序列插入一个散列表,输出每个输入的数字在 ...
- 软件工程大作业——“你帮我助”软件开发v2.0
项目简介 在疫情管控期间,很多物资由于信息不对称,不能达成资源的有效分配,尽管这样的事件已经基本不会在新冠疫情的场景中出现,但是开发出一个物品交换的公开信息平台在任何一个社区中都是有必要的,这是构建完 ...
- 痞子衡嵌入式:对比恩智浦全系列MCU(包含Kinetis/LPC/i.MXRT/MCX)的GPIO电平中断设计差异
大家好,我是痞子衡,是正经搞技术的痞子.今天痞子衡给大家介绍的是恩智浦全系列MCU(包含Kinetis, LPC, i.MXRT, MCX)的GPIO电平中断设计差异. 在痞子衡旧文 <以i.M ...
- 侦察工具——Httrack
前言 web渗透学习笔记,实验环境为Metasploitable靶机上的DVWA.此随笔介绍Web渗透侦察工具Httrack Httrack 简介 Httrack能够克隆拷贝目标网站上的所有可访问.可 ...
- JavaScript:显式转换数据类型:如何转换为数值、字符串和布尔值类型?
JS的运算符以及某些内置函数,会自动进行数据类型的转换,方便计算,即隐式转换数据类型: 但是很多时候,我们希望可以手动控制数据类型的转换,即显示转换数据类型: 转换为字符串 String()函数 使用 ...
- .NET周报【1月第1期 2023-01-06】
国内文章 [开源]基于.net6+gtksharp实现的Linux下的图形界面串口调试工具 https://www.cnblogs.com/flykai/p/17007554.html 由于公司的上位 ...
- Redis缓存何以一枝独秀?(2) —— 聊聊Redis的数据过期、数据淘汰以及数据持久化的实现机制
大家好,又见面了. 本文是笔者作为掘金技术社区签约作者的身份输出的缓存专栏系列内容,将会通过系列专题,讲清楚缓存的方方面面.如果感兴趣,欢迎关注以获取后续更新. 上一篇文章中呢,我们简单的介绍了下Re ...
- [cocos2d-x]关于3.x的触摸机制
触摸机制的概念 通过对要监听触摸的节点进行注册,然后自定义相应的触摸函数,由事件监听器实现对触摸的监听并且实现相应的响应动作. 触摸的分类 单点触摸 下面是实现单点触摸监听的步骤: //第一步:先创建 ...
- 深入探究Java中的对象类型变量声明操作——在声明对象时,系统究竟做了什么?
深入探究Java中的对象类型变量声明操作--在声明对象时,系统究竟做了什么? 摘要:本文主要对Java中的对象类型变量的声明的底层原理做了探究. 目录 深入探究Java中的对象类型变量声明操作--在声 ...
- P1005 [NOIP2007 提高组] 矩阵取数游戏
题目传送门 前言 今天依旧是不写高精的一天呢!(是的,这位作者又只拿了开 \(LL\) 的 \(\color{yellow}{60}\) 分) 思路描述 看到数据 \(n,m \le 80(30)\) ...