Style Bug in PHP Excel (1.7.x) on batch

Topics: Developer Forum, User Forum
Dec 15, 2010 at 8:13 AM


I have the Problem that if I process more then one excel file in one process to html then the styles will be wrong.

I do like this:

class grid_xml2xls extends PHPExcel
 ... read xml and write into phpexcel


class report()
 public function html() # html writer
  $xls = & new grid_xml2xls($this->xml_grid(true));

$r1 = new report('x');

$r2 = new report('y');

Inside grid_xml2xls:

I'm parsing a xml file an I store style definitions in an array. (a file can have 27.000 rows and 40 cols and many styles)

        self::$used_styles[$used_styles_idX] = $this->sheet->getCell($current_col_cel)->getXfIndex(); // returns integer e.g. 5

the first html and style will be correct, but the second style will be wrong. There are elements from the first run (report) inside.

        self::$used_styles[$used_styles_idX] = $current_col_cel; # remember the first cell with this style
        $this->sheet->duplicateStyle($this->sheet->getStyle(self::$used_styles[$used_styles_idX]), $current_col_cel);

this will be slower, but the styles are more correct, but not fine. Some styles will be wrong, too

Is there any caching/store/static array where phpexcel store the style information over the lifetime of an object?

I'm using 1.7.4 and now 1.7.5 with the same behavior.

I hope anywhere can help me, to solve this problem?




Dec 15, 2010 at 10:53 PM

All workbook styling should be maintained within the individual PHPExcel object, so there can be an XFIndex with a value of 5 in each PHPExcel object, and these can refer to different styles. Because each PHPExcel object is an autonomous object, this doesn't matter. However, you're using a static array (self::$used_styles) to maintain the styles, so the XFIndex of 5 read from one PHPExcel object can overwrite the XFIndex of 5 read from another within that array.

Dec 16, 2010 at 7:24 AM

Hello Mark,

thanks for your fast response, yes thats true. I found the bug in my skript, there was a status flag in a function that was static.