Home  >  Article  >  Backend Development  >  PHPExcel method to read pictures in EXCEL and save them locally, _PHP tutorial

PHPExcel method to read pictures in EXCEL and save them locally, _PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:06:341107browse

How PHPExcel reads pictures in EXCEL and saves them locally,

HPExcel is a very powerful MS Office Excel document generation library. When you need to output data in a more complex format, PHPExcel is a good choice.

After carefully studying the API documentation and checking the official documentation, I finally found how to read pictures in EXCEL. Currently, I can only read excel 2003 format. It seems that excel2007 does not support it yet. The main APIs used are PHPExcel_Worksheet, PHPExcel_Worksheet_BaseDrawing, PHPExcel_Worksheet_MemoryDrawing.

Stop talking nonsense and go straight to the code:

Copy code The code is as follows:

require_once './Classes/PHPExcel.php';
$objPHPExcel = new PHPExcel();
$objReader = PHPExcel_IOFactory::createReader('Excel5'); //Load 2003
$objPHPExcel = $objReader->load("goods_list.xls"); //Load file
foreach ($objPHPExcel->getSheet(0)->getDrawingCollection() as $k => $drawing) {
            $codata = $drawing->getCoordinates(); //Get unit data, such as G2 unit
           $filename = $drawing->getIndexedFilename(); //File name
         ob_start();
         call_user_func(
                 $drawing->getRenderingFunction(),
                $drawing->getImageResource()
);
$imageContents = ob_get_contents();
          file_put_contents('pic/'.$codata.'_'.$filename.'.jpg',$imageContents); //Save the file locally
         ob_end_clean();
}

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/958722.htmlTechArticlePHPExcel reads pictures in EXCEL and saves them locally. HPExcel is a very powerful MS Office Excel document generation Class library, when you need to output data in more complex formats, PHPE...
Statement:
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