Apart directly on the Code Comment section for Excel Export
Export Exam Results Details
Public Function Export ()
{
Export Exam Results Details (PDF)
$id = I (' id ');
$detailed = D (' Member_test_result ');
$parameter = $detailed->detailedresults ($id);
$name = $parameter [' member_name '];
$result = Json_decode ($parameter [' test_result_str ']);
foreach ($result as $k = = $v) {
$test = M (' Test_cont ');
$array [' question_title '] = $test->where (' id= '. $k)->getfield (' Qustion_title ');
Correct options
$array [' state '] = $test->where (' id= '. $k)->getfield (' state ');
Correct answer
$wheres [' test_id '] = $k;
$wheres [' state '] = $array [' state '];
$array [' stateresult '] = M (' test_answer ')->where ($wheres)->getfield (' Answer_name ');
Options
$array [' cont '] = $v;
Options content
$where [' test_id '] = $k;
$where [' state '] = $array [' cont '];
$array [' result '] = M (' test_answer ')->where ($where)->getfield (' Answer_name ');
$data [] = $array;
}
$content = ' <!doctype html> ';
$content. = ' $content. = ' $content. = ' <meta charset= ' UTF-8 '/> ';
$content. = ' <title> exam results </title> ';
$content. = ' $content. = ' <body> ';
$content. = ' <div class= ' content > ';
$content. = ' <p align= ' center ' style= ' color: #0a6ebd; font-size:24px ' ><b> exam results </b></p> ';
$content. = ' <div style= ' color: #6a6a6a; letter-spacing:4px ">";
$content. = ' <p><span> name: ';
$content. = $name;
$content. = ' </span> ';
$content. = ' <span style= ' color: #fff; " >1231 ';
$content. = ' </span> ';
$content. = ' <span style= ' > Test time: ';
$content. = Gmdate ("i:s", $parameter [' time_cost ']);
$content. = ' </span> ';
$content. = ' <span style= ' color: #fff; " >1231 ';
$content. = ' </span> ';
$content. = ' <span style= ' > Test score: ';
$content. = $parameter [' Score '];
$content. = ' </span> ';
$content. = ' foreach ($data as $k = = $v) {
$content. = ' <p style=font-size:20px><b> ';
$content. = $k + 1;
$content. = ', </b> ';
$content. = $v [' Question_title '];
$content. = ' </p> ';
$content. = ' <p style= ' font-size:14px ' > Your options are: <span style= "color: #0a6ebd;" > ';
$content. = $v [' cont '];
$content. = ' </span></p> ';
$content. = ' <p style= "font-size:14px" > Your answer is: <span style= "color: #0a6ebd;" > ';
$content. = $v [' result '];
$content. = ' </span></p> ';
$content. = ' <p style= ' font-size:14px ' > Correct option: <span style= "color:red;" > ';
$content. = $v [' state '];
$content. = ' </span></p> ';
$content. = ' <p style= ' font-size:14px ' > Correct answer to: <span style= "color:red;" > ';
$content. = $v [' Stateresult '];
$content. = ' </span></p> ';
};
$content. = ' </div> ';
$content. = ' </body> ';
$content. = ' PDF ($content);
Export Exam Results Details (Excel)
/* Header ("Content-typ:text/html;charset=utf-8");
Vendor (' Excel.phpexcel ');
Vendor (' Excel.PHPExcel.IOFactory ');
$objPHPExcel = new \phpexcel ();
$objPHPExcel->getactivesheet ()->setcellvalue (' A1 ', "exam questions");//Set the value of the column
$objPHPExcel->getactivesheet ()->setcellvalue (' B1 ', "options");//Set the value of the column
$objPHPExcel->getactivesheet ()->setcellvalue (' C1 ', "answer");//Set the value of the column
$objPHPExcel->getactivesheet ()->setcellvalue (' D1 ', "correct option");//Set the value of the column
$objPHPExcel->getactivesheet ()->setcellvalue (' E1 ', "correct answer");//Set the value of the column
if ($data) {
$i = 2;
foreach ($data as $key = = $value) {
$objPHPExcel->setactivesheetindex (0)
In column A of Excel, the UID is the key value you find in the array, and so on
->setcellvalue (' A '. $i, $value [' Question_title '])
->setcellvalue (' B '. $i, $value [' cont '])
->setcellvalue (' C '. $i, $value [' result '])
->setcellvalue (' D '. $i, $value [' State '])
->setcellvalue (' E '. $i, $value [' Stateresult ']);
$i + +;
}
}
$objPHPExcel->getactivesheet (0)->settitle (' Test Result details report ');
Header (' Content-type:application/vnd.ms-excel ');
Header ("Content-disposition:attachment;filename=". $time. " Exam Results Details report. docx ");
Header (' cache-control:max-age=0 ');
$objWriter = \phpexcel_iofactory::createwriter ($objPHPExcel, ' Excel5 ');
$objWriter->save (' php://output ');
*/
}
Thinkphp-php Realizing PDF export function