Home > Backend Development > PHP Tutorial > PHPExcel无法加入图片

PHPExcel无法加入图片

WBOY
Release: 2016-06-13 11:59:28
Original
2192 people have browsed it

求助:PHPExcel无法加入图片
$objPHPExcel = new PHPExcel();

$objDrawing = new PHPExcel_Worksheet_Drawing(); 
$objPHPExcel->setActiveSheetIndex(0);
$objDrawing->setPath('D:\wwwroot\user\upimg\201460dZeETjg_1.jpg');
$objDrawing->setCoordinates("A1");
$objDrawing->setWorksheet($objPHPExcel->getActiveSheet());


返回错误:Fatal error: Uncaught exception 'PHPExcel_Exception' with message 'A PHPExcel_Worksheet has already been assigned. Drawings can only exist on one PHPExcel_Worksheet.' in D:\wwwroot\user\upimg\Classes\PHPExcel\Worksheet\BaseDrawing.php:240 Stack trace: #0 D:\wwwroot\user\upimg\xls.php(71): PHPExcel_Worksheet_BaseDrawing->setWorksheet(Object(PHPExcel_Worksheet)) #1 {main} thrown in D:\wwwroot\user\upimg\Classes\PHPExcel\Worksheet\BaseDrawing.php on line 240
------解决方案--------------------
对呀!
你的 $objDrawing = new PHPExcel_Worksheet_Drawing();  在循环外面
而 $objDrawing->setWorksheet($objPHPExcel->getActiveSheet()); 在循环里面
你如何能保证 $objDrawing = new PHPExcel_Worksheet_Drawing(); 只被这行一次呢?
虽然是套在条件分支中的,你有如何能保证条件只成立一次呢?

你只需把 $objDrawing = new PHPExcel_Worksheet_Drawing(); 放到循环里面,一切都解决了

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template