原文安装链接:https://github.com/Maatwebsite/Laravel-Excel

代码如下:

        if ($rows = DB::connection('glist')->table('program_view')->where('v_type', $type)->get())
{
$head = array('Pid', 'Name', 'Play Times');
$height = array();
$movie_prog = array();
$movie_height = array();
$series_prog = array();
$series_height = array(); foreach ($rows as $row)
{
$pro_pid = $row->v_pid;
$pro_name = $row->v_prog;
$play_time = 0; if ($counts = DB::connection('glist')->table('program_date_view')->where('prog_id', $pro_pid)
->whereBetween('date', array($start_time, $end_time))->lists('view_count'))
{
foreach ($counts as $count)
{
$play_time += $count;
}
} $play_times[] = strval($play_time);
$prog[] = array($pro_pid, $pro_name, strval($play_time)); if (isset($this->mMonitorProgTypes[$pro_pid]) &&
self::VOD_PROGRAM_TYPE == $this->mMonitorProgTypes[$pro_pid] &&
isset($this->mMonitorProgCategories[$pro_pid]) &&
"Series" != $this->mMonitorProgCategories[$pro_pid])
{
$movie_play_times[] = strval($play_time);
$movie_prog[] = array($pro_pid, $pro_name, strval($play_time));
}
else if (isset($this->mMonitorProgTypes[$pro_pid]) &&
self::VOD_PROGRAM_TYPE == $this->mMonitorProgTypes[$pro_pid] &&
isset($this->mMonitorProgCategories[$pro_pid]) &&
"Series" == $this->mMonitorProgCategories[$pro_pid])
{
$series_play_times[] = strval($play_time);
$series_prog[] = array($pro_pid, $pro_name, strval($play_time));
}
} if (!empty($prog))
{
array_multisort($play_times, SORT_DESC, $prog);
array_unshift($prog, $head);
$height = array_fill(0, count($prog) + 1, 20); //20——excel cell height
} if (!empty($movie_prog))
{
array_multisort($movie_play_times, SORT_DESC, $movie_prog);
array_unshift($movie_prog, $head);
$movie_height = array_fill(0, count($movie_prog) + 1, 20);
} if (!empty($series_prog))
{
array_multisort($series_play_times, SORT_DESC, $series_prog);
array_unshift($series_prog, $head);
$series_height = array_fill(0, count($series_prog) + 1, 20);
}
} Excel::create($type . ' Program Statistics Data', function($excel) use ($type, $prog, $height, $movie_prog, $movie_height, $series_prog, $series_height) { $excel->sheet('program_ranking', function($sheet) use ($prog, $height) { $sheet->fromArray($prog, null, 'A1', false, false);
$sheet->setWidth(array('A' => 25, 'B' => 35, 'C' => 15));
$sheet->setHeight($height); $sheet->cells('A1:C1', function ($cells) {
$cells->setFont(array(
'family' => 'Calibri',
'size' => '14',
'bold' => true
));
}); $sheet->cells('A1:C' . count($height), function ($cells) {
$cells->setAlignment('center');
$cells->setValignment('middle');
});
}); if ("VOD" == $type)
{
$excel->sheet('series_ranking', function($sheet) use ($series_prog, $series_height) { $sheet->fromArray($series_prog, null, 'A1', false, false);
$sheet->setWidth(array('A' => 25, 'B' => 35, 'C' => 15));
$sheet->setHeight($series_height); $sheet->cells('A1:C1', function ($cells) {
$cells->setFont(array(
'family' => 'Calibri',
'size' => '14',
'bold' => true
));
}); $sheet->cells('A1:C' . count($series_height), function ($cells) {
$cells->setAlignment('center');
$cells->setValignment('middle');
});
}); $excel->sheet('other_ranking', function($sheet) use ($movie_prog, $movie_height) { $sheet->fromArray($movie_prog, null, 'A1', false, false);
$sheet->setWidth(array('A' => 25, 'B' => 35, 'C' => 15));
$sheet->setHeight($movie_height); $sheet->cells('A1:C1', function ($cells) {
$cells->setFont(array(
'family' => 'Calibri',
'size' => '14',
'bold' => true
));
}); $sheet->cells('A1:C' . count($movie_height), function ($cells) {
$cells->setAlignment('center');
$cells->setValignment('middle');
});
});
}
})->export('xls');
}

