久久久久久久视色,久久电影免费精品,中文亚洲欧美乱码在线观看,在线免费播放AV片

<center id="vfaef"><input id="vfaef"><table id="vfaef"></table></input></center>

    <p id="vfaef"><kbd id="vfaef"></kbd></p>

    
    
    <pre id="vfaef"><u id="vfaef"></u></pre>

      <thead id="vfaef"><input id="vfaef"></input></thead>

    1. 站長(zhǎng)資訊網(wǎng)
      最全最豐富的資訊網(wǎng)站

      利用php實(shí)現(xiàn)讀取excel中的圖片

      利用php實(shí)現(xiàn)讀取excel中的圖片

      要實(shí)現(xiàn)讀取excel中的圖片,可以通過(guò)phpspreadsheet來(lái)實(shí)現(xiàn)。phpspreadsheet是一個(gè)純php編寫(xiě)的庫(kù),并引入了命名空間、PSR規(guī)范等。

      使用composer安裝phpspreadsheet

      composer require phpoffice/phpspreadsheet

      GitHub下載:

      https://github.com/PHPOffice/PhpSpreadsheet

      (免費(fèi)視頻教程推薦:php視頻教程)

      excel圖片如下圖:

      利用php實(shí)現(xiàn)讀取excel中的圖片

      項(xiàng)目實(shí)例:

      use PhpOfficePhpSpreadsheetCellCoordinate; use PhpOfficePhpSpreadsheetIOFactory; $imageFilePath = './uploads/imgs/'; //圖片本地存儲(chǔ)的路徑 if (!file_exists($imageFilePath)) { //如果目錄不存在則遞歸創(chuàng)建  mkdir($imageFilePath, 0777, true); } try {  $inputFileName = './files/1.xlsx'; //包含圖片的Excel文件  $objRead = IOFactory::createReader('Xlsx');  $objSpreadsheet = $objRead->load($inputFileName);  $objWorksheet = $objSpreadsheet->getSheet(0);  $data = $objWorksheet->toArray();  foreach ($objWorksheet->getDrawingCollection() as $drawing) {   list($startColumn, $startRow) = Coordinate::coordinateFromString($drawing->getCoordinates());   $imageFileName = $drawing->getCoordinates() . mt_rand(1000, 9999);   switch ($drawing->getExtension()) {    case 'jpg':    case 'jpeg':     $imageFileName .= '.jpg';     $source = imagecreatefromjpeg($drawing->getPath());     imagejpeg($source, $imageFilePath . $imageFileName);     break;    case 'gif':     $imageFileName .= '.gif';     $source = imagecreatefromgif($drawing->getPath());     imagegif($source, $imageFilePath . $imageFileName);     break;    case 'png':     $imageFileName .= '.png';     $source = imagecreatefrompng($drawing->getPath());     imagepng($source, $imageFilePath, $imageFileName);     break;   }   $startColumn = ABC2decimal($startColumn);   $data[$startRow-1][$startColumn] = $imageFilePath . $imageFileName;  }  dump($data);die(); } catch (Exception $e) {  throw $e; } public function ABC2decimal($abc) {  $ten = 0;  $len = strlen($abc);  for($i=1;$i<=$len;$i++){   $char = substr($abc,0-$i,1);//反向獲取單個(gè)字符   $int = ord($char);   $ten += ($int-65)*pow(26,$i-1);  }  return $ten; }

      結(jié)果如圖:

      利用php實(shí)現(xiàn)讀取excel中的圖片

      相關(guān)文章教程推薦:php教程

      贊(0)
      分享到: 更多 (0)
      網(wǎng)站地圖   滬ICP備18035694號(hào)-2    滬公網(wǎng)安備31011702889846號(hào)