How to save pictures in EXCEL with PHP

*文
Release: 2023-03-18 12:16:01
Original
1972 people have browsed it

How to save pictures in EXCEL in PHP? This article mainly introduces the method of reading pictures in EXCEL through PHPExcel and saving the file. I hope that using PHPExcel to read pictures in EXCEL and save the file will give everyone a clearer understanding of PHPExcel.

HPExcel is a very powerful MS Office Excel document generation class 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 the way to read pictures in EXCEL. Currently, I can only read the 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:

require_once './Classes/PHPExcel.php';
$objPHPExcel = new PHPExcel();
$objReader = PHPExcel_IOFactory::createReader('Excel5');  //加载2003的
$objPHPExcel = $objReader->load("goods_list.xls");  //载入文件
foreach ($objPHPExcel->getSheet(0)->getDrawingCollection() as $k => $drawing) {
        $codata = $drawing->getCoordinates(); //得到单元数据 比如G2单元
        $filename = $drawing->getIndexedFilename();  //文件名
        ob_start();
        call_user_func(
            $drawing->getRenderingFunction(),
            $drawing->getImageResource()
        );
        $imageContents = ob_get_contents();
        file_put_contents('pic/'.$codata.'_'.$filename.'.jpg',$imageContents); //把文件保存到本地
        ob_end_clean();
}
Copy after login

Related recommendations:

Example sharing of solving PHPExcel memory leaks

Thinkphp5+PHPExcel realizes the function of batch uploading table data_php example

##Using ThinkPHP, uploadify, upload, PHPExcel how to import data without refreshing

The above is the detailed content of How to save pictures in EXCEL with PHP. For more information, please follow other related articles on the PHP Chinese website!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!