Skip to content

Commit

Permalink
piter
Browse files Browse the repository at this point in the history
  • Loading branch information
ptrnov committed Aug 11, 2016
1 parent 19ba2be commit 7affb4c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 22 deletions.
50 changes: 29 additions & 21 deletions Postman4ExcelBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,40 +212,45 @@ public function save4Excel($excel_content, $excel_file
$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
//set sheet's current title
$_columnIndex = 'A';
$_columnIndex = 'A';


/*
* --HEADER sheet_title
*/
if (array_key_exists('sheet_title', $each_sheet_content) && !empty($each_sheet_content['sheet_title'])) {
if(self::is_multidim_array($each_sheet_content['sheet_title'])==true){ //validation array multi
/*
* MULTI ARRAY - new version
* 'sheet_title' =>[$excel_title1],
* @author ptrnov [[email protected]]
* @since 1.1.0
*/
/*
* MULTI ARRAY - new version
* 'sheet_title' =>[$excel_title1],
* @author ptrnov [[email protected]]
* @since 1.1.0
*/
if(self::is_multidim_array($each_sheet_content['sheet_title'])==true){ //validation array multi
//print_r(count($each_sheet_content['sheet_title']));
$cnt_sheet_title = count($each_sheet_content['sheet_title']); // count rows of header title
$startRowContent=$cnt_sheet_title+1; // start rows of ceils content
$startRowContent=$cnt_sheet_title+1; // start rows of ceils content

//sheet_title -> one or more header state
for ($y = 0; $y < $cnt_sheet_title; $y++) { //Count Array sheet_title
//print_r([count($each_sheet_content['sheet_title'][$y])]);
for ($x = 0; $x < count($each_sheet_content['sheet_title'][$y]); $x++) { //Count sub Array sheet_title by [$y]
//Header data value- sheet_title value and state position
//$current_sheet->setCellValueByColumnAndRow($j, 1, $each_sheet_content['sheet_title'][$j]); //old
//$lineRange = "A" . $y. ":" . self::excelColumnName(count($each_sheet_content['sheet_title'][$y][$x])) . $y; //add sub Array | $y=row title
//$current_sheet->setSharedStyle($style_obj, $lineRange); //set php excel
//Header data value

//$lineRange = "A1:" . self::excelColumnName(count($each_sheet_content['sheet_title'][$y][$x])) . count($each_sheet_content['sheet_title']);
//$current_sheet->setSharedStyle($style_obj, $lineRange);



$current_sheet->setCellValueByColumnAndRow($x, $y+1, $each_sheet_content['sheet_title'][$y][$x]); //put value on [startCrm, row=$y+1; Endcolumn).



//$lineRange = "A1:" . "B" . '2'; //state range [col.row:col.row ]
$lineRange = "A" . ($y+1) . ":" . self::excelColumnName(count($each_sheet_content['sheet_title'][$y])) . ($y+1);
$current_sheet->setSharedStyle($style_obj, $lineRange);

if (array_key_exists('headerColor', $each_sheet_content) && is_array($each_sheet_content['headerColor']) and !empty($each_sheet_content['headerColor'])) {
if (isset($each_sheet_content['headerColor']["color"]) and $each_sheet_content['headerColor']['color'])
$current_sheet->getStyle($lineRange)->getFont()->getColor()->setARGB($each_sheet_content['headerColor']['color']);
//background
if (isset($each_sheet_content['headerColor']["background"]) and $each_sheet_content['headerColor']['background']) {
$current_sheet->getStyle($lineRange)->getFill()->getStartColor()->setRGB($each_sheet_content['headerColor']["background"]);
$current_sheet->getStyle($lineRange)->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
}
}


//start handle hearder column css
Expand Down Expand Up @@ -278,8 +283,10 @@ public function save4Excel($excel_content, $excel_file
/*
* SINGLE ARRAY - old version
* 'sheet_title' =>$excel_title1,
* @author ptrnov [ptr.nov@gmail.com]
* @author scotthuangzl - Scott Huang [zhiliang.huang@gmail.com]
* @since 1.0.0
* @update ptrnov [[email protected]]
* @since 1.0.1
*/
$startRowContent=2;
$lineRange = "A1:" . self::excelColumnName(count($each_sheet_content['sheet_title'])) . "1";
Expand Down Expand Up @@ -525,6 +532,7 @@ private static function openDataFile($file_name='',$file_type='excel',$deleteAft
* Example: $excel_title = ['ID','USERNAME','TEST1','TEST2','TEST3','TEST4'];
* 'sheet_title' =>$excel_title // is single Array
* 'sheet_title' =>[$excel_title] // is Multi-dimensional arrays
* http://stackoverflow.com/questions/9678290/check-if-an-array-is-multi-dimensional
*/
private static function is_multidim_array($arr) {
if (!is_array($arr))
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ Once the extension is installed, simply use it in your code by :
//'sheet_title' => [$excel_title1,$excel_title2], //new version
'ceils' => $excel_ceilsAll,
//'freezePane' => 'E2',
'headerColor' => Postman4ExcelBehavior::getCssClass("header"),
'headerColor' => Postman4ExcelBehavior::getCssClass("header"), //All Header Color font and Backgroud
'headerColumnCssClass' => [
'id' => Postman4ExcelBehavior::getCssClass('header'),
'username' => Postman4ExcelBehavior::getCssClass('header'),
Expand Down

0 comments on commit 7affb4c

Please sign in to comment.