简体   繁体   中英

Fit one image into a cell (Excel) without overflow Phpspreadsheet

How can I put an image into a cell without overflowing other cells using phpspreadsheet? Purpose is to fit many images on one column in an Excel file.

use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;

$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();

$drawing = new \PhpOffice\PhpSpreadsheet\Worksheet\Drawing();
$drawing->setPath('ImageLAN/twitter.png'); 
$drawing->setCoordinates('A1');
$drawing->setWidth(100);
$drawing->setHeight(100);

$drawing->setWorksheet($spreadsheet->getActiveSheet());

$writer = new Xlsx($spreadsheet);
$writer->save('image.xlsx');

Rendering of the above code

Thank you !

I've found a solution actually if your images presume to be all the same size you can simply resize your cells the size you want by doing this:

$spreadsheet->getActiveSheet()->getColumnDimension('A')->setWidth(60); $spreadsheet->getActiveSheet()->getRowDimension('1')->setRowHeight(310);

Then your images size:

$drawing->setWidth(400); $drawing->setHeight(400);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM