使用PHPExcel导出Excel多个图像

时间:2014-04-29 13:26:53

标签: phpexcel

我希望使用PHPExcel从php导出excel。我的Excel包含多个图像,但只能查看一个图像。我如何查看其他图像?这是我的代码

    $objDrawing = new PHPExcel_Worksheet_Drawing();
    $objDrawing->setName("name");
    $objDrawing->setDescription("Description");

    $objDrawing->setWorksheet($objPHPExcel->getActiveSheet());

    $logo = "application/views/templates/default/img/Mutiara.jpg";
    $objDrawing->setPath($logo);
    $objDrawing->setHeight(96);     
            $objDrawing->setCoordinates('A1');
            $objDrawing->setCoordinates('H1');

2 个答案:

答案 0 :(得分:0)

单个绘图对象只能有一个坐标;所以取一个绘图对象并将坐标设置为A1,然后再将其设置为H1仍然只是一个绘图对象。

创建绘图对象并设置其主要属性后,克隆它以便拥有多个副本,每个副本都可以设置为不同的坐标

$objDrawing = new PHPExcel_Worksheet_Drawing();
$objDrawing->setName("name");
$objDrawing->setDescription("Description");

$objDrawing->setWorksheet($objPHPExcel->getActiveSheet());

$logo = "application/views/templates/default/img/Mutiara.jpg";
$objDrawing->setPath($logo);
$objDrawing->setHeight(96);     
$objDrawing->setCoordinates('A1');

$objDrawing2 = clone $objDrawing;
$objDrawing2->setCoordinates('H1');

答案 1 :(得分:0)

$assign = $line; 
$objDrawing = new PHPExcel_Worksheet_Drawing();
$objDrawing->setWorksheet($objPHPExcel->getActiveSheet());
$objDrawing->setPath('application/views/templates/default/img/Mutiara.jpg');
$objDrawing->setCoordinates('A'.$assign.'');
$objDrawing2 = new PHPExcel_Worksheet_Drawing();
$objDrawing2->setWorksheet($objPHPExcel->getActiveSheet());
$objDrawing2->setPath('application/views/templates/default/img/Mutiara.jpg');
$objDrawing2->setCoordinates('H'.$assign.'');