From db4f4d76cc250865322bd16a1e3fc91c1e57b67b Mon Sep 17 00:00:00 2001 From: ptrnov Date: Mon, 6 Feb 2017 23:28:49 +0700 Subject: [PATCH] piter --- CHANGE.md | 12 ++++++++ Postman4ExcelBehavior.php | 61 ++++++++++++++++++++++++++++++++------- README.md | 6 ++-- 3 files changed, 65 insertions(+), 14 deletions(-) diff --git a/CHANGE.md b/CHANGE.md index 71f8652..5c787af 100644 --- a/CHANGE.md +++ b/CHANGE.md @@ -1,6 +1,18 @@ ```php Change Log: `yii2-postman4excel` =================================== + +## Version 2.4.5, +**Date:** 2017-02-06 +1. (chg): columnAutoSize +2. (chg): headerStyle width (columnAutoSize==false) +3. (enh): valign +4. (enh): Text Wrap + +## Version 2.4.4, +**Date:** 2016-10-06 +1. (bug): path custimize + ## Version 2.4.3, **Date:** 2016-08-18 1. (bug): containStyle diff --git a/Postman4ExcelBehavior.php b/Postman4ExcelBehavior.php index b818502..f057b5b 100644 --- a/Postman4ExcelBehavior.php +++ b/Postman4ExcelBehavior.php @@ -91,6 +91,8 @@ private static function getTypeExport($widgetType=''){ $folder_='tmp_download'; }elseif($folder=='CRONJOB'){ $folder_='tmp_cronjob'; + }elseif($folder=='CUSTOMPATH'){ + $folder_=''; }elseif($folder=='MAIL'){ $folder_='tmp_mail'; }else{ @@ -226,7 +228,7 @@ public function save4Excel($excel_content, $excel_file * --HEADER set sheet */ $current_sheet->setTitle(str_replace(array('/', '*', '?', '\\', ':', '[', ']'), array('_', '_', '_', '_', '_', '_', '_'), substr($each_sheet_content['sheet_name'], 0, 30))); //add by Scott - $current_sheet->getColumnDimension()->setAutoSize(true); //Scott, set column autosize + // $current_sheet->getColumnDimension()->setAutoSize(true); //Scott, set column autosize //set sheet's current title $_columnIndex = 'A'; @@ -270,7 +272,9 @@ public function save4Excel($excel_content, $excel_file } //Last Header-columnAutoSize //echo $autoSize; - $current_sheet->getColumnDimension($_columnIndex)->setAutoSize($autoSize=='true'?true:false); + // $current_sheet->getColumnDimension($_columnIndex)->setAutoSize($autoSize=='true'?true:false); + // $coltest=self::excelColumnName(count($each_sheet_content['sheet_title'][$y])); + // $current_sheet->getColumnDimension('F')->setWidth('120'); $_columnIndex++; @@ -313,11 +317,23 @@ public function save4Excel($excel_content, $excel_file //Compare Array headerColumnCssClass and Array sheet_title $tempStyle = $each_sheet_content["headerStyle"][$y][$each_sheet_content['sheet_title'][$y][$x]]; $tempColumn= self::excelColumnName($x+1) . ($y+1); //State range [[0]=>A1,[1]=>B1] + $tempColumnPosition= self::excelColumnName($x+1); - //column width - // if (isset($tempStyle["width"]) and $tempStyle['width']) { - // $current_sheet->getStyle($tempColumn)->setWidth($tempStyle["width"]); - // } + //col width + //update by : ptr.nov@gmail.com + //update at : 06/02/2017 + $current_sheet->getColumnDimension($_columnIndex)->setAutoSize($autoSize=='true'?true:false); + if (isset($tempStyle["width"]) and $tempStyle['width']) { + $current_sheet->getColumnDimension($tempColumnPosition)->setWidth($tempStyle['width']); + } + + //col Wrap text. + //update by : ptr.nov@gmail.com + //update at : 06/02/2017 + if (isset($tempStyle["wrap"]) and $tempStyle['wrap']) { + //$current_sheet->getColumnDimension($tempColumnPosition)->setTextWrap(true); + $current_sheet->getStyle($tempColumnPosition)->getAlignment()->setWrapText('true'); + } //color Merge ////$current_sheet->mergeCells('A1:B1'); @@ -330,6 +346,18 @@ public function save4Excel($excel_content, $excel_file $current_sheet->mergeCells($tempColumnMerge); } + //valign + if (isset($tempStyle["valign"]) and $tempStyle['valign']){ + $getvAligin=strtoupper($tempStyle["valign"]); + if ($getvAligin=='TOP'){ + $current_sheet->getStyle($tempColumnPosition)->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_TOP); + }elseif($getvAligin=='CENTER'){ + $current_sheet->getStyle($tempColumnPosition)->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER); + }elseif($getvAligin=='BOTTEM'){ + $current_sheet->getStyle($tempColumnPosition)->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_BOTTOM); + } + } + //align if (isset($tempStyle["align"]) and $tempStyle['align']){ $getAligin=strtoupper($tempStyle["align"]); @@ -342,7 +370,9 @@ public function save4Excel($excel_content, $excel_file }else{ $current_sheet->getStyle($tempColumn)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT); } - } + } + + //font color if (isset($tempStyle["color-font"]) and $tempStyle['color-font']){ @@ -354,7 +384,8 @@ public function save4Excel($excel_content, $excel_file $current_sheet->getStyle($tempColumn)->getFill()->getStartColor()->setRGB($tempStyle["color-background"]); $current_sheet->getStyle($tempColumn)->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID); } - + + } } @@ -457,7 +488,7 @@ public function save4Excel($excel_content, $excel_file $current_sheet->setCellValueByColumnAndRow($l, $row + $startRowContent, $each_sheet_content['ceils'][$row][$l]); //update@ptr.nov - $startRowContent -> mulai rows nilai data } //All column AutoSize, Not last Header more the one - $current_sheet->getColumnDimension($_columnIndex)->setAutoSize($autoSize=='true'?true:false); // + //$current_sheet->getColumnDimension($_columnIndex)->setAutoSize($autoSize=='true'?true:false); // $_columnIndex++; //all border content $current_sheet->getStyle($lineRange)->getBorders()->getAllBorders()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN); @@ -498,6 +529,14 @@ public function save4Excel($excel_content, $excel_file } } + //WrapText. + if (isset($tempStyleContent["wrap"]) and $tempStyleContent['wrap']){ + $getWrapContent=strtoupper($tempStyleContent["wrap"]); + if ($getAliginContent=='WRAP'){ + $current_sheet->getStyle($tempColumnContent)->getAlignment()->setWrapText(true); + } + } + //font color if (isset($tempStyleContent["color-font"]) and $tempStyleContent['color-font']){ $current_sheet->getStyle($tempColumnContent)->getFont()->getColor()->setARGB($tempStyleContent['color-font']); @@ -537,12 +576,12 @@ public function save4Excel($excel_content, $excel_file //$lastHeaderStyle =$each_sheet_content['sheet_title'][$xA][$colA]; //$lastHeaderStyle[] =$each_sheet_content["headerStyle"][$yA]; $lastHeaderColumn= self::excelColumnName($colA+1); - if($autoSize=='false'){ + /* if($autoSize=='false'){ if (isset($lastHeaderStyle["width"]) and $lastHeaderStyle['width']){ $current_sheet->getColumnDimension($lastHeaderColumn)->setWidth($lastHeaderStyle['width']); //$current_sheet->getColumnDimension($lastHeaderColumn)->setWidth('20'); } - } + } */ } } } diff --git a/README.md b/README.md index 7cf2eb5..f14c8df 100644 --- a/README.md +++ b/README.md @@ -75,7 +75,7 @@ Once the extension is installed, simply use it in your code by : $excel_content = [ [ - 'sheet_name' => 'TEST EXPORT 1', + 'sheet_name' => 'TEST EXPORT 1 old version', 'sheet_title' => $excel_title1, //old version 'ceils' => $excel_ceilsAll, //'freezePane' => 'E2', @@ -95,7 +95,7 @@ Once the extension is installed, simply use it in your code by : 'evenCssClass' => Postman4ExcelBehavior::getCssClass("even"), ], [ - 'sheet_name' => 'TEST EXPORT 2', + 'sheet_name' => 'TEST EXPORT 2 new version ', //'sheet_title' => [$excel_title1], //new version | one Header 'sheet_title' => [ //new version | two or more Header $excel_title1, @@ -115,7 +115,7 @@ Once the extension is installed, simply use it in your code by : 'headerStyle' => [ //new version [ //the first Header 'id' => ['align'=>'CENTER','color-font'=>'0000FF','color-background'=>'FFCCCC','merge'=>'0,2','width'=>'2,0'], - 'username' => ['align'=>'left','color-font'=>'FF0000','color-background'=>'CCFF99','merge'=>'2,1'], + 'username' => ['align'=>'left','color-font'=>'FF0000','color-background'=>'CCFF99','merge'=>'2,1','width'=>'32.29','valign'=>'center','wrap'=>true], ], [ //The second Header 'ID' => ['align'=>'right','color-font'=>'0000FF','color-background'=>'CCFFCC'],