本文介绍了需要在phpexcel中为每个搜索循环创建新工作表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! **我已经放弃了这个编程的新功能。我想知道如何为每个搜索结果创建新工作表。 以下是我当前的代码。 但是,它只显示最后一个数组的结果。请帮帮我。** 我尝试过: $ arr = array(); $ main = 选择ige_international的独特位置,其中city ='UAE'和mental_grade!=''' ; $ resultmain = mysqli_query($ MySQLi_CON,$ main)或 die(mysqli_error($ MySQLi_CON) )); while($ row1 = mysqli_fetch_assoc($ resultmain)){ array_push($ arr,$ row1 [' 位置']); } $ length = count($ arr); for ($ i = 0 ; $我< $ length ; $ i ++){ $ sql = SELECT位置,CONCAT('IGEMA-0',MONTH(exam_date),YEAR(exam_date),' - ',id)AS stud_id, UPPER( std_name)作为std_name,mental_grade,UPPER(结果)作为结果, DATE_FORMAT(exam_date,'%d /%m /%Y')作为ige_international的日期,其中city ='UAE'和结果不是in('Fail')和mental_grade!=''和location ='$ arr [$ i]'; $ result = mysqli_query($ MySQLi_CON,$ sql)或 die(mysqli_error($ MySQLi_CON) )); if (mysqli_num_rows($ result)> 0){ $ objPHPExcel = new PHPExcel(); header(' Content-Type:application / vnd.ms-excel'); header(' Content-Disposition:attachment; filename =Final Result.xlsx' ); header(' Cache-Control:max-age = 0'); $ s = 0; if ($ s< $ length){ $ objPHPExcel-> createSheet(); $ objPHPExcel-> setActiveSheetIndex($ s); $ objPHPExcel-> getActiveSheet() - > setTitle($ arr [$ i]); $ objPHPExcel-> getActiveSheet() - > SetCellValue(' A1', NO); $ objPHPExcel-> getActiveSheet() - > SetCellValue(' B1', CENTER); $ objPHPExcel-> getActiveSheet() - > SetCellValue(' C1', EXAMINATION CODE); $ objPHPExcel-> getActiveSheet() - > SetCellValue(' D1', 学生姓名); $ objPHPExcel-> getActiveSheet() - > SetCellValue(' E1', MENTAL GRADE); $ objPHPExcel-> getActiveSheet() - > SetCellValue(' E1', RESULT); $ objPHPExcel-> getActiveSheet() - > SetCellValue(' E1', DATE); $ rowCount = 2 ; $ n = 1 ; while($ row = mysqli_fetch_assoc($ result)){ $ objPHPExcel-> getActiveSheet() - > SetCellValue(' A'。$ rowCount,$ n); $ objPHPExcel-> getActiveSheet() - > SetCellValue(' B'。$ rowCount,$ row [' location']); $ objPHPExcel-> getActiveSheet() - > SetCellValue(' C'。$ rowCount,$ row [' stud_id']); $ objPHPExcel-> getActiveSheet() - > SetCellValue(' D'。$ rowCount,$ row [' std_name']); $ objPHPExcel-> getActiveSheet() - > SetCellValue(' E'。$ rowCount,$ row [' mental_grade']); $ objPHPExcel-> getActiveSheet() - > SetCellValue(' E'。$ rowCount,$ row [' result']); $ objPHPExcel-> getActiveSheet() - > SetCellValue(' E'。$ rowCount,$ row [' date']); $ rowCount ++; $ n ++; } $ s ++; } } } $ objWriter = new PHPExcel_Writer_Excel2007($ objPHPExcel); 解决方案 arr = array(); main = 选择ige_international的不同位置,其中city ='UAE'和mental_grade!=''; resultmain = mysqli_query( **Hi, I'm quit new for this programming. I would like to know how to create new sheet for every search result.Below is my current code.However, its only showing the result for the last array. Please help me on this.**What I have tried:$arr = array();$main="select Distinct location from ige_international where city = 'UAE' and mental_grade != ''";$resultmain = mysqli_query($MySQLi_CON, $main) or die(mysqli_error($MySQLi_CON));while($row1 = mysqli_fetch_assoc($resultmain)){array_push($arr, $row1['location']);}$length = count($arr);for ($i = 0; $i < $length; $i++) {$sql="SELECT location, CONCAT('IGEMA-0',MONTH(exam_date),YEAR(exam_date),'-',id) AS stud_id,UPPER(std_name)as std_name, mental_grade , UPPER(result) as result ,DATE_FORMAT(exam_date, '%d/%m/%Y') as date from ige_international where city = 'UAE' andresult not in ( 'Fail' ) and mental_grade != '' and location = '$arr[$i]' ";$result = mysqli_query($MySQLi_CON, $sql) or die(mysqli_error($MySQLi_CON));if (mysqli_num_rows($result) > 0) {$objPHPExcel = new PHPExcel();header('Content-Type: application/vnd.ms-excel');header('Content-Disposition: attachment;filename="Final Result.xlsx"');header('Cache-Control: max-age=0'); $s=0; if ($s < $length) {$objPHPExcel->createSheet();$objPHPExcel->setActiveSheetIndex($s);$objPHPExcel->getActiveSheet()->setTitle($arr[$i]);$objPHPExcel->getActiveSheet()->SetCellValue('A1', "NO"); $objPHPExcel->getActiveSheet()->SetCellValue('B1', "CENTRE");$objPHPExcel->getActiveSheet()->SetCellValue('C1', "EXAMINATION CODE"); $objPHPExcel->getActiveSheet()->SetCellValue('D1', "STUDENT NAME");$objPHPExcel->getActiveSheet()->SetCellValue('E1', "MENTAL GRADE");$objPHPExcel->getActiveSheet()->SetCellValue('E1', "RESULT");$objPHPExcel->getActiveSheet()->SetCellValue('E1', "DATE");$rowCount = 2;$n = 1;while($row = mysqli_fetch_assoc($result)){ $objPHPExcel->getActiveSheet()->SetCellValue('A'.$rowCount, $n); $objPHPExcel->getActiveSheet()->SetCellValue('B'.$rowCount, $row['location']);$objPHPExcel->getActiveSheet()->SetCellValue('C'.$rowCount, $row['stud_id']); $objPHPExcel->getActiveSheet()->SetCellValue('D'.$rowCount, $row['std_name']);$objPHPExcel->getActiveSheet()->SetCellValue('E'.$rowCount, $row['mental_grade']);$objPHPExcel->getActiveSheet()->SetCellValue('E'.$rowCount, $row['result']);$objPHPExcel->getActiveSheet()->SetCellValue('E'.$rowCount, $row['date']);$rowCount++;$n++;}$s++;}}}$objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel); 解决方案 arr = array();main="select Distinct location from ige_international where city = 'UAE' and mental_grade != ''";resultmain = mysqli_query( 这篇关于需要在phpexcel中为每个搜索循环创建新工作表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 07-04 18:37