Skip to content

Commit

Permalink
piter
Browse files Browse the repository at this point in the history
  • Loading branch information
ptrnov committed Feb 6, 2017
1 parent b5de034 commit db4f4d7
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 14 deletions.
12 changes: 12 additions & 0 deletions CHANGE.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
61 changes: 50 additions & 11 deletions Postman4ExcelBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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';

Expand Down Expand Up @@ -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++;


Expand Down Expand Up @@ -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 : [email protected]
//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 : [email protected]
//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');
Expand All @@ -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"]);
Expand All @@ -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']){
Expand All @@ -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);
}




}
}
Expand Down Expand Up @@ -457,7 +488,7 @@ public function save4Excel($excel_content, $excel_file
$current_sheet->setCellValueByColumnAndRow($l, $row + $startRowContent, $each_sheet_content['ceils'][$row][$l]); //[email protected] - $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);
Expand Down Expand Up @@ -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']);
Expand Down Expand Up @@ -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');
}
}
} */
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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,
Expand All @@ -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'],
Expand Down

0 comments on commit db4f4d7

Please sign in to comment.