首页 > 其他分享 >web页面中导出Excel (方法二) 前端easyui-datagrid导出Excel 使用 datagrid-export.js

web页面中导出Excel (方法二) 前端easyui-datagrid导出Excel 使用 datagrid-export.js

时间:2023-06-14 13:12:09浏览次数:42  
标签:stop Excel 导出 len datagrid start time row

这个示例使用  前端 easyui-datagrid  后端 php 

前端 easyui-datagrid 导出Excel 使用了 datagrid-export.js 

datagrid-export.js 文件可自行搜索下载

优点:查询结果显示在datagrid中(不能分页),前端直接下载不用回后端,效率高速度快。

缺点:查询结果不能分页,必须显示全部内容,显示的内容即是导出后的内容。此方法多用于统计报表中,比如以日期分组统计,结果不可能是几万行(一行为一天分组)。

界面

html

在<body>前 引用 datagrid-export.js

<script type="text/javascript" src="themes/easyui/datagrid-export.js"></script>
<body> 
<div style='padding:0px 0px 15px 12px ;'> 
        <table> 
            <tr> 
                <td style="width:65px;">呼叫时间:</td> 
                <td style="padding: 0px 0px 0px 2px;"> <input id="start_date_entered" value="<{$start_date}>" placeholder="开始日期" class="my_input laydate-icon" style="height:29px;"  onclick="laydate({istime: true, format: 'YYYY-MM-DD hh:mm:ss'})" readonly ></input></td> 
                <td><span class="input-group-addon" style="height:28px;">至</span></td> 
                <td><input id="stop_date_entered" value="<{$stop_date}>" placeholder="结束日期" class="my_input laydate-icon" style="height:29px;" onclick="laydate({istime: true, format: 'YYYY-MM-DD hh:mm:ss'})"  readonly  ></input>    </td> 
                <td style="width:10px;"> </td>
                <td class='width:75px;'>坐席员:</td> 
                <td><select id="select_agent_name" name="select_agent_name" class="easyui-combobox" style="height:28px;width:160px;" editable=false  ><{$select_option_agent_name}></select></td> 
                <td style="width:10px;"> </td>
                <td style="padding: 0px 0px 0px 5px;"> 
                    <a href='#' class='easyui-linkbutton'   iconCls='icon-select' style="height:29px;width:64px;" onclick='Select()'>查询</a> 
                </td>
            </tr>
        </table> 
    </div> 
    <table id='grid'class='easyui-datagrid' style='width:1000px;min-height:450px'  
            title='列表' iconCls='icon-table'  rownumbers='true' fitColumns='true' singleSelect='true' toolbar='#toolbar'  remoteSort='false'>  
        <thead>  
            <tr>  
                <!-- <th field='select' width='30' align='center'></th>   
                <th field='id' width='10' hidden='true'>编号</th>       --> 
                <th field='user_id' width='25'align='center' sortable='true' >坐席工号</th> 
                <th field='user_name' width='25'align='center' sortable='true' >坐席员</th> 

                <th field='login_date' width='30'align='center' sortable='true' >日期</th>
                <th field='time_len' width='30'align='center' sortable='true' >在线时长</th>  
                <th field='time_len_s' width='30'align='center' sortable='true' >在线时长(秒)</th> 
 
            </tr>  
        </thead>  
    </table>  

    <div id='toolbar' style='display: flex;align-items:Center; height:35px;' > 
        <a href='javascript:void(0)' class='easyui-linkbutton' iconCls='icon-excel' plain='true' onclick='ToExcel()' <{$ToExcel_disabled}> >导出</a> 
        <div class="btn-separator"></div>
        <a href='#' class='easyui-linkbutton' iconCls='icon-refresh' plain='true' onclick='Refresh()'>刷新</a> 
        <a href='#' class='easyui-linkbutton'  iconCls='icon-cancel' plain='true' onclick='parent.TabClose();'>关闭</a>   
    </div>   

js

<script type='text/javascript'>  
    function Select(){   
        var agent_name=$('#select_agent_name').combobox('getValue');
   
        var start_time=$('#start_date_entered').val();   
        var stop_time=$('#stop_date_entered').val();
        
        var url='Api-index.php?module=<{$module_name}>&action=Api_ReportView_Agent_Login_Report_Day_Select';  
        var query={'agent_name':agent_name,'start_time':start_time,'stop_time':stop_time   };
        $('#grid').datagrid('options').url=url;   
        $('#grid').datagrid('options').queryParams=query;   
        $('#grid').datagrid('reload');       
    }  
    
    function ToExcel(){
        $('#grid').datagrid('toExcel','Book.xls');
    }

</script>  

php

Api_ReportView_Agent_Login_Report_Day_Select.php

<?php 
//-----------------------------------------------坐席在线时长 日统计------------------------------------
/*          
foreach($_POST as $k=>$v){    
    WriteLog("POST " . $k .'--' .$v);    
}    
foreach($_GET as $k=>$v){    
    WriteLog("GET " .  $k .'--' .$v);    
}    
*/
      
    $arr_result = array(); //返回值  
    $where='';//查询条件  
    
    if(!empty($_POST['start_time'])){
        $start_time=$_POST['start_time'];    
        $stop_time=$_POST['stop_time'];    
    }
    else{
        //当天
        $start_time=date("Y-m-d 0:0:0",strtotime("now"));
        //$last_month= GetMonthToday("-1");//上个月的今天   //默认查询一个月
        //$start_time=$last_month .' 00:00:00';
        $stop_time=date("Y-m-d 23:59:59",strtotime("now"));    
    }    
    //$where=" date_time >='{$start_time}' and date_time <='{$stop_time}' ";  
    $where=" login_time >='{$start_time}' and login_time <='{$stop_time}' ";  
    
    //坐席
    if($_REQUEST['agent_name']!='' && $_REQUEST['agent_name']!='0'){  // 
        $where .=" and agent_name = '{$_REQUEST['agent_name']}' ";  
    } 
    //结果集      
    $items = array(); 

    $sql="SELECT user.user_id , agent_name as user_name,login_date,SEC_TO_TIME(sum(time_len_s)) as time_len,sum(time_len_s) as time_len_s FROM ";
    $sql.=" cti_agent_login join user on cti_agent_login.agent_name=user.user_id where ";
    $sql.=" " .$where ." GROUP BY login_date ORDER BY login_date";
    //WriteLog($sql);  

    $result_rows=$db->query($sql); 
    $row_count=$db->num_rows($result_rows);//行数

    while($row=$db->fetch_array($result_rows))  
    {      
        array_push($items, $row); 
        //WriteLog($row[2]);   
 
        $time_len=$row['time_len'];
        $time_len_s=$row['time_len_s'];
             
        $time_len_s_sum=$time_len_s_sum+$time_len_s;//所有坐席的  在线时长(秒)
                 
    }
         
    //合计-------------------------------------
       $row['user_name']='合计';
        $row['date']=$row_count."天";//行数 表示上班天数

        if($time_len_s_sum!=''){//为空则不计算
            $row['time_len']=Sec2Time($time_len_s_sum);//所有坐席的 在线时长
        }
        else {
            $row['time_len']=$time_len_s_sum;
        }
        $row['time_len_s']=$time_len_s_sum;//所有坐席的 在线时长(秒)
     
        array_push($items, $row); //加入数组


        $arr_result['rows'] = $items;       

        //WriteLog(json_encode($arr_result['rows'] ));  

        echo json_encode($arr_result);   

?>   

 

标签:stop,Excel,导出,len,datagrid,start,time,row
From: https://www.cnblogs.com/hailexuexi/p/17479905.html

相关文章

  • web页面中导出Excel 方法一 后端php导出Excel
    这个示例使用 前端easyui-datagrid 后端php 其中前端是不是easyui-datagrid不重要,这个方法主要是使用后端php来实现导出Excel优点:现在的应用中大部分是分页显示的,在前台只显示一部分,但导出Excel是要看全部的。所以此时用前端js导出则不太好实现。缺点:当查询数据量较......
  • jexcel_删除行并同步数据库
    写在*.aspx中1//删除行OK2varmyDeleteRow=function(){3varDBID=document.getElementById("my_textbox").value;4//vartempConfirm=confirm("DBID为:"+DBID);//弹出确认框5vartempConfirm=confir......
  • jexcel_增加行并同步数据库
    写在*.aspx中1//增加行OK2varaddRow=function(){3varfieldName="type";//字段名4varmodifyValue="请输入";//值5//vartempConfirm=confirm("modifyValue:"+modifyValue+"......
  • jexcel_最简单的框架
    1. 固定数据的jexcel框架<%@PageLanguage="C#"AutoEventWireup="true"CodeFile="test.aspx.cs"Inherits="web_page_ssc_test"%><!DOCTYPEhtml><htmlxmlns="http://www.w3.org/1999/xhtml"><......
  • 案例4 基于Excel的接口测试框架
    简单版读取以下格式excel(仅第一张Sheet),逐个发送接口,断言接口返回200,并将状态及错误信息写回Excel已知:Excel中接口编写格式规范如下url如果有查询参数,要写到url中,例如?a=1&b=2如果需要添加自定义请求头按key:value格式编写,:左右允许有空格,每行一个请求数据支持表单和JSO......
  • windows使用navicate 导出导入MongoDB数据
    1.下载安装navicate以及mongodb-database-tools-windowsmongodb-database-tools-windows下载地址 https://www.mongodb.com/try/download/database-tools 2.navicate设置MongoDBdump、mongorestore可执行文件路径(mongodb-database-tools里的bin目录)3.选择要备份或恢复......
  • 关于导出图片的事宜
    1.数据库存的图片路径,表格导出的时候,需要展示成图片2.需要将图片路径转化为字节码3.先获取图片路径4.转为字节码5.接收的传参格式‘:@JsonProperty("product_back_url")privateStringproductBackUrl;@Excel(name="商品背面",width=15,height=35,type=2,imageTyp......
  • python: read excel
     """Insurance。pyedit:geovindu,GeovinDu,涂聚文date2023-06-13保险类"""importsysimportosclassInsurance:"""保险类"""def__init__(self,InsuranceName,InsuranceCost,IMo......
  • 7.excel寻找替换技巧
    ?代表单个字符提示: 可以在搜索条件中使用 通配符 -问号(?)、星号(*)、字号(~)。使用问号(?)查找任意单个字符,例如,s?t可找到"sat"和"set"。使用星号(*)查找任意多个字符,例如,s*d可找到"sad"和"started"。使用字号(~)后跟?、*或~查找问号、星号或其他代字-例如fy91......
  • WinForm下DataGridView导出Excel的实现
    WinForm下DataGridView导出Excel的实现 1.说明:导出的效率说不上很高,但至少是可以接收的.参考网上很多高效导出Excel的方法,实现到时能够实现的,导出速度也很快,不过缺陷在与不能很好的进行单元格的格式化,比如上图中的"拼音码"字段中的值"000000000012120",在导出后就显示"1212......