laravel安装excel功能的更多相关文章

  1. laravel安装Excel安装不上

    1.生明版本号 composer require maatwebsite/excel 2.1我的PHP是7.0安装Excel得2.1 2.在composer.json中加入 "maatweb ...

  2. laravel 安装excel扩展

    1,使用Composer安装依赖 在Laravel项目根目录下使用Composer安装依赖: composer require maatwebsite/excel ~2.1 ps:一定要加上~2.1! ...

  3. laravel实现excel表的导入导出功能

    1.这是个我去公司之后曾经折磨我很久很久的功能查阅了很多资料但是功夫不负有心人在本人的不懈努力下还是实现了这个功能 (ps看不懂我下面说讲述的可以参考这个laravel学院的官方文档 https:// ...

  4. 项目笔记:导出Excel功能

    1.前台这块: var ids=""; $.post("${basePath}/assets/unRegDeviceAction_getDeviceIds.do" ...

  5. laravel基础课程---1、laravel安装及基础介绍(laravel如何安装)

    laravel基础课程---1.laravel安装及基础介绍(laravel如何安装) 一.总结 一句话总结: [修改composer镜像地址].[明确laravel的安装要求].[安装指定版本的la ...

  6. vue项目导出EXCEL功能

    因为一些原因导出EXCEL功能必须前端来做,所以就研究了一下,在网上也找了一些文章来看,有一些不完整,我做完了就记录下来,供大家参考: 1.首先先安装依赖: npm install file-save ...

  7. Laravel安装方法 (windows)

    Laravel安装方法(windows) 安装PHP 下载PHP7 http://windows.php.net/download#php-7.0 进入上述网站下载PHP7 选择zip包解压安装 配置 ...

  8. virtualbox安装增强功能时【未能加载虚拟光盘】

    virtualbox安装增强功能时[未能加载虚拟光盘] 今天在使用Virtualbox中的Ubuntu虚拟机,想安装增强功能来实现更改分辨率,但是在安装时出错:未能加载虚拟光驱 VBoxsGuestA ...

  9. laravel安装学习步骤

    在看知乎比较php框架的优劣的时候提到为什么laravel这么好国内用的少,还有就是yii2,有人提到原因就是composer在国内无法使用.这制约了使用composer进行包管理的框架在国内的传播和 ...

随机推荐

  1. UVALive - 3942 Remember the Word

    input 字符串s  1<=len(s)<=300000 n 1<=n<=4000 word1 word2 ... wordn 1<=len(wordi)<=10 ...

  2. 运行第一个SparkKPI程序

    1.复制一个examples中SparkPi.scala到IntelliJ IDEA编辑器,运行,出现错误: “org.apache.spark.SparkException: A master UR ...

  3. 在vim下,实现nesC语句的高亮

    默认的vim没有支持nesC语法高亮,给阅读源码带来不便.不过可以通过装NesC Syntax Highlighting插件来解决这个问题,具体操作如下: 步骤一:下载插件 在http://www.v ...

  4. Git学习 -- 新建版本库

    创建目录 mkdir git cd git 2 初始化git init #会在目录下自动创建一个.git目录,用于跟踪管理版本库,不要修改 3 向版本库中添加文件git add readme.txt ...

  5. Linux中的挂载和卸载

    mkdir /home/xxx   创建挂载点 mount /dev/cdrom /home/xxx   把cdrom中的内容挂载到xxx目录 umount /dev/cdrom 卸载 /dev/sr ...

  6. android 5.0新特性学习--视图轮廓

    ViewOutlineProvider -- 视图轮廓setOutlineProvider--可以使用View.setClipToOutline方法去剪切一个视图的outline区域.只有rectan ...

  7. JS中三目运算符和if else的区别分析与示例

    本文是通过示例详细分析了JS中三目运算符和if else的区别,是篇非常不错的文章,这里推荐给大家.   今天写了一个图片轮播的小demo,用到了判断 先试了一下if else,代码如下: 复制代码代 ...

  8. jquery 延迟执行实例介绍

    代码如下: $(function(){ var $inputs = $('input[type=button]') .delay(500) .queue(function(){$(this).hide ...

  9. CSS样式覆盖规则

    有一下问题, 想让下面的border生效 ,#比. 优先级高, #navigator { height: 100%; width: 200; position: absolute; left: 0; ...

  10. JSON资料整理(转)

    目录 1.什么是json 2.json语法规则 3.json基础结构 4.json基础示例 5.JSON和XML比较 6. .NET操作JSON 原始方式 通用方式 内置方式 契约方式 通过序列化将. ...