PHPExcel_Style_Fill infinite recursion
Yo uso la bibliotecaPHPExcel 1.7.9
trabajar conExcel
archivos. Primero, creo una plantilla, la estilizo y la lustro. Luego, para evitar el código de estilo, utilizando la biblioteca mencionada anteriormente, abro esa plantilla, cambio algunos valores y los guardo como un nuevo.xlsx
expediente.
Primero, buscamos ese estilo desde las celdas.
$this->styles = array() ;
$this->styles['category'] = $sheet->getStyle("A4");
$this->styles['subcategory'] = $sheet->getStyle("A5");
Aquí está la función recursiva, que muestra categorías y subcategorías.
private function displayCategories($categories, &$row, $level = 0){
$sheet = $this->content ;
foreach($categories as $category){
if ($category->hasChildren() || $category->hasItems()){ //Check if the row has changed.
$sheet->getRowDimension($row)->setRowHeight(20);
$sheet->mergeCells(Cell::NUMBER . $row . ":" . Cell::TOTAL . $row) ;
$name = ($level == 0) ? strtoupper($category->name) : str_repeat(" ", $level*6) ."- {$category->name}" ;
$sheet->setCellValue(Cell::NUMBER . $row, $name) ;
$sheet->duplicateStyle((($level == 0) ? $this->styles['category'] : $this->styles['subcategory']), Cell::NUMBER . $row);
$row++ ;
if ($category->hasChildren()){
$this->displayCategories($category->children, $row, $level+1);
}
}
}
}
El problema
Si$sheet->duplicateStyle()
se utiliza, será imposible guardar el documento debido a la recursión infinita.
Se alcanzó el máximo nivel de anidamiento de la función de '200', ¡abortando! <- ERROR FATAL
El problema está en la siguiente pieza de código, dentro dePHPExcel_Style_Fill
clase, un objeto se refiere a sí mismo una y otra vez.
public function getHashCode() { //class PHPExcel_Style_Fill
if ($this->_isSupervisor) {
var_dump($this === $this->getSharedComponent()); //Always true 200 times
return $this->getSharedComponent()->getHashCode();
}
return md5(
$this->getFillType()
. $this->getRotation()
. $this->getStartColor()->getHashCode()
. $this->getEndColor()->getHashCode()
. __CLASS__
);
}
¿Hay alguna solución para resolver esto? También aceptaría cualquier idea sobre cómo aplicar un estilo completo de una celda a otra.
Solución:
Como dijo @MarkBaker en comentarios, ramadevelop
en GitHub realmente contiene correcciones al error.