我真的是 PHPSpreadsheet 上的 mad ,以及为什么函数没有在 PHPExcel 中命名,或者为什么在文档中没有提到“ PHPExcel_Worksheet_Drawing ”,我可以在哪里找到它? 。

PHPExcel 中,我有以下内容:

$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());

现在,我该如何实现呢?

最佳答案

好吧,对我来说,答案是发现每个类都可以“匹配” 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

然后我的代码:
$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());

就是现在:
$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");

诀窍是,必须在每个与PHPSpreadsheet文件匹配的PHPExcel_ *类中查找函数名称,这就是我实现此目标的方法。请注意https://phpspreadsheet.readthedocs.io/en/develop/topics/migration-from-PHPExcel/#migration-from-phpexcel,即比较表。

我希望这会有所帮助。

关于phpexcel - PHPSpreadsheet- "PHPExcel_Worksheet_Drawing"在哪里,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/48122220/

10-13 07:43