當我探索PHPExcel.php我得到的解決方案,我將與其他人分享。
$target_file = $path . basename($_FILES["files"]["name"]);// storing the excel file to folder
$file_id = basename($_FILES["files"]["name"]);
$FileType = pathinfo($target_file, PATHINFO_EXTENSION);
move_uploaded_file($_FILES["files"]["tmp_name"], $target_file);
$load_file = $target_file;
$update4 = array('file_id' => $file_id,);
$this -> load -> library('Excel');
$objPHPExcel = PHPExcel_IOFactory::load($load_file);
$sheet_count = $objPHPExcel->getSheetCount();// this function give me worksheets count.
for($s=0; $s<$sheet_count; $s++){// using for lop to get specific worksheet data
$cell_collection= $objPHPExcel->getSheet($s)->getCellCollection();
foreach ($cell_collection as $cell) {
$column = $objPHPExcel -> getSheet() -> getCell($cell) -> getColumn();
$row = $objPHPExcel -> getSheet() -> getCell($cell) -> getRow();
$data_value = $objPHPExcel -> getSheet() -> getCell($cell) -> getValue();
if ($row == 1) {// if you have header in your excel or want to store then store in header.
$header[$s][$row][$column] = $data_value;
} else {// i get my meaningful data from here :)
$arr_data[$s][$row][$column] = $data_value;
}
}
}// end of for loop for getting the work sheet
感謝您的回覆。我已經在使用這個。我正在尋找如何訪問我的第二個和第三個工作表?
我使用這個代碼'$ this - > load - > library('Excel'); \t $ objPHPExcel = PHPExcel_IOFactory :: load($ load_file); \t $ cell_collection = $ objPHPExcel-> getActiveSheet() - > getCellCollection(); ' –
@ user3548569試試上面的示例函數我在我的程序中使用它讀取excel文件中的多個工作表。並感謝您的反饋:P –
感謝您的回覆。但我得到我自己的答案,它的超級快,我也在我的答案中顯示。感謝你的支持 :) –