public function actionExport($id) { $filepath = dirname(__FILE__) . '/../runtime/result.docx'; $template_filepath = dirname(__FILE__) . '/../runtime/templates/Template.docx'; if (file_exists($template_filepath)) { $resource = Resource::findOne($id); $filename = $resource->name . '.docx'; $coordinates = json_decode($resource->coordinates); $owner = PersonalData::findOne($resource->owner_data_id); $owner_name = $owner->last_name . ' ' . $owner->first_name . ' ' . $owner->middle_name; $resource_class = ResourceClass::findOne($resource->class_id)->name; $parameters = Parameter::find()->where(['resource_id' => $id])->all(); $attributes = []; foreach ($parameters as $parameter) { $parameter_name = ResourceAttribute::findOne($parameter->attribute_id); $attributes[$parameter_name->name] = $parameter->value; } $linear_size = $attributes['length']; if ($attributes['width']) { $linear_size .= ':' . $attributes['width']; } if ($attributes['height']) { $linear_size .= ':' . $attributes['height']; } \PhpOffice\PhpWord\Autoloader::register(); $templateProcessor = new \PhpOffice\PhpWord\TemplateProcessor($template_filepath); // Template processing $templateProcessor->setValue('name', htmlspecialchars($resource->name, ENT_COMPAT, 'UTF-8')); $templateProcessor->setValue('class', htmlspecialchars($resource_class, ENT_COMPAT, 'UTF-8')); $templateProcessor->setValue('subclass', htmlspecialchars($subclass, ENT_COMPAT, 'UTF-8')); $templateProcessor->setValue('owner', htmlspecialchars($owner_name, ENT_COMPAT, 'UTF-8')); $templateProcessor->setValue('linear_size', htmlspecialchars($linear_size, ENT_COMPAT, 'UTF-8')); $templateProcessor->setValue('area', htmlspecialchars($attributes['square'], ENT_COMPAT, 'UTF-8')); $templateProcessor->setValue('weight', htmlspecialchars($attributes['weight'], ENT_COMPAT, 'UTF-8')); $templateProcessor->setValue('perimeter', htmlspecialchars($attributes['perimeter'], ENT_COMPAT, 'UTF-8')); $templateProcessor->setValue('volume', htmlspecialchars($attributes['volume'], ENT_COMPAT, 'UTF-8')); $templateProcessor->setValue('reason', htmlspecialchars($reason, ENT_COMPAT, 'UTF-8')); $templateProcessor->setValue('registrar', htmlspecialchars($registrar, ENT_COMPAT, 'UTF-8')); $templateProcessor->setValue('registrar_address', htmlspecialchars($registrar, ENT_COMPAT, 'UTF-8')); $templateProcessor->setValue('registration_number', htmlspecialchars($registration_number, ENT_COMPAT, 'UTF-8')); $templateProcessor->setValue('registration_date', htmlspecialchars($creation_date, ENT_COMPAT, 'UTF-8')); $templateProcessor->setValue('registrar_shortname', htmlspecialchars($registrar_short_name, ENT_COMPAT, 'UTF-8')); for ($i = 1; $i <= 20; $i++) { $lat = ""; $lng = ""; if (count($coordinates) >= $i) { $lat = $coordinates[$i - 1][0]; $lng = $coordinates[$i - 1][1]; } $templateProcessor->setValue('lat#' . $i, htmlspecialchars($lat, ENT_COMPAT, 'UTF-8')); $templateProcessor->setValue('lng#' . $i, htmlspecialchars($lng, ENT_COMPAT, 'UTF-8')); } // Saving the document as OOXML file... $templateProcessor->saveAs($filepath); if (file_exists($filepath)) { return \Yii::$app->response->sendFile($filepath, $filename, ['inline' => false])->send(); } } }
function readDocument($path){ $conf =& JFactory::getConfig(); $tmp_path = $conf->getValue('config.tmp_path'); $acceptableFiles = array( 'application/msword' => "doc",//doc 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' => "docx",//docx, 'application/pdf' => "pdf" //pdf ); $finfo = finfo_open(FILEINFO_MIME_TYPE); $file_extension = finfo_file($finfo, $path); finfo_close($finfo); if(array_key_exists($file_extension, $acceptableFiles)){ if($acceptableFiles[$file_extension] == "doc" || $acceptableFiles[$file_extension] == "docx"){ require_once 'libraries/PHPWord-master/src/PhpWord/Autoloader.php'; \PhpOffice\PhpWord\Autoloader::register(); $phpWord = \PhpOffice\PhpWord\IOFactory::load($path); $result = $this->write($phpWord, "temp", array('HTML' => 'html'),$tmp_path); $contents = file_get_contents($tmp_path.'/temp.html', true); }else if($acceptableFiles[$file_extension] == "pdf"){ include 'libraries/pdfparser/vendor/autoload.php'; $parser = new \Smalot\PdfParser\Parser(); $pdf = $parser->parseFile($path); $contents = $pdf->getText(); } } return $contents; }
function __construct($testResultsHandler) { Autoloader::register(); Settings::loadConfig(); $this->testResultsHandler = $testResultsHandler; $this->phpWord = new PhpWord(); }
/** * Autoload */ public function testAutoload() { $declaredCount = count(get_declared_classes()); Autoloader::autoload('Foo'); $this->assertCount($declaredCount, get_declared_classes(), 'PhpOffice\\PhpWord\\Autoloader::autoload() is trying to load ' . 'classes outside of the PhpOffice\\PhpWord namespace'); // TODO change this class to the main PhpWord class when it is namespaced Autoloader::autoload('PhpOffice\\PhpWord\\Exception\\InvalidStyleException'); $this->assertTrue(in_array('PhpOffice\\PhpWord\\Exception\\InvalidStyleException', get_declared_classes()), 'PhpOffice\\PhpWord\\Autoloader::autoload() failed to autoload the ' . 'PhpOffice\\PhpWord\\Exception\\InvalidStyleException class'); }
function __construct() { parent::__construct(); Autoloader::register(); Settings::loadConfig(); Settings::setTempDir(getcwd() . TMPDIR_WORD); // Set writers $writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf', 'HTML' => 'html', 'PDF' => 'pdf'); // Set PDF renderer if (Settings::getPdfRendererPath() === null) { $writers['PDF'] = null; } // Return to the caller script when runs by CLI if (PHP_SAPI == 'cli') { return; } }
<?php include "../core/autoload.php"; include "../core/app/model/ReservationData.php"; include "../core/app/model/PacientData.php"; include "../core/app/model/MedicData.php"; include "../core/app/model/StatusData.php"; include "../core/app/model/PaymentData.php"; session_start(); require_once '../PhpWord/Autoloader.php'; use PhpOffice\PhpWord\Autoloader; use PhpOffice\PhpWord\Settings; Autoloader::register(); $word = new PhpOffice\PhpWord\PhpWord(); $alumns = $_SESSION["report_data"]; $section1 = $word->AddSection(); $section1->addText("REPORTE DE CITAS", array("size" => 22, "bold" => true, "align" => "right")); $styleTable = array('borderSize' => 6, 'borderColor' => '888888', 'cellMargin' => 40); $styleFirstRow = array('borderBottomColor' => '0000FF', 'bgColor' => 'AAAAAA'); $table1 = $section1->addTable("table1"); $table1->addRow(); $table1->addCell()->addText("Asunto"); $table1->addCell()->addText("Paciente"); $table1->addCell()->addText("Medico"); $table1->addCell()->addText("Fecha"); $table1->addCell()->addText("Estado"); $table1->addCell()->addText("Pago"); $table1->addCell()->addText("Costo"); $total = 0; foreach ($alumns as $al) { $medic = $al->getMedic();
<?php include_once dirname(__FILE__) . '/../../lib/PHPWord/src/PhpWord/Autoloader.php'; \PhpOffice\PhpWord\Autoloader::register(); class RTipoDocumento { private $dataSource; private $plantilla; //Ruta relativa para incluir la plantilla public function __construct($PlantillaReporte) { $this->plantilla = $PlantillaReporte; } public function setDataSource(DataSource $dataSource) { $this->dataSource = $dataSource; } public function getDataSource() { return $this->dataSource; } function write($fileName) { $phpWord = new \PhpOffice\PhpWord\PhpWord(); //echo dirname(__FILE__).'/'.$this->plantilla;exit; $document = $phpWord->loadTemplate(dirname(__FILE__) . '/' . $this->plantilla); setlocale(LC_ALL, "es_ES@euro", "es_ES", "esp"); //var_dump($this->dataSource); foreach ($this->dataSource->getParameters() as $col => $val) { //echo 'kkk:'. $col .' '.$val; $document->setValue($col, $val);
function ciniki_conferences_conferenceScheduleDownload($ciniki) { // // Find all the required and optional arguments // ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'prepareArgs'); $rc = ciniki_core_prepareArgs($ciniki, 'no', array('business_id' => array('required' => 'yes', 'blank' => 'no', 'name' => 'Business'), 'conference_id' => array('required' => 'yes', 'blank' => 'no', 'name' => 'Conference'))); if ($rc['stat'] != 'ok') { return $rc; } $args = $rc['args']; // // Make sure this module is activated, and // check permission to run this function for this business // ciniki_core_loadMethod($ciniki, 'ciniki', 'conferences', 'private', 'checkAccess'); $rc = ciniki_conferences_checkAccess($ciniki, $args['business_id'], 'ciniki.conferences.conferenceScheduleDownload'); if ($rc['stat'] != 'ok') { return $rc; } ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'dbHashQuery'); ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'dbHashQueryArrayTree'); ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'dbHashQueryIDTree'); // // Load business settings // ciniki_core_loadMethod($ciniki, 'ciniki', 'businesses', 'private', 'intlSettings'); $rc = ciniki_businesses_intlSettings($ciniki, $args['business_id']); if ($rc['stat'] != 'ok') { return $rc; } $intl_timezone = $rc['settings']['intl-default-timezone']; $intl_currency_fmt = numfmt_create($rc['settings']['intl-default-locale'], NumberFormatter::CURRENCY); $intl_currency = $rc['settings']['intl-default-currency']; ciniki_core_loadMethod($ciniki, 'ciniki', 'users', 'private', 'dateFormat'); ciniki_core_loadMethod($ciniki, 'ciniki', 'users', 'private', 'timeFormat'); $date_format = ciniki_users_dateFormat($ciniki, 'php'); $time_format = ciniki_users_timeFormat($ciniki, 'php'); $mysql_date_format = ciniki_users_dateFormat($ciniki, 'mysql'); // // Load conference maps // ciniki_core_loadMethod($ciniki, 'ciniki', 'conferences', 'private', 'maps'); $rc = ciniki_conferences_maps($ciniki); if ($rc['stat'] != 'ok') { return $rc; } $maps = $rc['maps']; $strsql = "SELECT ciniki_conferences.id, " . "ciniki_conferences.name, " . "ciniki_conferences.permalink, " . "ciniki_conferences.status, " . "ciniki_conferences.status AS status_text, " . "ciniki_conferences.flags, " . "DATE_FORMAT(ciniki_conferences.start_date, '" . ciniki_core_dbQuote($ciniki, $mysql_date_format) . "') AS start_date, " . "DATE_FORMAT(ciniki_conferences.end_date, '" . ciniki_core_dbQuote($ciniki, $mysql_date_format) . "') AS end_date, " . "ciniki_conferences.synopsis, " . "ciniki_conferences.description, " . "ciniki_conferences.imap_mailbox, " . "ciniki_conferences.imap_username, " . "ciniki_conferences.imap_password, " . "ciniki_conferences.imap_subject " . "FROM ciniki_conferences " . "WHERE ciniki_conferences.business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . "AND ciniki_conferences.id = '" . ciniki_core_dbQuote($ciniki, $args['conference_id']) . "' " . ""; $rc = ciniki_core_dbHashQuery($ciniki, $strsql, 'ciniki.conferences', 'conference'); if ($rc['stat'] != 'ok') { return array('stat' => 'fail', 'err' => array('pkg' => 'ciniki', 'code' => '3631', 'msg' => 'Conference not found', 'err' => $rc['err'])); } if (!isset($rc['conference'])) { return array('stat' => 'fail', 'err' => array('pkg' => 'ciniki', 'code' => '3632', 'msg' => 'Unable to find Conference')); } $conference = $rc['conference']; if (isset($maps['conference']['status'][$conference['status_text']])) { $conference['status_text'] = $maps['conference']['status'][$conference['status_text']]; } $strsql = "SELECT ciniki_conferences_sessions.id, " . "CONCAT_WS('-', ciniki_conferences_sessions.id, ciniki_conferences_presentations.id) AS rowid, " . "ciniki_conferences_sessions.conference_id, " . "ciniki_conferences_sessions.room_id, " . "ciniki_conferences_rooms.name AS room, " . "ciniki_conferences_rooms.sequence, " . "ciniki_conferences_sessions.name, " . "ciniki_conferences_sessions.session_start AS start_time, " . "ciniki_conferences_sessions.session_start AS start_date, " . "ciniki_conferences_sessions.session_end AS end_time, " . "IFNULL(ciniki_conferences_presentations.id, 0) AS presentation_id, " . "IFNULL(ciniki_conferences_presentations.customer_id, 0) AS customer_id, " . "IFNULL(ciniki_conferences_presentations.presentation_number, '') AS presentation_number, " . "IFNULL(ciniki_conferences_presentations.title, '') AS presentation_title, " . "IFNULL(ciniki_conferences_presentations.description, '') AS presentation_description, " . "IFNULL(ciniki_customers.display_name, '') AS display_name, " . "IFNULL(ciniki_conferences_presentations.status, 0) AS status, " . "IFNULL(ciniki_conferences_presentations.status, '') AS status_text, " . "IFNULL(ciniki_conferences_attendees.status, 0) AS registration, " . "IFNULL(ciniki_conferences_attendees.status, 0) AS registration_text " . "FROM ciniki_conferences_sessions " . "INNER JOIN ciniki_conferences_rooms ON (" . "ciniki_conferences_sessions.room_id = ciniki_conferences_rooms.id " . "AND ciniki_conferences_rooms.business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . ") " . "LEFT JOIN ciniki_conferences_presentations ON (" . "ciniki_conferences_sessions.id = ciniki_conferences_presentations.session_id " . "AND ciniki_conferences_presentations.business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . ") " . "LEFT JOIN ciniki_conferences_attendees ON (" . "ciniki_conferences_presentations.customer_id = ciniki_conferences_attendees.customer_id " . "AND ciniki_conferences_presentations.conference_id = ciniki_conferences_attendees.conference_id " . "AND ciniki_conferences_attendees.business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . ") " . "LEFT JOIN ciniki_customers ON (" . "ciniki_conferences_presentations.customer_id = ciniki_customers.id " . "AND ciniki_customers.business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . ") " . "WHERE ciniki_conferences_sessions.business_id = '" . ciniki_core_dbQuote($ciniki, $args['business_id']) . "' " . "AND ciniki_conferences_sessions.conference_id = '" . ciniki_core_dbQuote($ciniki, $args['conference_id']) . "' " . "ORDER BY ciniki_conferences_sessions.session_start, " . "ciniki_conferences_rooms.name, " . "ciniki_conferences_rooms.sequence, " . "ciniki_conferences_presentations.title " . ""; ciniki_core_loadMethod($ciniki, 'ciniki', 'core', 'private', 'dbHashQueryArrayTree'); $rc = ciniki_core_dbHashQueryArrayTree($ciniki, $strsql, 'ciniki.conferences', array(array('container' => 'times', 'fname' => 'start_time', 'fields' => array('start_time', 'start_date', 'end_time'), 'utctotz' => array('start_time' => array('format' => $time_format, 'timezone' => $intl_timezone), 'start_date' => array('format' => $date_format, 'timezone' => $intl_timezone), 'end_time' => array('format' => $time_format, 'timezone' => $intl_timezone))), array('container' => 'rooms', 'fname' => 'room_id', 'fields' => array('id' => 'room_id', 'name' => 'room', 'session_name' => 'name', 'presentation_id')), array('container' => 'presentations', 'fname' => 'presentation_id', 'fields' => array('id', 'conference_id', 'room_id', 'room', 'sequence', 'name', 'start_time', 'start_date', 'end_time', 'presentation_id', 'customer_id', 'presentation_number', 'presentation_title', 'presentation_description', 'display_name', 'status', 'status_text', 'registration', 'registration_text'), 'utctotz' => array('start_time' => array('format' => $time_format, 'timezone' => $intl_timezone), 'start_date' => array('format' => $date_format, 'timezone' => $intl_timezone), 'end_time' => array('format' => $time_format, 'timezone' => $intl_timezone)), 'maps' => array('status_text' => $maps['presentation']['status'], 'registration_text' => $maps['attendee']['status'])))); if ($rc['stat'] != 'ok') { return $rc; } if (isset($rc['times'])) { $timeslots = $rc['times']; } else { $timeslots = array(); } // // Generate the word file // require_once $ciniki['config']['core']['lib_dir'] . '/PHPWord/src/PhpWord/Autoloader.php'; \PhpOffice\PhpWord\Autoloader::register(); require $ciniki['config']['core']['lib_dir'] . '/PHPWord/src/PhpWord/PhpWord.php'; $PHPWord = new \PhpOffice\PhpWord\PhpWord(); $PHPWord->addTitleStyle(1, array('bold' => true, 'size' => 18), array('spaceBefore' => 240, 'spaceAfter' => 120)); $PHPWord->addTitleStyle(2, array('bold' => true, 'size' => 16), array('spaceBefore' => 120, 'spaceAfter' => 120)); $PHPWord->addTitleStyle(3, array('bold' => false, 'size' => 14), array('spaceBefore' => 120, 'spaceAfter' => 120)); $style_table = array('cellMargin' => 80, 'borderColor' => 'aaaaaa', 'borderSize' => 6); $style_header = array('borderSize' => 6, 'borderColor' => 'aaaaaa', 'bgColor' => 'dddddd', 'valign' => 'center'); $style_cell = array('borderSize' => 6, 'borderColor' => 'aaaaaa', 'valign' => 'center', 'bgcolor' => 'ffffff'); $style_header_font = array('bold' => true, 'spaceAfter' => 20); $style_cell_font = array(); $style_header_pleft = array('align' => 'left'); $style_header_pright = array('align' => 'right'); $style_cell_pleft = array('align' => 'left'); $style_cell_pright = array('align' => 'right'); $section = $PHPWord->addSection(); $header = $section->addHeader(); $table = $header->addTable(); $table->addRow(); $cell = $table->addCell(9600); $cell->addText($conference['name'], array('size' => '16'), array('align' => 'center')); //print "<pre>" . print_r($timeslots, true) . "</pre>"; //exit; // // Create a table with a row for each time slot // $cur_date = ''; $table = $section->addTable($style_table); $session_number = 1; foreach ($timeslots as $timeslot) { // // Add the date as a header // if ($timeslot['start_date'] != $cur_date) { $table->addRow(); $cell = $table->addCell(1500, $style_cell); $cell->addText($timeslot['start_date']); $cell->setGridSpan(2); $cur_date = $timeslot['start_date']; // $session_number = 1; } // // Add the time slot // $table->addRow(); $cell = $table->addCell(1500, $style_cell); $cell->addText($timeslot['start_time'] . ' - ' . $timeslot['end_time'], $style_cell_font); $nonsession_info = array(); $session_info = array(); if (isset($timeslot['rooms']) && count($timeslot['rooms']) > 0) { foreach ($timeslot['rooms'] as $room) { if (!isset($room['presentations']) || $room['presentation_id'] == 0) { if (isset($room['presentations'][0])) { $session = $room['presentations'][0]; if ($session['name'] != '') { $nonsession_info[] = $session['name']; } } $nonsession_info[] = "Location: " . $room['name']; } else { $session_info[] = $session_number . ". " . $room['session_name'] . ": "; $presentation_number = 1; $presentation_info = ''; foreach ($room['presentations'] as $presentation) { if ($presentation_number > 1) { $presentation_info .= "; "; } $presentation_info .= $presentation_number . ") " . $presentation['display_name']; $presentation_number++; } $session_info[] = $presentation_info; $session_info[] = "Location: " . $room['name']; $session_info[] = ""; $session_number++; } } } $cell = $table->addCell(2500, $style_cell); foreach ($nonsession_info as $line) { $cell->addText($line, $style_cell_font); } $cell = $table->addCell(5500, $style_cell); foreach ($session_info as $line) { $cell->addText($line, $style_cell_font); } } $section = $PHPWord->addSection(); $header = $section->addHeader(); $table = $header->addTable(); $table->addRow(); $cell = $table->addCell(9600); $cell->addText($conference['name'], array('size' => '16'), array('align' => 'center')); $session_number = 1; foreach ($timeslots as $timeslot) { if (isset($timeslot['rooms']) && count($timeslot['rooms']) > 0) { foreach ($timeslot['rooms'] as $room) { if (!isset($room['presentations']) || $room['presentation_id'] == 0) { continue; } $section->addTitle($session_number . ". " . $room['session_name'], 1); if (isset($room['presentations']) && $room['presentation_id'] != 0) { foreach ($room['presentations'] as $pid => $presentation) { $section->addTitle($presentation['display_name'], 2); $section->addTitle(htmlspecialchars($presentation['presentation_title']), 3); $lines = explode("\n", $presentation['presentation_description']); foreach ($lines as $line) { $section->addText(htmlspecialchars($line), array()); } $section->addText(''); } } $session_number++; } } } // // Output the word file // header('Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document'); header('Content-Disposition: attachment;filename="' . preg_replace("/[^A-Za-z0-9]/", '', $conference['name']) . '.docx"'); header('Cache-Control: max-age=0'); $objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($PHPWord, 'Word2007'); $objWriter->save('php://output'); return array('stat' => 'exit'); }
/** * Generate export file of current result */ protected function _genExport($po_result, $ps_output_type, $ps_output_filename, $ps_title = null) { $this->view->setVar('criteria_summary', $vs_criteria_summary = $this->getCriteriaForDisplay()); // add displayable description of current search/browse parameters $this->view->setVar('criteria_summary_truncated', mb_substr($vs_criteria_summary, 0, 60) . (mb_strlen($vs_criteria_summary) > 60 ? '...' : '')); $this->opo_result_context->setParameter('last_export_type', $ps_output_type); $this->opo_result_context->saveContext(); if (substr($ps_output_type, 0, 4) !== '_pdf') { switch ($ps_output_type) { case '_xlsx': require_once __CA_LIB_DIR__ . "/core/Parsers/PHPExcel/PHPExcel.php"; require_once __CA_LIB_DIR__ . "/core/Parsers/PHPExcel/PHPExcel/Writer/Excel2007.php"; $vs_content = $this->render('Results/xlsx_results.php'); return; case '_docx': require_once __CA_LIB_DIR__ . "/core/Parsers/PHPWord/Autoloader.php"; \PhpOffice\PhpWord\Autoloader::register(); $vs_content = $this->render('Results/docx_results.php'); return; case '_csv': $vs_delimiter = ","; $vs_output_file_name = mb_substr(preg_replace("/[^A-Za-z0-9\\-]+/", '_', $ps_output_filename . '_csv'), 0, 30); $vs_file_extension = 'txt'; $vs_mimetype = "text/plain"; break; case '_tab': $vs_delimiter = "\t"; $vs_output_file_name = mb_substr(preg_replace("/[^A-Za-z0-9\\-]+/", '_', $ps_output_filename . '_tab'), 0, 30); $vs_file_extension = 'txt'; $vs_mimetype = "text/plain"; default: break; } header("Content-Disposition: attachment; filename=export_" . $vs_output_file_name . "." . $vs_file_extension); header("Content-type: " . $vs_mimetype); // get display list self::Index(null, null); $va_display_list = $this->view->getVar('display_list'); $va_rows = array(); // output header $va_row = array(); foreach ($va_display_list as $va_display_item) { $va_row[] = $va_display_item['display']; } $va_rows[] = join($vs_delimiter, $va_row); $po_result->seek(0); $t_display = $this->view->getVar('t_display'); while ($po_result->nextHit()) { $va_row = array(); foreach ($va_display_list as $vn_placement_id => $va_display_item) { $vs_value = html_entity_decode($t_display->getDisplayValue($po_result, $vn_placement_id, array('convert_codes_to_display_text' => true, 'convertLineBreaks' => false)), ENT_QUOTES, 'UTF-8'); // quote values as required if (preg_match("![^A-Za-z0-9 .;]+!", $vs_value)) { $vs_value = '"' . str_replace('"', '""', $vs_value) . '"'; } $va_row[] = $vs_value; } $va_rows[] = join($vs_delimiter, $va_row); } $this->opo_response->addContent(join("\n", $va_rows), 'view'); } else { // // PDF output // $va_template_info = caGetPrintTemplateDetails('results', substr($ps_output_type, 5)); if (!is_array($va_template_info)) { $this->postError(3110, _t("Could not find view for PDF"), "BaseFindController->PrintSummary()"); return; } try { $this->view->setVar('base_path', $vs_base_path = pathinfo($va_template_info['path'], PATHINFO_DIRNAME)); $this->view->addViewPath(array($vs_base_path, "{$vs_base_path}/local")); $vs_content = $this->render($va_template_info['path']); $o_dompdf = new DOMPDF(); $o_dompdf->load_html($vs_content); $o_dompdf->set_paper(caGetOption('pageSize', $va_template_info, 'letter'), caGetOption('pageOrientation', $va_template_info, 'portrait')); $o_dompdf->set_base_path(caGetPrintTemplateDirectoryPath('results')); $o_dompdf->render(); $o_dompdf->stream(caGetOption('filename', $va_template_info, 'export_results.pdf')); } catch (Exception $e) { $this->postError(3100, _t("Could not generate PDF"), "BaseFindController->PrintSummary()"); } return; } }
public function downloadWord() { // echo COMMON_PATH . 'Org/PhpWord/Autoloader.php';exit; require_once COMMON_PATH . 'Org/PhpWord/Autoloader.php'; \PhpOffice\PhpWord\Autoloader::register(); \PhpOffice\PhpWord\Settings::loadConfig(); echo date('H:i:s'), ' Create new PhpWord object', EOL; $phpWord = new \PhpOffice\PhpWord\PhpWord(); $section = $phpWord->addSection(); $header = array('size' => 16, 'bold' => true); $styleTable = array('borderSize' => 6, 'borderColor' => '000000', 'cellMargin' => 80, 'width' => '100%'); $styleFirstRow = array('borderBottomSize' => 18, 'borderBottomColor' => '0000FF', 'bgColor' => '66BBFF'); $styleCell = array('align' => 'center'); $fontStyle = array('bold' => true, 'align' => 'center'); $section->addText("用户相关", $header); $phpWord->addTableStyle('Table', $styleTable); $table = $section->addTable('Table'); $table->addRow(30); $table->addCell(2000, $styleCell)->addText("字段", $fontStyle); $table->addCell(1000, $styleCell)->addText("类型", $fontStyle); $table->addCell(800, $styleCell)->addText("必选", $fontStyle); $table->addCell()->addText("说明", $fontStyle); for ($i = 1; $i <= 8; $i++) { $table->addRow(); $table->addCell(2000)->addText("userTel"); $table->addCell(1000)->addText("字符串"); $table->addCell(800)->addText("是"); $table->addCell()->addText(htmlspecialchars("手机号码")); } $section->addPageBreak(); $fileName = "word报表" . date("YmdHis") . ".docx"; // header("Content-type: application/vnd.ms-word"); // header("Content-Disposition:attachment;filename=".$fileName.".docx"); // header('Cache-Control: max-age=0'); $phpWord->save($fileName, 'Word2007'); }
/** * @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; }
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; }
public function actionExport($id) { $templateFilepath = dirname(__FILE__) . '/../runtime/templates/Template2.docx'; $source = dirname(__FILE__) . '/../runtime/temp.docx'; \PhpOffice\PhpWord\Autoloader::register(); $templateProcessor = new \PhpOffice\PhpWord\TemplateProcessor($templateFilepath); $months = ['Січня', 'Лютого', 'Березня', 'Квітня', 'Травня', 'Червня', 'Липня', 'Серпня', 'Вересня', 'Жовтня', 'Листопада', 'Грудня']; $date = getdate(); $currentDate = $date['mday'] . ' ' . $months[$date['mon'] - 1] . ' ' . $date['year'] . ' року'; $extractNumber = '№' . $date['mday'] . ($date['mon'] - 1) . substr($date['year'], -2); $templateProcessor->setValue('date', $currentDate); $templateProcessor->setValue('number', $extractNumber); $templateProcessor->saveAs($source); $phpWord = \PhpOffice\PhpWord\IOFactory::load($source); //$phpWord = new \PhpOffice\PhpWord\PhpWord(); $phpWord->setDefaultFontName('Times New Roman'); $phpWord->setDefaultFontSize(11); $sectionStyle = ['marginTop' => 1000]; $tableStyle = ['borderSize' => 6, 'borderColor' => '000', 'cellMargin' => 0]; $innerTableStyle = ['cellMargin' => 20]; $boldFontStyle = ['bold' => true]; $italicFontStyle = ['italic' => true]; $styleCell = ['valign' => 'center']; $styleCellBTLR = ['valign' => 'center', 'textDirection' => \PhpOffice\PhpWord\Style\Cell::TEXT_DIR_BTLR]; $innerTableCellStyle = ['borderRightSize' => 6, 'borderRightColor' => '000', 'borderLeftSize' => 6, 'borderLeftColor' => '000', 'borderBottomSize' => 6, 'borderBottomColor' => '000']; $innerTableRightCellStyle = ['borderLeftSize' => 6, 'borderLeftColor' => '000', 'borderBottomSize' => 6, 'borderBottomColor' => '000']; $innerTableFontStyle = ['size' => 9]; $innerTableParagraphStyle = ['align' => 'center']; // Get resource data $resource = Resource::findOne($id); $filename = $resource->name . '.docx'; $coordinates = json_decode($resource->coordinates); $owner_name = 'народ України (Український народ)'; $resource_class = 'природний ресурс'; $resource_subclass = ResourceClass::findOne($resource->class_id)->name; $creation_date = $resource->date; $registrar = PersonalData::findOne($resource->registrar_data_id); $registrar_info = $registrar->last_name . ' ' . $registrar->first_name . ' ' . $registrar->middle_name . ' ' . $registrar->address; $registrar_shortname = $registrar->last_name . $registrar->first_name[0] . '. ' . $registrar->middle_name[0] . '.'; $parameters = Parameter::find()->where(['resource_id' => $id])->all(); $attributes = []; foreach ($parameters as $parameter) { $parameter_name = ResourceAttribute::findOne($parameter->attribute_id); $attributes[$parameter_name->name] = $parameter->value; } $length = $attributes['length']; $width = $attributes['width']; $height = $attributes['height']; if ($length || $width || $height) { if (!$length) { $length = '0'; } if (!$width) { $width = '0'; } if (!$height) { $height = '0'; } $attributes['linear_size'] = $length . ':' . $width . ':' . $height; } $reason = $resource->reason; function formatCoords($num) { $num = round($num, 4, PHP_ROUND_HALF_DOWN); $degrees = floor($num); $minfloat = ($num - $degrees) * 60; $minutes = floor($minfloat); $secfloat = ($minfloat - $minutes) * 60; $seconds = round($secfloat); if ($seconds == 60) { $minutes++; $seconds = 0; } if ($minutes == 60) { $degrees++; $minutes = 0; } return (string) $degrees . '°' . (string) $minutes . '\'' . (string) $seconds . '"'; } $tableFields = ['Найменування об’єкту' => $resource->name, 'Клас об’єкту' => $resource_class, 'Підклас об’єкту' => $resource_subclass, 'Власник об’єкту' => $owner_name, 'Географічні координати кутів (вершин) об’єкту у форматі ГГ°ММ\'СС,СС". ' => $coordinates, 'Лінійні розміри об’єкту, Д:Ш:В, м' => $attributes['linear_size'], 'Загальна площа об’єкту, га' => $attributes['square'] / 10000, 'Маса (вага) об’єкту, кг' => $attributes['weight'], 'Периметр об’єкту, м' => $attributes['perimeter'], 'Об’єм об’єкту, м3' => $attributes['volume'], 'Підстава для внесення відомостей до Реєстру' => $reason, 'ПІБ та поштова адреса народного реєстратора' => $registrar_info, 'Реєстраційний номер об’єкту' => $registration_number, 'Дата створення запису' => $creation_date]; $tableUnitalicFields = ['Клас об’єкту', 'Власник об’єкту']; $sections = $phpWord->getSections(); $section = $sections[0]; $phpWord->addTableStyle('Resource Table', $tableStyle); $table = $section->addTable('Resource Table'); foreach ($tableFields as $key => $value) { if ($value) { if (!is_array($value)) { $valueFontStyle = []; if (in_array($key, $tableUnitalicFields)) { $valueFontStyle = $italicFontStyle; } $table->addRow(200); $table->addCell(\PhpOffice\PhpWord\Shared\Converter::cmToTwip(8))->addText(htmlspecialchars($key, ENT_COMPAT, 'UTF-8'), $boldFontStyle); $table->addCell(\PhpOffice\PhpWord\Shared\Converter::cmToTwip(15))->addText(htmlspecialchars($value, ENT_COMPAT, 'UTF-8'), $valueFontStyle); } else { $row = $table->addRow(); $row->addCell(\PhpOffice\PhpWord\Shared\Converter::cmToTwip(8))->addText(htmlspecialchars($key, ENT_COMPAT, 'UTF-8'), $boldFontStyle); $cell = $row->addCell(); $innerTable = $cell->addTable($innerTableStyle); $innerTable->addRow(10); $innerTable->addCell(\PhpOffice\PhpWord\Shared\Converter::cmToTwip(4), $innerTableCellStyle)->addText(htmlspecialchars('Північна широта', ENT_COMPAT, 'UTF-8'), $innerTableFontStyle, $innerTableParagraphStyle); $innerTable->addCell(\PhpOffice\PhpWord\Shared\Converter::cmToTwip(4), $innerTableCellStyle)->addText(htmlspecialchars('Східна довгота', ENT_COMPAT, 'UTF-8'), $innerTableFontStyle, $innerTableParagraphStyle); $innerTable->addCell(\PhpOffice\PhpWord\Shared\Converter::cmToTwip(4), $innerTableCellStyle)->addText(htmlspecialchars("Північна широта \n(продовження)", ENT_COMPAT, 'UTF-8'), $innerTableFontStyle, $innerTableParagraphStyle); $innerTable->addCell(\PhpOffice\PhpWord\Shared\Converter::cmToTwip(4), $innerTableRightCellStyle)->addText(htmlspecialchars("Східна довгота \n(продовження)", ENT_COMPAT, 'UTF-8'), $innerTableFontStyle, $innerTableParagraphStyle); $coordinatesNumber = count($coordinates); for ($i = 1; $i <= round($coordinatesNumber / 2); $i++) { $lat = ''; $lng = ''; $latCont = ''; $lngCont = ''; if ($coordinatesNumber >= $i) { $lat = formatCoords($coordinates[$i - 1][0]); $lng = formatCoords($coordinates[$i - 1][1]); } if ($coordinatesNumber >= round($coordinatesNumber / 2) + $i) { $latCont = formatCoords($coordinates[$i + round($coordinatesNumber / 2) - 1][0]); $lngCont = formatCoords($coordinates[$i + round($coordinatesNumber / 2) - 1][1]); } $innerTable->addRow(10); $innerTable->addCell(\PhpOffice\PhpWord\Shared\Converter::cmToTwip(4), $innerTableCellStyle)->addText(htmlspecialchars($lat, ENT_COMPAT, 'UTF-8'), $italicFontStyle); $innerTable->addCell(\PhpOffice\PhpWord\Shared\Converter::cmToTwip(4), $innerTableCellStyle)->addText(htmlspecialchars($lng, ENT_COMPAT, 'UTF-8'), $italicFontStyle); $innerTable->addCell(\PhpOffice\PhpWord\Shared\Converter::cmToTwip(4), $innerTableCellStyle)->addText(htmlspecialchars($latCont, ENT_COMPAT, 'UTF-8'), $italicFontStyle); $innerTable->addCell(\PhpOffice\PhpWord\Shared\Converter::cmToTwip(4), $innerTableRightCellStyle)->addText(htmlspecialchars($lngCont, ENT_COMPAT, 'UTF-8'), $italicFontStyle); } } } } $section->addTextBreak(2); $section->addText('Народний реєстратор', $boldFontStyle); $section->addText(htmlspecialchars($registrar_shortname, ENT_COMPAT, 'UTF-8')); header("Content-Description: File Transfer"); header('Content-Disposition: attachment; filename="' . $filename . '"'); header('Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document'); header('Content-Transfer-Encoding: binary'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Expires: 0'); $xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007'); $xmlWriter->save("php://output"); }
public function report($project_id) { $data = new ProjectComData(); $data->project_check($project_id); $chart = new WordChart(); $project = Project::findFirst($project_id); //----------------------------------- \PhpOffice\PhpWord\Autoloader::register(); $this->wordHandle = new \PhpOffice\PhpWord\PhpWord(); // layout $sectionStyle = array('orientation' => 'portrait', 'marginLeft' => \PhpOffice\PhpWord\Shared\Converter::cmToTwip(2.2), 'marginRight' => \PhpOffice\PhpWord\Shared\Converter::cmToTwip(2.2), 'marginTop' => \PhpOffice\PhpWord\Shared\Converter::cmToTwip(2.2), 'marginBottom' => \PhpOffice\PhpWord\Shared\Converter::cmToTwip(1.9), 'pageSizeW' => \PhpOffice\PhpWord\Shared\Converter::cmToTwip(21), 'pageSizeH' => \PhpOffice\PhpWord\Shared\Converter::cmToTwip(29.7), 'headerHeight' => \PhpOffice\PhpWord\Shared\Converter::cmToTwip(1), 'footerHeight' => \PhpOffice\PhpWord\Shared\Converter::cmToTwip(0.8)); //add section $section = $this->wordHandle->addSection($sectionStyle); $section->getStyle()->setPageNumberingStart(1); $header = $section->addHeader(); $header = $header->createTextrun(); $header->addImage('reportimage/logo_2.jpg', array('marginTop' => -1, 'marginLeft' => \PhpOffice\PhpWord\Shared\Converter::cmToInch(1), 'width' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(5.98), 'height' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(1.54), 'wrappingStyle' => 'square')); $header->addText($project->name . "总体分析报告", array('color' => 'red', 'size' => 11), array('lineHeight' => 1, 'alignment' => 'right')); $footer = $section->addFooter(); $footer->addPreserveText('{PAGE}', array('size' => 10, 'color' => '000000'), array('alignment' => 'center', 'lineHeight' => 1)); //cover part $paragraphStyle = array('alignment' => 'center', 'lineHeight' => 1.5); $defaultParagraphStyle = array('lineHeight' => 1.5); $captionFontStyle = array('name' => 'Microsoft YaHei', 'size' => 22, 'color' => 'red', 'bold' => true); $section->addTextBreak(6); $section->addText($project->name . "总体分析报告", $captionFontStyle, $paragraphStyle); $section->addPageBreak(); //set title style---TOC $this->wordHandle->addTitleStyle(1, array('size' => 16, 'bold' => true), array('lineHeight' => 1.5)); $this->wordHandle->addTitleStyle(2, array('size' => 15, 'bold' => true), array('lineHeight' => 1.5)); $this->wordHandle->addTitleStyle(3, array('size' => 12, 'bold' => true), array('lineHeight' => 1.5)); //catalog part $section->addText("目录", array('color' => 'blue', 'size' => 12), $paragraphStyle); $section->addTOC(array('size' => 12), \PhpOffice\PhpWord\Style\TOC::TABLEADER_LINE, 1, 3); $section->addPageBreak(); $captionFontStyle2 = array('name' => 'Microsoft YaHei', 'size' => 18, 'color' => 'red', 'bold' => true); $section->addText($project->name . "总体分析报告", $captionFontStyle2, $paragraphStyle); //part1 项目背景 $section->addTitle("一、项目背景", 1); //------------------------------------------------------------------------- $examinee = Examinee::find(array('project_id=?1 AND type = 0 ', 'bind' => array(1 => $project_id))); $examinee = $examinee->toArray(); $examinee_num = count($examinee); //总人数 $exam_date_start = explode(' ', $project->begintime)[0]; //开始时间 $exam_date_end = explode(' ', $project->endtime)[0]; //结束时间 $min_time = 0; $total_time = 0; $level_array = array(1 => 0, 2 => 0, 3 => 0, 4 => 0); foreach ($examinee as $examinee_record) { if ($min_time == 0 || $min_time > $examinee_record['exam_time']) { $min_time = $examinee_record['exam_time']; } $total_time += $examinee_record['exam_time']; $level = ReportData::getLevel($examinee_record['id']); $level_array[$level]++; } $min_time_str = null; foreach (array(3600 => '小时', 60 => '分', 1 => '秒') as $key => $value) { if ($min_time >= $key) { $min_time_str .= floor($min_time / $key) . $value; $min_time %= $key; } } //最短答题时间 $average_time = $total_time / $examinee_num; $average_time_str = null; foreach (array(3600 => '小时', 60 => '分', 1 => '秒') as $key => $value) { if ($average_time >= $key) { $average_time_str .= floor($average_time / $key) . $value; $average_time %= $key; } } //平均答题时间 $rate_1 = sprintf('%.2f', $level_array[1] / $examinee_num) * 100 . '%'; //优秀率 $rate_2 = sprintf('%.2f', $level_array[2] / $examinee_num) * 100 . '%'; //良好率 $rate_3 = sprintf('%.2f', $level_array[3] / $examinee_num) * 100 . '%'; //中等率 // --------------------------------------------------------- $section->addText(" 为了充分开发中青年人才资源,了解中青年人才水平、培养有潜力人才及科技骨干、选拔一批经验丰富,德才兼备的中青年高技能人才,北京XXX集团(后简称“集团”),采用第三方北京技术交流培训中心(以下简称“中心”)自主研发26年,通过上下、左右、前后六维(简称“6+1”)测评技术,对集团" . $examinee_num . "名中青年人才进行了一次有针对性的测评。从" . $exam_date_start . "到" . $exam_date_end . ",在集团培训中心进行上机测试。规定测评时间为3小时,最短完成时间为" . $min_time_str . ",一般为" . $average_time_str . "左右。 ", $defaultParagraphStyle); $section->addText(" 测评后进行专家(四位局级以上领导干部)与中青年人才一对一人均半小时的沟通(简称“面询”), 这是区别国内所有综合测评机构的独有特色。面询内容有三:一是根据测评结果按优劣势分析归纳与评价;二是双方互动理解与确认测评结果;三是现场解答每位人才提出的问题,并给予针对性、个性化的解决方案与建议。", $defaultParagraphStyle); $section->addText(" 通过对" . $examinee_num . "位中青年人才综合统计分析,按优良中差排序结果为:全体优秀率达" . $rate_1 . ",良好" . $rate_2 . "。在测评和专家面询后,对全部人才进行了无记名的满意度调查,参加调查83人,回收有效问卷83份,有效率100%,满意度100%。(满意度调查报告详见附件1) ", $defaultParagraphStyle); $section->addTitle("1、测评目的", 2); $section->addTitle("第一、为中青年人才培训提供科学参考依据", 3); $section->addText(" 在传统的人事管理信息系统中,人与人之间的差别只体现在性别、年龄、职务、工种、学历、职称、工作经历上,而却忽略了内隐素质能力上的差异。综合测评可以帮助集团领导了解中青年人才更多重要的信息,为个性化培养与培训提供科学、准确的依据。在对人才进行精准识别后,还进行了人岗匹配,针对岗位胜任程度和潜质提出了使用与培养的建议。通过本次测评,清晰了集团中青年人才职业心理、职业素质、智体结构、职业能力和发展潜质,为集团下一步的培训工作提供了科学、客观、准确的依据。", $defaultParagraphStyle); $section->addTitle("第二、为中青年人才提供自我认知和自我提升的工具", 3); $section->addText(" 通过综合测评,帮助了这些人才全面、系统、客观、准确了解自我;通过结合岗位职责一对一面询,让这些人才更加明确自身优势与劣势;清晰哪些技能和素质需要进一步培训,在实际工作中扬长避短,促进自我职业生涯与集团战略的有机结合。", $defaultParagraphStyle); $section->addTitle("2、测评流程", 2); $section->addText(" 综合测评分为五个阶段:", $defaultParagraphStyle); $section->addText(" 一是测评前准备。这一阶段确定测试人才的人数、测评时间、测评内容、测评群体的总体情况;收集测评人才简历;编制测评总体需求量表。", $defaultParagraphStyle); $section->addText(" 二是人机对话测评。通过“6+1”系统综合测评,人均获取近1000个定性与定量数据,经过数据处理与统计分析,为专家面询提供科学、准确、客观、真实的测评结果。", $defaultParagraphStyle); $section->addText(" 三是专家面询。这一过程人均半小时,目的是让有较高领导岗位经历和复合学科背景的专家依据测评结果,与中青年人才一对一的互动沟通:首先,帮他们清晰自己的优劣势;其次,为他们排忧解惑;最后,为每位中青年人才梳理出与集团发展匹配的对策。", $defaultParagraphStyle); $section->addText(" 四是撰写总体与个体报告。依据对“6+1”大数据分析结果撰写总体综合素质分析报告;整合个人测评结果和专家面询评价,撰写每位人才的综合测评分析报告。", $defaultParagraphStyle); $section->addText(" 五是汇报与反馈。向集团领导汇报总体与个体测评结果,反馈无记名满意度调查报告等,针对集团发展战略和现代人力资源管理提出针对性的建议与对策。", $defaultParagraphStyle); $section->addTitle("3、技术路径", 2); $section->addText(" “中心”的综合测评系统始于1988年博士研究成果,经历了26年实践检验,其过程(1)测评地域:北京、上海、天津、广东、山西、湖南、湖北、陕西、内蒙、海南、浙江、山东、辽宁、河南等省市;(2)年龄:20~68岁;(3)学历:大专~博士后;(4)职称:初级~两院士;(5)职务:初、中级~政府副部长、部队中将(陆海空);(6)类型:跨国公司高管、各类企业高管与技术人才;(7)测评人数:3万多人;(8)测评数据:每人925个;(9)获得荣誉:7次获国家自然科学基金资助,2次获航空科学基金资助,4次获省部级科学技术进步二等奖和管理成果一等奖;在国内外核心刊物发表论文30多篇,专著一本;测评软件50多套;培养出3名博士、9名硕士;经调查,客户反映测评准确率高、效果明显,平均满意度达97.8%,受到被测评人才和用人单位的普遍欢迎和认可。", $defaultParagraphStyle); //part2 基本情况分析 $section->addTitle("二、综合测评基本情况分析", 1); $inquery_data = $data->getInqueryAnsComDetail($project_id); //-------------------------------------------------------------------- #获取inquery_data 第一个数据项 以及 总体人数 $section->addText(" 参加本次测评对象是集团的中青年人才(或简称“人才”),有" . (count($inquery_data[0]['options']) + 1) . "个重要定义:", $defaultParagraphStyle); $textrun = $section->addTextRun(array('lineHeight' => 1.5)); $textrun->addText('第一,'); $textrun->addText('总体', array('color' => 'red')); $textrun->addText(':' . $examinee_num . '人'); $time_array = array('第二', '第三', '第四', '第五', '第六', '第七', '第八', '第九', '第十', '第十一', '第十二', '第十三', '第十四', '第十五'); $i = 0; foreach ($inquery_data[0]['options'] as $value) { $textrun = $section->addTextRun(array('lineHeight' => 1.5)); $textrun->addText($time_array[$i] . ','); $textrun->addText($value, array('color' => 'red')); $textrun->addText(':' . array_sum($inquery_data[0]['value'][$i++]) . '人'); } $section->addTitle("(一)基本信息分析", 2); //先分析简单项-----按照题目需求量表来 n项 $i = 1; foreach ($inquery_data as $value) { $section->addTitle($i . '-逐项分析', 3); $table = $section->addTable(array('borderSize' => 1, 'borderColor' => '000000')); $row = $table->addRow(500); $row->addCell(1000, array('valign' => 'center'))->addText('分类', array('size' => 10.5), array('alignment' => 'center')); $row->addCell(1000, array('valign' => 'center'))->addText('人数', array('size' => 10.5), array('alignment' => 'center')); $row->addCell(1000, array('valign' => 'center'))->addText('比例', array('size' => 10.5), array('alignment' => 'center')); $j = 0; foreach ($value['options'] as $option_value) { $row = $table->addRow(500); $row->addCell(1000, array('valign' => 'center'))->addText($option_value, array('size' => 10.5), array('alignment' => 'center')); $row->addCell(1000, array('valign' => 'center'))->addText(array_sum($inquery_data[$i - 1]['value'][$j]), array('size' => 10.5), array('alignment' => 'center')); $row->addCell(1000, array('valign' => 'center'))->addText(sprintf('%.2f', array_sum($inquery_data[$i - 1]['value'][$j]) / $examinee_num) * 100 . '%', array('size' => 10.5), array('alignment' => 'center')); $j++; } $i++; //add chart -- 饼图 -- 加不了 无法湖区到图表名称 //add text $section->addTextBreak(); $section->addText(' 相关分析:', array('color' => 'blue', 'bold' => true), array('lineHeight' => 1.5)); $section->addTextBreak(); } //交叉项分析----从第二道题开始 与第一项进行比较 综合分析 n-1项 $i = 1; foreach ($inquery_data as $value) { $section->addTitle($i . '-交叉项分析', 3); $table = $section->addTable(array('borderSize' => 1, 'borderColor' => '000000')); $row = $table->addRow(500); $row->addCell(1000, array('valign' => 'center'))->addText('分类', array('size' => 10.5), array('alignment' => 'center')); foreach ($inquery_data[0]['options'] as $level_name) { $row->addCell(1000, array('valign' => 'center'))->addText($level_name, array('size' => 10.5), array('alignment' => 'center')); } $j = 0; foreach ($value['options'] as $option_value) { $row = $table->addRow(500); $row->addCell(1000, array('valign' => 'center'))->addText($option_value, array('size' => 10.5), array('alignment' => 'center')); foreach ($inquery_data[$i - 1]['value'][$j] as $value_level_number) { $row->addCell(1000, array('valign' => 'center'))->addText($value_level_number, array('size' => 10.5), array('alignment' => 'center')); } $j++; } $i++; $section->addTextBreak(); $section->addText(' 相关分析:', array('color' => 'blue', 'bold' => true), array('lineHeight' => 1.5)); $section->addTextBreak(); } $level_examinees = $data->getBaseLevels($project_id); // //测评结果 $section->addTitle("三、测评结果及特点分析", 1); $section->addTitle("1、突出优势的特征", 2); $advantage_data = $data->getProjectAdvantages($project_id); $number = 1; $existed_factors = array(); //遍历优势结果集 foreach ($advantage_data as $advantage_record) { $section->addTitle($number++ . $advantage_record['chs_name'], 3); $children_str = $advantage_record['children']; $children_array = explode(',', $children_str); //图表数据 storage $storage = array(); foreach ($level_examinees as $level_record) { $storage[] = array(); } //遍历优势指标的下属 $factor = 'A'; //保证每个指标的下属因子少于26 foreach ($children_array as $children_name) { $factor_value_by_level = $data->getFactorGrideByLevel(null, $children_name, $level_examinees, $project_id); for ($i = 0, $len = count($storage); $i < $len; $i++) { $storage[$i][$factor] = $factor_value_by_level[$i]; } $factor++; } //各层人员各种因子的数据获取完成 $storage ; $table = $section->addTable(array('borderSize' => 1, 'borderColor' => '000000')); $row = $table->addRow(500); $row->addCell(1000, array('valign' => 'center'))->addText('分类', array('size' => 10.5), array('alignment' => 'center')); foreach ($storage[0] as $stor_key => $stor_value) { $row->addCell(1000, array('valign' => 'center'))->addText($stor_key, array('size' => 10.5), array('alignment' => 'center')); } $j = 0; foreach ($storage as $storage_record) { $row = $table->addRow(500); $row->addCell(1000, array('valign' => 'center'))->addText($inquery_data[0]['options'][$j], array('size' => 10.5), array('alignment' => 'center')); foreach ($storage_record as $storage_record_value) { $row->addCell(1000, array('valign' => 'center'))->addText($storage_record_value, array('size' => 10.5), array('alignment' => 'center')); } $j++; } $section->addTextBreak(); //优势3项下属 $advantage_three = array(); $advantage_count = 0; foreach ($advantage_record['detail'] as $factor_info) { //优势指标中选取前三 if ($advantage_count >= 3) { break; } if (in_array($factor_info['chs_name'], $existed_factors)) { continue; } else { $existed_factors[] = $factor_info['chs_name']; } //获取前三因子 factor_info['chs_name'] $advantage_three[$factor_info['chs_name']] = array(); $advantage_count++; //优势因子获取优势评语 //取 28项指标的下属 // $advantage_comment = ReportComment::findFirst(array( // 'name=?1', // 'bind'=>array(1=>$factor_info['chs_name'])))->advantage; // $advantage_comment_array = explode("|", $advantage_comment); $advantage_comment = ChildIndexComment::findFirst(array('index_chs_name = ?1 AND child_chs_name =?2', 'bind' => array(1 => $advantage_record['chs_name'], 2 => $factor_info['chs_name'])))->advantage; $advantage_comment_array = json_decode($advantage_comment, true); $rand_key = array_rand($advantage_comment_array); $comment = $advantage_comment_array[$rand_key]; //优势因子评语 $advantage_three[$factor_info['chs_name']]['comment'] = $comment; $factor_by_level = $data->getFactorGrideByLevel($factor_info['chs_name'], null, $level_examinees, $project_id); arsort($factor_by_level); //逆序排列 $level_arsort_array = array(); foreach ($factor_by_level as $arsort_key => $arsort_value) { $level_arsort_array[] = $inquery_data[0]['options'][$arsort_key]; } $advantage_three[$factor_info['chs_name']]['level_arsort'] = $level_arsort_array; } //优势3项获取完毕 ----- $advantage_three $section->addText('特征描述', array('color' => 'blue', 'size' => 11, 'bold' => true)); $number_array = array('一', '二', '三'); $i = 0; foreach ($advantage_three as $value) { $section->addText($number_array[$i++] . $value['comment'], $defaultParagraphStyle); } $section->addTextBreak(); foreach ($advantage_three as $key => $value) { $section->addText($key . ':' . implode(',', $value['level_arsort']), $defaultParagraphStyle); } $section->addTextBreak(); } $section->addTitle('2、需要完善和提升的方面', 2); //$level_examinees =$data->getBaseLevels($project_id); $disadvantage_data = $data->getProjectDisadvantages($project_id); $number = 1; $existed_factors = array(); //遍历劣势结果集 foreach ($disadvantage_data as $disadvantage_record) { $section->addTitle($number++ . $disadvantage_record['chs_name'], 3); $children_str = $disadvantage_record['children']; $children_array = explode(',', $children_str); //图表数据 storage $storage = array(); foreach ($level_examinees as $level_record) { $storage[] = array(); } //遍历优势指标的下属 $factor = 'A'; //保证每个指标的下属因子少于26 foreach ($children_array as $children_name) { $factor_value_by_level = $data->getFactorGrideByLevel(null, $children_name, $level_examinees, $project_id); for ($i = 0, $len = count($storage); $i < $len; $i++) { $storage[$i][$factor] = $factor_value_by_level[$i]; } $factor++; } //各层人员各种因子的数据获取完成 $storage ; $table = $section->addTable(array('borderSize' => 1, 'borderColor' => '000000')); $row = $table->addRow(500); $row->addCell(1000, array('valign' => 'center'))->addText('分类', array('size' => 10.5), array('alignment' => 'center')); foreach ($storage[0] as $stor_key => $stor_value) { $row->addCell(1000, array('valign' => 'center'))->addText($stor_key, array('size' => 10.5), array('alignment' => 'center')); } $j = 0; foreach ($storage as $storage_record) { $row = $table->addRow(500); $row->addCell(1000, array('valign' => 'center'))->addText($inquery_data[0]['options'][$j], array('size' => 10.5), array('alignment' => 'center')); foreach ($storage_record as $storage_record_value) { $row->addCell(1000, array('valign' => 'center'))->addText($storage_record_value, array('size' => 10.5), array('alignment' => 'center')); } $j++; } $section->addTextBreak(); //劣势3项下属 $disadvantage_three = array(); $disadvantage_count = 0; foreach ($disadvantage_record['detail'] as $factor_info) { //劣势指标中选取前三 if ($disadvantage_count >= 3) { break; } if (in_array($factor_info['chs_name'], $existed_factors)) { continue; } else { $existed_factors[] = $factor_info['chs_name']; } //获取前三因子 factor_info['chs_name'] $disadvantage_three[$factor_info['chs_name']] = array(); $disadvantage_count++; //劣势因子获取劣势因子 // $disadvantage_comment = ReportComment::findFirst(array( // 'name=?1', // 'bind'=>array(1=>$factor_info['chs_name'])))->disadvantage; // $disadvantage_comment_array = explode("|", $disadvantage_comment); $disadvantage_comment = ChildIndexComment::findFirst(array('index_chs_name = ?1 AND child_chs_name =?2', 'bind' => array(1 => $disadvantage_record['chs_name'], 2 => $factor_info['chs_name'])))->disadvantage; $disadvantage_comment_array = json_decode($disadvantage_comment, true); $rand_key = array_rand($disadvantage_comment_array); $comment = $disadvantage_comment_array[$rand_key]; //优势因子评语 $disadvantage_three[$factor_info['chs_name']]['comment'] = $comment; $factor_by_level = $data->getFactorGrideByLevel($factor_info['chs_name'], null, $level_examinees, $project_id); arsort($factor_by_level); //逆序排列 $level_arsort_array = array(); foreach ($factor_by_level as $arsort_key => $arsort_value) { $level_arsort_array[] = $inquery_data[0]['options'][$arsort_key]; } $disadvantage_three[$factor_info['chs_name']]['level_arsort'] = $level_arsort_array; } //劣势3项获取完毕 ----- $disadvantage_three $section->addText('特征描述', array('color' => 'blue', 'size' => 11, 'bold' => true)); $number_array = array('一', '二', '三'); $i = 0; foreach ($disadvantage_three as $value) { $section->addText($number_array[$i++] . $value['comment'], $defaultParagraphStyle); } $section->addTextBreak(); foreach ($disadvantage_three as $key => $value) { $section->addText($key . ':' . implode(',', $value['level_arsort']), $defaultParagraphStyle); } $section->addTextBreak(); } $section->addTitle("四、职业素质综合评价", 1); $comprehensive_data = $data->getComprehensiveData($project_id); if (empty($comprehensive_data)) { $section->addText('素质测评模块没有被选中', array('size' => 14, 'bold' => true), array('lineHeight' => 1.5)); $section->addTextBreak(); } else { //chart data $chart_labels = array(); $chart_values = array(); foreach ($comprehensive_data as $comprehensive_record) { $chart_labels[] = $comprehensive_record['name']; //图表中的标签名称 $chart_values[] = $comprehensive_record['value']; //图表中对应项的得分数据 } //add data chart $table = $section->addTable(array('borderSize' => 1, 'borderColor' => '000000')); $row = $table->addRow(500); foreach ($chart_labels as $chart_label_value) { $row->addCell(1000, array('valign' => 'center'))->addText($chart_label_value, array('size' => 10.5), array('alignment' => 'center')); } $row = $table->addRow(500); foreach ($chart_values as $chart_label_value) { $row->addCell(1000, array('valign' => 'center'))->addText($chart_label_value, array('size' => 10.5), array('alignment' => 'center')); } $number_tk = 1; foreach ($comprehensive_data as $comprehensive_record) { $module_record = Module::findFirst(array("name = ?1", 'bind' => array(1 => $comprehensive_record['name_in_table']))); //MemoryCache::getModuleDetail($comprehensive_record['name_in_table']); //根据数据库中存储的模块名称获取模块的下属children ,之后按照原有的children顺序来排列指标得分 $children = explode(',', $module_record->children); $search_array = array(); foreach ($comprehensive_record['children'] as $com_value) { $search_array[$com_value['id']] = sprintf('%.2f', $com_value['score']); } foreach ($children as &$value) { $index_info = Index::findFirst(array('name=?1', 'bind' => array(1 => $value))); $value = $search_array[$index_info->id]; } //$children 按顺序排列的指标得分 $section->addTitle($number_tk++ . $comprehensive_record['name'], 2); $table = $section->addTable(array('borderSize' => 1, 'borderColor' => '000000')); $row = $table->addRow(500); $number = count($children); $start = 'A'; for ($i = 0; $i < $number; $i++) { $row->addCell(1000, array('valign' => 'center'))->addText($start++, array('size' => 10.5), array('alignment' => 'center')); } $row = $table->addRow(500); foreach ($children as $chart_label_value) { $row->addCell(1000, array('valign' => 'center'))->addText($chart_label_value, array('size' => 10.5), array('alignment' => 'center')); } //前三指标评语 $three_index = array_slice($comprehensive_record['children'], 0, 3); $comment = array(); foreach ($three_index as $three_value) { $comment[] = ComprehensiveComment::findFirst(array('index_chs_name = ?1', 'bind' => array(1 => $three_value['chs_name'])))->comment; } $section->addTextBreak(); $section->addText(implode(';', $comment) . '。', $defaultParagraphStyle); $section->addTextBreak(); } } // //结论与建议 $section->addTitle("五、结论与建议", 1); $section->addTitle("(一)本次综合测评的基本评价", 2); $section->addTitle("1、印证了集团对中青年人才培养前瞻性、系统性和实效性", 3); $section->addText(" 通过本次综合测评与统计分析,得到了具有优秀发展潜质的中青年人才占" . $rate_1 . "、有良好发展潜质占" . $rate_2 . "、中等潜质为" . $rate_3 . "的测评结果,进一步证明了集团在中青年人才培养体系的系统性、科学性、精准性、可行性及实操性。", $defaultParagraphStyle); $section->addTitle("2、量化了集团中青年人才的发展潜质和培养与培训路径", 3); $section->addText(" 以人均1000多个数据为基础,有复合的理论体系和系统的方法体系为支撑,对所有参加测评的中青年人才量化的内容有四:一是进行了发展潜质的量化排序;二是精确了能否胜任现有岗位的五级评分;三是明确了今后的培养方向;四是清晰了下一步培训的重点。", $defaultParagraphStyle); $section->addTitle("3、形成了具有XXX集团特色的中青年人才队伍", 3); $section->addText(" 集团有一支性别结构均衡、有行业特点,人才梯队结构年龄分布合理,专业门类较齐全、理工科配备合适,学历结构适当,对集团发展前景高度认可的中青年人才队伍。", $defaultParagraphStyle); $section->addTitle("4、突显了集团中青年人才特质", 3); $section->addText(" 形成了外向开朗、身心健康、阳光向上、精力充沛的人格;思路清晰,有追求和不断总结的归纳提炼能力;具有后天勤奋和先天聪明,勇于实践,训练有素的分析能力;还具有自律谨严,心胸开阔,持之以恒的纪律性;能很好胜任现有岗位的中青年人才特质。", $defaultParagraphStyle); $section->addTitle("5、彰显了集团对人才培养与培训合理性", 3); $section->addText(" 以XXX类专业技术人才为主体的中青年人才结构,能够与承担的集团工作任务特点相适应;通过培训需求和学历调查得知,中青年人才均受过高等教育,有较高的工作能力和职业素质,有丰富的工作经验,是一支总体素质较高的人才队伍。", $defaultParagraphStyle); $section->addTitle("6、突出了中青年人才较高的自知之明,普遍比较低调", 3); $section->addText(" 总体对自身发展有较明确定位,对个人能力的特长、胜任岗位的优势,以及能力素质的短板有比较客观的认识与评价,对职业生涯发展规划有迫切的需求。如:在在专家面询中,他们与专家互动最多的是如何改进自己的不足。而在“6+1”调查中,统计自认为非常胜任现有工作岗位是25%,但实际测评结果却是50%。", $defaultParagraphStyle); $section->addTitle("7、达成了个人与集团发展较一致的职业目标", 3); $section->addText(" 对自身建设的努力方向、存在的问题和面临的任务,有比较一致的认识,并与集团促进人才发展目标较相吻合。因为100%的人对集团发展有信心,这些人才以在XXX工作为荣,把个人目标与集团目标匹配期望度非常高。", $defaultParagraphStyle); $section->addTitle("8、锻炼了一支经过基层磨练、综合素质高的集团总部中青年人才队伍", 3); $section->addText(" 集团总部中青年人才在心理健康、归纳能力、分析能力、聪慧性及对自我约束等均高于其他测评人才,而且他们大都经过基层历练,为集团机关发展与改革储备了优质与可靠的人才基础。", $defaultParagraphStyle); $section->addTitle("(二)本次测评出现的主要问题", 2); $section->addTitle("1、集团在引进中青年人才来源还需要进一步优化", 3); $section->addText(" 中青年人才的专业结构较全面,学历水平比较高,职称层次较多。但来自名牌高校的优秀人才并不多,这也为什么在相应专业领域没有形成领军人才的直接原因。", $defaultParagraphStyle); $section->addTitle("2、集团总部人才优势与实际工作相矛盾的影响要引起重视", 3); $section->addText(" 测评结果显示,集团总部人才在工作的执著性、人际关系调节和独立工作能力均得分不高,但他们的实际潜质证明对应这三方面的短板是恰恰是他们的优势。为什么会出现这样矛盾呢?原因为:一是在集团总部有些部门存在管理传统和领导强势或无序;二是某些重要岗位出现人岗不匹配,理论上是出现了“彼德原理”现象,实际上是影响到下级或整个部门综合素质水平;三是集团总部“官本位”与现代管理相互交织产生的“蝴蝶效应”,不仅影响到这些人才,更重要的是已波及到总部管理层和下属企业。", $defaultParagraphStyle); $section->addTitle("3、危机感、局限性、依赖性较高比例不容忽视", 3); $section->addText(" 特别要强调的是:本次测评中68%的中青年人才工作求稳怕乱,除与本岗位有关的内容外,对其他的事情关心或关注很少,长此以往就会出现眼界不开阔、洞察力不强的局面;有79%的人才做事依靠上级布置,缺乏自主意识,不考虑工作为什么做,怎么样做;有75%的人才工作的执着性不强,自己有正确意见也不愿意或不敢发表,不太关心集团期望目标,只关注自己是否能完成局部的任务。长此下去,出了问题很难找到责任人,岗位责任与集团的绩效管理和绩效考核会形同虚设。", $defaultParagraphStyle); $section->addTitle("4、集团需要系统化的培训体系", 3); $section->addText(" 从综合测评看到:集团的培训年年都在不断创新,不断改进,不断提升。但随着外部环境不断变化,应对式的培训已经满足不了集团各层级人才的需求,这就需要从集团战略顶层面系统思考的培训规划与体系。如:中青年人才非常需要职业技能、管理方法、沟通技巧等系统的综合素质与能力方面的培训,也期望集团在这些方面加大对他们训练的力度,尽快提升他们的综合素质。", $defaultParagraphStyle); $section->addTitle("5、岗位稳定性过高,晋升困难,“天花板”和“温水煮青蛙”并存", 3); $section->addText(" 大部分中青年人才在当前职位上长久得不到调整或者提升,有些人才在基层助理职位上工作已有8年或更长。虽然岗位稳定能让人才在现有职务上游刃有余的完成工作,但思维模式和工作方法容易禁锢于固有的模式之中,“温水煮青蛙”的现象在这些人才中比较这普遍,长此下去,他们对职业前景的期待成为了“天花板”,随之带来就是理想逐渐倦怠,工作缺乏激情。", $defaultParagraphStyle); $section->addTitle("6、薪酬福利急待提升", 3); $section->addText(" 调查结果显示,大量中青年人才选择在集团工作的原因只有很少是因为薪资福利优厚;在希望集团能够改善的问题,更多人的期望能提高收入,增加福利。这说明集团在吸引优秀人才上,薪资福利的吸引力较弱,这也是吸引不到国内外优秀人才的重要原因所在。", $defaultParagraphStyle); $section->addTitle("(三)建议与对策", 2); $section->addTitle("1、建立与集团战略匹配的现代化人力资源管理体系", 3); $section->addText(" 综合考虑本次测评结果,建议集团尽快建立与集团战略匹配的现代化人力资源管理体系。以中青年人才综合素质测评作为切入点,制定科学、规范、合理的人才发展规划;以培养高层次、复合型人才为重点,打造有目标、有重点、有计划、有针对性的现代化人力资源管理体系。", $defaultParagraphStyle); $section->addTitle("2、建立完善的薪酬福利体系,加大激励与吸引优秀人才的力度", 3); $section->addText(" 通过本次测评,中青年人才普遍希望集团的薪酬福利能够进一步得到提升,希望能引起集团领导的关注并提出匹配的解决对策。尽管XXX属于城市公共服务类,但其服务水平、所承担的职责和忠诚度远远高于一般的企业,而这一切取决于人才综合素质。", $defaultParagraphStyle); $section->addTitle("3、建立基于集团战略的现代人力资源管理的培训体系", 3); $section->addText(" 以集团人才规划为出发点,根据不同层次的人才,建立健全适合集团发展战略的培训体系已迫在眉睫。并在此基础上开展针对各层次人才的短板、个性化的培训,提升集团人才队伍的整体综合素质能力;注重中青年人才结合岗位需求有针对性培训,加大对这些人才培养与培训力度,重点就专业技能、管理方法、团队合作、人际沟通等进行全方位、多形式的培训。", $defaultParagraphStyle); $section->addTitle("4、建立合理的调岗及晋升制度,搭建中青年人才成长平台", 3); $section->addText(" 中青年人才在集团工作的稳定性普遍很高,但同时存在的问题就是没有多余的岗位吸引新的优秀人才加入。集团建立合理的调岗及晋升制度之后,不仅能促进现有人才的工作积极行,明确他们的职业发展道路,激发其工作热情,避免“天花板”现象;调岗和人才晋升之后,空余的岗位可以吸纳更多优秀的人才,给集团人才梯队注入新鲜血液,带来新思想、新技能。", $defaultParagraphStyle); $section->addTitle("5、对不同层次后备人才进行职业生涯规划", 3); $section->addText(" 结合集团战略与人才发展规划,以各层次后备人才综合测评作为切入点,以培养高层次、复合型人才为重点,打造有目标、有重点、有计划、有针对性的人才职业生涯规划和针对性、使用与培养相结合的体系。", $defaultParagraphStyle); $section->addTitle("6、建立不同层次人才综合素质体系,让优秀人才脱颖而出", 3); $section->addText(" 针对集团管理层和领导方法等有待提升的空间,以本次中青年人才综合测评结果为契机,在不同层次、不同群体人才综合素质与需求动机进行对比分析基础上,建立与集团发展战略需求相匹配胜任力标准,让德才兼备,想干事、能干事、干成事的人才在集团平台上施展自己的才华,使XXX集团成为行业的标杆!", $defaultParagraphStyle); //命名 //临时文件命名规范 $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; }
function mergeDOCX($source_file, $merged_file) { // Important: we get the merge data first, because the phpWord // autoloader included below stuffs up the Jethro autoloader // and causes errors. $data = array_values($this->getMergeData()); // NB THIS FILE HAS BEEN CHANGED! require_once 'include/phpword/src/PhpWord/Autoloader.php'; \PhpOffice\PhpWord\Autoloader::register(); \PhpOffice\PhpWord\Settings::setTempDir(dirname($source_file)); $templateProcessor = new \PhpOffice\PhpWord\TemplateProcessor($source_file); if (!$templateProcessor->cloneBlock('MERGEBLOCK', count($data))) { $vars = $templateProcessor->getVariables(); if (empty($vars)) { trigger_error("You don't seem to have included any \${keywords} in your file; cannot merge"); return; } $templateProcessor->cloneRow(reset($vars), count($data)); } foreach ($data as $num => $row) { foreach ($row as $k => $v) { $templateProcessor->setValue(strtoupper($k) . '#' . ($num + 1), $this->xmlEntities($v)); } } $templateProcessor->saveAs($merged_file); }