function PlantillaCorrespondencia() { try { $this->objParam->addParametro('id_funcionario_usuario', $_SESSION["ss_id_funcionario"]); $this->objParam->defecto('ordenacion', 'id_correspondencia'); $this->objParam->defecto('dir_ordenacion', 'desc'); $this->objParam->addFiltro("cor.id_correspondencia = " . $this->objParam->getParametro('id_correspondencia')); $this->objFunc = $this->create('MODCorrespondencia'); $this->res = $this->objFunc->listarCorrespondencia(); if ($this->res->getTipo() == 'ERROR') { $this->res->imprimirRespuesta($this->res->generarJson()); exit; } $correspondencia = $this->res->getDatos(); //obtener detalle de envios $this->objParam->parametros_consulta['ordenacion'] = 'id_correspondencia'; $this->objParam->parametros_consulta['filtro'] = ' 0 = 0 '; $this->objParam->parametros_consulta['cantidad'] = '1000'; $this->objParam->addFiltro("cor.id_correspondencia_fk = " . $this->objParam->getParametro('id_correspondencia')); $this->objFunc = $this->create('MODCorrespondencia'); $this->res = $this->objFunc->listarCorrespondenciaDetalle($this->objParam); if ($this->res->getTipo() == 'ERROR') { $this->res->imprimirRespuesta($this->res->generarJson()); exit; } $correspondenciaDetalle = $this->res->getDatos(); //desc_funcionario -> es el funcionario que lo envia //desc_uo -> //numero numero de la correspondencia /*generamos una imagen qr para ingresar a la plantilla*/ $cadena_qr = '|' . $correspondencia[0]['numero'] . '|' . $correspondencia[0]['desc_uo'] . '|' . $correspondencia[0]['desc_funcionario'] . ''; $barcodeobj = new TCPDF2DBarcode($cadena_qr, 'QRCODE,M'); //todo cambiar ese nombre por algo randon $nombre_archivo = md5($_SESSION["ss_id_usuario_ai"] . $_SESSION["_SEMILLA"]); $png = $barcodeobj->getBarcodePngData($w = 8, $h = 8, $color = array(0, 0, 0)); $im = imagecreatefromstring($png); if ($im !== false) { header('Content-Type: image/png'); imagepng($im, dirname(__FILE__) . "/../../reportes_generados/" . $nombre_archivo . ".png"); imagedestroy($im); $img_qr = dirname(__FILE__) . "/../../reportes_generados/" . $nombre_archivo . ".png"; if ($correspondencia[0]['desc_ruta_plantilla_documento'] == NULL) { throw new Exception('no tiene plantilla o no esta en el formato correspondiente'); } /*agrego a la plantilla word los datos */ $templateProcessor = new \PhpOffice\PhpWord\TemplateProcessor($correspondencia[0]['desc_ruta_plantilla_documento']); $templateProcessor->cloneRow('destinatario', count($correspondenciaDetalle)); for ($i = 0; $i < count($correspondenciaDetalle); $i++) { $xml_destinatario = htmlspecialchars($correspondenciaDetalle[$i]['desc_funcionario']) . '</w:t> </w:r> </w:p> <w:p w:rsidR="003D7875" w:rsidRDefault="006C602F" w:rsidP="006C602F"> <w:pPr> <w:pStyle w:val="Encabezado"/> <w:tabs> <w:tab w:val="clear" w:pos="4818"/> <w:tab w:val="left" w:pos="1276"/> <w:tab w:val="left" w:pos="2268"/> <w:tab w:val="left" w:pos="2552"/> </w:tabs> <w:jc w:val="both"/> <w:rPr> <w:b/> <w:bCs/> <w:iCs/> <w:color w:val="000000"/> <w:lang w:val="es-ES"/> </w:rPr> </w:pPr> <w:r> <w:rPr> <w:b/> <w:bCs/> <w:iCs/> <w:color w:val="000000"/> <w:lang w:val="es-ES"/> </w:rPr> <w:t>' . htmlspecialchars($correspondenciaDetalle[$i]["desc_cargo"]) . '</w:t> </w:r> </w:p>'; $numero_key = $i + 1; $key_name = '${destinatario#' . $numero_key . '}</w:t></w:r></w:p>'; $key_2 = '${destinatario#1}</w:t></w:r></w:p>'; $templateProcessor->setValueDestinatario($key_name, $xml_destinatario); //$templateProcessor->setValue($key_name, $correspondenciaDetalle[$i]['desc_funcionario'].'<br /> '.$correspondenciaDetalle[$i]['desc_cargo']); } setlocale(LC_ALL, "es_ES@euro", "es_ES", "esp"); $fecha_documento = strftime("%d/%m/%Y", strtotime($correspondencia[0]['fecha_documento'])); $templateProcessor->setImg('firma_digital', array('src' => $img_qr, 'swh' => '150')); $templateProcessor->setImgFooter('qr', array('src' => $img_qr, 'swh' => '250')); //$templateProcessor->setImgHeader('qrh',array('src' => $img_qr, 'swh'=>'250')); $templateProcessor->setValue('remitente', htmlspecialchars($correspondencia[0]['desc_funcionario'])); $templateProcessor->setValue('cargo_remitente', htmlspecialchars($correspondencia[0]['desc_cargo'])); $templateProcessor->setValue('referencia', htmlspecialchars($correspondencia[0]['referencia'])); $templateProcessor->setValue('fecha', htmlspecialchars($fecha_documento)); $templateProcessor->setValue('mensaje', htmlspecialchars($correspondencia[0]['mensaje'])); $templateProcessor->setValue('numero', htmlspecialchars($correspondencia[0]['numero'])); //$templateProcessor->setValue('uo', htmlspecialchars($correspondencia[0]['desc_uo'])); $templateProcessor->saveAs(dirname(__FILE__) . '/../../reportes_generados/' . $nombre_archivo . '.docx'); $temp['docx'] = $nombre_archivo . '.docx'; $this->res->setDatos($temp); $this->res->imprimirRespuesta($this->res->generarJson()); } else { echo 'ocurrio un error al guardar la imagen.'; } } catch (Exception $e) { throw new Exception($e->getMessage(), 2); } //fin catch }
$templateProcessor = new \PhpOffice\PhpWord\TemplateProcessor('PHPWord/src/PhpWord/pingjia.docx'); $templateProcessor->setValue('proname', $pro_name); $templateProcessor->setValue('date', date('Y-m-d')); //$templateProcessor->setValue('proname', '项目DDDD'); $templateProcessor->setValue('prolevel', $pro_level); $templateProcessor->setValue('meet', $meet); $templateProcessor->setValue('scores', $scores); //$templateProcessor->cloneRow('num',2); //$templateProcessor->saveAs('./test32.docx'); $str = 'num'; $sum = 0; foreach ($data as $val) { $tec = $val["keywords"]; $sum += count($tec); } $templateProcessor->cloneRow('num', $sum); $j = 1; foreach ($data as $value) { $techs = $value["keywords"]; foreach ($techs as $tech) { //echo "过程名:".$value['name']."|"."技术名称:".$tech['name']."|"."权重:".$tech['weight']."|"."分数:".$tech['pass_score']."</br>"; $templateProcessor->setValue('num#' . $j, $j); $templateProcessor->setValue('pro#' . $j, $value['name']); $templateProcessor->setValue('tech#' . $j, $tech['name']); $templateProcessor->setValue('wt#' . $j, $tech['weight']); $templateProcessor->setValue('fsh#' . $j, $tech['_score']); if ($tech['pass_score'] <= $tech['_score']) { $b = "是"; $templateProcessor->setValue('tf#' . $j, $b); } else { $b = "否";
public function generateDocInvoice($data) { try { //$InvoiceNo = ; $today = date("Y-m-d"); //$contacPerson = $data->ContactPerson; //$taxSize = sizeof($data->TaxJson); $invoiceDetails = $data->Invoice; $rownum = sizeof($data->Details); $templateProcessor = new \PhpOffice\PhpWord\TemplateProcessor('resources/Invoice.docx'); $templateProcessor->setValue('InvoiceNo', $invoiceDetails->InvoiceNo); $templateProcessor->setValue('InvoiceDate', $invoiceDetails->InvoiceDate); $templateProcessor->setValue('QuotationNo', $invoiceDetails->QuotationId); $templateProcessor->setValue('QuotationDate', $invoiceDetails->QuotationDate); $templateProcessor->setValue('WorkorderDate', $invoiceDetails->WorkOrderDate); $templateProcessor->setValue('ContactPerson', "Technicia"); $templateProcessor->cloneRow('Description', $rownum); for ($i = 0; $i < $rownum; $i++) { $y = $i + 1; $sr = "SrNo#" . $y; $des = "Description#" . $y; $qt = "Qty#" . $y; $rat = "rate#" . $y; $amt = "Amount#" . $y; $templateProcessor->setValue($sr, htmlspecialchars($y, ENT_COMPAT, 'UTF-8')); $templateProcessor->setValue($des, htmlspecialchars($data->Details[$i]->quotationDescription, ENT_COMPAT, 'UTF-8')); $templateProcessor->setValue($qt, htmlspecialchars($data->Details[$i]->quotationQuantity, ENT_COMPAT, 'UTF-8')); $templateProcessor->setValue($rat, htmlspecialchars($data->Details[$i]->quotationUnitRate, ENT_COMPAT, 'UTF-8')); $templateProcessor->setValue($amt, htmlspecialchars($data->Details[$i]->amount, ENT_COMPAT, 'UTF-8')); } $templateProcessor->setValue('TotalAmount', $invoiceDetails->TotalAmount); $templateProcessor->setValue('RoundOff', $invoiceDetails->RoundingOffFactor); $templateProcessor->setValue('GrandTotal', $invoiceDetails->GrandTotal); $templateProcessor->saveAs('GeneratedDocs/Invoices/' . $invoiceDetails->InvoiceNo . '.docx'); } catch (PDOException $e) { return "Exception in generateDocInvoice" . $e->getMessage(); } return "Success"; }
<?php include_once 'Sample_Header.php'; // Template processor instance creation echo date('H:i:s'), ' Creating new TemplateProcessor instance...', EOL; $templateProcessor = new \PhpOffice\PhpWord\TemplateProcessor('resources/Sample_07_TemplateCloneRow.docx'); // Variables on different parts of document $templateProcessor->setValue('weekday', htmlspecialchars(date('l'))); // On section/content $templateProcessor->setValue('time', htmlspecialchars(date('H:i'))); // On footer $templateProcessor->setValue('serverName', htmlspecialchars(realpath(__DIR__))); // On header // Simple table $templateProcessor->cloneRow('rowValue', 10); $templateProcessor->setValue('rowValue#1', htmlspecialchars('Sun')); $templateProcessor->setValue('rowValue#2', htmlspecialchars('Mercury')); $templateProcessor->setValue('rowValue#3', htmlspecialchars('Venus')); $templateProcessor->setValue('rowValue#4', htmlspecialchars('Earth')); $templateProcessor->setValue('rowValue#5', htmlspecialchars('Mars')); $templateProcessor->setValue('rowValue#6', htmlspecialchars('Jupiter')); $templateProcessor->setValue('rowValue#7', htmlspecialchars('Saturn')); $templateProcessor->setValue('rowValue#8', htmlspecialchars('Uranus')); $templateProcessor->setValue('rowValue#9', htmlspecialchars('Neptun')); $templateProcessor->setValue('rowValue#10', htmlspecialchars('Pluto')); $templateProcessor->setValue('rowNumber#1', htmlspecialchars('1')); $templateProcessor->setValue('rowNumber#2', htmlspecialchars('2')); $templateProcessor->setValue('rowNumber#3', htmlspecialchars('3')); $templateProcessor->setValue('rowNumber#4', htmlspecialchars('4')); $templateProcessor->setValue('rowNumber#5', htmlspecialchars('5')); $templateProcessor->setValue('rowNumber#6', htmlspecialchars('6'));
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); }