Esempio n. 1
0
 public function test2Action()
 {
     try {
         WordChart::scatter_horiz_Graph_cpi();
     } catch (Exception $e) {
         echo $e->getMessage();
     }
 }
 public function report($examinee_id)
 {
     \PhpOffice\PhpWord\Autoloader::register();
     $this->wordHandle = new \PhpOffice\PhpWord\PhpWord();
     $data = $this->getBasic($examinee_id);
     $chart = new WordChart();
     //----------------------------------------------------
     // layout
     $sectionStyle = array('borderColor' => '000000', 'borderSize' => 1, 'orientation' => 'portrait', 'marginLeft' => \PhpOffice\PhpWord\Shared\Converter::cmToTwip(1.59), 'marginRight' => \PhpOffice\PhpWord\Shared\Converter::cmToTwip(1.25), 'marginTop' => \PhpOffice\PhpWord\Shared\Converter::cmToTwip(2.25), 'marginBottom' => \PhpOffice\PhpWord\Shared\Converter::cmToTwip(2.25), 'pageSizeW' => \PhpOffice\PhpWord\Shared\Converter::cmToTwip(21), 'pageSizeH' => \PhpOffice\PhpWord\Shared\Converter::cmToTwip(29.7), 'headerHeight' => \PhpOffice\PhpWord\Shared\Converter::cmToTwip(1.5), 'footerHeight' => \PhpOffice\PhpWord\Shared\Converter::cmToTwip(1.75));
     //add section
     $section = $this->wordHandle->addSection($sectionStyle);
     $section->getStyle()->setPageNumberingStart(1);
     $header = $section->addHeader();
     $footer = $section->addFooter();
     $footer->addPreserveText('{PAGE}/{NUMPAGES}', array('size' => 10, 'color' => '000000'), array('alignment' => 'center', 'lineHeight' => 1));
     //set first logo pic
     $section->addImage('reportimage/logo.png', array('width' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(6.88), 'height' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(3.06), 'positioning' => \PhpOffice\PhpWord\Style\Image::POSITION_ABSOLUTE, 'posHorizontal' => \PhpOffice\PhpWord\Style\Image::POSITION_HORIZONTAL_LEFT, 'posHorizontalRel' => \PhpOffice\PhpWord\Style\Image::POSITION_RELATIVE_TO_OMARGIN, 'posVertical' => \PhpOffice\PhpWord\Style\Image::POSITION_VERTICAL_TOP, 'posVerticalRel' => \PhpOffice\PhpWord\Style\Image::POSITION_RELATIVE_TO_OMARGIN));
     $section->addTextBreak(4, array('size' => 12), array('lineHeight' => 1.5));
     // set caption block
     $caption = $section->createTextrun();
     $caption->addImage('reportimage/fengmian.png', array('marginTop' => -1, 'marginLeft' => \PhpOffice\PhpWord\Shared\Converter::cmToInch(1), 'width' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(4.86), 'height' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(4.06), 'wrappingStyle' => 'square'));
     $caption->addText('综合素质测评报告', array('color' => 'red', 'size' => 36));
     $section->addTextBreak(1, array('size' => '22'), array('lineHeight' => 1.5));
     //set examinee textrun
     $examineeinfotextrun = $section->addTextRun(array('borderTopSize' => 1, 'borderTopColor' => '000000', 'lineHeight' => 1.5, 'valign' => 'center'));
     $basicInfoFontStyle = array('size' => 14, 'bold' => true);
     $examineeinfotextrun->addTextBreak();
     $examineeinfotextrun->addText('测评对象: ' . $data['name'], $basicInfoFontStyle);
     $examineeinfotextrun->addTextBreak();
     $examineeinfotextrun->addText('性    别: ' . $data['sex'], $basicInfoFontStyle);
     $examineeinfotextrun->addTextBreak();
     $examineeinfotextrun->addText('出生年月: ' . $data['birth'], $basicInfoFontStyle);
     $examineeinfotextrun->addTextBreak();
     $examineeinfotextrun->addText('测试单位: 北京国合点金管理咨询有限公司', $basicInfoFontStyle);
     $examineeinfotextrun->addTextBreak();
     $examineeinfotextrun->addText('测试时间: ' . $data['test_date'], $basicInfoFontStyle);
     $section->addPageBreak();
     // Define the TOC font style
     $section->addText("目录", array('size' => 18, 'color' => 'red'), array('alignment' => 'center', 'lineHeight' => 1.5));
     $section->addTOC(array('size' => 14), \PhpOffice\PhpWord\Style\TOC::TABLEADER_LINE, 1, 3);
     $section->addPageBreak();
     // Add title styles
     $this->wordHandle->addTitleStyle(1, array('size' => 14, 'color' => 'red', 'bold' => true), array('lineHeight' => 1.5));
     $this->wordHandle->addTitleStyle(2, array('size' => 14, 'color' => 'blue', 'bold' => true), array('lineHeight' => 1.5));
     $this->wordHandle->addTitleStyle(3, array('size' => 14, 'color' => 'blue', 'bold' => true), array('lineHeight' => 1.5));
     $section->addTitle('一、个人情况综述', 1);
     $section->addTitle('个人信息', 2);
     $section->addListItem("姓名: " . $data['name'] . "(" . $data['sex'] . ")", 0, array('size' => 14), \PhpOffice\PhpWord\Style\ListItem::TYPE_SQUARE_FILLED, array('lineHeight' => 1.5));
     $section->addListItem("毕业院校: " . $data['school'] . $data['degree'], 0, array('size' => 14), \PhpOffice\PhpWord\Style\ListItem::TYPE_ALPHANUM, array('lineHeight' => 1.5));
     $section->addListItem("规定测试时间: 3小时", 0, array('size' => 14), \PhpOffice\PhpWord\Style\ListItem::TYPE_ALPHANUM, array('lineHeight' => 1.5));
     $section->addListItem("实际完成时间:" . $data['exam_time'], 0, array('size' => 14), \PhpOffice\PhpWord\Style\ListItem::TYPE_ALPHANUM, array('lineHeight' => 1.5));
     $section->addTitle('工作经历', 2);
     $table = $section->addTable(array('borderSize' => 1, 'borderColor' => '000000', 'align' => 'center'));
     //判断工作经历是否为空
     if (empty($data['works'])) {
         $section->addText('空');
     } else {
         $row = $table->addRow(600);
         $row->addCell(2500, array('valign' => 'center'))->addText("工作单位", array('size' => 14), array('alignment' => 'center'));
         $row->addCell(2500, array('valign' => 'center'))->addText('部门', array('size' => 14), array('alignment' => 'center'));
         $row->addCell(2500, array('valign' => 'center'))->addText('职位', array('size' => 14), array('alignment' => 'center'));
         $row->addCell(2500, array('valign' => 'center'))->addText('工作时间', array('size' => 14), array('alignment' => 'center'));
         foreach ($data['works'] as $value) {
             $table->addRow(600);
             $table->addCell(2500, array('valign' => 'center'))->addText($value['employer'], array('size' => 14), array('alignment' => 'center'));
             $table->addCell(2500, array('valign' => 'center'))->addText($value['unit'], array('size' => 14), array('alignment' => 'center'));
             $table->addCell(2500, array('valign' => 'center'))->addText($value['duty'], array('size' => 14), array('alignment' => 'center'));
             $table->addCell(2500, array('valign' => 'center'))->addText($value['date'], array('size' => 14), array('alignment' => 'center'));
         }
     }
     $section->addTextBreak(1, array('size' => 14), array('lineHeight' => 1.5));
     $text = '    测试要求3小时,以' . $data['exam_time'] . '完成,' . $data['name'] . $data['exam_time_flag']['value'] . ',且回答' . $data['exam_auth_flag']['value'] . ',说明其阅读' . $data['exam_evalute'] . '。 ';
     $section->addText($text, array('size' => 14), array('lineHeight' => 1.5));
     $section->addTextBreak(1, array('size' => 14), array('lineHeight' => 1.5));
     $table = $section->addTable();
     $row = $table->addRow();
     $text = '    根据测试结果和综合统计分析,分别从职业心理、职业素质、职业心智、职业能力等做出系统评价,按优、良、中、差四个等级评分。综合得分:优秀率为' . $data['excellent_rate'][0] . '%,良好率为' . $data['excellent_rate'][1] . '%,中为' . $data['excellent_rate'][2] . '%,差为' . $data['excellent_rate'][3] . '%,综合发展潜质为' . $data['excellent_evaluate'] . ',如右图所示。 ';
     $row->addCell(7000)->addText($text, array('size' => 14), array('lineHeight' => 1.5));
     //add chart
     $fileName = $chart->barGraph_1($data['excellent_rate'], $examinee_id);
     if (file_exists($fileName)) {
         $row->addCell(3000)->addImage($fileName, array('width' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(5.77), 'height' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(5.48), 'wrappingStyle' => 'square'));
     }
     $section->addPageBreak();
     $section->addTitle('二、测评结果', 1);
     $section->addTitle('1、突出优势', 2);
     foreach ($data['advantage'] as $value) {
         $section->addTitle($value['chs_name'], 3);
         $children = explode(",", $value['children']);
         $count = count($children);
         $j = 0;
         $comments = array();
         foreach ($value['detail'] as $svalue) {
             $advantages = ChildIndexComment::findFirst(array('child_chs_name=?1 AND index_chs_name=?2', 'bind' => array(1 => $svalue['chs_name'], 2 => $value['chs_name'])))->advantage;
             $advantage = json_decode($advantages, true);
             $rand_key = array_rand($advantage);
             $convert_array = array('一', '二', '三');
             $comments[] = $convert_array[$j++] . $advantage[$rand_key];
         }
         $table = $section->addTable();
         $row = $table->addRow();
         $text_1 = "    本项内容共由" . $count . "项指标构成,满分10分。根据得分的高低排序,分析" . $data['name'] . "得分排在前三项具体特点为:";
         $text_2 = "。具体分布如右图所示: ";
         $textrun = $row->addCell(7000)->addTextRun(array('lineHeight' => 1.5));
         $textrun->addText($text_1, array('size' => 14));
         $textrun->addText(implode(';', $comments), array('size' => 14, 'bold' => true));
         $textrun->addText($text_2, array('size' => 14));
         //add chart
         $fileName = $chart->barGraph_2($value['detail'], $examinee_id, 'Cyan');
         if (file_exists($fileName)) {
             $row->addCell(3000)->addImage($fileName, array('width' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(5.77), 'height' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(5.48), 'wrappingStyle' => 'square'));
         }
         $section->addTextBreak();
     }
     $section->addTitle('2、需要改进方面', 2);
     foreach ($data['disadvantage'] as $value) {
         $section->addTitle($value['chs_name'], 3);
         $children = explode(",", $value['children']);
         $count = count($children);
         $j = 0;
         $comments = array();
         foreach ($value['detail'] as $svalue) {
             $advantages = ChildIndexComment::findFirst(array('child_chs_name=?1 AND index_chs_name=?2', 'bind' => array(1 => $svalue['chs_name'], 2 => $value['chs_name'])))->disadvantage;
             $advantage = json_decode($advantages, true);
             $rand_key = array_rand($advantage);
             $convert_array = array('一', '二', '三');
             $comments[] = $convert_array[$j++] . $advantage[$rand_key];
         }
         $table = $section->addTable();
         $row = $table->addRow();
         $text_1 = "    本项内容共由" . $count . "项指标构成,满分10分。根据得分的由低到高排序,分析" . $data['name'] . "得分偏低的原因为:";
         $text_2 = "。具体分布如右图所示: ";
         $textrun = $row->addCell(7000)->addTextRun(array('lineHeight' => 1.5));
         $textrun->addText($text_1, array('size' => 14));
         $textrun->addText(implode(';', $comments), array('size' => 14, 'bold' => true));
         $textrun->addText($text_2, array('size' => 14));
         //add chart
         $fileName = $chart->barGraph_2($value['detail'], $examinee_id, 'darkgreen');
         if (file_exists($fileName)) {
             $row->addCell(3000)->addImage($fileName, array('width' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(5.77), 'height' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(5.48), 'wrappingStyle' => 'square'));
         }
         $section->addTextBreak();
     }
     $section->addTextBreak();
     $section->addTitle('三、综合评价', 1);
     if (empty($data['com'])) {
         $section->addText('素质测评模块没有被选中', array('size' => 14, 'bold' => true), array('lineHeight' => 1.5));
         $section->addTextBreak();
     } else {
         $table = $section->addTable();
         $row = $table->addRow();
         $key_array = array();
         //图表名称数组
         $value_array = array();
         // 图表值数组   一位小数
         $new_key_array = array();
         // 文本名称数组
         $des_array = array();
         //描述数组
         $index_array = array();
         foreach ($data['com'] as $key => $value) {
             $key_array[] = $key;
             $value_array[] = $value[0];
             $new_key_array[] = $value['name'];
             $des_array[] = $value['des'];
             $tmp = array();
             $tmp[] = $value[1][0]['name'];
             $tmp[] = $value[1][1]['name'];
             $tmp[] = $value[1][2]['name'];
             $index_array[] = $tmp;
         }
         $text_1 = "    综合评价分析包括对";
         $text_2 = "的分析。其中";
         $text_3 = "。由各指标的得分平均值得出";
         $text_4 = "的综合分。 ";
         $textrun = $row->addCell(7000)->addTextRun(array('lineHeight' => 1.5));
         $textrun->addText($text_1, array('size' => 14));
         $textrun->addText(implode('、', $new_key_array), array('size' => 14, 'bold' => true));
         $textrun->addText($text_2, array('size' => 14));
         $textrun->addText(implode(',', $des_array), array('size' => 14));
         $textrun->addText($text_3, array('size' => 14));
         $textrun->addText(implode('、', $new_key_array), array('size' => 14));
         $textrun->addText($text_4, array('size' => 14));
         //add chart
         $fileName = $chart->radarGraph_1($value_array, $key_array, $examinee_id);
         if (file_exists($fileName)) {
             $row->addCell(3000)->addImage($fileName, array('width' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(5.77), 'height' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(4.92), 'wrappingStyle' => 'square'));
         }
         $i = 0;
         foreach ($new_key_array as $value) {
             $section->addTitle($value, 2);
             $textrun = $section->addTextRun(array('lineHeight' => 1.5));
             $textrun->addText($data['name'], array('size' => 14, 'color' => 'blue'));
             //综合项指标评语  ComprehensiveComment
             $comment = array();
             foreach ($index_array[$i++] as $value) {
                 $comment[] = ComprehensiveComment::findFirst(array('index_chs_name = ?1', 'bind' => array(1 => $value)))->comment;
             }
             $textrun->addText(implode(';', $comment), array('size' => 14));
             $textrun->addText('。', array('size' => 14));
         }
         $section->addTextBreak();
     }
     $section->addTitle('四、结论与建议', 1);
     $table = $section->addTable(array('borderSize' => 1, 'borderColor' => '000000', 'align' => 'center'));
     $row = $table->addRow(600);
     $firstCell = $row->addCell(2000, array('valign' => 'center'))->addText('优势', array('size' => 14, 'color' => 'blue'), array('alignment' => 'center', 'lineHeight' => 1.5));
     $secondCell = $row->addCell(2000);
     $secondCell->getStyle()->setGridSpan(4);
     $i = 1;
     foreach ($data['advantages'] as $value) {
         $secondCell->addText($i++ . '.' . $value, array('size' => 14), array('alignment' => 'left', 'lineHeight' => 1.5));
     }
     $row = $table->addRow(600);
     $firstCell = $row->addCell(2000, array('valign' => 'center'))->addText('改进', array('size' => 14, 'color' => 'blue'), array('alignment' => 'center', 'lineHeight' => 1.5));
     $secondCell = $row->addCell(2000);
     $secondCell->getStyle()->setGridSpan(4);
     $i = 1;
     foreach ($data['disadvantages'] as $value) {
         $secondCell->addText($i++ . '.' . $value, array('size' => 14), array('alignment' => 'left', 'lineHeight' => 1.5));
     }
     $row = $table->addRow(600);
     $row->addCell(2000, array('valign' => 'center', 'vMerge' => 'restart'))->addText('潜质', array('size' => 14, 'color' => 'blue'), array('alignment' => 'center', 'lineHeight' => 1.5));
     $row->addCell(2000, array('valign' => 'center'))->addText("优", array('size' => 14), array('alignment' => 'center', 'lineHeight' => 1.5));
     $row->addCell(2000, array('valign' => 'center'))->addText("良", array('size' => 14), array('alignment' => 'center', 'lineHeight' => 1.5));
     $row->addCell(2000, array('valign' => 'center'))->addText("中", array('size' => 14), array('alignment' => 'center', 'lineHeight' => 1.5));
     $row->addCell(2000, array('valign' => 'center'))->addText("差", array('size' => 14), array('alignment' => 'center', 'lineHeight' => 1.5));
     $row = $table->addRow(600);
     $row->addCell(2000, array('vMerge' => 'continue'));
     for ($i = 0; $i < 4; $i++) {
         if ($data['excellent_evaluate_key'] == $i + 1) {
             $table->addCell(2000)->addText('√', array('size' => 14, 'color' => 'red'), array('alignment' => 'center', 'lineHeight' => 1.5));
         } else {
             $table->addCell(2000);
         }
     }
     $row = $table->addRow(600);
     $firstCell = $row->addCell(2000, array('valign' => 'center'))->addText('评价', array('size' => 14, 'color' => 'blue'), array('alignment' => 'center', 'lineHeight' => 1.5));
     $secondCell = $row->addCell(2000);
     $secondCell->getStyle()->setGridSpan(4);
     $secondCell->addText($data['remark'], array('size' => 14), array('lineHeight' => 1.5));
     $objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($this->wordHandle, 'Word2007');
     //临时文件命名规范    $examinee_id_$date_rand(100,900)
     $date = date('H_i_s');
     $stamp = rand(100, 900);
     $fileName = './tmp/' . $examinee_id . '_' . $date . '_' . $stamp . '.docx';
     $objWriter->save($fileName);
     return $fileName;
 }
 /**
  * @usage 系统胜任力报告生成
  * @param
  */
 public function systemReport($project_id)
 {
     //get basic info
     $systemCompetency = new CompetencyData();
     $data = $systemCompetency->getSystemData($project_id);
     $data_pro = $systemCompetency->getProjectAvgIndex($project_id);
     \PhpOffice\PhpWord\Autoloader::register();
     $this->wordHandle = new \PhpOffice\PhpWord\PhpWord();
     //cell style
     $CellNum = $data['count'] + 1;
     $CellLength = \PhpOffice\PhpWord\Shared\Converter::cmToTwip(18.76) / $CellNum;
     //set section style
     $sectionStyle = array('orientation' => 'portrait', 'marginLeft' => \PhpOffice\PhpWord\Shared\Converter::cmToTwip(3.17), 'marginRight' => \PhpOffice\PhpWord\Shared\Converter::cmToTwip(3.17), 'marginTop' => \PhpOffice\PhpWord\Shared\Converter::cmToTwip(2.54), 'marginBottom' => \PhpOffice\PhpWord\Shared\Converter::cmToTwip(2.54), 'pageSizeW' => \PhpOffice\PhpWord\Shared\Converter::cmToTwip(21), 'pageSizeH' => \PhpOffice\PhpWord\Shared\Converter::cmToTwip(29.7), 'headerHeight' => \PhpOffice\PhpWord\Shared\Converter::cmToTwip(1.5), 'footerHeight' => \PhpOffice\PhpWord\Shared\Converter::cmToTwip(1.75));
     $section = $this->wordHandle->addSection($sectionStyle);
     //set default style
     $this->wordHandle->setDefaultFontName("Microsoft YaHei");
     $captionFontStyle = array('color' => 'red', 'size' => 18, 'bold' => true);
     $titleFontStyle = array('color' => 'blue', 'size' => 14, 'bold' => true);
     $fontStyle1 = array('bold' => true, 'size' => 14);
     $fontStyle2 = array('color' => 'blue', 'size' => 14, 'bold' => true);
     $paragraphStyle1 = array('lineHeight' => 1.5);
     $paragraphStyle2 = array('alignment' => 'center', 'lineHeight' => 1.5);
     $paragraphStyle3 = array('alignment' => 'center');
     //set table style
     $styleTable = array('borderSize' => 6, 'borderColor' => 'black', 'cellMargin' => 80);
     //report part
     $table = $section->addTable($styleTable);
     $table->addRow();
     $cell1_19 = $table->addCell($CellLength);
     $cell1_19->getStyle()->setGridSpan($CellNum);
     $cell1_19->addText("系统胜任力测评结果", $captionFontStyle, $paragraphStyle3);
     $table->addRow();
     $cell2_13 = $table->addCell($CellLength);
     $hebing = floor($CellNum / 3);
     $cell2_13->getStyle()->setGridSpan($hebing);
     $cell2_13->addText("系统名称", $fontStyle1, $paragraphStyle3);
     $cell2_49 = $table->addCell($CellLength);
     $cell2_49->getStyle()->setGridSpan($CellNum - $hebing);
     $cell2_49->addText("XX系统", $fontStyle1, $paragraphStyle3);
     $table->addRow();
     $cell3_19 = $table->addCell($CellLength);
     $cell3_19->getStyle()->setGridSpan($CellNum);
     $cell3_19->addText("胜任素质评分", $titleFontStyle, $paragraphStyle2);
     $table->addRow();
     foreach ($data['advantage']['value'] as $key => $value) {
         $table->addCell($CellLength)->addText($value['chs_name'], $fontStyle1, $paragraphStyle3);
     }
     foreach ($data['disadvantage']['value'] as $key => $value) {
         $table->addCell($CellLength)->addText($value['chs_name'], $fontStyle1, $paragraphStyle3);
     }
     $table->addCell($CellLength)->addText('总分', $fontStyle1, $paragraphStyle3);
     $table->addRow();
     foreach ($data['advantage']['value'] as $key => $value) {
         $table->addCell($CellLength)->addText($value['score'], $fontStyle1, $paragraphStyle3);
     }
     foreach ($data['disadvantage']['value'] as $key => $value) {
         $table->addCell($CellLength)->addText($value['score'], $fontStyle1, $paragraphStyle3);
     }
     $table->addCell($CellLength)->addText($data['value'], $fontStyle1, $paragraphStyle3);
     $table->addRow();
     $cell6_19 = $table->addCell($CellLength);
     $cell6_19->getStyle()->setGridSpan($CellNum);
     //add chart
     $chart = new WordChart();
     $fileName = $chart->radarGraph_2($data, $data_pro, $project_id);
     if (file_exists($fileName)) {
         $cell6_19->addImage($fileName, array('width' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(13.76), 'height' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(7.09), 'wrappingStyle' => 'square'));
     }
     $table->addRow();
     $cell7_19 = $table->addCell($CellLength);
     $cell7_19->getStyle()->setGridSpan($CellNum);
     $cell7_19->addText("胜任力评价 ", $titleFontStyle, $paragraphStyle3);
     $table->addRow();
     $cell8_19 = $table->addCell($CellLength);
     $cell8_19->getStyle()->setGridSpan($CellNum);
     $cell8_19->addText("主要优势有:", array('color' => 'blue', 'size' => 12, 'bold' => true), $paragraphStyle1);
     $array1 = array('一', '二', '三', '四', '五');
     $i = 0;
     foreach ($data['advantage']['value'] as $key => $value) {
         $cell8_19->addText($array1[$i++] . "是" . $value['comment'], array('size' => 12));
     }
     $table->addRow();
     $cell9_19 = $table->addCell($CellLength);
     $cell9_19->getStyle()->setGridSpan($CellNum);
     $cell9_19->addText("有待改进有:", array('color' => 'blue', 'size' => 12, 'bold' => true), $paragraphStyle1);
     $array2 = array('一', '二', '三');
     $i = 0;
     foreach ($data['disadvantage']['value'] as $key => $value) {
         $cell9_19->addText($array2[$i++] . "是" . $value['comment'], array('size' => 12));
     }
     //命名
     //临时文件命名规范    $project_id_$date_rand(100,900)
     $objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($this->wordHandle, 'Word2007');
     $date = date('H_i_s');
     $stamp = rand(100, 900);
     $fileName = './tmp/' . $project_id . '_' . $date . '_' . $stamp . '.docx';
     $objWriter->save($fileName);
     return $fileName;
 }
