利用PhpExcel读取Excel中文件
程序员文章站
2022-04-20 14:16:34
...
?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
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中文件, 感谢原作者分享。
上一篇: 用Python实现协同过滤的教程