$inputFileType1 = 'Excel2007'; $inputFileName1 = __DIR__."/订单列表分析2.xlsx"; $inputFileType2 = 'Excel2007'; $inputFileName2 = __DIR__."/订单列表分析11.xlsx"; $outputFileType = 'Excel2007'; $outputFileName = __DIR__.'/outputData12222.xlsx'; // Load the first workbook (an xlsx file) $objPHPExcelReader1 = \PHPExcel_IOFactory::createReader($inputFileType1); $objPHPExcel1 = $objPHPExcelReader1->load($inputFileName1); // Load the second workbook (an xls file) $objPHPExcelReader2 = \PHPExcel_IOFactory::createReader($inputFileType2); $objPHPExcel2 = $objPHPExcelReader2->load($inputFileName2); // Merge the second workbook into the first $objPHPExcel2->getActiveSheet()->setTitle('Unique worksheet name'); $res = $objPHPExcel2->getActiveSheet()->toArray(); foreach ($res as $k=>$val){ // $objPHPExcel1->getActiveSheet()->insertNewRowBefore(3,1); $objPHPExcel1->getActiveSheet()->setCellValue('A3',1); } // $objPHPExcel1->getActiveSheet()->insertNewRowBefore(4,1); $objPHPExcel1->getActiveSheet()->setCellValue('A4',"sssss"); ob_end_clean(); $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel1, $inputFileType1); $objWriter->save($outputFileName);//只是保存 不导出 下面的是导出 exit;