Adding a logo to an excel sheet using php excel

后端 未结 3 962
清酒与你
清酒与你 2021-01-05 15:55

I am trying to add a logo image on a generated excel worksheet using the code listing below but for some reason it does nothing

    $objReader = PHPExcel_IO         


        
3条回答
  •  余生分开走
    2021-01-05 16:35

    Use:

    setActiveSheetIndex(0)
            ->setCellValue('A1', 'Hello')
            ->setCellValue('B2', 'world!')
            ->setCellValue('C1', 'Hello')
            ->setCellValue('D2', 'world!');
    
    $objDrawing = new PHPExcel_Worksheet_Drawing();
    $objDrawing->setName('Logo');
    $objDrawing->setDescription('Logo');
    $logo = 'images/logo.png'; // Provide path to your logo file
    $objDrawing->setPath($logo);  //setOffsetY has no effect
    $objDrawing->setCoordinates('E1');
    $objDrawing->setHeight(200); // logo height
    $objDrawing->setWorksheet($excel->getActiveSheet()); 
    
    
    // Do your stuff here
    
    writer = PHPExcel_IOFactory::createWriter($excel, 'Excel5');
    
    // This line will force the file to download
    $writer->save('php://output');
    

提交回复
热议问题