Adding Image to the Excel in phpexcel in php
Specifying coordinates for the image might help, as per the examples and the documentation
$objDrawing->setCoordinates('A3');
Note that an image isn't in a cell/column/row, but overlaid over the main sheet at the same position as that cell/column/row
PHPSpreadsheet - How do i place a image from link into my excel file?
I got a solution for you. But unfortunately i couldn't find a way to use a url but an image localy. take a look.
require 'vendor/autoload.php';
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$drawing = new \PhpOffice\PhpSpreadsheet\Worksheet\Drawing();
$drawing->setName('Paid');
$drawing->setDescription('Paid');
$drawing->setPath('images/paid.png'); // put your path and image here
$drawing->setCoordinates('B15');
$drawing->setOffsetX(110);
$drawing->setRotation(25);
$drawing->getShadow()->setVisible(true);
$drawing->getShadow()->setDirection(45);
$drawing->setWorksheet($spreadsheet->getActiveSheet());
$writer = new Xlsx($spreadsheet);
$writer->save('image.xlsx');
It's working just fine, enjoy :)
PHPExcel: How do I insert an image to header/footer, using a template?
So I was able to replicate your issue and the only way I got it working was like this:
Change your template file to a 2007 style file and load:
$objPHPExcel = PHPExcel_IOFactory::load('template.xlsx');
Then I added the following to the header code:
$objPHPExcel->getActiveSheet()->getHeaderFooter()->addImage($objDrawing, PHPExcel_Worksheet_HeaderFooter::IMAGE_HEADER_LEFT);
$objPHPExcel->getActiveSheet()->getHeaderFooter()->setOddHeader('&L&G&');
I don't know why it doesn't automatically add that header info during the writer. But that comes from the big comment in the HeaderFooter file on GitHub - * &G - code for "picture as background"
. The &L
is code for the left section which seemed to be where you wanted it.
The docs or code also mention that if nothing is given for evenHeader
then setOddHeader
is assumed to be used everywhere and the result file seems to reflect that, it is on every page.
This only works when saving to 2007 style file, not sure if that is a bug in the library or what because saving through Excel works fine for the older format.
Let me know if that doesn't work for you and I can send you the working example I have.
Related Topics
Download a Facebook Video (.Mp4) Via PHP
How to Get Next Id of Autogenerated Field in Laravel for Specific Table
Update Data on a Page Without Refreshing
Curl (7): Failed to Connect to Localhost Port 8000: Connection Refused
General Error: 1364 Field 'User_Id' Doesn't Have a Default Value
How to Remove a Directory That Is Not Empty
How to Count Columns With the Same Value in a Specific Row in MySQL
How to Pass Variable Between Two Web Pages With PHP Without Using Session
Php Warning: Mysqli_Connect(): (Hy000/2002): Connection Refused
How to Get All Month Record Count in Laravel
Passing an Array to a Query Using a Where Clause
How to Add Auto Numbering With Each Fetching Row
How to Run a PHP Script in the Background After a Form Is Submitted
Check If Class Property Is Not Null Before Calling Any Public Class Method
What Is the Default Username and Password of Phpmyadmin
How to Parameterize the Table Name in a Prepared Statement