4

I want to copy cells styles to an array and than use

$arr = array();
$arr[] = $PHPExcel->getActiveSheet()->getStyle('A1');
$arr[] = $PHPExcel->getActiveSheet()->getStyle('B1');
$arr[] = $PHPExcel->getActiveSheet()->getStyle('C1');

//do smth .... 

$PHPExcel->getActiveSheet()->duplicateStyle($arr[0],'A2');
$PHPExcel->getActiveSheet()->duplicateStyle($arr[1],'B2');
$PHPExcel->getActiveSheet()->duplicateStyle($arr[2],'C2');

But all cells A2,B2,C2 get the same style as C1. What's wrong?

ImClarky
  • 1,933
  • 1
  • 25
  • 29
KDI
  • 81
  • 1
  • 7

1 Answers1

1

Solution 1: Please use the latest version of PHPExcel from github

Solution 2: Manually apply fix to the duplicateStyle() method in Classes/PHPExcel/Worksheet.php from:

if ($this->_parent->cellXfExists($pCellStyle)) {
    // there is already this cell Xf in our collection
    $xfIndex = $pCellStyle->getIndex();
} else {
    // we don't have such a cell Xf, need to add
    $workbook->addCellXf($pCellStyle);
    $xfIndex = $pCellStyle->getIndex();
}

change to:

if ($existingStyle = $this->_parent->getCellXfByHashCode($pCellStyle-
>getHashCode())) {
    // there is already such cell Xf in our collection
    $xfIndex = $existingStyle->getIndex();
} else {
    // we don't have such a cell Xf, need to add
    $workbook->addCellXf($pCellStyle);
    $xfIndex = $pCellStyle->getIndex();
}
The Anh Nguyen
  • 748
  • 2
  • 11
  • 27