填报表动态控制单元格可写
需求背景:
填报表,根据前一个单元格的值,来判断下一个单元格是否可写。
如下图,选中”企业法人”,只有企业法人栏可写:
选中”事业法人”,只有事业法人栏可写:
选中”其他”,则都不可写:
应用例子:
1 制作一张填报表,命名为test.raq:
将C6单元格的数据类型设置为html,这里是为了报表加载的时候,函数就触发。
在A6数据的填报属性中,在自动计算里调用一下C1单元格的触发函数,如下图:
2 Jsp页面
<%@ page contentType=”text/html;charset=GBK” %>
<%@ taglib uri=”/WEB-INF/runqianReport4.tld” prefix=”report” %>
<html>
<head>
</head>
<script type=”text/javascript”>
function checkkexie(a) {
//alert(“a=1″);
var val = document.getElementById (“report1_C1″).value;
var cellA2 = document.getElementById(“report1_A2″);
var cellB2 = document.getElementById(“report1_B2″);
var cellB3 = document.getElementById(“report1_B3″);
var cellC2 = document.getElementById(“report1_C2″);
var cellC3 = document.getElementById(“report1_C3″);
var cellA4 = document.getElementById(“report1_A4″);
var cellB4 = document.getElementById(“report1_B4″);
var cellB5 = document.getElementById(“report1_B5″);
var cellC4 = document.getElementById(“report1_C4″);
var cellC5 = document.getElementById(“report1_C5″);
if(val==1){
//修改单元格的背景色
cellA2.style.backgroundColor=”#FFFFFF”;
cellB2.style.backgroundColor=”#FFFFFF”;
cellB3.style.backgroundColor=”#FFFFFF”;
cellC2.style.backgroundColor=”#FFFFFF”;
cellC3.style.backgroundColor=”#FFFFFF”;
cellA4.style.backgroundColor=”#808080″;
cellB4.style.backgroundColor=”#808080″;
cellB5.style.backgroundColor=”#808080″;
cellC4.style.backgroundColor=”#808080″;
cellC5.style.backgroundColor=”#808080″;
//修改单元格可写
cellC2.disabled=false;
cellC3.disabled=false;
cellC4.disabled=true;
cellC5.disabled=true;
}else if (val==2)
//修改单元格的背景色
cellA2.style.backgroundColor=”#808080″;
cellB2.style.backgroundColor=”#808080″;
cellB3.style.backgroundColor=”#808080″;
cellC2.style.backgroundColor=”#808080″;
cellC3.style.backgroundColor=”#808080″;
cellA4.style.backgroundColor=”#FFFFFF”;
cellB4.style.backgroundColor=”#FFFFFF”;
cellB5.style.backgroundColor=”#FFFFFF”;
cellC4.style.backgroundColor=”#FFFFFF”;
cellC5.style.backgroundColor=”#FFFFFF”;
//修改单元格可写
cellC2.disabled=true;
cellC3.disabled=true;
cellC4.disabled=false;
cellC5.disabled=false;
}else if (val==3)
//修改单元格的背景色
cellA2.style.backgroundColor=”#808080″;
cellB2.style.backgroundColor=”#808080″;
cellB3.style.backgroundColor=”#808080″;
cellC2.style.backgroundColor=”#808080″;
cellC3.style.backgroundColor=”#808080″;
cellA4.style.backgroundColor=”#808080″;
cellB4.style.backgroundColor=”#808080″;
cellB5.style.backgroundColor=”#808080″;
cellC4.style.backgroundColor=”#808080″;
cellC5.style.backgroundColor=”#808080″;
//修改单元格可写
cellC2.disabled=true;
cellC3.disabled=true;
cellC4.disabled=true;
cellC5.disabled=true;
</script>
<body >
<table align=center >
<tr><td>
<report:html name=”report1″
reportFileName=”test.raq”
exceptionPage=”/reportJsp/myError2.jsp”
/>
</td></tr>
</table>
</body>
</html>
在浏览器中,访问这个页面就能看到需求中的效果了。