Here is an idea:
You need to determine the maximum width / height (by experimenting). Save the values.
$maxWidth = 700;
$maxHeight = 40;
Here is the rest of the code:
$objDrawing = new PHPExcel_Worksheet_Drawing();
$objDrawing->setWorksheet($objPHPExcel->getActiveSheet());
$objDrawing->setName("Logo");
$objDrawing->setDescription("Company Logo");
$objDrawing->setPath('logo.png');
$objDrawing->setCoordinates('A1');
$objDrawing->setHeight($maxHeight);
$offsetX =$maxWidth - $objDrawing->getWidth();
$objDrawing->setOffsetX($offsetX);
Hope this helps.
source
share