Skip to content
This repository has been archived by the owner on Jan 2, 2019. It is now read-only.

1+1 = 10 #257

Closed
samuelgmartins opened this issue Oct 17, 2013 · 3 comments
Closed

1+1 = 10 #257

samuelgmartins opened this issue Oct 17, 2013 · 3 comments
Milestone

Comments

@samuelgmartins
Copy link

$objPHPExcel->getActiveSheet()->setCellValue('A1', 'Teste 1')
                              ->setCellValue('B1', '=2*5')
                              ->setCellValue('C1', '=1+1');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'HTML');
$objWriter->save('php://output');

returns
Teste 1 10 10


The problem is in the cache control when writing HTML.
The function getCoordinate() returns the last location in the cache (_currentObjectID) and not the current cell.
I managed to solve the function "_genererateRow" in "Writer/HTML.php" line in 1112, but this is not the ultimate solution.

// Write cells
$colNum = 0;
foreach ($pValues as $cell) {
                $pSheet->getCellByColumnAndRow($colNum, $pRow);
@eplaut
Copy link

eplaut commented Dec 5, 2013

Hi,

done some research here.
The problem is cell->getCoordinate() using the cache, which is shared to all cells (it is actually part of $cell->_parent which is the worksheet itself)
meaning while generating the rows cell (Writer_HTML:430-436) the "pointer" of the current row is progressing to the last cell in the row. later (at Writer_HTML->_generateRow()) when trying $cell->getCalculateValue() (line 1174) it always get the calculate value from the last cell.

there are two solutions:

  1. BAD ONE: for each cell on the constructor set $this->_parent as clone of the instance $parent. (will take a lot of memory, and will lose the ability of really get to the parent).
  2. GOOD ONE: set the coordinate of the cell as new private parameter, and change getCoordinate/Row/Column (and maybe some more functions) to read from that parameter.

Please add your input.

Thanks,
Eli

@eplaut eplaut mentioned this issue Dec 8, 2013
@MarkBaker
Copy link
Member

I've taken the approach of passing an array of cell addresses to the _generateRow() method rather than an array of cells, and selecting each cell within _generateRow() which eliminates this issue.

MarkBaker pushed a commit that referenced this issue Dec 28, 2013
…) in the HTML/PDF Writer causes caching problems with last cell in the range
@MarkBaker
Copy link
Member

Thanks for the investigation work @eplaut

@Progi1984 Progi1984 added this to the 1.8.0 milestone Aug 14, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants