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进行包管理的框架在国内的传播和 ...
随机推荐
- 内存管理 & 内存优化技巧 浅析
内存管理 浅析 下列行为都会增加一个app的内存占用: 1.创建一个OC对象: 2.定义一个变量: 3.调用一个函数或者方法. 如果app占用内存过大,系统可能会强制关闭app,造成闪退现象,影响用户 ...
- 《CSS设计指南》阅读笔记
一.HTML实体 HTML实体常用于生成那些键盘上没有的印刷字符.以一个和号(&)开头,一个分号(:)结尾,二者之间是表示实体的字符串. 如:“左引号(") ”右引号(&qu ...
- java应用程序中判断用户输入的一个整数是否在已知数组里。
import java.util.*; class Example2_5 { public static void main(String args[]) { int start=0,end,midd ...
- Bootstrap学习 - JavaScript插件
模态框 <div class="modal" id="myModal" tabindex="-1" role="dialo ...
- Linux学习 -- 用户和用户组管理
1 用户配置文件 1.1 用户信息文件 /etc/passwd 查看帮助 man 5 passwd -- account:password:UID:GID:GECOS:directory:shell ...
- C# 初步学习
这学期有了C#开发这门课....先做了计算器,还有进制转换,别人看来似乎很强,其实在ACM中算是两个简单的水题了.....参加竞赛一年下来,发现学到的算法和数据结构都是十分有用的东西. 计算器最核心的 ...
- update set from where
原文链接:http://blog.csdn.net/xcbsdu/article/details/6736503 关于update set from where 下面是这样一个例子: 两个表a.b,想 ...
- 第13章 Swing程序设计----常用面板
面板也是一个Swing容器,它可以作为容器容纳其他组件,但它也必须被添加到其他容器中. Swing常用的面板包括JPanel面板和JScrollPanel面板. 1.JPanel面板 import j ...
- iOSFMDB和CoreData
转发:http://wenku.baidu.com/link?url=LSPSZSPxN4pVwWNwqEXSoY0-jlnXq-_14C7qV1FV9_gFIMPjdKlXrG4Nrh_08EZS1 ...
- C++ 输出Cstring遇见的奇葩问题
先上代码 // webConteng.cpp : Defines the entry point for the console application. // #include "stda ...