php代碼
/* * 將excel轉(zhuǎn)換為數(shù)組 by aibhsc * */ require(ROOT_PATH . 'includes/PHPExcel.php');//引入PHP EXCEL類 function format_excel2array($filePath='',$sheet=0){ if(empty($filePath) or !file_exists($filePath)){die('file not exists');} $PHPReader = new PHPExcel_Reader_Excel2007(); //建立reader對象 if(!$PHPReader->canRead($filePath)){ $PHPReader = new PHPExcel_Reader_Excel5(); if(!$PHPReader->canRead($filePath)){ echo 'no Excel'; return ; } } $PHPExcel = $PHPReader->load($filePath); //建立excel對象 $currentSheet = $PHPExcel->getSheet($sheet); //**讀取excel文件中的指定工作表*/ $allColumn = $currentSheet->getHighestColumn(); //**取得最大的列號*/ $allRow = $currentSheet->getHighestRow(); //**取得一共有多少行*/ $data = array(); for($rowIndex=1;$rowIndex<=$allRow;$rowIndex++){ //循環(huán)讀取每個單元格的內(nèi)容。注意行從1開始,列從A開始 for($colIndex='A';$colIndexgetCell($addr)->getValue(); if($cell instanceof PHPExcel_RichText){ //富文本轉(zhuǎn)換字符串 $cell = $cell->__toString(); } $data[$rowIndex][$colIndex] = $cell; } } return $data; } 使用方法: $filePath = ROOT_PATH.'data/diamondStock.xlsx'; //鉆石庫存文件 $data = format_excel2array($filePath); print_r($data);die; 輸出結(jié)果示例: Array ( [1] => Array ( [A] => 商品編號 [B] => 商品名稱 [C] => 總重量 [D] => 進(jìn)貨價格 [E] => 銷售價格 [F] => 4C備注 ) [2] => Array ( [A] => 10001 [B] => GIA-2156685995 [C] => 0.7 [D] => 1760 [E] => 1848 [F] => G色、0.7ct、SI1、FR ) [3] => Array ( [A] => 10002 [B] => GIA-2156685996 [C] => 0.7 [D] => 1760 [E] => 1848 [F] => G色、0.7ct、SI1、FR ) [4] => Array ( [A] => 10003 [B] => GIA-2156685997 [C] => 0.7 [D] => 1760 [E] => 1848 [F] => G色、0.7ct、SI1、FR ) [5] => Array ( [A] => 10004 [B] => GIA-2156685998 [C] => 0.7 [D] => 1760 [E] => 1848 [F] => G色、0.7ct、SI1、FR ) [6] => Array ( [A] => 10005 [B] => GIA-2156685999 [C] => 0.7 [D] => 1760 [E] => 1848 [F] => G色、0.7ct、SI1、FR ) [7] => Array ( [A] => 10006 [B] => GIA-2156686000 [C] => 0.7 [D] => 1760 [E] => 1848 [F] => G色、0.7ct、SI1、FR ) [8] => Array ( [A] => 10007 [B] => GIA-2156686001 [C] => 0.7 [D] => 1760 [E] => 1848 [F] => G色、0.7ct、SI1、FR ) [9] => Array ( [A] => 10008 [B] => GIA-2156686002 [C] => 0.7 [D] => 1760 [E] => 1848 [F] => G色、0.7ct、SI1、FR ) [10] => Array ( [A] => 10009 [B] => GIA-2156686003 [C] => 0.7 [D] => 1760 [E] => 1848 [F] => G色、0.7ct、SI1、FR ) [11] => Array ( [A] => 10010 [B] => GIA-2156686004 [C] => 0.7 [D] => 1760 [E] => 1848 [F] => G色、0.7ct、SI1、FR ) [12] => Array ( [A] => 10011 [B] => GIA-2156686005 [C] => 0.7 [D] => 1760 [E] => 1848 [F] => G色、0.7ct、SI1、FR ) [13] => Array ( [A] => 10012 [B] => GIA-2156686006 [C] => 0.7 [D] => 1760 [E] => 1848 [F] => G色、0.7ct、SI1、FR ) [14] => Array ( [A] => 10013 [B] => GIA-2156686007 [C] => 0.7 [D] => 1760 [E] => 1848 [F] => G色、0.7ct、SI1、FR ) )
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

Hot AI Tools

Undress AI Tool
Undress images for free

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

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

Clothoff.io
AI clothes remover

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

Hot Article
Guide: Stellar Blade Save File Location/Save File Lost/Not Saving
4 weeks ago
By DDD
Oguri Cap Build Guide | A Pretty Derby Musume
2 weeks ago
By Jack chen
Agnes Tachyon Build Guide | A Pretty Derby Musume
1 weeks ago
By Jack chen
Dune: Awakening - Advanced Planetologist Quest Walkthrough
4 weeks ago
By Jack chen
Date Everything: Dirk And Harper Relationship Guide
4 weeks ago
By Jack chen

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

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