table数据导入到Excel js实现

<%@page contentType="text/html; charset=GBK"%> <%@page import="java.util.List"%> <%@page import="java.util.Map"%> <%@page import="com.opensymphony.xwork.ActionContext"%> <%@ taglib prefix="ww" uri="webwork" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <META http-equiv=Content-Type content="text/html; charset=gb2312"> <link rel="stylesheet" href="<%=request.getContextPath()%>/css/style_1.css" type="text/css"> <title>财务报表结果</title> <META content="MSHTML 6.00.2800.1578" name=GENERATOR> </HEAD> <mce:script language="javascript" src="<%=request.getContextPath()%><!-- /js/check.jsp"> // --></mce:script> <mce:script language="javascript" src="<%=request.getContextPath()%><!-- /script/prototype.js"> // --></mce:script> <mce:script language="javascript" src="<%=request.getContextPath()%><!-- /script/buffalo.js"> // --></mce:script> <mce:script language="javascript" src="<%=request.getContextPath()%><!-- /script/template.js"> // --></mce:script> <mce:script language="javascript" src="<%=request.getContextPath()%><!-- /js/My97DatePicker/WdatePicker.js"> // --></mce:script> <mce:script language="javascript"><!-- function init(){ var END_POINT="<%=request.getContextPath()%>/bfapp"; var buffalo = new Buffalo(END_POINT,false); var identifier=document.getElementById("identifier").value; var department_id=document.getElementById("department_id").value; var level=document.getElementById("level").value; var sign=document.getElementById("sign").value; var project_ids=document.getElementById("project_ids").value; if(identifier == "qproject1"){ <ww:iterator value="dept_List" status="rowstatus4"> var yTotal=0; //y坐标金额和变量 var x=0; // x行数 var id1 = document.getElementById("dept_"+<ww:property value="#rowstatus4.index"/>).value.toString(); <ww:iterator value="type_view_List" status="rowstatus5"> var id2 =document.getElementById("type_"+<ww:property value="#rowstatus5.index"/>).value.toString(); //alert(project_ids); //alert(id1); //alert(id2); //alert(department_id); //alert(level); alert(sign); var data; buffalo.remoteCall("type_viewService.querydept_project",[project_ids,id1,id2,department_id,level,sign], function(reply) { data = reply.getResult(); x++; }) // 赋值给每个单元格 document.all("mytable").rows[<ww:property value="#rowstatus5.index"/>+1].cells[<ww:property value="#rowstatus4.index"/>+1].innerText=data; yTotal+=data; // return; </ww:iterator> //赋值给Y坐标 统计 document.all("mytable").rows[x+1].cells[<ww:property value="#rowstatus4.index"/>+1].innerText=yTotal; </ww:iterator> } if(identifier == "qproject2"){ <ww:iterator value="dept_List" status="rowstatus4"> var yTotal=0; //y坐标金额和变量 var x=0; // x行数 var id1 = document.getElementById("dept_"+<ww:property value="#rowstatus4.index"/>).value.toString(); <ww:iterator value="type_view_List" status="rowstatus5"> var id2 =document.getElementById("type_"+<ww:property value="#rowstatus5.index"/>).value.toString(); var data; buffalo.remoteCall("type_viewService.querydept_project",[project_ids,id2,id1,department_id,level,sign], function(reply) { data = reply.getResult(); x++; }) // 赋值给每个单元格 document.all("mytable").rows[<ww:property value="#rowstatus5.index"/>+1].cells[<ww:property value="#rowstatus4.index"/>+1].innerText=data; yTotal+=data; </ww:iterator> //赋值给Y坐标 统计 document.all("mytable").rows[x+1].cells[<ww:property value="#rowstatus4.index"/>+1].innerText=yTotal; </ww:iterator> } <ww:iterator value="type_view_List" status="rowstatus6"> var yTotal=0; //y坐标金额和变量 var y=0; // y行数 <ww:iterator value="dept_List" status="rowstatus7"> var data=0; y++; data=document.all("mytable").rows[<ww:property value="#rowstatus6.index"/>+1].cells[<ww:property value="#rowstatus7.index"/>+1].innerText; yTotal+=parseFloat(data); //赋值给Y坐标 统计 </ww:iterator> document.all("mytable").rows[<ww:property value="#rowstatus6.index"/>+1].cells[y+1].innerText=yTotal; </ww:iterator> var total_amounts; buffalo.remoteCall("type_viewService.querydept_project_total",[project_ids,id1,id2,department_id,level,sign], function(reply) { total_amounts = reply.getResult(); }) //document.getElementById("total_Amount").value=total_amounts; document.getElementById("total_Amount").innerHTML = total_amounts; } //Excel导出 var excelObj; function printTable(obj){ rows=obj.rows.length; if(rows>0){ try{ cells=obj.rows[0].cells.length; excelObj = new ActiveXObject("Excel.Application"); excelObj.Visible = true; excelObj.WorkBooks.Add; for(i=0;i<rows;i++){ for(j=0;j<cells;j++) excelObj.Cells(i+1,j+1).Value=obj.rows[i].cells[j].innerText; } } catch(e){alert("生成Excel失败!");} } else{alert("no data");} } // --></mce:script> <body topmargin="0" class="body4" οnlοad="init()"> <form name="myform" method="post"> <input type="hidden" name="common_menu_id" value="<ww:property value="common_menu_id"/>"> <input type="hidden" name="level" value="<ww:property value="level"/>"> <input type="hidden" name="department_id" value="<ww:property value="department_id"/>"> <input type="hidden" name="identifier" value="<ww:property value="identifier"/>"> <input type="hidden" name="sign" value="<ww:property value="sign"/>" id="sign"> <input type="hidden" name="project_ids" value="<ww:property value="project_ids"/>" id="project_ids"> <center> <table width="100%" border="0" cellspacing="0" cellpadding="0" align="center" class="bg_lead_22"> <tr height="20" align="" > <td height="20" class="bg_lead_l"><ww:property value="project_name"/></td> <td align="right"><input type="button" name="button2" class="new2" value="Excel导出" onClick="printTable(mytable)"> </td> </tr> </table> <table width="80%" border="0" cellspacing="0" cellpadding="0" class="table_g1" align="center"> <tr class="bg_w" height="60" align="center" > <td height="40" align="center"><p size="40" >报表统计</p></td> </td> </tr> </table> <table width="100%" border="0" cellspacing="1" cellpadding="1" class="table_g1" align="center" id="mytable"> <!--报销项目--> <tr class="bg_w" height="26" align="center" > <td height="15"></td> <ww:iterator value="dept_List" status="rowstatus1"> <td height="15" valign="top"> <input id="dept_<ww:property value="#rowstatus1.index"/>" value="<ww:property value="id"/>" type="hidden"/ > <input style="border-width:0px;height: 1" readonly size="30"> <ww:property value="name"/> </td> </ww:iterator> <td valign="top"> <input style="border-width:0px;height: 1" readonly size="30"> 小计:</td> </tr> <ww:iterator value="type_view_List" status="rowstatus2"> <tr class="bg_w" height="26" align="center"> <td height="15" valign="top"> <input id="type_<ww:property value="#rowstatus2.index"/>" type="hidden" value="<ww:property value="id"/>" /> <input style="border-width:0px;height: 1" readonly size="30"> <ww:property value="name"/> </td> <ww:iterator value="dept_List" status="rowstatus3"> <td height="15"> <input id="value_<ww:property value="#rowstatus3.index"/>_<ww:property value="#rowstatus2.index"/>" style="border-width:0px;" value=""> </td> </ww:iterator> <td > <input id="" style="border-width:0px;" mce_style="border-width:0px;" value=""> </td> </tr> </ww:iterator> <tr class="bg_w" height="26" align="center"> <td height="15" > <input style="border-width:0px;height: 1" readonly size="30"> 小计: </td> <ww:iterator value="dept_List" status="rowstatus3"> <td height="15"> <input id="value_<ww:property value="#rowstatus3.index"/>_<ww:property value="#rowstatus2.index"/>" style="border-width:0px;" value=""> </td> </ww:iterator> <td ><input style="border-width:0px;height: 1" readonly size="30"> 总金额:<div id="total_Amount"></div> </td> </tr> </table> </center> </form> </body> </html>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值