当我探索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 –
感谢您的回复。但我得到我自己的答案,它的超级快,我也在我的答案中显示。感谢你的支持 :) –