PHPExcel is a PHP class library that helps us simply and efficiently read Excel data from Excel and export data to Excel.
Related video courses: "PHP Quick Control of Excel - PhpSpreadsheet"
First download the compressed package:
http://www.php.cn/xiazai/leiku/1491
After decompression, it is as follows:
Create a test in the root directory. PHP is used to read the content of excel. The content of the excel file is as follows:
Then the test.php code is as follows:
<?php header("content-type:text/html;charset=utf8"); include './Classes/PHPExcel/IOFactory.php';//引入PHPExcel类 $inputFileName = './test.xls';//读取的excel文件 date_default_timezone_set('PRC'); // 读取excel文件 try { $inputFileType = PHPExcel_IOFactory::identify($inputFileName); $objReader = PHPExcel_IOFactory::createReader($inputFileType); $objPHPExcel = $objReader->load($inputFileName); } catch(Exception $e) { die('加载文件发生错误:"'.pathinfo($inputFileName,PATHINFO_BASENAME).'": '.$e->getMessage()); } $sheet = $objPHPExcel->getSheet(0); $data=$sheet->toArray();//该方法读取不到图片 图片需单独处理 $imageFilePath='./images/'.date('Y-m-d').'/';//图片在本地存储的路径 if (! file_exists ( $imageFilePath )) { mkdir("$imageFilePath", 0777, true); } //处理图片 foreach($sheet->getDrawingCollection() as $img) { list($startColumn,$startRow)= PHPExcel_Cell::coordinateFromString($img->getCoordinates());//获取图片所在行和列 $imageFileName = $img->getCoordinates() . mt_rand(100, 999); switch($img->getMimeType()) { case 'image/jpg': $imageFileName.='.jpg'; imagejpeg($img->getImageResource(),$imageFilePath.$imageFileName); break; case 'image/gif': $imageFileName.='.gif'; imagegif($img->getImageResource(),$imageFilePath.$imageFileName); break; case 'image/png': $imageFileName.='.png'; imagepng($img->getImageResource(),$imageFilePath.$imageFileName); break; } $startColumn = ABC2decimal($startColumn);//由于图片所在位置的列号为字母,转化为数字 $data[$startRow-1][$startColumn]=$imageFilePath.$imageFileName;//把图片插入到数组中 } print_r($data);die;
function ABC2decimal($abc){ $ten = 0; $len = strlen($abc); for($i=1;$i<=$len;$i++){ $char = substr($abc,0-$i,1);//反向获取单个字符 $int = ord($char); $ten += ($int-65)*pow(26,$i-1); } return $ten; }
The above code only processes pictures, and gets The image path is inserted into the array. If you need to store data into the database, you can loop the insert and process it yourself. The print result is as follows:
The above is the detailed content of PHPExcel data import (graphics and text). For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 Mac version
God-level code editing software (SublimeText3)

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

SublimeText3 Linux new version
SublimeText3 Linux latest version

Zend Studio 13.0.1
Powerful PHP integrated development environment
