小技巧

1.使用phpexcel导入数据由于行是字母A.....AE 不是简单的A+数字,通过下面的方式将列转换为数字

//将行的字母转换为数字 因为是AE不是简单的A+number

$highestColumnIndex = \PHPExcel_Cell::columnIndexFromString($highestColumn);

使用的时候

getCellByColumnAndRow ( $k,$j )

2.去除字符串的所有空格

$span_time=preg_replace('# #','',$array[3][2]);

3.截取字符串前5位,后5位

substr($time_str,0,5)    substr($time_str,-5)   

 

4.二维数组位空 array=['1'=>,'2'=>]

empty(implode("",$array))

 5.变量可以作为函数名使用

        $type='exportStandardSalary';
        $this->$type();
//        $this->exportStandardSalary(); 

6.导出到excel 单元格内换行

$objPHPExcel->getActiveSheet()->setCellValue($row[$k2+1].$i, "你\r\n好")->getStyle($row[$k2+1].$i)->applyFromArray($styleThinBlackBorderOutline)->getAlignment()->setWrapText(true);;

 7.返回某月天数

$days = date('t', strtotime("2017-4-1"));

8.返回某月开始时间结束时间

 public static function getMonthDays($date){
//      $date = date("Y-m-d");
        $firstday = date('Y-m-01', strtotime($date));
        $lastday = date('Y-m-d', strtotime("$firstday +1 month -1 day"));
        return array($firstday,$lastday);
    }    

9.获取上个月最后一天,结合上面可以获取上个月开始 结束时间

 $timestamp=strtotime(date('Y-m-01'));
 $firstday=date('Y-m-01',strtotime(date('Y',$timestamp).'-'.(date('m',$timestamp)-1).'-01'));
 $lastday=date('Y-m-d',strtotime("$firstday +1 month -1 day"));

 10.表单只读 表单隐藏

<?= $form->field($model, 'span_time')->textInput([ 'readonly' => 'true'])?> 

<?= $form->field($model, 'oldusername')->hiddenInput(['1'])->label(false); ?>

 

posted on 2017-09-11 14:15  coderWilson  阅读(117)  评论(0编辑  收藏  举报

导航