Problem with image in a cycle. Error 'Must Not Be Cell Coordinate absolute'

Topics: Developer Forum, Project Management Forum, User Forum
May 23, 2011 at 3:04 AM

Hello. 
Sorry for my bad English. 
I have the following problem. 
I'm reading a file excel2007, and then in writing a table from a MySQL database. 
This is achieved through a cycle, and then filled each cell with a call by a variable. For example 
 

 

$ObjPHPExcel-> getActiveSheet () -> setCellValue ("A$cont", "any value");

Here,  all ok. The problem is that each row has an associated image. 

If filled with a fixed value, no problem. For example: 

$ObjDrawing PHPExcel_Worksheet_Drawing = new ();
$ObjDrawing-> setName ('photo$cont')
$ObjDrawing-> setDescription ('photo$cont')
$ObjDrawing-> setPath ($myphoto)
$ObjDrawing-> setCoordinates ('N9');
$ObjDrawing-> setHeight (80);
$ObjDrawing-> setWorksheet ($ objPHPExcel-> getActiveSheet());

If I use a variable to fill in the cycle, as follows: 

$ObjDrawing PHPExcel_Worksheet_Drawing = new ();
$ObjDrawing-> setName ('photo$cont');
$ObjDrawing-> setDescription ('photo$cont');
$ObjDrawing-> setPath ($myfoto);
$ObjDrawing-> setCoordinates ('N$cont');
$ObjDrawing-> setHeight (80);
$ObjDrawing-> setWorksheet ($objPHPExcel-> getActiveSheet ());


I get the following error. 

 

Fatal error: Uncaught exception 'Exception' with message 'Cell coordinate must not be absolute.' in 
C:\wamp\www\Tests\PHPExcel\Worksheet.php:935 Stack trace: #0 C:\wamp\www\Tests\PHPExcel\Worksheet\BaseDrawing.php(222): 
PHPExcel_Worksheet->getCell('N$cont') #1 C:\wamp\www\Tests\fichageneradaNF0311.php(114): PHPExcel_Worksheet_BaseDrawing->setWorksheet(Object(PHPExcel_Worksheet)) #2 {main} 
thrown inC:\wamp\www\Tests\PHPExcel\Worksheet.php on line 935


Any idea how to solve? 
There is another way to fill the table with the images in a cycle? 

Thanks for all the help. 

May 23, 2011 at 8:50 PM

I wrote my own image component, it uses the built in work sheet iterators. This function:

protected function row_range($initial_row){
      if($this->next_row !== null && $this->initial_row !== null) return $this->next_row - $this->initial_row;
       
       $this->initial_row = $this->next_row = $initial_row instanceof PHPExcel_Worksheet_Row? $initial_row->getRowIndex():$initial_row;
        $height = $this->data->height;
       while($height >= 0 ){
         $row_dimension = self::$sheet->getRowDimension();
         $row_height = ($row_dimension->getRowHeight() === -1)? 20:$row_dimension->getRowHeight();
         $height -= $row_height;
         $this->next_row++;
        
       }
      
      return $this->next_row - $this->initial_row;
  }

will tell you the amount of rows the image is taking up. From there you should be able to figure out where to put the next image. You'll have to tweak it a bit because it's inside a class i have, and I'm on php 5.3.6.

Coordinator
May 24, 2011 at 8:57 PM
Edited May 24, 2011 at 8:58 PM

Assuming $cont is a PHP variable, then PHP quoted string rules apply:

'N$cont' (within single quotes) is a string containing the characters N, $, c, o, n and t

"N$cont" (in double quotes) will be interpreted as a string containing N and the value of the $cont variable