PHPSpreadsheet - “PHPExcel_Worksheet_Drawing”在哪里
Posted
技术标签:
【中文标题】PHPSpreadsheet - “PHPExcel_Worksheet_Drawing”在哪里【英文标题】:PHPSpreadsheet - Where is "PHPExcel_Worksheet_Drawing" 【发布时间】:2018-06-15 18:35:30 【问题描述】:我对 PHPSpreadsheet 真的很疯狂,为什么这些函数没有在 PHPExcel 中命名,或者为什么文档中没有提到关于“PHPExcel_Worksheet_Drawing”的内容,我在 PHPSpreadsheet 哪里可以找到它?
在 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());
现在,我该如何实现?
【问题讨论】:
您在两个不同的库中进行比较,请参阅:Migration file 或 Drawing object 文件本身或 Documentation 我尝试运行 Migration exec,但所有类名都出错了 "class \PHPOffice\Worksheets\Drawing" 这是一个语法错误。 您使用的是什么版本的 PHP?在 PHP 5.5 中添加了::class
常量
PHP FPM 7......
【参考方案1】:
嗯,我的答案是找到每个类来“匹配”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");
诀窍是,必须在每个 PHPExcel_* 类中找到与 PHPSpreadsheet 文件匹配的函数名称,这就是我实现这一目标的方法。注意https://phpspreadsheet.readthedocs.io/en/develop/topics/migration-from-PHPExcel/#migration-from-phpexcel,那个比较表。
我希望这会有用。
【讨论】:
以上是关于PHPSpreadsheet - “PHPExcel_Worksheet_Drawing”在哪里的主要内容,如果未能解决你的问题,请参考以下文章