laravel安装excel功能
原文安装链接: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功能的更多相关文章
- laravel安装Excel安装不上
1.生明版本号 composer require maatwebsite/excel 2.1我的PHP是7.0安装Excel得2.1 2.在composer.json中加入 "maatweb ...
- laravel 安装excel扩展
1,使用Composer安装依赖 在Laravel项目根目录下使用Composer安装依赖: composer require maatwebsite/excel ~2.1 ps:一定要加上~2.1! ...
- laravel实现excel表的导入导出功能
1.这是个我去公司之后曾经折磨我很久很久的功能查阅了很多资料但是功夫不负有心人在本人的不懈努力下还是实现了这个功能 (ps看不懂我下面说讲述的可以参考这个laravel学院的官方文档 https:// ...
- 项目笔记:导出Excel功能
1.前台这块: var ids=""; $.post("${basePath}/assets/unRegDeviceAction_getDeviceIds.do" ...
- laravel基础课程---1、laravel安装及基础介绍(laravel如何安装)
laravel基础课程---1.laravel安装及基础介绍(laravel如何安装) 一.总结 一句话总结: [修改composer镜像地址].[明确laravel的安装要求].[安装指定版本的la ...
- vue项目导出EXCEL功能
因为一些原因导出EXCEL功能必须前端来做,所以就研究了一下,在网上也找了一些文章来看,有一些不完整,我做完了就记录下来,供大家参考: 1.首先先安装依赖: npm install file-save ...
- Laravel安装方法 (windows)
Laravel安装方法(windows) 安装PHP 下载PHP7 http://windows.php.net/download#php-7.0 进入上述网站下载PHP7 选择zip包解压安装 配置 ...
- virtualbox安装增强功能时【未能加载虚拟光盘】
virtualbox安装增强功能时[未能加载虚拟光盘] 今天在使用Virtualbox中的Ubuntu虚拟机,想安装增强功能来实现更改分辨率,但是在安装时出错:未能加载虚拟光驱 VBoxsGuestA ...
- laravel安装学习步骤
在看知乎比较php框架的优劣的时候提到为什么laravel这么好国内用的少,还有就是yii2,有人提到原因就是composer在国内无法使用.这制约了使用composer进行包管理的框架在国内的传播和 ...
随机推荐
- POJ 2368 巴什博奕
题目大意:给出n个按钮,每次最多可以按L个,按下最后一个按钮的人获胜.求使后手必定获胜的L的最小值(L>=2). 题目思路: 巴什博弈:只有一堆n个物品,两个人轮流从这堆物品中取物,规定每次至少 ...
- Top 100 Best Blogs for iOS Developers
(by JP Zhang | Last updated: Apr 5, 2016 ) 转载自:http://www.softwarehow.com/best-blogs-for-ios-develo ...
- 在写一个iOS应用之前必须做的7件事
转载自:http://www.cocoachina.com/ios/20160316/15685.html 原文:https://medium.com/ios-os-x-development/7-t ...
- 如何在Eclipse中添加Servlet-api.jar的方法
方法一: 点击窗口->首选项->java->构建路径->类路径变量->新建:将你的tomcat目录下的common/lib/servlet.jar加进来.如果你建立了一个 ...
- 转:Ant使用指南
一.概述 ant 是一个将软件编译.测试.部署等步骤联系在一起加以自动化的一个工具,大多用于Java环境中的软件开发.在实际软件开发中,有很多地方可以用到ant. 开发环境: System:Windo ...
- HDU 2671 Can't be easier
简单的几何题目 点(a,b)关于直线Ax+By+C=1对称点的公式 #include<cstdio> #include<cstring> #include<cmath&g ...
- Photoshop学习之路
网易云课堂中有的提升课程:http://study.163.com/course/courseMain.htm?courseId=765016&6925ecaa9614a750=Individ ...
- 提升html5的性能体验系列之四使用原生ui
原生UI即nativeUI的设计目的 HTML和css有一个优势就是灵活的样式设计.在大多数情况下,我们都应该使用HTML+css来负责UI.但是有些情况下,我们发现HTML+css的UI不满足需求. ...
- java集合框架list和set
为什么出现集合类? 面向对象语言对事物的体现都是以对象的形式,所以为了方便对多个对象的操作,就对对象进行存储,集合就是存储对象最常用的一中方式 数组和集合类同是容器,有何不同? 数组虽然也可以存储对象 ...
- FACE++学习二、获得face属性
http://blog.csdn.net/lyq8479/article/details/17362685 为了防止网页丢失还是自己保存一份安全一点 人脸检测API介绍 在Face++网站的“API文 ...