Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHPSpreadsheet - Where is "PHPExcel_Worksheet_Drawing"

I am really mad at PHPSpreadsheet, and why the functions are not named as in PHPExcel, or why in documentation doesn't mention something about "PHPExcel_Worksheet_Drawing", where can I find it in PHPSpreadsheet?.

In PHPExcel I have this:

$objDrawing = new PHPExcel_Worksheet_Drawing();
$objDrawing->setName('Logo');
$objDrawing->setDescription('Logo');
$objDrawing->setPath(Sys::$_R["images"].'logo_med.png');
$objDrawing->setHeight(110);
$objDrawing->setWorksheet($objPHPExcel->getActiveSheet());

Now, how can I achieve that?

like image 920
Máxima Alekz Avatar asked Jan 05 '18 22:01

Máxima Alekz


1 Answers

Well, the answer for me was find every class to "match" PHPExcel-PHPSpreadsheet..

require_once 'path/to/vendor/autoload.php';

use PhpOffice\PhpSpreadsheet\Spreadsheet as spreadsheet; // instead PHPExcel
use PhpOffice\PhpSpreadsheet\Writer\Xlsx as xlsx; // Instead PHPExcel_Writer_Excel2007
use PhpOffice\PhpSpreadsheet\Worksheet\Drawing as drawing; // Instead PHPExcel_Worksheet_Drawing
use PhpOffice\PhpSpreadsheet\Style\Alignment as alignment; // Instead PHPExcel_Style_Alignment
use PhpOffice\PhpSpreadsheet\Style\Fill as fill; // Instead PHPExcel_Style_Fill
use PhpOffice\PhpSpreadsheet\Style\Color as color_; //Instead PHPExcel_Style_Color
use PhpOffice\PhpSpreadsheet\Worksheet\PageSetup as pagesetup; // Instead PHPExcel_Worksheet_PageSetup
use PhpOffice\PhpSpreadsheet\IOFactory as io_factory; // Instead PHPExcel_IOFactory

Then my code:

$objDrawing = new PHPExcel_Worksheet_Drawing();
$objDrawing->setName('Logo');
$objDrawing->setDescription('Logo');
$objDrawing->setPath(Sys::$_R["images"].'logo_med.png');
$objDrawing->setHeight(110);
$objDrawing->setWorksheet($objPHPExcel->getActiveSheet());

Is now:

$objPHPExcel = new spreadsheet();
...
$objDrawing = new drawing();
$objDrawing->setName('Logo');
$objDrawing->setDescription('Logo');
$objDrawing->setPath(Sys::$_R["images"].'logo_med.png');
$objDrawing->setHeight(110);
$objDrawing->setWorksheet($objPHPExcel->getActiveSheet());
...
$objWriter = io_factory::createWriter($objPHPExcel, 'Xlsx');
$objWriter->save("route/to/save/file.xlsx");

The trick was, that have to find function names in every PHPExcel_* class that match with PHPSpreadsheet files, and that's how I achieved this. Take care about https://phpspreadsheet.readthedocs.io/en/develop/topics/migration-from-PHPExcel/#migration-from-phpexcel , that comparing table.

I hope this will be useful.

like image 98
Máxima Alekz Avatar answered Nov 17 '22 01:11

Máxima Alekz