我正在尝试将Yii2中的图像插入导出的Excel中;
这是代码:
<?php
$logo = Html::img("@web/img/Logo.jpg", ['width' => '60px', 'height' => '50px', 'margin-top' => '-10px']);
$downloadedTime = $downloadTZ->format('Y-m-d');
$bulan = \Yii::t('app', $month);
$filename = 'Report'.'xls';
header("Content-Disposition: attachment; filename=\"" . $filename . "\"");
header("Pragma: no-cache");
header("Expires: 0");
header("Content-Type: application/force-download");
header("refresh:0;url=../master/index");
echo $logo;
echo "Name\t";
echo "Class\t";
echo "Age\t";
echo "\r\n";
?>
如果我echo $logo;
在浏览器中打印,但是在Excel中它将打印代码而不是图像,就像这样
为什么会这样?以及我该如何解决呢?
谢谢
答案 0 :(得分:0)
我使用PHPExcel类,然后调用PHPExcel_Worksheet_Drawing;
$objPHPExcel = new PHPExcel();
$objPHPExcel->setActiveSheetIndex(0);
$objDrawing = new PHPExcel_Worksheet_Drawing();
$objDrawing->setName('Logo');
$objDrawing->setDescription('Logo');
$objDrawing->setPath('img/logo.png');
$objDrawing->setCoordinates('A1');
$objDrawing->setWorksheet($objPHPExcel->getActiveSheet());
像这样