1: Method introduction
Export and insert pictures mainly use \PhpOffice\PhpSpreadsheet\Worksheet\Drawing
$drawing = new \PhpOffice\PhpSpreadsheet\Worksheet\Drawing(); $drawing->setName('Logo');//Set the picture name$drawing->setDescription('Logo');//Description of equipment picture$drawing->setPath('./images/');//Set the picture address$drawing->setHeight(36);//Set the image height$drawing->setCoordinates('A1');//Set the picture to draw to the specified cell$drawing->setWorksheet($spreadsheet->getActiveSheet());//Draw the picture to the worksheet
Two: Implementation example
$spreadsheet = new Spreadsheet();//Create a new excel document$sheet = $spreadsheet->getActiveSheet();//Get the object of the current operation sheet//Draw the image into excel$drawing = new \PhpOffice\PhpSpreadsheet\Worksheet\Drawing(); $drawing->setPath($img); $drawing->setHeight(50); $drawing->setCoordinates('A1'); $drawing->setWorksheet($sheet); $writer = new Xlsx($spreadsheet); $writer->save('');//Generate excel file//Draw multiple pictures into excel$spreadsheet = new Spreadsheet();//Create a new excel document$sheet = $spreadsheet->getActiveSheet();//Get the object of the current operation sheet//Draw the image into excelforeach ($imgs as $img) { $drawing = new \PhpOffice\PhpSpreadsheet\Worksheet\Drawing(); $drawing->setPath($img); $drawing->setHeight(50); $drawing->setCoordinates('A1'); $drawing->setWorksheet($sheet); } $writer = new Xlsx($spreadsheet); $writer->save('');//generateexceldocument
Three: Reference
Basic operation reference:https:///program/
Document address:/
Github address:/PHPOffice/PhpSpreadsheet
The above is the detailed content of php using phpoffice/phpspreadsheet to export image instances. For more information about phpoffice/phpspreadsheet to export images, please follow my other related articles!