Esempio n. 4
0
 public function checkoutCpi($examinee, $objActSheet)
 {
     $objActSheet->getDefaultRowDimension()->setRowHeight(16);
     $objActSheet->getDefaultColumnDimension()->setWidth(12);
     $objActSheet->mergeCells('A1:F1');
     $objActSheet->setCellValue('A1', '青年性格问卷(CPI)测试结果');
     $objActSheet->getStyle('A1')->getFont()->setBold(true);
     $this->position($objActSheet, 'A1');
     $objActSheet->setCellValue('A2', '分类号');
     $this->position($objActSheet, 'A2');
     $objActSheet->mergeCells('B2:F2');
     $objActSheet->setCellValue('A3', '编号');
     $this->position($objActSheet, 'A3');
     $objActSheet->setCellValue('B3', $examinee->number);
     $this->position($objActSheet, 'B3');
     $objActSheet->setCellValue('C3', '姓名');
     $this->position($objActSheet, 'C3');
     $objActSheet->setCellValue('D3', $examinee->name);
     $this->position($objActSheet, 'D3');
     $objActSheet->setCellValue('E3', '性别');
     $this->position($objActSheet, 'E3');
     $objActSheet->setCellValue('F3', $examinee->sex == "1" ? "男" : "女");
     $this->position($objActSheet, 'F3');
     $objActSheet->setCellValue('A4', '年龄');
     $this->position($objActSheet, 'A4');
     $age = floor(FactorScore::calAge($examinee->birthday, $examinee->last_login));
     $objActSheet->setCellValue('B4', $age);
     $this->position($objActSheet, 'B4');
     $objActSheet->setCellValue('C4', '职业');
     $this->position($objActSheet, 'C4');
     $objActSheet->setCellValue('D4', $examinee->duty);
     $this->position($objActSheet, 'D4');
     $objActSheet->setCellValue('E4', '测试日期');
     $this->position($objActSheet, 'E4');
     $date = explode(' ', $examinee->last_login)[0];
     $objActSheet->setCellValue('F4', $date);
     $this->position($objActSheet, 'F4');
     $styleArray = array('borders' => array('allborders' => array('style' => PHPExcel_Style_Border::BORDER_THIN)));
     $objActSheet->getStyle('A2:F4')->applyFromArray($styleArray);
     $objActSheet->mergeCells('A5:F5');
     $objActSheet->setCellValue('B6', '因子名称');
     $this->position($objActSheet, 'B6');
     $objActSheet->setCellValue('C6', '代号');
     $this->position($objActSheet, 'C6');
     $objActSheet->setCellValue('D6', '原始分');
     $this->position($objActSheet, 'D6');
     $objActSheet->setCellValue('E6', 'T分');
     $this->position($objActSheet, 'E6');
     $styleArray = array('borders' => array('outline' => array('style' => PHPExcel_Style_Border::BORDER_THIN)));
     $objActSheet->getStyle('A6:F6')->applyFromArray($styleArray);
     $data = CheckoutData::getCPIdata($examinee);
     if (empty($data)) {
         return;
     }
     $array1 = array('do', 'cs', 'sy', 'sp', 'sa', 'wb');
     $array2 = array('re', 'so', 'sc', 'po', 'gi', 'cm');
     $array3 = array('ac', 'ai', 'ie');
     $array4 = array('py', 'fx', 'fe');
     $objActSheet->mergeCells("A7:F7");
     $objActSheet->setCellValue('A7', '第一类  人际关系适应能力的测验');
     $objActSheet->getStyle('A7')->getFont()->setBold(true);
     $this->position($objActSheet, 'A7', 'left');
     $startRow = 7;
     $lastRow = $startRow;
     foreach ($array1 as $value) {
         if (isset($data[$value])) {
             $startRow++;
             $lastRow = $startRow;
             $objActSheet->setCellValue('B' . $startRow, $data[$value]['chs_name']);
             $this->position($objActSheet, 'B' . $startRow);
             $objActSheet->setCellValue('C' . $startRow, ucwords($value));
             $this->position($objActSheet, 'C' . $startRow);
             $objActSheet->setCellValue('D' . $startRow, $data[$value]['score']);
             $this->position($objActSheet, 'D' . $startRow);
             $objActSheet->setCellValue('E' . $startRow, $data[$value]['std_score']);
             $this->position($objActSheet, 'E' . $startRow);
         }
     }
     $objActSheet->getStyle('A7:F' . $lastRow)->applyFromArray($styleArray);
     $startRow++;
     $firstRow = $startRow;
     $lastRow = $startRow;
     $objActSheet->mergeCells('A' . $startRow . ':F' . $startRow);
     $objActSheet->setCellValue('A' . $startRow, '第二类  社会化、成熟度、责任心及价值观念的测验');
     $objActSheet->getStyle('A' . $startRow)->getFont()->setBold(true);
     $this->position($objActSheet, 'A' . $startRow, 'left');
     foreach ($array2 as $value) {
         if (isset($data[$value])) {
             $startRow++;
             $lastRow = $startRow;
             $objActSheet->setCellValue('B' . $startRow, $data[$value]['chs_name']);
             $this->position($objActSheet, 'B' . $startRow);
             $objActSheet->setCellValue('C' . $startRow, ucwords($value));
             $this->position($objActSheet, 'C' . $startRow);
             $objActSheet->setCellValue('D' . $startRow, $data[$value]['score']);
             $this->position($objActSheet, 'D' . $startRow);
             $objActSheet->setCellValue('E' . $startRow, $data[$value]['std_score']);
             $this->position($objActSheet, 'E' . $startRow);
         }
     }
     $objActSheet->getStyle('A' . $firstRow . ':F' . $lastRow)->applyFromArray($styleArray);
     $startRow++;
     $firstRow = $startRow;
     $lastRow = $startRow;
     $objActSheet->mergeCells("A" . $startRow . ":F" . $startRow);
     $objActSheet->setCellValue('A' . $startRow, '第三类  成就能力与智能效率的测验');
     $objActSheet->getStyle('A' . $startRow)->getFont()->setBold(true);
     $this->position($objActSheet, 'A' . $startRow, 'left');
     foreach ($array3 as $value) {
         if (isset($data[$value])) {
             $startRow++;
             $lastRow = $startRow;
             $objActSheet->setCellValue('B' . $startRow, $data[$value]['chs_name']);
             $this->position($objActSheet, 'B' . $startRow);
             $objActSheet->setCellValue('C' . $startRow, ucwords($value));
             $this->position($objActSheet, 'C' . $startRow);
             $objActSheet->setCellValue('D' . $startRow, $data[$value]['score']);
             $this->position($objActSheet, 'D' . $startRow);
             $objActSheet->setCellValue('E' . $startRow, $data[$value]['std_score']);
             $this->position($objActSheet, 'E' . $startRow);
         }
     }
     $objActSheet->getStyle('A' . $firstRow . ':F' . $lastRow)->applyFromArray($styleArray);
     $startRow++;
     $firstRow = $startRow;
     $lastRow = $startRow;
     $objActSheet->mergeCells("A" . $startRow . ":F" . $startRow);
     $objActSheet->setCellValue('A' . $startRow, '第四类  个人的生活态度与倾向的测验');
     $objActSheet->getStyle('A' . $startRow)->getFont()->setBold(true);
     $this->position($objActSheet, 'A' . $startRow, 'left');
     foreach ($array4 as $value) {
         if (isset($data[$value])) {
             $startRow++;
             $lastRow = $startRow;
             $objActSheet->setCellValue('B' . $startRow, $data[$value]['chs_name']);
             $this->position($objActSheet, 'B' . $startRow);
             $objActSheet->setCellValue('C' . $startRow, ucwords($value));
             $this->position($objActSheet, 'C' . $startRow);
             $objActSheet->setCellValue('D' . $startRow, $data[$value]['score']);
             $this->position($objActSheet, 'D' . $startRow);
             $objActSheet->setCellValue('E' . $startRow, $data[$value]['std_score']);
             $this->position($objActSheet, 'E' . $startRow);
         }
     }
     $objActSheet->getStyle('A' . $firstRow . ':F' . $lastRow)->applyFromArray($styleArray);
     $startRow++;
     $startRow++;
     //edit bruce_w 2015-12-9 分页打印
     $startRow += 20;
     $objActSheet->mergeCells("A" . $startRow . ":F" . $startRow);
     $objActSheet->setCellValue('A' . $startRow, '青年性格问卷测试(CPI)剖析图');
     $this->position($objActSheet, 'A' . $startRow);
     $objActSheet->getStyle('A' . $startRow)->getFont()->setBold(true);
     $startRow++;
     $filePath = WordChart::scatter_horiz_Graph_cpi($data, $examinee);
     $objDrawing = new PHPExcel_Worksheet_Drawing();
     $objDrawing->setPath($filePath);
     $width = 15 * 39;
     $height = 20 * 39;
     $objDrawing->setWidthAndHeight($width, $height);
     $objDrawing->setCoordinates("A" . $startRow);
     $objDrawing->setWorksheet($objActSheet);
 }