首页 > 解决方案 > 如何使用 phpexcel 库在 excel 中嵌入(插入对象)文档?

问题描述

我可以使用 MS Excel手动嵌入文档(插入 -> 对象 -> 从文件创建) 。请参考图片。

https://thewindowsclub-thewindowsclubco.netdna-ssl.com/wp-content/uploads/2016/08/select-format-option.png

如何通过 PHPExcel 或任何其他 PHP 库来实现这一点?

标签: phpphpexcel

解决方案


首先,你应该使用phpspreadsheet,phpexcel已经被它取代了。我在我的 phpspreadsheet 安装的子目录 /templates/sampleSpreadsheet.php 中找到了这段代码。您可能会在 phpexcel 安装中找到它?

    // Add a drawing to the worksheet
$helper->log('Add a drawing to the worksheet');
$drawing = new Drawing();
$drawing->setName('PhpSpreadsheet logo');
$drawing->setDescription('PhpSpreadsheet logo');
$drawing->setPath(__DIR__ . '/images/PhpSpreadsheet_logo.png');
$drawing->setHeight(36);
$drawing->setCoordinates('D24');
$drawing->setOffsetX(10);
$drawing->setWorksheet($spreadsheet->getActiveSheet());

推荐阅读