-------------------ssbxd_print_ocx.asp
<!--#include file="../vbf.asp"-->
<html>
<head>
<title>实施费用报销单打印</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<%
bxd_code=request("bxd_code")
xmlTemplate = getServerHost()&"fina_template/ssbxd.xml"
cllTemplate = getServerHost()&"fina_template/ssbxd.cll"
xmlGen = getServerHost()&"shishibaoxiao/ssbxd_xml2.asp?bxd_code="&bxd_code
%>
<table width="96%" border="0" class="noprint">
<TR>
<TD ><! 注意codeBase的用法,让IE自动下载cellweb5的cab包,version为版本号,用于IE识别并自动更新>
<OBJECT
classid=clsid:3F166327-8030-4881-8BD2-EA25350E574A width="950" height="435"
id=DCellWeb1
name="DCellWeb1"
CODEBASE="../fina_template/cellweb5.cab#version=5,2,5,1228"
VIEWASTEXT>
<PARAM NAME="_Version" VALUE="65536"><PARAM NAME="_ExtentX" VALUE="14790">
<PARAM NAME="_ExtentY" VALUE="8652"><PARAM NAME="_StockProps" VALUE="0">
</OBJECT>
</TD>
</TR>
<tr>
<td align="center">
<input type="button" id=btn_print value="打 印">
<input name="button" type="button" id="btn_printview" value="打印预览">
<input type="button" id="btn_saveas" value="另存为">
<input name="button1" type="button" onclick="javascript:window.close()" value="退 出">
</td>
</tr>
</table>
</body>
</html>
<SCRIPT ID=clientEventHandlersJS LANGUAGE=javascript>
<!--
var nRows = 0; // 记录数据库记录索引号
var nPages = 0; // 记录分页总数
function window_onload()
{
//var file = DCellWeb1.OpenFile("http://ufpmp002/xmglnet/item_weihu/fina_template/ssbxd.cll" ,"");
var file = DCellWeb1.OpenFile("<%=cllTemplate%>" ,"");
if (file<0)
{
alert("模板文件有误!");
return;
}
DCellWeb1.WorkbookReadonly = true;
//DCellWeb1.ShowHScroll(0, 0);
//DCellWeb1.ShowVScroll(0, 0);
// 发送xmlHttp请求到服务器端
var xmlDom = new ActiveXObject("Microsoft.XMLDOM");
this.sender = new ActiveXObject("Microsoft.XMLHTTP");
//var str= "http://localhost/xmglnet/item_weihu/shishibaoxiao/xmltest.asp";
//var str= "http://localhost/xmglnet/item_weihu/fina_template/ssbxd2.xml";
var str= "<%=xmlGen%>";
this.sender.open("GET",str,false);
this.sender.send();
//if (this.sender.readystate==4) alert("suss");
// 从服务器得到处理后的xml对象
this.sender.responseXML.createProcessingInstruction("xml"," version=\"1.0\" encoding=\"gb2312\"");
var root = this.sender.responseXML;
// 把xml中的数据填充到cell中
root = root.childNodes[1];
if (root==null)
{
alert("数据加载有误!");
return;
}
//DCellWeb1.OpenFile(root.childNodes[0].text,""); // 载入cell模板文件
//--header-----
var header = root.childNodes[1]; //node1 header
if (header==null) return;
var col,row,cdown,rdown,dtype,Name;
var datas = header.childNodes;
for(var i = 0; i< datas.length; i++)
{
var attributes = datas[i].attributes;
//获取数据
col = attributes.getNamedItem("col").value;
row = attributes.getNamedItem("row").value;
cdown = attributes.getNamedItem("cdown").value;
rdown = attributes.getNamedItem("rdown").value;
dtype = attributes.getNamedItem("dtype").value;
Name = attributes.getNamedItem("Name").value;
if (cdown>"0"||rdown>"0")
{
DCellWeb1.MergeCells(col, row, parseInt(col)+parseInt(cdown), parseInt(row)+parseInt(rdown));
}
if(parseInt(rdown)<0)
{
DCellWeb1.DeleteRow(row,Math.abs(parseInt(rdown)),0);
}
if(parseInt(cdown)<0)
{
DCellWeb1.DeleteCol(col,Math.abs(parseInt(cdown)),0);
}
if (dtype=="d")
{
if (Name!="") DCellWeb1.D(col,row,0,Name);
}
else
{
DCellWeb1.S(col,row,0,Name);
}
}
//--middle-----
nRows = 6;
var middler = root.childNodes[2]; //node1 middle
if (header==null) return;
var datas = middler.childNodes;
DCellWeb1.InsertRow(nRows, parseInt(datas.length/5)-1, 0);
for(var i = 0; i< datas.length; i++)
{
var attributes = datas[i].attributes;
//获取数据
col = attributes.getNamedItem("col").value;
row = attributes.getNamedItem("row").value;
cdown = attributes.getNamedItem("cdown").value;
rdown = attributes.getNamedItem("rdown").value;
dtype = attributes.getNamedItem("dtype").value;
Name = attributes.getNamedItem("Name").value;
if (cdown>"0"||rdown>"0")
{
//alert(col);alert(row);alert(parseInt(col)+parseInt(cdown));alert(parseInt(row)+parseInt(rdown));
DCellWeb1.MergeCells(col, row, parseInt(col)+parseInt(cdown), parseInt(row)+parseInt(rdown));
}
if(parseInt(rdown)<0)
{
DCellWeb1.DeleteRow(row,Math.abs(parseInt(rdown)),0);
}
if(parseInt(cdown)<0)
{
DCellWeb1.DeleteCol(col,Math.abs(parseInt(cdown)),0);
}
if (dtype=="d")
{
if (Name!="") DCellWeb1.D(col,row,0,Name);
}
else
{
DCellWeb1.S(col,row,0,Name);
}
//DCellWeb1.SetCellString(attributes.getNamedItem("col").value,
//attributes.getNamedItem("row").value,0,attributes.getNamedItem("Name").value);
//DCellWeb1.SetCellAlign(attributes.getNamedItem("col").value,
//attributes.getNamedItem("row").value,0,32+4);
nRows ++;
//row = parseInt(attributes.getNamedItem("row").value);
//DCellWeb1.SetRowPageBreak(7, 1) //设置行硬分页符
//DCellWeb1.MergeCells(1, 1, 4, 4) //把A1:D4单元格组合
}
//--tailer-----
var tailer = root.childNodes[3]; // tailer
if (header==null) return;
var datas = tailer.childNodes;
for(var i = 0; i< datas.length; i++)
{
var attributes = datas[i].attributes;
//获取数据
col = attributes.getNamedItem("col").value;
row = attributes.getNamedItem("row").value;
cdown = attributes.getNamedItem("cdown").value;
rdown = attributes.getNamedItem("rdown").value;
dtype = attributes.getNamedItem("dtype").value;
Name = attributes.getNamedItem("Name").value;
if (cdown>"0"||rdown>"0")
{
DCellWeb1.MergeCells(col, row, parseInt(col)+parseInt(cdown), parseInt(row)+parseInt(rdown));
}
if(parseInt(rdown)<0)
{
DCellWeb1.DeleteRow(row,Math.abs(parseInt(rdown)),0);
}
if(parseInt(cdown)<0)
{
DCellWeb1.DeleteCol(col,Math.abs(parseInt(cdown)),0);
}
if (dtype=="d")
{
if (Name!="") DCellWeb1.D(col,row,0,Name);
}
else
{
DCellWeb1.S(col,row,0,Name);
}
}
//--footer-----
var footer = root.childNodes[4]; // footer
if (header==null) return;
var datas = footer.childNodes;
for(var i = 0; i< datas.length; i++)
{
var attributes = datas[i].attributes;
//获取数据
col = attributes.getNamedItem("col").value;
row = attributes.getNamedItem("row").value;
cdown = attributes.getNamedItem("cdown").value;
rdown = attributes.getNamedItem("rdown").value;
dtype = attributes.getNamedItem("dtype").value;
Name = attributes.getNamedItem("Name").value;
if (cdown>"0"||rdown>"0")
{
DCellWeb1.MergeCells(col, row, parseInt(col)+parseInt(cdown), parseInt(row)+parseInt(rdown));
}
if(parseInt(rdown)<0)
{
DCellWeb1.DeleteRow(row,Math.abs(parseInt(rdown)),0);
}
if(parseInt(cdown)<0)
{
DCellWeb1.DeleteCol(col,Math.abs(parseInt(cdown)),0);
}
if (dtype=="d")
{
if (Name!="") DCellWeb1.D(col,row,0,Name);
}
else
{
DCellWeb1.S(col,row,0,Name);
}
}
//--footer
}
window.attachEvent("onload", window_onload);
//-->
</SCRIPT>
<SCRIPT ID=clientEventHandlersVBS LANGUAGE=vbscript>
<!--
Sub btn_about_onclick
DCellWeb1.AboutBox
End Sub
Sub btn_saveas_onclick
DCellWeb1.SaveFile
End Sub
Sub btn_printview_onclick
DCellWeb1.PrintPreview 1,DCellWeb1.GetCurSheet
End Sub
Sub btn_print_onclick
//DCellWeb1.PrintPara 1, 1, 1, 1
//DCellWeb1.PrintLabel 1, 1
DCellWeb1.PrintSheet 1,DCellWeb1.GetCurSheet
End Sub
Sub btn_open_onclick
DCellWeb1.WorkbookReadonly = True
DCellWeb1.ShowHScroll 0, 0
DCellWeb1.ShowVScroll 0, 0
//DCellWeb1.OpenFile "http://ufpmp002/xmglnet/item_weihu/fina_template/实施费用报销5.cll" ,""
DCellWeb1.OpenFile "/fina_template/clbxd.cll" ,""
End Sub
Sub DCellWeb1_MouseLClick(col, row, updn)
//If col=1 And row=1 And updn = 0 then
MsgBox("打印格式已经调试好,请不要再调整,请将凭证打印纸(210mm×133mm)放入打印机")
//End If
End Sub
-->
</SCRIPT>
<%
sub getnodes(node)
dim i
response.write("<br><b>NodeName:</b>"&node.nodename&"<br><b>NodeTypeString:</b>"&node.nodetypestring&"<br><b>NodeValue:</b>"&node.nodevalue&"<br><b>Text:</b>"&node.text&"<br><b>node.childnodes.length:</b>"&node.childnodes.length&"<p>")
if node.childnodes.length<>0 then
for i=0 to node.childnodes.length-1
getnodes(node.childnodes(i))
next
end if
end sub
%>
-------------------------------ssbxd_xml2.asp
<%
' 生成xml文件对象
set xmlDoc = Server.CreateObject("Microsoft.XMLDOM")
xmlDoc.async = false
' 载入xml模板
returnval = xmlDoc.Load(Server.MapPath("../fina_template/ssbxd.xml"))
if not returnval then
response.Write("XML文件加载失败!")
end if
//5把xml对象发送给客户端
Response.ContentType="text/xml"
temp = Session.CodePage
Session.CodePage = 65001
Response.ContentType = "text/xml; charset=utf-8"
Response.Write(xmlDoc.xml)
Session.CodePage = temp
Response.End
%>
----------------------------------------ssbxd_xml.asp
<!--#include file="http://www.cnblogs.com/dbconnection.asp"-->
<!--#include file="http://www.cnblogs.com/vbf.asp"-->
<!--#include file="http://www.cnblogs.com/inc/vbf_num.asp"-->
<%
bxd_code = Request("bxd_code")
'bxd_code = 506
'bxd_code = 212
sql_header = " select case a.bx_type when '0' then '有效人天' else '指定项目' end as bx_typename,"& _
" isnull(bx_type,'1') as bx_type,b.ssbname,a.sp_id,c.sp_name as bxr"& _
" from ssbxd_info a"& _
" left join xm_subssb b on a.ssbcode=b.ssbcode"& _
" left join xm_member c on c.sp_id=a.sp_id"& _
" where a.bxd_code='"&bxd_code&"'"
set rs_header = cn.execute(sql_header)
if rs_header.eof then aspalert("1sql_header数据有误!")
bx_type = rs_header("bx_type")
if bx_type = 1 then
'bx_type=1指定项目
sql_middler = "select a.fyname,c.itemname, "&_
" isnull(b.money,0) as je,b.cost_desc,b.ysxm,a.rdown "&_
" from (select bxd_code,fyname,count(bxd_code) as rdown "&_
" from shishi_bxd "&_
" where bxd_code = '"&bxd_code&"' "&_
" group by bxd_code,fyname) a "&_
" left join shishi_bxd b on a.bxd_code=b.bxd_code and a.fyname=b.fyname "&_
" left join xm_item c on b.xmxh=c.xh "&_
" order by a.fyname "
else
sql_middler = " select a.fyname,isnull(d.itemname,'公共项目') as itemname, "& _
" cast(isnull(c.money*b.worktime/isnull(b.workday,1),0) as dec(19,2)) as je,c.cost_desc,c.ysxm,a.rdown "& _
" from ( "& _
" select bxd_code,fyname,count(bxd_code) as rdown "& _
" from dbo.uf_ssbxdtb('"&bxd_code&"') "& _
" group by bxd_code,fyname) a "& _
" left join dbo.uf_ssbxdtb('"&bxd_code&"') b on a.bxd_code=b.bxd_code and a.fyname=b.fyname "& _
" left join shishi_bxd c on c.bxd_code=b.bxd_code and c.fyname=b.fyname and c.fromdate=b.fromdate and c.todate=b.todate "& _
" left join xm_item d on b.xmxh=d.xh "& _
" order by a.fyname "
end if
set rs_middler = cn.execute(sql_middler)
if rs_middler.eof then aspalert("2sql_middler数据有误!")
sql_tailer = "select ssjl_spr,caiwu_spr,isnull(yujie,0) as yujienew,"& _
" isnull(yhyujie,0) as yhyujienew,je ,jl_spr ,sp_flag,cwjl_spr,sp_id "& _
" from ssbxd_info a "& _
" left join (select bxd_code,sum(money) as je from shishi_bxd "&_
" where bxd_code='"&bxd_code&"' group by bxd_code) b on a.bxd_code=b.bxd_code "& _
" where a.bxd_code='"&bxd_code&"'"
set rs_tailer = cn.execute(sql_tailer)
if rs_tailer.eof then aspalert("3sql_tailer数据有误!")
' 生成xml文件对象
set xmlDoc = Server.CreateObject("Microsoft.XMLDOM")
xmlDoc.async = false
' 载入xml模板
returnval = xmlDoc.Load(Server.MapPath("../fina_template/ssbxd.xml"))
if not returnval then
aspalert("XML文件加载失败!")
end if
//0表的固定格式关系
rowheader = 4
rowmiddler = rowheader + 1
rowtailer = rowmiddler + 2
rowfooter = rowtailer + 2
//1表头数据,选择Header节点,把指定的数据库数据装入xml
set xmlheader = xmldoc.selectsinglenode("//Header")
Set data = xmlheader.getElementsByTagName("Data")
data.Item(0).attributes.item(5).value = rs_header("ssbname")&"费用报销单"
data.Item(1).attributes.item(5).value = "部门:"&rs_header("ssbname")
data.Item(2).attributes.item(5).value = "报销人:"&rs_header("bxr")
data.Item(3).attributes.item(5).value = "报销方式:"&rs_header("bx_typename")
data.Item(4).attributes.item(5).value = "编号:"&bxd_code
//2数据节点,选择Middler节点,把指定的数据库数据装入xml
set xmlmiddler = xmldoc.selectsinglenode("//Middler")
column_count = rs_middler.fields.count
for i=0 to 4
Set newNode = xmlmiddler.childNodes.item(i)
newNode.setAttribute "row",rowmiddler
newNode.setAttribute "col",i+1
newNode.setAttribute "rdown",iif(rs_middler(i).name="fyname",rs_middler("rdown")-1,0)
newNode.setAttribute "cdown",0
newNode.setAttribute "dtype",iif(rs_middler(i).name="je","d","s")
newNode.setAttribute "Name",cnull(rs_middler(i).value)
next
fyname = rs_middler("fyname")
rs_middler.movenext
rowmiddler = rowmiddler+1
while not rs_middler.eof
for i=0 to 4
set newNode = newNode.cloneNode(true)
newNode.setAttribute "row",rowmiddler
newNode.setAttribute "col",i+1
newNode.setAttribute "rdown",iif((rs_middler(i).name="fyname") and (rs_middler("fyname")<>fyname),rs_middler("rdown")-1,0)
newNode.setAttribute "cdown",0
newNode.setAttribute "dtype",iif(rs_middler(i).name="je","d","s")
newNode.setAttribute "Name",cnull(rs_middler(i).value)
xmlmiddler.appendChild(newNode)
next
rowmiddler = rowmiddler+1
fyname = rs_middler("fyname")
rs_middler.movenext
wend
//3表尾数据,选择Tailer节点,把指定的数据库数据装入xml
set xmltailer = xmldoc.selectsinglenode("//Tailer")
rowtailer = rowmiddler + 1
set newNode = xmltailer.childNodes.item(0) '金额大写
newNode.setAttribute "row",rowtailer
newNode.setAttribute "Name",y_big_write(rs_tailer("je"))
set newNode = xmltailer.childNodes.item(1) '金额小写
newNode.setAttribute "row",rowtailer
newNode.setAttribute "Name",rs_tailer("je")
rowtailer = rowtailer + 1
set newNode = xmltailer.childNodes.item(2) '现金预借
newNode.setAttribute "row",rowtailer
newNode.setAttribute "Name",iif(rs_tailer("yujienew")<=0.001,"",rs_tailer("yujienew"))
set newNode = xmltailer.childNodes.item(3) '银行预借
newNode.setAttribute "row",rowtailer
newNode.setAttribute "Name",iif(rs_tailer("yhyujienew")<=0.001,"",rs_tailer("yhyujienew"))
rowtailer = rowtailer + 1
buling = rs_tailer("je")-rs_tailer("yhyujienew")-rs_tailer("yujienew")
set newNode = xmltailer.childNodes.item(4) '补领金额
newNode.setAttribute "row",rowtailer
newNode.setAttribute "Name",iif(buling>0.001,buling,"")
set newNode = xmltailer.childNodes.item(5) '退还金额
newNode.setAttribute "row",rowtailer
newNode.setAttribute "Name",iif(buling<0.0,-buling,"")
//4表脚数据,选择Footer节点,把指定的数据库数据装入xml
set xmlfooter = xmldoc.selectsinglenode("//Footer")
rowfooter = rowtailer + 2
set newNode = xmlfooter.childNodes.item(0) '上级主管..
newNode.setAttribute "row",rowfooter
ssjl_spr = iif(rs_tailer("sp_flag")=1,"",getsp_name(rs_tailer("ssjl_spr")))
newNode.setAttribute "Name","上级主管:"&getsp_name(rs_tailer("jl_spr"))&space(33-lenb(getsp_name(rs_tailer("jl_spr"))))&"部门经理:"&ssjl_spr&space(35-lenb(ssjl_spr))&"财务经理:"&getsp_name(rs_tailer("cwjl_spr"))
set newNode = xmlfooter.childNodes.item(1) '会计..
newNode.setAttribute "row",rowfooter+1
newNode.setAttribute "Name","会计:"&space(37)&"出纳:"&getsp_name(rs_tailer("caiwu_spr"))&space(38-lenb(getsp_name(rs_tailer("caiwu_spr"))))&"领款人:"&getsp_name(rs_tailer("sp_id"))
set newNode = xmlfooter.childNodes.item(2) '打印日期
newNode.setAttribute "row",rowfooter+2
newNode.setAttribute "Name",space(86)&"打印日期:"&date
//5把xml对象发送给客户端
Response.ContentType="text/xml"
temp = Session.CodePage
Session.CodePage = 65001
Response.ContentType = "text/xml; charset=utf-8"
Response.Write(xmlDoc.xml)
Session.CodePage = temp
Response.End
%>
https://files.cnblogs.com/shuang/ASP报表设计源码.rar