PHPSpreadsheet - "PHPExcel_Worksheet_Drawing" 在哪里
PHPSpreadsheet - Where is "PHPExcel_Worksheet_Drawing"
我真的 mad PHPSpreadsheet,为什么函数没有像 PHPExcel[=25] 那样命名=],或者为什么在文档中没有提到关于“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());
现在,我怎样才能实现?
好吧,我的答案是找到每个 class 到 "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
然后我的代码:
$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_* class 中找到与 PHPSpreadsheet 文件匹配的函数名称,这就是我实现这一点的方法。注意 https://phpspreadsheet.readthedocs.io/en/develop/topics/migration-from-PHPExcel/#migration-from-phpexcel ,比较 table.
希望对您有所帮助。
我真的 mad PHPSpreadsheet,为什么函数没有像 PHPExcel[=25] 那样命名=],或者为什么在文档中没有提到关于“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());
现在,我怎样才能实现?
好吧,我的答案是找到每个 class 到 "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
然后我的代码:
$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_* class 中找到与 PHPSpreadsheet 文件匹配的函数名称,这就是我实现这一点的方法。注意 https://phpspreadsheet.readthedocs.io/en/develop/topics/migration-from-PHPExcel/#migration-from-phpexcel ,比较 table.
希望对您有所帮助。