Phpexcel Cannot add images

Source: Internet
Author: User
Help: Phpexcel Unable to add image
$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 ());


Return Error: Fatal error:uncaught exception ' phpexcel_exception ' with message ' A Phpexcel_worksheet have 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: phpexcel_worksheet_basedrawing-> Setworksheet (Object (phpexcel_worksheet)) #1 {main} thrown in D:\wwwroot\user\upimg\Classes\PHPExcel\Worksheet\ basedrawing.php on line 240
------Solution--------------------
Yes!
Your $objDrawing = new phpexcel_worksheet_drawing (); Outside of the loop
and $objDrawing->setworksheet ($objPHPExcel->getactivesheet ()); Inside the loop.
How can you guarantee $objDrawing = new phpexcel_worksheet_drawing (); Only this line once?
Although it is set in the conditional branch, how can you guarantee that the condition is only set once?

All you need to do is $objDrawing = new phpexcel_worksheet_drawing (); Put it in the loop, everything's settled.
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.