代码之家  ›  专栏  ›  技术社区  ›  Máxima Alekz

PHPSReadSheet-其中是“PHPExcel\u Worksheet\u Drawing”

  •  5
  • Máxima Alekz  · 技术社区  · 6 年前

    我真的 PHPSReadSheet ,以及为什么函数未命名为 PHPExcel公司 或者为什么在文档中没有提及“的内容” PHPExcel_工作表_绘图 “,我在哪里可以找到它 PHPSReadSheet ?.

    在里面 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());
    

    现在,我怎么能 实现 那个

    1 回复  |  直到 6 年前
        1
  •  10
  •   Máxima Alekz    6 年前

    好吧,我的答案是找到每个类“匹配”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_*类中找到与PHPSReadSheet文件匹配的函数名,这就是我实现这一点的方法。注意 https://phpspreadsheet.readthedocs.io/en/develop/topics/migration-from-PHPExcel/#migration-from-phpexcel ,即比较表。

    我希望这会有用。