#324
展开↯#325
作者:未知
laravel 使用excel 设计表格的样式
if ($res->code == 1) {
if($query['excel'] == 'Y'){
if(!($res->results)){
return redirect()
->back()
->withErrors('数据为空,请检查报表条件~')
->withInput();
}
$arr[] = ['ID','用户ID','用户名称','数据ID','状态','金额(元)','创建日期'];
$amount = 0.00 ;
$total = count($res->results);
foreach($res->results as $val){
$arr[] =[$val->id,$val->u_id,$val->username,$val->d_id,$val->type,$val->amount,date('Y-m-d',$val->created_at)];
$amount += $val->amount;
}
$arr[] = ['','','','','总额:',$amount];
$arr[] = ['',' ',' ','',''];
$arr[] = ['','总条数',$total,'',''];
$arr[] = ['','总金额',$amount,'备注:',''];
$arr[] = ['','用户注册','','','徒弟收益(11001)',''];
$arr[] = ['','点击任务','','','师傅收益(11002)',''];
$arr[] = ['','任务大厅','','','师爷收益(11003)',''];
$arr[] = ['','徒弟收益','','','代理收益(11004)',''];
$arr[] = ['','徒孙收益','','','股东收益(11005)',''];
$arr[] = ['','代理收益','','',''];
$arr[] = ['','股东收益','','',''];
$arr[] = ['','','','',''];
$arr[] = ['','报表用户',$query['username']];
$arr[] = ['','报表日期',$query['start_date'].'至'.$query['end_date'],];
$arr[] = ['','报表类型:'.$query['type'],'','',''];
$cellData = $arr;
Excel::create('财务报表',function($excel) use ($cellData){
$excel->sheet('财务报表', function($sheet) use ($cellData){
$tot = count($cellData) ;
$sheet->setWidth(array(
'A' => 12,
'B' => 12,
'C' => 12,
'D' => 12,
'E' => 12,
'F' => 12,
'G' => 12,
))->rows($cellData)->setFontSize(12);
//
// $sheet->row($tot-13, function($row) {
// $row->setBackground('#87eabd');
// });
// 数据内容主题 左对齐
$sheet->cells('A1:F'.$tot, function($cells) {
$cells->setAlignment('left');
});
// 菜单 样式
$sheet->cells('A1:G1', function($cells) {
$cells->setAlignment('center');
$cells->setFontWeight('bold');
});
// 数据统计 样式
$sheet->cells('A'.($tot-13).':F'.$tot, function($cells) {
$cells->setAlignment('left');
$cells->setFontWeight('bold');
});
// 备注 右对齐
$sheet->cells('D'.($tot-11), function($cells) {
$cells->setAlignment('right');
});
// 备注内容样式
$sheet->cells('E'.($tot-10).':F'.($tot-6), function($cells) {
$cells->setAlignment('left');
$cells->setFontColor('#a09b9b');
$cells->setFontFamily('Calibri');
$cells->setFontWeight('normal');
$cells->setFontSize(12);
});
// 总金额 高亮显示
$sheet->cells('F'.($tot-14), function($cells) {
$cells->setBackground('#87eabd');
$cells->setFontWeight('bold');
$cells->setFontSize(14);
});
});
})->export('xls');
}else{
$totalItems = $res->pagination->total;
$itemsPerPage = $res->pagination->per_page;
$currentPage = $res->pagination->current_page;
if ($http_build_query)
{
$urlPattern = url('finance/listing?'.$http_build_query.'&page=') . '(:num)';
}else{
$urlPattern = url('finance/listing') .'?page=(:num)';
}
$paginator = new Paginator($totalItems, $itemsPerPage, $currentPage, $urlPattern);
$paginator->setPreviousText('上一页');
$paginator->setNextText('下一页');
$data['listing'] = $res->results;
$data['paginator'] = $paginator;
$data['query'] = $query;
return view('financeRecords.listing', $data);
}
} else {
return redirect()
->back()
->withErrors($res->message)
->withInput();
}
Run code
Cut to clipboard
文章:laravel phpexcel设置单元格 发表时间:2019-11-25, 20:44:21
#326
作者:未知
之前用就可以显示四周的边框
最近使用的时候发现边框只剩下竖条
下面这种写法只能设置外层边框,想要全部的边框智能一个一个的设置单元格
最后使用了下面的写法
$sheet->setBorder('A' . ($i * 22 + 2) . ':H' . ($i * 22 + 7), 'thin');
Run code
Cut to clipboard
最近使用的时候发现边框只剩下竖条
下面这种写法只能设置外层边框,想要全部的边框智能一个一个的设置单元格
$sheet->cells('A' . ($i * 22 + 13) . ':A' . ($i * 22 + 20), function ($cells) {
$cells->setBorder('none', 'thin', 'none', 'thin');
});
Run code
Cut to clipboard
最后使用了下面的写法
$style_array = array(
'borders' => array(
'allborders' => array(
'style' => \PHPExcel_Style_Border::BORDER_THIN
)
)
);
$sheet->getStyle('A' . ($i * 21 + 3) . ':I' . ($i * 21 + 6))->applyFromArray($style_array);
Run code
Cut to clipboard
文章:laravel phpexcel设置单元格 发表时间:2019-11-25, 20:43:30
#327
作者:未知
PHP截取指定长度的字符串,超出部分用 ..替换
还有
#,未知,2019-11-20,20:08:17,
function substr_format($text, $length, $replace='..', $encoding='UTF-8')
{
if ($text && mb_strlen($text, $encoding)>$length)
{
return mb_substr($text, 0, $length, $encoding).$replace;
}
return $text;
}
Run code
Cut to clipboard
还有
function cut_string($str, $len)
{
// 检查长度
if (mb_strwidth($str, 'UTF-8')<=$len)
{
return $str;
}
// 截取
$i = 0;
$tlen = 0;
$tstr = '';
while ($tlen < $len)
{
$chr = mb_substr($str, $i, 1, 'UTF-8');
$chrLen = ord($chr) > 127 ? 2 : 1;
if ($tlen + $chrLen > $len) break;
$tstr .= $chr;
$tlen += $chrLen;
$i ++;
}
if ($tstr != $str)
{
$tstr .= '...';
}
return $tstr;
}
Run code
Cut to clipboard
文章:PHP将数字金额转换成中文大写金额的函数 发表时间:2019-11-20, 20:04:11
#328
作者:广西南宁市
vs code 缩进4格
"editor.detectIndentation": false,
"editor.tabSize": 4, //vscode设置的缩进量
"editor.formatOnSave": true, //保存时候自动格式化
Run code
Cut to clipboard
文章:vscode代码规范修改缩进,保存代码自动格式化,VScode代码格式自动修正 发表时间:2019-11-12, 09:45:31
#330
作者:广西南宁市
laravel wherein order by 排序
->whereIn('os.id',$oi_id)
->orderByRaw("FIELD(pre_os.id, " . implode(", ", $oi_id) . ")")
Run code
Cut to clipboard
文章:laravel wokerman启动没有显示监听端口 发表时间:2019-10-30, 11:49:03
#331
作者:广西南宁市
唐僧每次出场都这样介绍自己:1.贫僧唐三藏;2.从东土大唐而来;3.去往西天拜佛取经。 短短一个开场白道破了这个困扰着古今中外的世间三问
文章:@意见反馈/技术支持/伊网/安企网 发表时间:2019-10-30, 11:31:01
#332
作者:广西南宁市
VSCode代码自动换行设置
File>>Preferences>>settings>>UserSettings>>CommonlyUsed>>找到Editor:WordWrap,将off修改为on即可
Run code
Cut to clipboard
文章:程序员编程常用网页工具集[游戏] 发表时间:2019-10-28, 09:47:08
#333
作者:广西玉林市
十分钟一次就是:
crontab -e
Run code
Cut to clipboard
*/10 * * * * /usr/bin/curl https://xx.com/v2/other/strun
Run code
Cut to clipboard
文章:服务器定时执行计划任务 发表时间:2019-10-24, 01:45:37
#334
作者:广西南宁市
js判断json对象是否为空
JSON.stringify(a)!="{}"
&& JSON.stringify(a)!="[]"
&& a && a!='null'
Run code
Cut to clipboard
文章:微信小程序开发笔记 发表时间:2019-10-23, 14:48:53
#336
作者:广西河池市
二维码 QR Code 翻译 #,广西南宁市,2019-09-27,18:14:32,
$url='http://www.baidu.com';
$img = \QrCode::format('png')->size(200)->generate($url); //format 是指定生成文件格式 默认格式是svg,可以直接在浏览器打开,png不能直接显示
return $data = 'data:image/png;base64,' . base64_encode($img ); //转成base64,放在img的src里就可以显示
Run code
Cut to clipboard
文章:使用PHP生成二维码的两种方法(带logo图像) 发表时间:2018-09-13, 12:13:17
#337
作者:广西南宁市
<?php
$url = 'http://localhost/3.php';
$opt_data = 'name=BY2&age=999&sex=MAXMAN';
$curl = curl_init(); //初始化
curl_setopt($curl,CURLOPT_URL,$url); //设置url
curl_setopt($curl,CURLOPT_HTTPAUTH,CURLAUTH_BASIC); //设置http验证方法
curl_setopt($curl,CURLOPT_HEADER,0); //设置头信息
curl_setopt($curl,CURLOPT_RETURNTRANSFER,1); //设置curl_exec获取的信息的返回方式
curl_setopt($curl,CURLOPT_POST,1); //设置发送方式为post请求
curl_setopt($curl,CURLOPT_POSTFIELDS,$opt_data); //设置post的数据
$result = curl_exec($curl);
if($result === false){
echo curl_errno($curl);
exit();
}
print_r($result);
curl_close($curl);
?>
Run code
Cut to clipboard
PHP删除n天以前的文件,删除指定目录下指定类型(扩展名)的文件,包括子目录子和目录下的文件.
其中$ext数组代表不删除的文件扩展名.
调用函数trash('目录名',时间值);如trash('./files',3600)
参数时间值的单位是秒,如果省略不写,使用trash('./'),将删除当前时间10秒前及更早的文件.
<?php
function trash($folder,$time=10){
$ext=array('php','htm','html'); //带有这些扩展名的文件不会被删除.
$o=opendir($folder);
while($file=readdir($o)){
if($file !='.' && $file !='..' && !in_array(substr($file,strrpos($file,'.')+1),$ext)){
$fullPath=$folder.'/'.$file;
if(is_dir($fullPath)){
trash($fullPath);
@rmdir($fullPath);
} else {
if(time()-filemtime($fullPath) > $time){
unlink($fullPath);
}
}
}
}
closedir($o);
}
trash('./');//调用自定义函数
?>
Run code
Cut to clipboard
文章:PHP下使用CURL方式POST数据至API接口的代码 发表时间:2019-09-18, 17:56:10
#338
作者:广西河池市
//echo 'dfasfads';
//dump(count($mendian_info));
if(!count($mendian_info)){
$mendian_info=[];
$mendian_info['0']['mendian_info_num']=0;
$mendian_info['0']['sttt']=$sttt;
//$mendian_info->{0}='';
//$mendian_info->{0}->mendian_info_num=0;//$mendian_info_num;
//$mendian_info->{0}->sttt=$sttt;
}//Base::exitError('fail');
else{
//$mendian_info['0']->mendian_info_num=count($mendian_info);//$mendian_info_num;
//$mendian_info['0']->sttt=$sttt;
}
//dump($mendian_info);
Base::exitSuccess('success',$mendian_info);
Run code
Cut to clipboard
在别的地方看到了答案,贴到这里让更多同学们学习一下吧
$a = new \stdClass();
$a->{0} = "test";
var_dump($a); //object(stdClass)#1 (1) { ["0"]=> string(4) "test" }
echo $a->{0}; //test
Run code
Cut to clipboard
obj[0]['字段名字']
Run code
Cut to clipboard
$where[] = ['in'=>['tn_user_base.id'=>$medical_number_ids]];
Run code
Cut to clipboard
$where[] = ['in'=>['tn_user_base.id'=>$medical_number_ids]];
Run code
Cut to clipboard
//in查询应该用whereIn
$condition[] =['check_doctor_uid','in',$check_doctor_id]; // 错误
// Illuminate\Database\Query\Builder关于operators定义中,并没有in
public $operators = [
'=', '<', '>', '<=', '>=', '<>', '!=',
'like', 'like binary', 'not like', 'between', 'ilike',
'&', '|', '^', '<<', '>>',
'rlike', 'regexp', 'not regexp',
'~', '~*', '!~', '!~*', 'similar to',
'not similar to', 'not ilike', '~~*', '!~~*',
];
//->where($condition) 这种写法有问题
Run code
Cut to clipboard
文章:Laravel 5.4 结合 Workerman 实现 TCP 长连接 发表时间:2019-09-22, 03:12:46
#339
作者:广西南宁市
Workerman kill
#,广西南宁市,2019-09-04,11:42:10, 调试模式
killall -9 php
php artisan workman start --d
Run code
Cut to clipboard
killall -9 php
ps aux|grep WorkerMan|awk '{print $2}'|xargs kill -9
Run code
Cut to clipboard
php artisan workman start
Run code
Cut to clipboard
文章:Laravel 5.4 结合 Workerman 实现 TCP 长连接 发表时间:2019-09-03, 18:23:45
#340
作者:广西南宁市
nginx 反向代理 wss转ws 服务端不变
#服务器socket连接端口9999,为了避免冲突,这里用9990反向代理到9999,同时实现了wss转ws,服务器端不需要做修改
server {
listen 9990;
server_name xx.xx.xx.xx;
ssl on;
ssl_certificate "/usr/cert/barrage.crt";
ssl_certificate_key "/usr/cert/barrage.key";
ssl_protocols SSLv3 SSLv2 TLSv1 TLSv1.1 TLSv1.2;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 10m;
ssl_prefer_server_ciphers on;
location /{
#反向代理到9999端口,同时协议转换为http,这样服务器端代码就不需要做修改
proxy_pass http://120.77.222.242:9999;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
#由于服务器端源码(建议大家做好大小写匹配)只匹配了"Upgrade"字符串,所以如果这里填"upgrade"服务器端会将这条http请求当成普通的请求,导致websocket握手失败
proxy_set_header Connection "Upgrade";
proxy_set_header Remote_addr $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_read_timeout 600s;
}
}
Run code
Cut to clipboard
文章:Laravel 5.4 结合 Workerman 实现 TCP 长连接 发表时间:2019-09-03, 18:19:44
#342
展开↯
Excel 导出使用的是 Maatwebsite/Laravel-Excel 2.1 的 composer 包,Excel 表单元格行列合并同时使用时,后用的将会失效。
$sheet->mergeCells('D1:F1'); $sheet->mergeCells('D2:F2'); $sheet->setMergeColumn([ 'columns' => ['D', 'E', 'F'], 'rows' => [ [1, 2] ] ]);
$sheet->setMergeColumn([ 'columns' => ['D', 'E', 'F'], 'rows' => [ [1, 2] ] ]); $sheet->mergeCells('D1:F1'); $sheet->mergeCells('D2:F2');
public function exportExcel() //$course_list 需要打印的课程列表 $course_list = []; $filename = '结算账单' . date('Y-m-d H_i'); Excel::create($filename, function($excel) use ($course_list) { $data[] = ["结算账单"]; $data[] = ['收入来源:课程结算']; $data[] = ['结算周期:2019.09-2019.10'; $data[] = ['结算时间:2019.09.25']; $data[] = ['课程名称', '课程ID','主讲人','主讲人uid','价格(¥)', '会员总数', '获利金额(¥)']; foreach ($course_list as $key=>$course) { $data[] = $item_info; } $excel->sheet('课程结算账单', function ($sheet) use ($data, $width_list) { //第一行到第四行合并单元格 $sheet->mergeCells("A1:G1"); $sheet->mergeCells("A2:G2"); $sheet->mergeCells("A3:G3"); $sheet->mergeCells("A4:G4"); //第一行标题居中、加粗、设置字符大小 $sheet->cells("A1:G1", function ($cells) { $cells->setAlignment('center'); $cells->setFontWeight('bold'); $cells->setFontSize(20); }); //子标题文字居中、背景色设置、加粗 $sheet->cells("A5:G5", function($cells) { $cells->setAlignment('center'); $cells->setBackground('#C8EAFF'); $cells->setFontWeight('bold'); $cells->setFontSize(16); }); //剩下单元格设置 $sheet->fromArray($data, null, 'A1', false, false)->setFontSize(16); }); })->export('xlsx'); }
$objPHPExcel; $filepath="c:\temp.xlsx"; try { $objReader = PHPExcel_IOFactory::createReader('Excel2007'); $objPHPExcel = $objReader->load($filepath); } catch (Exception $e) { die(); } $column_index = "A"; //清空要合并的首行单元格值,用于填充合并后的单元格值 $objPHPExcel->getActiveSheet()->setCellValue($column_index.''.$beginRow,''); //合并单元格,值为'' $objPHPExcel->getActiveSheet()->mergeCells($column_index.''.$beginRow.":".$column_index.''.$endRow); //拆分单元格,将清空合并前单元格的值并还原合并前单元格的样式 $objPHPExcel->getActiveSheet()->unmergeCells($column_index.''.$beginRow.":".$column_index.''.$endRow);