user3928276
user3928276

Reputation: 21

Cannot insert images using PHPExcel & Codeigniter

i have some problem in this part. There is no exported images in worksheet.

$objDrawing = new PHPExcel_Worksheet_Drawing();
              $objDrawing->setName("logo_sci");
              $objDrawing->setDescription("logo_sci");
              $objDrawing->setPath('./assets/images/sucofindo_logo.PNG');
              $objDrawing->setCoordinates('C6');
              $objDrawing->setHeight(120); 
              $objDrawing->setWidth(120);
              $objDrawing->setWorksheet($objPHPExcel->getActiveSheet());

need help! Thanks..

Upvotes: 2

Views: 5556

Answers (1)

Adrian P.
Adrian P.

Reputation: 5228

This code works for me:

    if (file_exists('includes/temp/signatures/'.$id.'.jpg')) {
        $objDrawing = new PHPExcel_Worksheet_Drawing();
        $objDrawing->setName('Customer Signature');
        $objDrawing->setDescription('Customer Signature');
        //Path to signature .jpg file
        $signature = FCPATH.'/includes/temp/signatures/'.$id.'.jpg';    
        $objDrawing->setPath($signature);
        $objDrawing->setOffsetX(8);                     //setOffsetX works properly
        $objDrawing->setCoordinates('E38');             //set image to cell E38
        $objDrawing->setHeight(75);                     //signature height  
        $objDrawing->setWorksheet($this->excel->getActiveSheet());  //save      
    }

As you can see all is different from your code is the setPath(). Needs to be root path to your file

Note: I'm using PHPExcel as a library of Codeigniter. See here how: http://fally.ro/using-phpexcel-class-with-codeigniter/

Upvotes: 2

Related Questions