asp调用WORD
我想用ASP调用WORD,并在网页上显示出来,内容有图片和表格,我看过一些资料,说可以用ASP的组件把WORD另存为HTML再显示和修改,可是没有可用的代码,希望大家给个...
我想用ASP调用WORD,并在网页上显示出来,内容有图片和表格,我看过一些资料,说可以用ASP的组件把WORD另存为HTML再显示和修改,可是没有可用的代码,希望大家给个能用的代码,我的环境是server 2003+word 2003,高分求高效.
现在是想把已有的WORD文件在页面显示出来,不是打印,也就是用的是服务器上的WORD,因为我还要在显示出来的网页上禁用好多的功能,所以只能用HTML格式的,
找到了我再加分~~~不过要能用的全部代码
<%''点击"打印"按钮,调用vbscript函数buildDoc生成本地Word文档,实现本地打印。%>二楼的看好了,我要的是把现有的WORD写在网页上,不是把网页的写在WORD里~大家认真点~~~怎么全是打印啊?我要的是把用ASP的组件把WORD另存为HTML再用ASP输出到WEB页面上 展开
现在是想把已有的WORD文件在页面显示出来,不是打印,也就是用的是服务器上的WORD,因为我还要在显示出来的网页上禁用好多的功能,所以只能用HTML格式的,
找到了我再加分~~~不过要能用的全部代码
<%''点击"打印"按钮,调用vbscript函数buildDoc生成本地Word文档,实现本地打印。%>二楼的看好了,我要的是把现有的WORD写在网页上,不是把网页的写在WORD里~大家认真点~~~怎么全是打印啊?我要的是把用ASP的组件把WORD另存为HTML再用ASP输出到WEB页面上 展开
4个回答
展开全部
看看 这样可以不
ASP调用Word
<html>
<head>
<title>看看</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<!--media=print 这个属性可以在打印时有效-->
<style media=print>
.Noprint{display:none;}
.PageNext{page-break-after: always;}
</style>
<style>
.tdp
{
border-bottom: 1 solid #000000;
border-left: 1 solid #000000;
border-right: 0 solid #ffffff;
border-top: 0 solid #ffffff;
}
.tabp
{
border-color: #000000 #000000 #000000 #000000;
border-style: solid;
border-top-width: 2px;
border-right-width: 2px;
border-bottom-width: 1px;
border-left-width: 1px;
}
.NOPRINT {
font-family: "宋体";
font-size: 9pt;
}
</style>
</head>
<body >
<center class="Noprint" >
<p>
<OBJECT id=WebBrowser classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 width=0>
</OBJECT>
<input type=button value=打印 onclick=document.all.WebBrowser.ExecWB(6,1)>
<input type=button value=直接打印 onclick=document.all.WebBrowser.ExecWB(6,6)>
<input type=button value=页面设置 onclick=document.all.WebBrowser.ExecWB(8,1)>
</p>
<p> <input type=button value=打印预览 onclick=document.all.WebBrowser.ExecWB(7,1)>
<br/>
</p>
<hr align="center" width="90%" size="1" noshade>
</center>
<table width="90%" border="0" align="center" cellpadding="2" cellspacing="0" class="tabp">
<tr>
<td colspan="3" class="tdp">第1页</td>
</tr>
<tr>
<td width="29%" class="tdp"> </td>
<td width="28%" class="tdp"> </td>
<td width="43%" class="tdp"> </td>
</tr>
<tr>
<td colspan="3" class="tdp"> </td>
</tr>
<tr>
<td colspan="3" class="tdp"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="50%" class="tdp"><p>这样的报表</p>
<p>对一般的要求就够了。</p></td>
<td> </td>
</tr>
</table></td>
</tr>
</table>
<hr align="center" width="90%" size="1" noshade class="NOPRINT" >
<!--分页-->
<div class="PageNext"></div>
<table width="90%" border="0" align="center" cellpadding="2" cellspacing="0" class="tabp">
<tr>
<td class="tdp">第2页</td>
</tr>
<tr>
<td class="tdp">看到分页了吧</td>
</tr>
<tr>
<td class="tdp"> </td>
</tr>
<tr>
<td class="tdp"> </td>
</tr>
<tr>
<td class="tdp"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="50%" class="tdp"><p>这样的报表</p>
<p>对一般的要求就够了。</p></td>
<td> </td>
</tr>
</table></td>
</tr>
</table>
</body>
</html>
__________________________________________________________________
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<BODY>
<TABLE id="data" border="1">
<TR>
<TD><B>asdfaf</B></TD>
<TD><B>asfafaf</B></TD>
</TR>
<TR>
<TD>asdfaf</TD>
<TD>asfafaf</TD>
</TR>
</TABLE>
<input type="button" name="out_word" onclick="vbscript:buildDoc" value="导出到word" class="notPrint">
<script language="vbscript">
Sub buildDoc
set table = document.all.data
row = table.rows.length
column = table.rows(1).cells.length
Set objWordDoc = CreateObject("Word.Document")
'objWordDoc.Application.Documents.Add theTemplate, False
objWordDoc.Application.Visible=True
Dim theArray(20,10000)
for i=0 to row-1
for j=0 to column-1
theArray(j+1,i+1) = table.rows(i).cells(j).innerTEXT
next
next
objWordDoc.Application.ActiveDocument.Paragraphs.Add.Range.InsertBefore("综合查询结果集") //显示表格标题
objWordDoc.Application.ActiveDocument.Paragraphs.Add.Range.InsertBefore("")
Set rngPara = objWordDoc.Application.ActiveDocument.Paragraphs(1).Range
With rngPara
.Bold = True //将标题设为粗体
.ParagraphFormat.Alignment = 1 //将标题居中
.Font.Name = "隶书" //设定标题字体
.Font.Size = 18 //设定标题字体大小
End With
Set rngCurrent = objWordDoc.Application.ActiveDocument.Paragraphs(3).Range
Set tabCurrent = ObjWordDoc.Application.ActiveDocument.Tables.Add(rngCurrent,row,column)
for i = 1 to column
objWordDoc.Application.ActiveDocument.Tables(1).Rows(1).Cells(i).Range.InsertAfter theArray(i,1)
objWordDoc.Application.ActiveDocument.Tables(1).Rows(1).Cells(i).Range.ParagraphFormat.alignment=1
next
For i =1 to column
For j = 2 to row
objWordDoc.Application.ActiveDocument.Tables(1).Rows(j).Cells(i).Range.InsertAfter theArray(i,j)
objWordDoc.Application.ActiveDocument.Tables(1).Rows(j).Cells(i).Range.ParagraphFormat.alignment=1
Next
Next
End Sub
</SCRIPT>
</BODY>
</HTML>
这段程序可以把ASP中的表格导入到Word中,看看能不能对你有点帮助
----------------------------------------------------------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>看看</TITLE>
<META http-equiv=Content-Type content="text/html; charset=gb2312"><!--media=print 这个属性可以在打印时有效-->
<STYLE media=print>.Noprint {
DISPLAY: none
}
.PageNext {
PAGE-BREAK-AFTER: always
}
</STYLE>
<STYLE>.tdp {
BORDER-RIGHT: #ffffff 0px solid; BORDER-TOP: #ffffff 0px solid; BORDER-LEFT: #000000 1px solid; BORDER-BOTTOM: #000000 1px solid
}
.tabp {
BORDER-RIGHT: #000000 2px solid; BORDER-TOP: #000000 2px solid; BORDER-LEFT: #000000 1px solid; BORDER-BOTTOM: #000000 1px solid
}
.NOPRINT {
FONT-SIZE: 9pt; FONT-FAMILY: "宋体"
}
</STYLE>
<META content="MSHTML 6.00.2800.1106" name=GENERATOR></HEAD>
<BODY>
<CENTER class=Noprint>
<P>
<OBJECT id=WebBrowser height=0 width=0
classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2></OBJECT><INPUT onclick=document.all.WebBrowser.ExecWB(6,1) type=button value=打印>
<INPUT onclick=document.all.WebBrowser.ExecWB(6,6) type=button value=直接打印> <INPUT onclick=document.all.WebBrowser.ExecWB(8,1) type=button value=页面设置> </P>
<P><INPUT onclick=document.all.WebBrowser.ExecWB(7,1) type=button value=打印预览>
<BR></P>
<HR align=center width="90%" noShade SIZE=1>
</CENTER>
<TABLE class=tabp cellSpacing=0 cellPadding=2 width="90%" align=center
border=0><TBODY>
<TR>
<TD class=tdp colSpan=3>第1页</TD></TR>
<TR>
<TD class=tdp width="29%"> </TD>
<TD class=tdp width="28%"> </TD>
<TD class=tdp width="43%"> </TD></TR>
<TR>
<TD class=tdp colSpan=3> </TD></TR>
<TR>
<TD class=tdp colSpan=3>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR>
<TD class=tdp width="50%">
<P>这样的报表</P>
<P>对一般的要求就够了。</P></TD>
<TD> </TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE>
<HR class=NOPRINT align=center width="90%" noShade SIZE=1>
<!--分页-->
<DIV class=PageNext></DIV>
<TABLE class=tabp cellSpacing=0 cellPadding=2 width="90%" align=center
border=0><TBODY>
<TR>
<TD class=tdp>第2页</TD></TR>
<TR>
<TD class=tdp>看到分页了吧</TD></TR>
<TR>
<TD class=tdp> </TD></TR>
<TR>
<TD class=tdp> </TD></TR>
<TR>
<TD class=tdp>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR>
<TD class=tdp width="50%">
<P>这样的报表</P>
<P>对一般的要求就够了。</P></TD>
<TD> </TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></BODY></HTML>
ASP调用Word
<html>
<head>
<title>看看</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<!--media=print 这个属性可以在打印时有效-->
<style media=print>
.Noprint{display:none;}
.PageNext{page-break-after: always;}
</style>
<style>
.tdp
{
border-bottom: 1 solid #000000;
border-left: 1 solid #000000;
border-right: 0 solid #ffffff;
border-top: 0 solid #ffffff;
}
.tabp
{
border-color: #000000 #000000 #000000 #000000;
border-style: solid;
border-top-width: 2px;
border-right-width: 2px;
border-bottom-width: 1px;
border-left-width: 1px;
}
.NOPRINT {
font-family: "宋体";
font-size: 9pt;
}
</style>
</head>
<body >
<center class="Noprint" >
<p>
<OBJECT id=WebBrowser classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 width=0>
</OBJECT>
<input type=button value=打印 onclick=document.all.WebBrowser.ExecWB(6,1)>
<input type=button value=直接打印 onclick=document.all.WebBrowser.ExecWB(6,6)>
<input type=button value=页面设置 onclick=document.all.WebBrowser.ExecWB(8,1)>
</p>
<p> <input type=button value=打印预览 onclick=document.all.WebBrowser.ExecWB(7,1)>
<br/>
</p>
<hr align="center" width="90%" size="1" noshade>
</center>
<table width="90%" border="0" align="center" cellpadding="2" cellspacing="0" class="tabp">
<tr>
<td colspan="3" class="tdp">第1页</td>
</tr>
<tr>
<td width="29%" class="tdp"> </td>
<td width="28%" class="tdp"> </td>
<td width="43%" class="tdp"> </td>
</tr>
<tr>
<td colspan="3" class="tdp"> </td>
</tr>
<tr>
<td colspan="3" class="tdp"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="50%" class="tdp"><p>这样的报表</p>
<p>对一般的要求就够了。</p></td>
<td> </td>
</tr>
</table></td>
</tr>
</table>
<hr align="center" width="90%" size="1" noshade class="NOPRINT" >
<!--分页-->
<div class="PageNext"></div>
<table width="90%" border="0" align="center" cellpadding="2" cellspacing="0" class="tabp">
<tr>
<td class="tdp">第2页</td>
</tr>
<tr>
<td class="tdp">看到分页了吧</td>
</tr>
<tr>
<td class="tdp"> </td>
</tr>
<tr>
<td class="tdp"> </td>
</tr>
<tr>
<td class="tdp"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="50%" class="tdp"><p>这样的报表</p>
<p>对一般的要求就够了。</p></td>
<td> </td>
</tr>
</table></td>
</tr>
</table>
</body>
</html>
__________________________________________________________________
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<BODY>
<TABLE id="data" border="1">
<TR>
<TD><B>asdfaf</B></TD>
<TD><B>asfafaf</B></TD>
</TR>
<TR>
<TD>asdfaf</TD>
<TD>asfafaf</TD>
</TR>
</TABLE>
<input type="button" name="out_word" onclick="vbscript:buildDoc" value="导出到word" class="notPrint">
<script language="vbscript">
Sub buildDoc
set table = document.all.data
row = table.rows.length
column = table.rows(1).cells.length
Set objWordDoc = CreateObject("Word.Document")
'objWordDoc.Application.Documents.Add theTemplate, False
objWordDoc.Application.Visible=True
Dim theArray(20,10000)
for i=0 to row-1
for j=0 to column-1
theArray(j+1,i+1) = table.rows(i).cells(j).innerTEXT
next
next
objWordDoc.Application.ActiveDocument.Paragraphs.Add.Range.InsertBefore("综合查询结果集") //显示表格标题
objWordDoc.Application.ActiveDocument.Paragraphs.Add.Range.InsertBefore("")
Set rngPara = objWordDoc.Application.ActiveDocument.Paragraphs(1).Range
With rngPara
.Bold = True //将标题设为粗体
.ParagraphFormat.Alignment = 1 //将标题居中
.Font.Name = "隶书" //设定标题字体
.Font.Size = 18 //设定标题字体大小
End With
Set rngCurrent = objWordDoc.Application.ActiveDocument.Paragraphs(3).Range
Set tabCurrent = ObjWordDoc.Application.ActiveDocument.Tables.Add(rngCurrent,row,column)
for i = 1 to column
objWordDoc.Application.ActiveDocument.Tables(1).Rows(1).Cells(i).Range.InsertAfter theArray(i,1)
objWordDoc.Application.ActiveDocument.Tables(1).Rows(1).Cells(i).Range.ParagraphFormat.alignment=1
next
For i =1 to column
For j = 2 to row
objWordDoc.Application.ActiveDocument.Tables(1).Rows(j).Cells(i).Range.InsertAfter theArray(i,j)
objWordDoc.Application.ActiveDocument.Tables(1).Rows(j).Cells(i).Range.ParagraphFormat.alignment=1
Next
Next
End Sub
</SCRIPT>
</BODY>
</HTML>
这段程序可以把ASP中的表格导入到Word中,看看能不能对你有点帮助
----------------------------------------------------------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>看看</TITLE>
<META http-equiv=Content-Type content="text/html; charset=gb2312"><!--media=print 这个属性可以在打印时有效-->
<STYLE media=print>.Noprint {
DISPLAY: none
}
.PageNext {
PAGE-BREAK-AFTER: always
}
</STYLE>
<STYLE>.tdp {
BORDER-RIGHT: #ffffff 0px solid; BORDER-TOP: #ffffff 0px solid; BORDER-LEFT: #000000 1px solid; BORDER-BOTTOM: #000000 1px solid
}
.tabp {
BORDER-RIGHT: #000000 2px solid; BORDER-TOP: #000000 2px solid; BORDER-LEFT: #000000 1px solid; BORDER-BOTTOM: #000000 1px solid
}
.NOPRINT {
FONT-SIZE: 9pt; FONT-FAMILY: "宋体"
}
</STYLE>
<META content="MSHTML 6.00.2800.1106" name=GENERATOR></HEAD>
<BODY>
<CENTER class=Noprint>
<P>
<OBJECT id=WebBrowser height=0 width=0
classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2></OBJECT><INPUT onclick=document.all.WebBrowser.ExecWB(6,1) type=button value=打印>
<INPUT onclick=document.all.WebBrowser.ExecWB(6,6) type=button value=直接打印> <INPUT onclick=document.all.WebBrowser.ExecWB(8,1) type=button value=页面设置> </P>
<P><INPUT onclick=document.all.WebBrowser.ExecWB(7,1) type=button value=打印预览>
<BR></P>
<HR align=center width="90%" noShade SIZE=1>
</CENTER>
<TABLE class=tabp cellSpacing=0 cellPadding=2 width="90%" align=center
border=0><TBODY>
<TR>
<TD class=tdp colSpan=3>第1页</TD></TR>
<TR>
<TD class=tdp width="29%"> </TD>
<TD class=tdp width="28%"> </TD>
<TD class=tdp width="43%"> </TD></TR>
<TR>
<TD class=tdp colSpan=3> </TD></TR>
<TR>
<TD class=tdp colSpan=3>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR>
<TD class=tdp width="50%">
<P>这样的报表</P>
<P>对一般的要求就够了。</P></TD>
<TD> </TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE>
<HR class=NOPRINT align=center width="90%" noShade SIZE=1>
<!--分页-->
<DIV class=PageNext></DIV>
<TABLE class=tabp cellSpacing=0 cellPadding=2 width="90%" align=center
border=0><TBODY>
<TR>
<TD class=tdp>第2页</TD></TR>
<TR>
<TD class=tdp>看到分页了吧</TD></TR>
<TR>
<TD class=tdp> </TD></TR>
<TR>
<TD class=tdp> </TD></TR>
<TR>
<TD class=tdp>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR>
<TD class=tdp width="50%">
<P>这样的报表</P>
<P>对一般的要求就够了。</P></TD>
<TD> </TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></BODY></HTML>
博思aippt
2024-07-20 广告
2024-07-20 广告
作为深圳市博思云创科技有限公司的工作人员,对于Word文档生成PPT的操作,我们有以下建议:1. 使用另存为功能:在Word中编辑完文档后,点击文件->另存为,选择PowerPoint演示文稿(*.pptx)格式,即可将文档内容转换为PPT...
点击进入详情页
本回答由博思aippt提供
展开全部
给你一个例子,自己看吧
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta http-equiv="Content-Language" content="zh-cn">
</head>
<p align="center"><b>用户信息</b>
<div align="left">
<table id="data" cellpadding="0" cellspacing="0" width="100%" ,border="1" border="1">
<tr>
<td width="50%"><p align="center">姓名</td>
<td width="50%"><p align="center">职业</td>
</tr>
<tr>
<td width="50%"><p align="center">xjb</td>
<td width="50%"><p align="center">程序员</td>
</tr>
</table>
</div>
<p align="center">
<input type=button onclick="vbscript:buildDoc" value="打印">
<%''点击"打印"按钮,调用vbscript函数buildDoc生成本地Word文档,实现本地打印。%>
<script language="vbscript">
Sub buildDoc()
'定义数组变量,存放表格中的数据(开始数组没有具体大小,以后根据网页中的表格的实际大小通过redim确定数组大小)
Dim theArray()
set table = document.all.data '把html文档中的表格data的结构和数据赋值给table
row = table.rows.length 'row为table的行数
column = table.rows(1).cells.length 'colnum为table的列数
Set objWordDoc =CreateObject("Word.Document") '创建一个Word.Document的对象
'Set objWordDoc=CreateObject("Word.Document.8")
'Set objWordapp= CreateObject("Word.Application")
'objWordapp.Application.Visible = true
'set objWordDoc= new objWordapp.Documents.Add("",0,1)
objWordDoc.Application.visible=true
redim theArray(column,row) '根据网页中的表格的实际大小重新确定数组theArray的大小
'以下两层for循环将html文档的表格中的纯文本数据赋值给数组。
'VB数组从1开始而且为先行后列。而表格数组从0开始且先列后行
for i=0 to row-1
for j=0 to column-1
theArray(j+1,i+1) = table.rows(i).cells(j).innerTEXT
next
next
objWordDoc.Application.ActiveDocument.Paragraphs.Add.Range.InsertBefore("公司员工统计表")'显示表格标题
objWordDoc.Application.ActiveDocument.Paragraphs.Add.Range.InsertBefore("") '输出标题后回车换行
Set rngPara = objWordDoc.Application.ActiveDocument.Paragraphs(1).Range
'以下With代码段设置标题属性
With rngPara
.Bold = True '将标题设为粗体
.ParagraphFormat.Alignment = 1 '将标题居中
.Font.Name = "Arial" '设定标题字体
.Font.Size = 12 '设定标题字体大小
End With
Set rngCurrent = objWordDoc.Application.ActiveDocument.Paragraphs(3).Range
Set tabCurrent = ObjWordDoc.Application.ActiveDocument.Tables.Add(rngCurrent,row,column)
'以下for循环输出表头
for i = 1 to column
objWordDoc.Application.ActiveDocument.Tables(1).Rows(1).Cells(i).Range.InsertAfter theArray(i,1)
objWordDoc.Application.ActiveDocument.Tables(1).Rows(1).Cells(i).Range.ParagraphFormat.alignment=1
next
'以下两层for循环输出表格实际内容
For i =1 to column
For j = 2 to row
objWordDoc.Application.ActiveDocument.Tables(1).Rows(j).Cells(i).Range.InsertAfter theArray(i,j)
objWordDoc.Application.ActiveDocument.Tables(1).Rows(j).Cells(i).Range.ParagraphFormat.alignment=1
Next
Next
objWordDoc.Application.ActiveDocument.SaveAs
msgbox "输出到word成功"
End Sub
</script>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta http-equiv="Content-Language" content="zh-cn">
</head>
<p align="center"><b>用户信息</b>
<div align="left">
<table id="data" cellpadding="0" cellspacing="0" width="100%" ,border="1" border="1">
<tr>
<td width="50%"><p align="center">姓名</td>
<td width="50%"><p align="center">职业</td>
</tr>
<tr>
<td width="50%"><p align="center">xjb</td>
<td width="50%"><p align="center">程序员</td>
</tr>
</table>
</div>
<p align="center">
<input type=button onclick="vbscript:buildDoc" value="打印">
<%''点击"打印"按钮,调用vbscript函数buildDoc生成本地Word文档,实现本地打印。%>
<script language="vbscript">
Sub buildDoc()
'定义数组变量,存放表格中的数据(开始数组没有具体大小,以后根据网页中的表格的实际大小通过redim确定数组大小)
Dim theArray()
set table = document.all.data '把html文档中的表格data的结构和数据赋值给table
row = table.rows.length 'row为table的行数
column = table.rows(1).cells.length 'colnum为table的列数
Set objWordDoc =CreateObject("Word.Document") '创建一个Word.Document的对象
'Set objWordDoc=CreateObject("Word.Document.8")
'Set objWordapp= CreateObject("Word.Application")
'objWordapp.Application.Visible = true
'set objWordDoc= new objWordapp.Documents.Add("",0,1)
objWordDoc.Application.visible=true
redim theArray(column,row) '根据网页中的表格的实际大小重新确定数组theArray的大小
'以下两层for循环将html文档的表格中的纯文本数据赋值给数组。
'VB数组从1开始而且为先行后列。而表格数组从0开始且先列后行
for i=0 to row-1
for j=0 to column-1
theArray(j+1,i+1) = table.rows(i).cells(j).innerTEXT
next
next
objWordDoc.Application.ActiveDocument.Paragraphs.Add.Range.InsertBefore("公司员工统计表")'显示表格标题
objWordDoc.Application.ActiveDocument.Paragraphs.Add.Range.InsertBefore("") '输出标题后回车换行
Set rngPara = objWordDoc.Application.ActiveDocument.Paragraphs(1).Range
'以下With代码段设置标题属性
With rngPara
.Bold = True '将标题设为粗体
.ParagraphFormat.Alignment = 1 '将标题居中
.Font.Name = "Arial" '设定标题字体
.Font.Size = 12 '设定标题字体大小
End With
Set rngCurrent = objWordDoc.Application.ActiveDocument.Paragraphs(3).Range
Set tabCurrent = ObjWordDoc.Application.ActiveDocument.Tables.Add(rngCurrent,row,column)
'以下for循环输出表头
for i = 1 to column
objWordDoc.Application.ActiveDocument.Tables(1).Rows(1).Cells(i).Range.InsertAfter theArray(i,1)
objWordDoc.Application.ActiveDocument.Tables(1).Rows(1).Cells(i).Range.ParagraphFormat.alignment=1
next
'以下两层for循环输出表格实际内容
For i =1 to column
For j = 2 to row
objWordDoc.Application.ActiveDocument.Tables(1).Rows(j).Cells(i).Range.InsertAfter theArray(i,j)
objWordDoc.Application.ActiveDocument.Tables(1).Rows(j).Cells(i).Range.ParagraphFormat.alignment=1
Next
Next
objWordDoc.Application.ActiveDocument.SaveAs
msgbox "输出到word成功"
End Sub
</script>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
试试这个看。
<html>
<head>
<title>看看</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<!--media=print 这个属性可以在打印时有效-->
<style media=print>
.Noprint{display:none;}
.PageNext{page-break-after: always;}
</style>
<style>
.tdp
{
border-bottom: 1 solid #000000;
border-left: 1 solid #000000;
border-right: 0 solid #ffffff;
border-top: 0 solid #ffffff;
}
.tabp
{
border-color: #000000 #000000 #000000 #000000;
border-style: solid;
border-top-width: 2px;
border-right-width: 2px;
border-bottom-width: 1px;
border-left-width: 1px;
}
.NOPRINT {
font-family: "宋体";
font-size: 9pt;
}
</style>
</head>
<body >
<center class="Noprint" >
<p>
<OBJECT id=WebBrowser classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 width=0>
</OBJECT>
<input type=button value=打印 onclick=document.all.WebBrowser.ExecWB(6,1)>
<input type=button value=直接打印 onclick=document.all.WebBrowser.ExecWB(6,6)>
<input type=button value=页面设置 onclick=document.all.WebBrowser.ExecWB(8,1)>
</p>
<p> <input type=button value=打印预览 onclick=document.all.WebBrowser.ExecWB(7,1)>
<br/>
</p>
<hr align="center" width="90%" size="1" noshade>
</center>
<table width="90%" border="0" align="center" cellpadding="2" cellspacing="0" class="tabp">
<tr>
<td colspan="3" class="tdp">第1页</td>
</tr>
<tr>
<td width="29%" class="tdp"> </td>
<td width="28%" class="tdp"> </td>
<td width="43%" class="tdp"> </td>
</tr>
<tr>
<td colspan="3" class="tdp"> </td>
</tr>
<tr>
<td colspan="3" class="tdp"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="50%" class="tdp"><p>这样的报表</p>
<p>对一般的要求就够了。</p></td>
<td> </td>
</tr>
</table></td>
</tr>
</table>
<hr align="center" width="90%" size="1" noshade class="NOPRINT" >
<!--分页-->
<div class="PageNext"></div>
<table width="90%" border="0" align="center" cellpadding="2" cellspacing="0" class="tabp">
<tr>
<td class="tdp">第2页</td>
</tr>
<tr>
<td class="tdp">看到分页了吧</td>
</tr>
<tr>
<td class="tdp"> </td>
</tr>
<tr>
<td class="tdp"> </td>
</tr>
<tr>
<td class="tdp"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="50%" class="tdp"><p>这样的报表</p>
<p>对一般的要求就够了。</p></td>
<td> </td>
</tr>
</table></td>
</tr>
</table>
</body>
</html>
<html>
<head>
<title>看看</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<!--media=print 这个属性可以在打印时有效-->
<style media=print>
.Noprint{display:none;}
.PageNext{page-break-after: always;}
</style>
<style>
.tdp
{
border-bottom: 1 solid #000000;
border-left: 1 solid #000000;
border-right: 0 solid #ffffff;
border-top: 0 solid #ffffff;
}
.tabp
{
border-color: #000000 #000000 #000000 #000000;
border-style: solid;
border-top-width: 2px;
border-right-width: 2px;
border-bottom-width: 1px;
border-left-width: 1px;
}
.NOPRINT {
font-family: "宋体";
font-size: 9pt;
}
</style>
</head>
<body >
<center class="Noprint" >
<p>
<OBJECT id=WebBrowser classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 width=0>
</OBJECT>
<input type=button value=打印 onclick=document.all.WebBrowser.ExecWB(6,1)>
<input type=button value=直接打印 onclick=document.all.WebBrowser.ExecWB(6,6)>
<input type=button value=页面设置 onclick=document.all.WebBrowser.ExecWB(8,1)>
</p>
<p> <input type=button value=打印预览 onclick=document.all.WebBrowser.ExecWB(7,1)>
<br/>
</p>
<hr align="center" width="90%" size="1" noshade>
</center>
<table width="90%" border="0" align="center" cellpadding="2" cellspacing="0" class="tabp">
<tr>
<td colspan="3" class="tdp">第1页</td>
</tr>
<tr>
<td width="29%" class="tdp"> </td>
<td width="28%" class="tdp"> </td>
<td width="43%" class="tdp"> </td>
</tr>
<tr>
<td colspan="3" class="tdp"> </td>
</tr>
<tr>
<td colspan="3" class="tdp"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="50%" class="tdp"><p>这样的报表</p>
<p>对一般的要求就够了。</p></td>
<td> </td>
</tr>
</table></td>
</tr>
</table>
<hr align="center" width="90%" size="1" noshade class="NOPRINT" >
<!--分页-->
<div class="PageNext"></div>
<table width="90%" border="0" align="center" cellpadding="2" cellspacing="0" class="tabp">
<tr>
<td class="tdp">第2页</td>
</tr>
<tr>
<td class="tdp">看到分页了吧</td>
</tr>
<tr>
<td class="tdp"> </td>
</tr>
<tr>
<td class="tdp"> </td>
</tr>
<tr>
<td class="tdp"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="50%" class="tdp"><p>这样的报表</p>
<p>对一般的要求就够了。</p></td>
<td> </td>
</tr>
</table></td>
</tr>
</table>
</body>
</html>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
有意思,我找找.
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |