php生成exl

<?php
require '../webhead.php';
include_dev_model('weijinci.php');
//$end_date =gp('end');
$start_date=gp('start_date');
$end_date =gp('end_date');
if(!empty($start_date)&&!empty($end_date)){
    $start=' and unix_timestamp(pub_date) >= '.strtotime($start_date).'';
    $end=' and unix_timestamp(pub_date) < '.strtotime($end_date).'' ;
    $start1=' and create_time>='.strtotime($start_date).'';
    $end1=' and create_time <= '.strtotime($end_date).'' ;
    $kong=' ';
}else{
    $start=' ';
    $end=' ';
    $start1=' ';
    $end1=' ';
    $kong='and admin_user_id is null';
}
$sql_douyin_aweme_patch = "select * from douyin_aweme_patch where 1=1  "."$start"."$end"."$kong"."   and check_status=3 order by admin_user_id asc";
$sql_douyin_aweme = "select * from douyin_aweme where company_id=1 and digg_count>=200 "."$start1"."$end1"."$kong"."  and is_ad=1 order by admin_user_id asc";
/*print $sql_douyin_aweme_patch;
print $sql_douyin_aweme;*/
$request_douyin_aweme_patch = weijinci::select($sql_douyin_aweme_patch,'weijinci');
$request_douyin_aweme = weijinci::select($sql_douyin_aweme,'weijinci');

/*foreach($request_douyin_aweme as $k=>$row) {

    $author_short_id = $row['author_short_id'];
    $admin_user_id = $row['admin_user_id'];
    $author_name = '-';
    $admin_user_name = '-';
    $author_info = weijinci::select("select * from douyin_user where short_id=" . $author_short_id,'weijinci');
    foreach($author_info as $k=>$r):
        if (!empty($author_info)) {
            $author_name = $r['nickname'];
        }
    endforeach;
    $admin_user_info = weijinci::select("select * from pub_user where id=" . $admin_user_id,'weijinci');
    foreach($admin_user_info as $k=>$r):

        if(!empty($admin_user_info)){
            $admin_user_name = $r['user_name'];
        }
    endforeach;
}*/

$action = gp('act');
if($action == 'download'){
    include_vendor_file('Excel/PHPExcel.php');
    $objPHPExcel = new PHPExcel();
    $objPHPExcel
        ->getProperties()  //获得文件属性对象,给下文提供设置资源
        ->setCreator( "Maarten Balliauw")                 //设置文件的创建者
        ->setLastModifiedBy( "Maarten Balliauw")          //设置最后修改者
        ->setTitle( "Office 2007 XLSX Test Document" )    //设置标题
        ->setSubject( "Office 2007 XLSX Test Document" )  //设置主题
        ->setDescription( "Test document for Office 2007 XLSX, generated using PHP classes.") //设置备注
        ->setKeywords( "office 2007 openxml php")        //设置标记
        ->setCategory( "Test result file");
    $objPHPExcel->setActiveSheetIndex(0)             //设置第一个内置表(一个xls文件里可以有多个表)为活动的
    ->setCellValue( 'A1', '抖音ID' )         //给表的单元格设置数据
    ->setCellValue( 'B1', '抖音名称' )      //数据格式可以为字符串
    ->setCellValue( 'C1', '员工ID')            //数字型
    ->setCellValue( 'D1', '员工姓名')            //
    ->setCellValue( 'E1', '点赞量' )        //
    ->setCellValue( 'F1', '视频ID' )        //
    ->setCellValue( 'G1', '发布日期');
    $objPHPExcel->getActiveSheet()->getStyle('E')->getNumberFormat()
        ->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_TEXT);
    $objPHPExcel->getActiveSheet()->getStyle('F')->getNumberFormat()
        ->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_TEXT);
    $num = 0;

    //$sql_douyin_aweme = "select * from douyin_aweme where company_id=1 and digg_count>=200 and create_time>=".strtotime($start_date)." and create_time <= ".strtotime($end_date)." and is_ad=1 order by admin_user_id asc";
    // $res = mysqli_query($conn,$sql);
    $step_num = 2;
    foreach($request_douyin_aweme as $k=>$row){
        //while($row = mysqli_fetch_assoc($res)){
        $author_short_id = $row['author_short_id'];
        $admin_user_id = $row['admin_user_id'];
        $author_name = '-';
        $admin_user_name = '-';
        $author_info = weijinci::select("select * from douyin_user where short_id=" . $author_short_id,'weijinci');
            if (!empty($author_info)) {
                foreach($author_info as $k=>$r):
                $author_name = $r['nickname'];
            $sql3="'select * from pub_user where id=' . $admin_user_id";
                    print $sql3;
            $admin_user_info = weijinci::select("select * from pub_user where id=" . $admin_user_id,'weijinci');
            print $admin_user_info;
                if(!empty($admin_user_info)){
                    foreach($admin_user_info as $k=>$r1):
                    $admin_user_name = $r1['user_name'];


        /*$log_s = $author_short_id."@@".$author_name."@@".$admin_user_id.'@@'.$admin_user_name.'@@'.$row['digg_count'].'@@'.$row['aweme_id']."@@".date("Y-m-d H:i:s",$row['create_time'])."\n";
        file_put_contents("money_stat.txt",$log_s,FILE_APPEND);*/
        $num++;
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue( 'A'.$step_num,$author_short_id);
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue( 'B'.$step_num,$author_name);
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue( 'C'.$step_num,$admin_user_id);
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue( 'D'.$step_num,$admin_user_name);
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue( 'E'.$step_num,$row['digg_count']);
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue( 'F'.$step_num,$row['aweme_id'],PHPExcel_Cell_DataType::TYPE_STRING);
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue( 'G'.$step_num,date("Y-m-d H:i:s",$row['create_time']));

               endforeach;}
               endforeach;}
    }
    foreach($request_douyin_aweme_patch as $k=>$row){
        $step_num++;
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue( 'A'.$step_num,$row['douyin_id']);
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue( 'B'.$step_num,$row['douyin_name']);
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue( 'C'.$step_num,$row['admin_user_id']);
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue( 'D'.$step_num,$row['admin_user_name']);
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue( 'E'.$step_num,$row['dianzan']);
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue( 'F'.$step_num,$row['id'],PHPExcel_Cell_DataType::TYPE_STRING);
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue( 'G'.$step_num,$row['pub_date']);
        $step_num++;
    }

    $objActSheet = $objPHPExcel->getActiveSheet()->setTitle('抖音、快手、火山、微视、小红书');
    $file_name = 'a2.xlsx';
    header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
    header('Content-Disposition: attachment;filename="'.$file_name.'"');
    header('Cache-Control: max-age=0');
   // $objWriter = PHPExcel_IOFactory:: createWriter($objPHPExcel, 'Excel2007');
   $objWriter = PHPExcel_IOFactory:: createWriter($objPHPExcel, 'Excel5');
    $objWriter->save( 'php://output');
    exit;
    echo $num."\n";

}
?>
<!DOCTYPE HTML>
<html>
<head>
    <title>显示 <?php echo $last_date;?> 数据 - 抖音数据平台</title>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta content="yes" name="apple-mobile-web-app-capable">
    <meta content="yes" name="apple-touch-fullscreen">
    <link rel="stylesheet" type="text/css" media="all" href="/static/css/back.css?v=6"/>
    <script type="text/javascript" src="http://libs.baidu.com/jquery/1.7.2/jquery.min.js"></script>
    <script type="text/javascript" src="/static/js/jquery.form.js"></script>
    <style type="text/css">
        td.u_do a{font-size:16px;}
        .footer{width: 90%;margin: 0px auto;text-align: center;padding: 30px 0;}
        .dy_img_gif{width:100px;}
        p.top1{color:red;}
        p.top2{color:blue;}
        p.top3{color:green;}
        .company_info_class{padding-top:10px;}
        .company_info_class span{padding-right:10px;font-weight:bold;font-size: 16px;}
        .button2 {
            display: inline-block;
            position: relative;
            padding: 0 20px;
            text-align: center;
            text-decoration: none;
            font: bold 12px/25px Arial, sans-serif;
        }
        input{height:auto;}
        .show_num{font-size:16px;font-weight:bold;color:red;}
    </style>
    <script type="text/javascript">
        function save_nm() {
            $("#uploadform").ajaxSubmit(function(message) {
                var h = eval('(' + message + ')');
                if(h.code == 1 || h.code == 2){
                    alert(h.msg);
                    location.href = '/douyin/day_report.php?reload';
                }else if(h.code > 0){
                    alert(h.msg);
                }else{
                    alert(h.msg);
                }
            });
            return false;
        }
    </script>
</head>
<body>
<?php include(dirname(__FILE__).'/_block_header.php');?>
<div style="margin:20px;font-size:16px;">
    <a style="padding:5px 20px;font-size:16px;" href="/paiming/examine1.php?act=download&start_date=<?php echo $start_date;?>&end_date=<?php echo $end_date;?>" target="_blank">点此下载数据</a>
    <br />
</div>
<form action="#"  method="get" style="margin-left: 1200px; "><!--表单-->
    <input type="date" name="start_date" /><input type="date" name="end_date" />
    <input type="submit" value="搜索"/>
</form>

<table width="95%" style="margin:10px 20px;">
    <tr>

        <th>抖音ID</th>
        <th>抖音名称</th>
        <th>员工id</th>
        <th>员工姓名</th>
        <th>点赞量</th>
        <th>视频id</th>
        <th>发布日期</th>
    </tr>
    <!--sql1-->
    <?php foreach($request_douyin_aweme as $k=>$row):
        $author_short_id = $row['author_short_id'];
        $admin_user_id = $row['admin_user_id'];
        $author_name = '-';
        $admin_user_name = '-';
        $author_info = weijinci::select("select * from douyin_user where short_id=" . $author_short_id,'weijinci');
        if (!empty($author_info)) {
            foreach($author_info as $k=>$r):
                $author_name = $r['nickname'];
            endforeach;
        }

        $admin_user_info = weijinci::select("select * from pub_user where id=" . $admin_user_id,'weijinci');


        if(!empty($admin_user_info)){
            foreach($admin_user_info as $k=>$r):
                $admin_user_name = $r['user_name'];
            endforeach;
        }
        //$log_s = $author_short_id."@@".$author_name."@@".$admin_user_id.'@@'.$admin_user_name.'@@'.$row['digg_count'].'@@'.$row['aweme_id']."@@".date("Y-m-d H:i:s",$row['create_time'])."\n";
       // file_put_contents("money_stat.txt",$log_s,FILE_APPEND);
        ?>
        <tr <?php echo $k%2!=0?'style="background-color:#CDE2F8"':'';?>>

            <td><?php echo $author_short_id;?></td><!--抖音id-->
            <td><?php echo $author_name;?></td><!--抖音名称-->
            <td><?php echo $admin_user_id;?></td><!--员工id-->
            <td><?php echo $admin_user_name;?></td><!--员工姓名-->
            <td>  <?php echo $row['digg_count'];?>   </td><!--点赞量-->
            <td> <?php echo $row['aweme_id'];?> </td><!--视频id-->
            <td><?php echo date("Y-m-d H:i",$row['create_time']);?></td><!--发布日期-->
        </tr>
    <?php endforeach;?>
    <?php foreach($request_douyin_aweme_patch as $k=>$v):
        ?>
        <tr <?php echo $k%2!=0?'style="background-color:#CDE2F8"':'';?>>

            <td><?php echo $v['douyin_id'];?></td><!--抖音id-->
            <td><?php echo $v['douyin_name'];?></td><!--抖音名称-->
            <td><?php echo $v['admin_user_id'];?></td><!--员工id-->
            <td><?php echo $v['admin_user_name'];?></td><!--员工姓名-->
            <td>  <?php echo $v['dianzan'];?>   </td><!--点赞量-->
            <td> <?php echo $v['id'];?> </td><!--视频id-->
            <td><?php echo date("Y-m-d H:i",$v['pub_date']);?></td><!--发布日期-->
        </tr>
    <?php endforeach;?>

</table>
<div class="footer">
    <a href="/">首页</a> |
    <a href="javascript:alert('天天出爆文!')">关于我们</a> |
    <a href="/pub/account_edit.php">修改密码</a>
</div>
<?php include(dirname(__FILE__).'/_block_footer.php');?>
</body></html>
SAP EXCEL上传是指将Excel文件中的数据导入到SAP系统中的操作。这个功能非常方便,在处理大量数据时可以节省时间和劳动力。通过SAP EXCEL上传,用户可以一次性导入多个Excel文件,将文件中的数据快速准确地加载到SAP系统中。 要进行SAP EXCEL上传,首先需要准备好Excel文件并保存好。然后在SAP系统中打开相应的事务码,进入要上传数据的模块。一般来说,系统会提供一个标准的Excel上传模板,用户可以根据需要填写数据到模板中。填写完毕后,保存Excel文件。 接下来,在SAP系统中的导入界面选择Excel文件,并确定导入的参数和选项。一般来说,系统会提示用户设定数据的导入规则,比如哪些列对应SAP系统中的哪些字段。确保设定正确后,点击导入按钮。 系统会自动将Excel文件中的数据读取到SAP系统中,并根据事务码和设定的规则进行数据处理。导入过程中,系统会检查数据的准确性和合法性,如果存在错误或者不一致,系统会给出相应的提示。用户可以根据提示进行修改或者重新导入。 总的来说,SAP EXCEL上传是一种方便快捷的数据导入方式。通过合理使用该功能,用户可以减少手工输入数据的工作量,提高工作效率,并且减少因手工输入错误而导致的数据错误。它在需要大量数据导入的情况下特别有用,可以节省大量时间和精力。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值