function format_excel2array($filePath='',$sheet=0){
require PC_PATH.'libs/classes/PHPExcel.php';
require PC_PATH.'libs/classes/PHPExcel/IOFactory.php';
require PC_PATH.'libs/classes/PHPExcel/Reader/Excel2007.php';
require PC_PATH.'libs/classes/PHPExcel/Reader/Excel5.php';
if(empty($filePath) or !file_exists($filePath)){die('file not exists');}
$PHPReader = new PHPExcel_Reader_Excel2007(); //建立reader對(duì)象
if(!$PHPReader->canRead($filePath)){
$PHPReader = new PHPExcel_Reader_Excel5();
if(!$PHPReader->canRead($filePath)){
echo 'no Excel';
return ;
}
}
$PHPExcel = $PHPReader->load($filePath); //建立excel對(duì)象
$currentSheet = $PHPExcel->getSheet($sheet); //**讀取excel文件中的指定工作表*/
$allColumn = $currentSheet->getHighestColumn(); //**取得最大的列號(hào)*/
$allRow = $currentSheet->getHighestRow(); //**取得一共有多少行*/
$data = array();
for($rowIndex=1;$rowIndex<=$allRow;$rowIndex++){ //循環(huán)讀取每個(gè)單元格的內(nèi)容。注意行從1開始,列從A開始
for($colIndex='A';$colIndex<=$allColumn;$colIndex++){
$addr = $colIndex.$rowIndex;
$cell = $currentSheet->getCell($addr)->getValue();
if($cell instanceof PHPExcel_RichText){ //富文本轉(zhuǎn)換字符串
$cell = $cell->__toString();
}
$data[$rowIndex][$colIndex] = $cell;
}
}
return $data;
}
PHP將Excel轉(zhuǎn)成Array
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。
相關(guān)閱讀更多精彩內(nèi)容
- 由于在做這個(gè)項(xiàng)目的時(shí)候,用的是react,所以就將這篇文章放在這里吧 將HTML模板轉(zhuǎn)成pdf 2個(gè)關(guān)鍵點(diǎn),1,將...
- $resource_child_list為數(shù)組即:如下(精簡(jiǎn)部分字段) 0=>array 'id'=>'ro150...
- array_merge 合并一個(gè)或多個(gè)數(shù)組 array array_merge ( array $array1 [...
- 每年到這個(gè)時(shí)候,身邊就會(huì)有很多人開始咳嗽、咳痰、流鼻涕、打噴嚏的,有些是感冒、有些是哮喘、有些是氣管炎,有些的鼻炎...