首页 > 代码库 > PHP 读取EXCEL
PHP 读取EXCEL
PHPExcel 自己下载。
PHP读取EXCEL
public function import_Excel($file_name){ include_once LIB_ROOT_PATH."3rdParty/phpexcel/PHPExcel.php"; $objReader = PHPExcel_IOFactory::createReader(‘Excel2007‘); $objPHPExcel = $objReader->load($file_name,$encode=‘utf-8‘); $sheet = $objPHPExcel->getSheet(0); $highestRow = $sheet->getHighestRow();//取得总行数 $highestColumn = $sheet->getHighestColumn();//取得总列数 $data = array(); for($i=2;$i<=$highestRow;$i++){ for($j=‘A‘;$j<=$highestColumn;$j++){ $data[$i][] = $objPHPExcel->getActiveSheet()->getCell("$j$i")->getValue(); } } return $data; }
PHP导出EXCEL
public function data_excel(){ include_once LIB_ROOT_PATH."3rdParty/phpexcel/PHPExcel.php"; $objPHPExcel = new PHPExcel(); $objPHPExcel->setActiveSheetIndex(0) ->setCellValue(‘A1‘, ‘相近字‘) ->setCellValue(‘B1‘, ‘可能的字‘); $i = 0; foreach ($temp as $key => $value) { $i++; $objPHPExcel->getActiveSheet(0)->setCellValue(‘A‘.($i+1), $key); $objPHPExcel->getActiveSheet(0)->setCellValue(‘B‘.($i+1), $value); } // sheet命名 $objPHPExcel->getActiveSheet()->setTitle(‘易错字统计‘); $objPHPExcel->setActiveSheetIndex(0); // excel头参数 header(‘Content-Type: application/vnd.ms-excel‘); header(‘Content-Disposition: attachment;filename="(‘.date(‘Ymd-His‘).‘).xlsx"‘); //日期为文件名后缀 header(‘Cache-Control: max-age=0‘); $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, ‘Excel2007‘); //excel5为xls格式,excel2007为xlsx格式 $objWriter->save(‘php://output‘); exit; }
PHP 读取EXCEL
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。