遇到难题-----ASP中怎样把当前页面导入Word中编辑、打印(包括从数据库读出的数据),非常急!

lhf168 2006-02-21 08:14:36
本人为了打印的方便(因为一个页面上面有多个表格),想把生成的页面,通过点击页面按纽转到Word中根据需要编辑后打印,结果本人根据网上一些代码,自己总结了一段代码,这样虽然可以转到Word中了,但是从数据库里读出的数据却在Word中没有显示,代码如下:
<%
Dim fname,url,filename
url=Request.ServerVariables("path_info") '虚拟路径+文件名
fname=mid(url,instrRev(url,"/")+1) '文件名
trueurl=server.MapPath("./") +"\"&fname '绝对路径+文件名
filename="FileName.doc"

set objFso=server.CreateObject("scripting.filesystemobject")
set fn=objFso.GetFile(trueurl)
filesize=fn.size
set fn=nothing
set objFso=nothing

set objStream=server.CreateObject("adodb.stream")
objStream.Open
objStream.Type=1
objStream.LoadFromFile trueurl

Response.Clear()
Response.Buffer=true
Response.CharSet="Gb2312"
Response.AddHeader "Content-Disposition", "attachment; filename="&filename
Response.AddHeader "Content-Length", filesize
Response.ContentType="application/msword"
Response.BinaryWrite objStream.Read
Response.Write(oStringWriter)
Response.Flush
objStream.Close
set objStream=nothing
%>
由于一个页面的表格数据来源多样,且数据多,不想用ASP生成报表的方式,就想一键转到Word中,另外:我注意到在浏览器菜单->文件下,安装了Word的朋友可能有注意,有一个"使用Microsoft office Word编辑的子项,可一下转到Word中,且动态数据都在,这是不是用到了宏命令???各位大虾知道怎样做的吗?
给个答复,谢谢!
...全文
217 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
liangjianshi 2006-04-21
  • 打赏
  • 举报
回复
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>网页上内容导出到word</title>
</head>
<body>
<div id="Layer1" >
<input type=button name='button_export' title='导出到word' onclick=OpenWord() value=下载到word></div>
</div>
<table align="center" width="300" border="1" bordercolor="#2baeff" cellpadding="0" cellspacing="0" bgcolor="lightblue">
<Tr><Td>1</td><Td>2</td><Td>3</td></tr>
<Tr><Td>4</td><Td>5</td><Td>6</td></tr>
<Tr><Td>7</td><Td>8</td><Td>9</td></tr>
</table>
</body>
</html>
<script language="javascript">
function OpenWord(){
Layer1.style.border=0
ExcelSheet = new ActiveXObject('word.Application');
ExcelSheet.Application.Visible = true;
var mydoc=ExcelSheet.Documents.Add('',0,1);
myRange =mydoc.Range(0,1)
var sel=Layer1.document.body.createTextRange()
sel.select()
Layer1.document.execCommand('Copy')
sel.moveEnd('character')
myRange.Paste();
location.reload()
ExcelSheet.ActiveWindow.ActivePane.View.Type=9
}
</script>

xmzrh 2006-04-21
  • 打赏
  • 举报
回复
你那样写肯定不行,你没把要输出的数据库里读出的数据传递过去.
www_7di_net 2006-04-08
  • 打赏
  • 举报
回复
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>

<body>
<%

'设置输出为 word 格式
response.ContentType ="application/vnd.ms-word"
Response.AddHeader "Content-Disposition", "attachment; filename=1.doc"

'设置输出为 excel 格式
'response.ContentType ="application/vnd.ms-excel"
%>
<BR><BR><div align="center" style="font-size:26px "><strong> 计 划 申 报 表</strong></div><BR><BR>
<table border="1" width="100%" cellpadding="4" cellspacing="0" bordercolor="#000000" align="center" style="border-collapse: collapse">
<tr height="40">
<td style="font-size:22px " width="5%"><div align="center" style='font-family:"楷体_GB2312"'>序号</div></td>
<td style="font-size:22px " width="28%"><div align="center" style='font-family:"楷体_GB2312"'>内容及目的</div></td>
<td style="font-size:22px " width="10%"><div align="center" style='font-family:"楷体_GB2312"'>时间</div></td>
<td style="font-size:22px " width="10%"><div align="center" style='font-family:"楷体_GB2312"'>地点</div></td>
<td style="font-size:22px " width="20%"><div align="center" style='font-family:"楷体_GB2312"'>联系人及电话</div></td>
</tr>
</table>
</body>
</html>
lhf168 2006-02-22
  • 打赏
  • 举报
回复
怎么没人帮助解决啊?大家都没碰到类似问题吗?自己再!!!
lhf168 2006-02-21
  • 打赏
  • 举报
回复
大家没碰到类似问题吗???真的着急啊,在线等,顶个先,还请高手过来赐教啊!!!

28,406

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