/*
Remark: Download PHP excel--http://download-codeplex.sec.s-msft.com/download/release first? projectname=phpexcel&downloadid=809023&filetime=130382506270130000&build=20907
*/
/** Convert Excel to an array by aibhsc**/require (Root_path.'includes/phpexcel.php');//Introducing the PHP Excel classfunction Format_excel2array ($filePath ="', $sheet =0){ if(Empty ($filePath) or!file_exists ($filePath)) {Die ('File NOT exists');} $PHPReader=NewPhpexcel_reader_excel2007 ();//Create a Reader object if(! $PHPReaderCanRead ($filePath)) {$PHPReader=NewPhpexcel_reader_excel5 (); if(! $PHPReaderCanRead ($filePath)) {echo'No Excel'; return ; }} $PHPExcel= $PHPReader->load ($filePath);//Create an Excel object$currentSheet = $PHPExcel->getsheet ($sheet);//* * Read the specified worksheet in the Excel file * /$allColumn = $currentSheet->gethighestcolumn ();//* * Get the largest column number */$allRow = $currentSheet->gethighestrow ();//* * Get a total number of lines * /$data =Array (); for($rowIndex =1; $rowIndex <= $allRow; $rowIndex + +) {//iterates through the contents of each cell. Note that the row starts at 1 and the column starts from a for($colIndex ='A'; $colIndex <= $allColumn; $colIndex + +) {$addr=$colIndex. $rowIndex; $cell= $currentSheet->getcell ($addr)GetValue (); if($cell instanceof Phpexcel_richtext) {//Rich Text conversion string$cell = $cell__tostring (); } $data [$rowIndex] [$colIndex]=$cell; } } return$data;} How to use: $filePath= Root_path.'data/diamondstock.xlsx';//Diamond Stock Documents$data =Format_excel2array ($filePath); Print_r ($data);d ie; Example output: Array ([1] =Array ([A]=Product code [B]=product name [C]=total weight [D]=purchase price [E]=sales Price [F]=4C notes) [2] =Array ([A]=10001[B]= gia-2156685995[C]=0.7[D]=1760[E]=1848[F]= g color,0. 7ct, SI1, FR) [3] =Array ([A]=10002[B]= gia-2156685996[C]=0.7[D]=1760[E]=1848[F]= g color,0. 7ct, SI1, FR) [4] =Array ([A]=10003[B]= gia-2156685997[C]=0.7[D]=1760[E]=1848[F]= g color,0. 7ct, SI1, FR) [5] =Array ([A]=10004[B]= gia-2156685998[C]=0.7[D]=1760[E]=1848[F]= g color,0. 7ct, SI1, FR) [6] =Array ([A]=10005[B]= gia-2156685999[C]=0.7[D]=1760[E]=1848[F]= g color,0. 7ct, SI1, FR) [7] =Array ([A]=10006[B]= gia-2156686000[C]=0.7[D]=1760[E]=1848[F]= g color,0. 7ct, SI1, FR) [8] =Array ([A]=10007[B]= gia-2156686001[C]=0.7[D]=1760[E]=1848[F]= g color,0. 7ct, SI1, FR) [9] =Array ([A]=10008[B]= gia-2156686002[C]=0.7[D]=1760[E]=1848[F]= g color,0. 7ct, SI1, FR) [Ten] =Array ([A]=10009[B]= gia-2156686003[C]=0.7[D]=1760[E]=1848[F]= g color,0. 7ct, SI1, FR) [ One] =Array ([A]=10010[B]= gia-2156686004[C]=0.7[D]=1760[E]=1848[F]= g color,0. 7ct, SI1, FR) [ A] =Array ([A]=10011[B]= gia-2156686005[C]=0.7[D]=1760[E]=1848[F]= g color,0. 7ct, SI1, FR) [ -] =Array ([A]=10012[B]= gia-2156686006[C]=0.7[D]=1760[E]=1848[F]= g color,0. 7ct, SI1, FR) [ -] =Array ([A]=10013[B]= gia-2156686007[C]=0.7[D]=1760[E]=1848[F]= g color,0. 7ct, SI1, FR))
PHP Excel read Excel file conversion array