I am using Yii2 basic. I have 3 tables with the fields as,
ascteacherreport - ASCTeacherReportId,ASCId,UserId, DateofReport
ascteacherreportdetails - ASCReportDetailsId,ASCTeacherReportId, Time
ascteacherreporttimedetails - ASCTeacherReportTimeDetailsId, ASCReportDetailsId, StudentId ,Subject, Topic, Confidence
The relation between these 3 tables is as One ascteacherreport has many ascteacherreportdetails and One ascteacherreportdetails has many ascteacherreporttimedetails.
Now I am generating the data into excel using PHPExcel library. So the user creates the report for Date say 1st March for three hours like 11 to 12, 12 to 1 and 1 to 2.
And there are many student details for each hour(time) of each day. Say Student John for 11 to 12, 12 to 1 and 1 to 2. Similarly for student Nick for 11 to 12, 12 to 1 and 1 to 2 for 1st March.
Now each dates should be exported as new sheets in one excel file. And for each date sheet the particular time details and student details should be displayed. So for 1 st March there are time details for 2 hours like 11 to 12 and 12 to 1. Then the time should be displayed in 1st March sheet in Column C5 and D5.
Similarly for each time there are many student records. For 11 to 12 there are 3 student records then those student records should be displayed in 11 to 12 column.
I have a function actionExport in controller. The excel file gets downloaded and I can see the dates in different sheets coming but there is sheet Worksheet which should not be displayed.
The time is not displayed properly for each sheet
public function actionExport()
{
$objPHPExcel = new \PHPExcel();
$date = \Yii::$app->db->createCommand('SELECT ASCTeacherReportId, ASCId, DateofReport from
ascteacherreport where UserId=:Id order by ASCTeacherReportId DESC')->bindValues([':Id'=>\Yii::$app->user->identity->getonlyid()])->queryAll();
$timedetails = \Yii::$app->db->createCommand('SELECT Time from ascteacherreportdetailS,
ascteacherreport WHERE ascteacherreport.ASCTeacherReportId=ascteacherreportdetails.ASCTeacherReportId AND
ascteacherreport.UserId=:id1')->bindValues([':id1'=>\Yii::$app->user->identity->getonlyid()])
->queryAll();
foreach($date as $date1)
{
$objWorkSheet = $objPHPExcel->createSheet(0); //Setting index when creating
$objWorkSheet->setTitle(''.$date1['DateofReport']);
foreach($timedetails as $timedetails1)
{
$row = 8;
$lastColumn = $objWorkSheet->getHighestColumn();
$lastColumn++;
for ($column = 'C'; $column != $lastColumn; $column++)
{
$objWorksheet->setCellValue($column.'8',''.$timedetails1['Time']);
}
}
}
ob_end_clean();
header('Content-type: application/.xlsx');
header('Content-Disposition: attachment; filename="report.xlsx"');
$objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save('php://output');
}
Below is the excel file screenshot where dates are displayed in sheets. For each dates the time should be displayed in the respective sheets.