`

jsp动态生成table并且进行表头表列合并

 
阅读更多
<%@page import="java.util.Map"%>
<%@page import="java.util.List"%>
<%@page contentType="text/html; charset=GBK"%>
<%@taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles"%>
<%@taglib uri="/WEB-INF/struts-nested.tld" prefix="nested"%>
<%@taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%>
<%@taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<%@taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@page import="com.ist.util.db.Result"%>
<%@page import="com.ist.util.StringUtil"%>
<%@page import="com.ist.af.PubFunc"%>
<%@page import="java.math.BigDecimal" %>
<%String byUpper = request.getParameter("byUpper");
if (byUpper == null)
byUpper = "";
String reportid = request.getParameter("reportid");
String biz_class_id = request.getParameter("biz_class_id");
%>

<html>
<head>
<title>速递内部运费结算总表</title>
<script src="/js/cssjs.js" type="text/javascript"></script>
<script src="/js/zfwl.js" type="text/javascript"></script>

<script src="/js/BasicUtility.js" type="text/javascript"></script>
<script src="/js/jquery-1.4.2.min.js" type="text/javascript"></script>
<link href="/css/zfwl.css" type=text/css rel=STYLESHEET>
<script>

 
function getForm() {
return reportForm;
}

jQuery(function(){  //合并单元格
basicUtility.mergeCell("table1",3,2);
basicUtility.mergeCell("table1",3,1);

basicUtility.mergeCell("table1",3,0);
});

</script>
</head>

<body vlink=#000000 alink=#000000 link=#000000 bgColor=#ffffff>
<html:form action="/report.do" method="post">
<html:hidden property="settlePeriod" />
<input type="hidden" name="command" value="Query">
<input type="hidden" name="reportid" value=<%=reportid%>>
<input type="hidden" name="biz_class_id" value="<%=biz_class_id%>">
<%
String settlePeriod = request.getParameter("settlePeriod");
String year = settlePeriod.substring(0,4);
String month = settlePeriod.substring(4);
String[] lstDept = request.getParameterValues("dept");
if (lstDept != null) {
for (int i = 0; i < lstDept.length; i++) {
if (!StringUtil.isNullOrBlank(lstDept[i]))
out.println("<input type='hidden' name='dept' value='"
+ lstDept[i] + "'>");
}
}
    %>
<!-- 标题栏 -->
<div class=SectionTabTopBorder id=idSectionTabTopBorder style="DISPLAY: block">
</div>
<div class=SectionTabBackground id=idSectionTabBackground style="DISPLAY: block">
<table style="HEIGHT: 2em" border=0>
<tr>
<td class=TabCell>
<font class="beta" size="2"> &nbsp; <b>结算报表</b> &nbsp;&nbsp; <span class="bg-neg-alert">&raquo;</span> &nbsp;&nbsp; <b><a href="/report.do?reportid=0101_2&command=Init">速递内部运费结算总表</a></b> &nbsp;&nbsp; <span class="bg-neg-alert">&raquo;</span>
&nbsp;&nbsp; <b>查询结果</b>&nbsp; </font>
</td>
</tr>
</table>
</div>
<!-- 工具栏 -->
<div class=ToolbarBackground id="div2">
<table class=Displaytable cellSpacing=0 cellPadding=0 width="100%">
<tr>
<td width="10%">
<button class=Hyperlinkbutton onClick="javascript:doPrint()">
<table class=Toolbartable cellSpacing=0 cellPadding=0>
<tr>
<td vAlign="middle">
<img src="/images/print.gif">
</td>
<td style="WIDTH: 0.3em"></td>
<td vAlign="middle" noWrap>
打印
</td>
</tr>
</table>
</button>
</td>
<td width="1%">
|
</td>
<td width="10%">
<button class=Hyperlinkbutton onClick="javascript:doExport('Export')">
<table class=Toolbartable cellSpacing=0 cellPadding=0>
<tr>
<td vAlign="middle">
<img src="/images/export.gif">
</td>
<td style="WIDTH: 0.3em"></td>
<td vAlign="middle" noWrap>
导出Excel
</td>
</tr>
</table>
</button>
</td>
<td>
&nbsp;
</td>
</tr>
</table>
</div>
<p>
<!-- 报表头 -->
<table width=80% align="center">
<tr align="center">
<td>
<font size=4><b>营业环节结算支出表</b></font>
<br>
<%=year %>

<%=month %>

<br>
</td>
</tr>
<tr>
<td align="right">
单位:元
</td>
</tr>
</table>
<!-- 报表体 -->
<table cellspacing=0 bordercolordark=#ffffff cellpadding=3 width="90%" align=center bordercolorlight=#000000 border=1 id="table1">
        <%
        String strDeptName= (String)request.getAttribute("strDeptName");
        String strDeptCode= (String)request.getAttribute("strDeptCode"); 
          %>
      <tr class="beta" style="font-weight:bold" >
          <td colspan="6">机构名称:<%=strDeptName%></td><td colspan="7">机构代码:<%=strDeptCode%>  </td>
      </tr>
       <tr class="beta" style="font-weight:bold"  >
          <td rowspan="2">
          邮件种类
          </td>
         <td rowspan="2">
         产品
          </td  >
         <td  rowspan="2">
         按流向分类
          </td>
          <td colspan="10">
          显示该机构对应的责任中心属性(如函件责任中心等)
          </td>
      
       </tr>
       <tr class="beta" style="font-weight:bold"  >
       <td>业务量</td>
       <td>结算价</td>
       <td>结算额</td>
       <td>重量</td>
       <td>结算价</td>
       <td>结算额</td>
       <td>资费收入</td>
       <td>结算价</td>
       <td>结算额</td>
       <td>小计</td>
       </tr>
 
       
<%
List list=(List)request.getAttribute("reportData");
Double a_pieces=0.0; 
Double a_p_fee=0.0; 
Double a_weight=0.0;
Double a_w_fee=0.0;
Double a_mail_fee=0.0;
Double a_f_fee=0.0;
Double a_all_fee=0.0;
if(list!=null&&list.size()>0){
   for(int j=0;j<list.size();j++){
   Map map=(Map)list.get(j);
   String mailKind=(String)map.get("mailKind");
   String productType=(String)map.get("productType");
   String mailCode=(String)map.get("mailCode");
   String pieces=(String)map.get("pieces");
   a_pieces+=Double.parseDouble(pieces);
   String peiece_price=(String)map.get("peiecePrice");
   String p_fee=(String)map.get("pFee");
   a_p_fee+=Double.parseDouble(p_fee);
   String weight=(String)map.get("weight");
   a_weight+=Double.parseDouble(weight);
   String weight_price=(String)map.get("weightPrice");
   String w_fee=(String)map.get("wFee");
   a_w_fee+=Double.parseDouble(w_fee);
   String mail_fee=(String)map.get("mailFee");
   a_mail_fee+=Double.parseDouble(mail_fee);
 
   String mail_fee_price=(String)map.get("mailFeePrice");
   String f_fee=(String)map.get("fFee");
  
   a_f_fee+=Double.parseDouble(f_fee);
  
   String all_fee=(String)map.get("allFee");
  
   a_all_fee+=Double.parseDouble(all_fee);
 
   %>
   <tr class="bg" onClick="selectRow(this)">
             <td><%=mailKind %></td>               <!-- 第一列 -->
             <td><%=productType %></td>                <!-- 第二列 -->
              <td><%=mailCode %></td>
              <td><%=pieces %></td>
              <td><%=peiece_price %></td>
              <td><%=p_fee %></td>
                <td><%=weight %></td>
                 <td><%=weight_price %></td>
                 <td><%=w_fee %></td>
                 <td><%=mail_fee %></td>
                  <td><%=mail_fee_price %></td>
                  <td><%=f_fee%></td>
                  <td><%=all_fee%></td> 
    </tr>
<%
   }
       }
%>    

<tr class="bg" onClick="selectRow(this)">
<td colspan="3">合计
            (对应市分公司
                              平衡表收入)
        </td>
<td align="right"><%=a_pieces %></td>
<td align="right">&nbsp;</td>
<td align="right"><%=a_p_fee %></td>
<td align="right"><%=a_weight %></td>
<td align="right">&nbsp;</td>
<td align="right"><%=a_w_fee %></td>
<td align="right"><%=a_mail_fee %></td>
<td align="right">&nbsp;</td>
<td align="right"><%=a_f_fee %></td>
<td align="right"><%=a_all_fee %></td>
  </tr>
</table>
<p>
<table width=90%>
<tr>
<td align=right>
[<a href="javascript:history.back()">返回</a>]
</td>
</tr>
</table>
</html:form>
 


</body>
</html>

js
/*******************************************************************************
* Created on 2014-04-15 Title 基础工具类--依赖jquery.js等 Author kfzx-gaoyun version
* 1.0 修改历史 序号 日期 修改人 修改原因
*
******************************************************************************/
// Note: 创建StringBuilder类
StringBuilder = function() {
this.strings = new Array;
};
StringBuilder.prototype = {
append : function(str) {
this.strings.push(str);
return this;
},
toString : function(joinGap) {
return this.strings.join(typeof joinGap == 'undefined' ? "" : joinGap);
},
clear : function() {
this.strings = [];
}
};

// Note: 创建StringBuffer类继承StringBuilder类
StringBuffer = function() {
StringBuilder.apply(this, arguments);
};
StringBuffer.prototype = new StringBuilder();

// Note: 创建BigDecimal工具类
MathUtil = function() {
}
MathUtil.prototype = {
add : function(d1, d2) {
try {
// 进行加法运算
var b1 = new BigDecimal(String(d1));
var b2 = new BigDecimal(String(d2));

if (arguments.length == 3 && typeof arguments[2] != "undefined"
&& !isNaN(arguments[2])) {
return b1.add(b2).setScale(Number(arguments[2]),
BigDecimal.ROUND_HALF_UP);
}
return b1.add(b2);
} catch (e) {
alert(e + "运算错误!");
return false;
}
},
add2 : function() {
try {
// 进行加法运算
var b = new BigDecimal('0');
if (arguments.length > 1) {
for (var i = 0; i < arguments.length; i++) {
b = b.add(new BigDecimal(String(arguments[i])));
}
}
return b;// .setScale( 2, BigDecimal.ROUND_HALF_UP);
} catch (e) {
alert(e + "运算错误!");
return false;
}
},
sub : function(d1, d2) {
try {
// 进行减法运算
var b1 = new BigDecimal(String(d1));
var b2 = new BigDecimal(String(d2));

if (arguments.length == 3 && typeof arguments[2] != "undefined"
&& !isNaN(arguments[2])) {
return b1.subtract(b2).setScale(Number(arguments[2]),
BigDecimal.ROUND_HALF_UP);
}
return b1.subtract(b2);
} catch (e) {
alert(e + "运算错误!");
return false;
}
},
mul : function(d1, d2) {
try {
// 进行乘法运算
var b1 = new BigDecimal(String(d1));
var b2 = new BigDecimal(String(d2));

if (arguments.length == 3 && typeof arguments[2] != "undefined"
&& !isNaN(arguments[2])) {
return b1.multiply(b2).setScale(Number(arguments[2]),
BigDecimal.ROUND_HALF_UP);
}
return b1.multiply(b2);
} catch (e) {
alert(e + "运算错误!");
return false;
}
},
mul2 : function() {
try {
// 进行乘法运算
var b = new BigDecimal('1');
if (arguments.length > 1) {
for (var i = 0; i < arguments.length; i++) {
b = b.multiply(new BigDecimal(String(arguments[i])));
}
}
return b;
} catch (e) {
alert(e + "运算错误!");
return false;
}
},
div : function(d1, d2) {
try {
// 进行除法运算
var b1 = new BigDecimal(String(d1));
var b2 = new BigDecimal(String(d2));

if (arguments.length == 3 && typeof arguments[2] != "undefined"
&& !isNaN(arguments[2])) {
return b1.divide(b2, arguments[2], BigDecimal.ROUND_HALF_UP);
}
return b1.divide(b2, 2, BigDecimal.ROUND_HALF_UP);
} catch (e) {
alert(e + "运算错误!");
return false;
}
},
round : function(d1) {
try {
// 进行四舍五入运算
var b1 = new BigDecimal(String(d1));
var b2 = new BigDecimal('1');

if (arguments.length == 2 && typeof arguments[1] != "undefined"
&& !isNaN(arguments[1])) {
return b1.divide(b2, arguments[1], BigDecimal.ROUND_HALF_UP);
}
return b1.divide(b2, 2, BigDecimal.ROUND_HALF_UP);
} catch (e) {
alert(e + "运算错误!");
return false;
}
}
}

// Note: 初始化BigDecimal工具类
var MathUtil = new MathUtil();

// Note: 创建基础工具类
BasicUtility = function() {
};
BasicUtility.prototype = {
/**
* Note: Execute the function
*
* @param fncName:to
*            execute the method name
*/
executeFnc : function(fncName) {
try {
if (fncName != "" && fncName != null
&& typeof fncName != "undefined") {
if (fncName.indexOf("(") == -1) {
return eval(fncName + "()");
} else {
return eval(fncName);
}
}
} catch (e) {
alert(e + "使用错误:函数" + fncName + "未定义!");
return false;
}
},

/**
* Note: Get a parameter specified in the URL.
*
* @param parameterName
*            parameter to remove
*/
getURLParameter : function(url, parameterName) {
var paramString = "";
var paramStartIndex = url.indexOf(parameterName);
var equalSign = url.charAt(paramStartIndex + parameterName.length);

if (paramStartIndex >= 0 && (equalSign == "=" || equalSign == "&")) {
var paramEndIndex = url.indexOf("&", paramStartIndex);
if (paramEndIndex >= 0) {
paramString = "&"
+ url.substring(paramStartIndex, paramEndIndex);
} else {
paramString = "&" + url.substring(paramStartIndex); // get the
// substring
// till the
// end.
}
}
return paramString;
},

/**
* Note: Adds a parameter to a given URL.
*
* @param parameterName
*            parameter to add name
* @param parameterValue
*            parameter to add value
*/
addURLParameter : function(url, parameterName, parameterValue) {
var paramPart = encodeURI(parameterName) + "="
+ encodeURI(parameterValue)
var lastChar = url.charAt(url.length - 1);

if (lastChar != "&" && lastChar != "?") {
if (url.indexOf("?") > 0) {
paramPart = "&" + paramPart;
} else {
paramPart = "?" + paramPart;
}
}

return url += paramPart;;
},

/**
* Note: Deletes a parameter specified in the given URL.
*
* @param url
*            to process
* @param parameterName
*            parameter to remove
* @return processed url
*/
deleteURLParameter : function(url, parameterName) {
var reg = new RegExp("([&|?]{1})"
+ escape(encodeURIComponent(parameterName))
+ "\s*=[^&|^#]*", "gi");
return url.replace(reg, "$1");
},

/**
* Note: Get the parameters in the form
*/
param : function(formId) {
var p = {}, allFields = jQuery('#' + formId).serializeArray();

jQuery.each(allFields, function(i, field) {
p[field.name] = field.value;
});
return p;
},

/**
* Note: 构建Form中带有name的元素作为URL中参数.
*
* @param formId
*            要构建的form id
* @param url
*/
buildFormParamToURL : function(formId, url) {
var p = this.param(formId), href = url;

if (!this.isEmptyValue(url) && !this.isEmptyValue(p)) {
href = url.indexOf("?") == -1 ? (url + "?") : (url + "&");
href = href + jQuery.param(p);
}
return href;
},

/**
* Note: 合并Table中相同内容的单元格(PS:如果要合并多列,从索引大的列开始合并)
*
* @param tableId
*            :Table的Id
* @param beginRow:开始的行(索引从0开始)
* @param colIndex:合并的列(索引从0开始)
* @param property:获取内容的属性(innerHTML或innerText.
*            默认:innerHTML)
*/
mergeCell : function(tableId, beginRow, colIndex, property) {
var table = document.getElementById(tableId);
var att = (typeof property == "undefined" || property == "")
? "innerHTML"
: property;

var tempRow = beginRow;
var data = table.rows[tempRow].cells[colIndex][att];

for (var i = (tempRow + 1); i < table.rows.length; i++) {
if (data == table.rows[i].cells[colIndex][att]) {
table.rows[tempRow].cells[colIndex].rowSpan = table.rows[tempRow].cells[colIndex].rowSpan
+ 1;
table.rows[i].removeChild(table.rows[i].cells[colIndex]);
} else {
tempRow = i;
data = table.rows[tempRow].cells[colIndex][att];
}
table.rows[tempRow].cells[colIndex][att] = data;
}
},

/**
* Note: 计算百分比
*
* @param num:
*            除数
* @param total:
*            总数
*/
percent : function(num, total) {
num = parseFloat(num);
total = parseFloat(total);

if (isNaN(num) || isNaN(total)) {
return "──";
} else {
if (total > 0) {
return (Math.round(num / total * 10000) / 100.00);
} else {
if (num > 0) {
return 100;
} else {
return total == 0 ? 0 : (Math.round(num / Math.abs(total)
* 10000) / 100.00);
}
}
}
},

/**
* Note: 判断对象是否为空
*
* @param value:要判断的对象
*/
isEmptyValue : function(value) {
var type;

if (value == null) {
return true;
}

type = Object.prototype.toString.call(value).slice(8, -1);
switch (type) {
case 'String' :
return !jQuery.trim(value);
case 'Array' :
return !value.length;
case 'Object' :
return jQuery.isEmptyObject(value);
default :
return false;
}
},

/**
* Note: 判断select中是否存在值为value的项
*
* @param id:select的id
* @param value:要判断的值
*/
isExistOption : function(id, value) {
var isExist = false;
jQuery(jQuery("#" + id + " option")).each(function(i) {
if (jQuery(this).val() == value) {
isExist = true;
return false;
}
});
return isExist;
},

/**
* Note: 添加select项
*
* @param id:select的id
* @param value:要增加option的value
* @param text
*            :要增加option的text
*/
addOptionValue : function(id, value, text) {
if (!this.isExistOption(id, value)) {
jQuery('#' + id).append(jQuery("<option>").val(value).text(text));
}
},

/**
* Note: 根据select的value删除select项
*
* @param id:select的id
* @param value:要删除option的value
*/
delOptionByValue : function(id, value) {
jQuery("#" + id + " option[value=" + value + "]").remove();
},

/**
* Note: 删除select选中项
*
* @param id:select的id
*/
delSelectedOption : function(id) {
jQuery("#" + id + " option:selected").remove();
},

/**
* Note: 清空select所有项
*
* @param id:select的id
*/
cleanSelect : function(id) {
jQuery("#" + id).empty();
},

/**
* Note: 如果a为空, 取b的值
*/
nvl : function(a, b) {
return this.isEmptyValue(a) ? b : a;
}
};

// Note: 初始化基础工具类
var basicUtility = new BasicUtility();

// Note: 日期对象原型扩展-日期格式化
// +———————————————————————————————————————————————————
// | @param format :必选项。字符串表达式,表示格式化字符串说明如下
// | YYYY|yyyy|YY|yy:年份
// | MM|M :月份
// | W |w :星期
// | dd|DD|d|D :日期
// | hh|HH|h|H :时
// | mm|m :分
// | ss|SS|s|S :秒
// | 格式化会改变原始Date对象的月份,以1开始.
// +———————————————————————————————————————————————————
Date.prototype.Format = function(format) {
var str = format;
var Week = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];

str = str.replace(/yyyy|YYYY/, this.getFullYear());
str = str.replace(/yy|YY/, (this.getYear() % 100) > 9
? (this.getYear() % 100).toString()
: '0' + (this.getYear() % 100));

str = str.replace(/MM/, this.getMonth() + 1 > 9 ? (this.getMonth() + 1)
.toString() : '0' + (this.getMonth() + 1));
str = str.replace(/M/g, this.getMonth() + 1);

str = str.replace(/w|W/g, Week[this.getDay()]);

str = str.replace(/dd|DD/, this.getDate() > 9
? this.getDate().toString()
: '0' + this.getDate());
str = str.replace(/d|D/g, this.getDate());

str = str.replace(/hh|HH/, this.getHours() > 9
? this.getHours().toString()
: '0' + this.getHours());
str = str.replace(/h|H/g, this.getHours());
str = str.replace(/mm/, this.getMinutes() > 9 ? this.getMinutes()
.toString() : '0' + this.getMinutes());
str = str.replace(/m/g, this.getMinutes());

str = str.replace(/ss|SS/, this.getSeconds() > 9 ? this.getSeconds()
.toString() : '0' + this.getSeconds());
str = str.replace(/s|S/g, this.getSeconds());

return str;
}

// Note: 数组原型扩展-去除重复元素
Array.prototype.unique = function() {
var obj = new Object();
for (var i = 0, j = 0; i < this.length; i++) {
if (typeof obj[this[i]] == 'undefined') {
obj[this[i]] = j++;
}
}
this.length = 0;
for (var key in obj) {
this[obj[key]] = key;
}
return this;
};


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics