?phpini_set("display_errors",1);ini_set('include_path', ini_get('include_path').';F://sources//PHPExcel_1.7.8-with_documentation-msoffice_format//Classes//');//设置此页面包含路径include 'PHPExcel.php';include 'PHPExcel/IOFactory.php';defin
<?php ini_set("display_errors",1); ini_set('include_path', ini_get('include_path').';F://sources//PHPExcel_1.7.8-with_documentation-msoffice_format//Classes//');//设置此页面包含路径 include 'PHPExcel.php'; include 'PHPExcel/IOFactory.php'; define('EXCEL_EXTENSION_2003', "xls"); define('EXCEL_EXTENSION_2007', "xlsx"); $fileName2003 = "f://Standard_Format_File1.xls"; $fileName2007 = "f://Standard_Format_File1.xlsx"; $fileName = $fileName2003; //$fileName = $fileName2007; if(getExtendFileName($fileName) == EXCEL_EXTENSION_2003) { $reader = PHPExcel_IOFactory::createReader('Excel5'); } else if(getExtendFileName($fileName) == EXCEL_EXTENSION_2007) { $reader = new PHPExcel_Reader_Excel2007(); } $PHPExcel = $reader->load($fileName); $worksheet = $PHPExcel->getActiveSheet(); $imageInfo = extractImageFromWorksheet($worksheet,"f://"); print_r($imageInfo); function getExtendFileName($file_name) { $extend = pathinfo($file_name); $extend = strtolower($extend["extension"]); return $extend; } function extractImageFromWorksheet($worksheet,$basePath){ $result = array(); $imageFileName = ""; foreach ($worksheet->getDrawingCollection() as $drawing) { $xy=$drawing->getCoordinates(); $path = $basePath; // for xlsx if ($drawing instanceof PHPExcel_Worksheet_Drawing) { $filename = $drawing->getPath(); $imageFileName = $drawing->getIndexedFilename(); $path = $path . $drawing->getIndexedFilename(); copy($filename, $path); $result[$xy] = $path; // for xls } else if ($drawing instanceof PHPExcel_Worksheet_MemoryDrawing) { $image = $drawing->getImageResource(); $renderingFunction = $drawing->getRenderingFunction(); switch ($renderingFunction) { case PHPExcel_Worksheet_MemoryDrawing::RENDERING_JPEG: $imageFileName = $drawing->getIndexedFilename(); $path = $path . $drawing->getIndexedFilename(); imagejpeg($image, $path); break; case PHPExcel_Worksheet_MemoryDrawing::RENDERING_GIF: $imageFileName = $drawing->getIndexedFilename(); $path = $path . $drawing->getIndexedFilename(); imagegif($image, $path); break; case PHPExcel_Worksheet_MemoryDrawing::RENDERING_PNG: $imageFileName = $drawing->getIndexedFilename(); $path = $path . $drawing->getIndexedFilename(); imagegif($image, $path); break; case PHPExcel_Worksheet_MemoryDrawing::RENDERING_DEFAULT: $imageFileName = $drawing->getIndexedFilename(); $path = $path . $drawing->getIndexedFilename(); imagegif($image, $path); break; } $result[$xy] = $imageFileName; } } return $result; }
原文地址:利用PhpExcel读取Excel中文件, 感谢原作者分享。
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

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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Assassin's Creed Shadows: Seashell Riddle Solution
2 weeks agoByDDD
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

Zend Studio 13.0.1
Powerful PHP integrated development environment

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

SublimeText3 English version
Recommended: Win version, supports code prompts!

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.