public function test() { // Include the PHPWord.php, all other classes were loaded by an autoloader require_once APPPATH . '/libraries/PHPWord.php'; //$this->load->library('PHPWord'); // Create a new PHPWord Object $PHPWord = new PHPWord(); //$PHPWord = $this->phpword; // Every element you want to append to the word document is placed in a section. So you need a section: $section = $PHPWord->createSection(); // After creating a section, you can append elements: $section->addText('Hello world!'); // You can directly style your text by giving the addText function an array: $section->addText('Hello world! I am formatted.', array('name' => 'Tahoma', 'size' => 16, 'bold' => true)); // If you often need the same style again you can create a user defined style to the word document // and give the addText function the name of the style: $PHPWord->addFontStyle('myOwnStyle', array('name' => 'Verdana', 'size' => 14, 'color' => '1B2232')); $section->addText('Hello world! I am formatted by a user defined style', 'myOwnStyle'); // You can also putthe appended element to local object an call functions like this: $myTextElement = $section->addText('Hello World!'); //$myTextElement->setBold(); //$myTextElement->setName('Verdana'); //$myTextElement->setSize(22); $styleTable = array('borderColor' => '006699', 'borderSize' => 6, 'cellMargin' => 50); $styleFirstRow = array('bgColor' => '66BBFF'); $PHPWord->addTableStyle('myTable', $styleTable, $styleFirstRow); $table = $section->addTable('myTable'); $table->addRow(); $cell = $table->addCell(2000); $cell->addText('Cell 1'); $cell = $table->addCell(2000); $cell->addText('Cell 2'); // $cell = $table->addCell(2000); //$cell->addText('Cell 3'); // Add image elements $section->addImage(APPPATH . '/images/side/jqxs-l.JPG'); $section->addTextBreak(1); //$section->addImage(APPPATH.'/images/side/jqxs-l.JPG', array('width'=>210, 'height'=>210, 'align'=>'center')); //$section->addTextBreak(1); //$section->addImage(APPPATH.'/images/side/jqxs-l.jpg', array('width'=>100, 'height'=>100, 'align'=>'right')); // At least write the document to webspace: $objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007'); $objWriter->save('helloWorld.docx'); exit; //download /* $filename='just_some_random_name.docx'; //save our document as this file name header('Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document'); //mime type header('Content-Disposition: attachment;filename="'.$filename.'"'); //tell browser what's the file name header('Cache-Control: max-age=0'); //no cache $objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007'); $objWriter->save('php://output'); */ //force download // $this->load->helper('download'); // $data = file_get_contents("helloWorld.docx"); // Read the file's contents // $name = 'helloWorld.docx'; // force_download($name, $data); }
$sectionStyle = $section->getSettings(); // Add header $header = $section->createHeader(); $styleTable = array('borderColor' => '006699', 'borderSize' => 2); $styleFirstRow = array('bgColor' => '66BBFF'); $PHPWord->addTableStyle('myTable', $styleTable, $styleFirstRow); $table = $header->addTable(); $table->addRow(); //$table->addCell(1510)->addImage('./../img/logo.gif', array('width'=>151, 'height'=>43, 'align'=>'left')); replaceHtml($table->addCell(1510), '<img src="./../img/logo.jpg">'); // $table->addCell(4500)->addText('Proyecto FONDEF D08i-1074', array('size'=>12), array('align'=>'right')); // $table->addCell(4500)->addText('www.kelluwen.cl', array('size'=>10), array('align'=>'right')); $table->addCell(2500)->addText(''); $text = "<p><b><" . $lang_crear_diseno_word_proyecto . "</b></p><p>" . $lang_crear_diseno_url_kelluwen . "</p>"; replaceHtml($table->addCell(3700), $text, array('align' => 'right', 'border' => false, 'spaceAfter' => 10)); $PHPWord->addFontStyle('tamano_titulo', array('bold' => true, 'italic' => false, 'size' => 12)); $PHPWord->addParagraphStyle('parrafo_titulo', array('align' => 'center')); $section->addTextBreak(1); $section->addText($lang_crear_diseno_word_estructura . ": " . $fcd_nombre, 'tamano_titulo', 'pStyle'); // $section->addTextBreak(1); /*TABLA CON EL RESUMEN DE LAS ACTIVIDADES*/ /*Estilo tabla de resumen de actividades*/ $styleTableDiseno = array('borderSize' => 6, 'borderColor' => '000000', 'cellMargin' => 80); $styleFirstRowTableDiseno = array('bgColor' => 'D9D9D9'); /*Estilo celda nombre actividad*/ $styleCelda = array('bold' => true); $PHPWord->addTableStyle('StyleTableDiseno', $styleTableDiseno, $styleFirstRowTableDiseno); $tableDiseno = $section->addTable('StyleTableDiseno'); $tableDiseno->addRow(400); $tableDiseno->addCell(2890)->addText($lang_crear_diseno_word_etapa . ' 1', array('bold' => true, 'italic' => false, 'size' => 11)); $tableDiseno->addCell(2890)->addText($lang_crear_diseno_word_etapa . ' 2', array('bold' => true, 'italic' => false, 'size' => 11));
public function generate($id = 0) { $this->load->library('PHPWord'); $this->load->helper('util'); $date = date('Y-m-d_H-i-s'); $no = 1; $no2 = 1; //if ($id==0); $conf = $this->db->get($this->cms_complete_table_name('konfigurasi'))->result(); $cont = $this->db->get($this->cms_complete_table_name('master_cont_pkl'))->result(); $mhs = $this->db->where('fk_id_pkl', $id)->join($this->cms_complete_table_name('mas_jurusan'), 'mas_jurusan.id_jurusan=mhs_pkl.id_jurusan', 'left')->get($this->cms_complete_table_name('mhs_pkl'))->result(); $data = $this->db->where('id_pkl', $id)->join($this->cms_complete_table_name('mhs_pkl'), 'fk_id_pkl=fk_id_pkl', 'left')->join($this->cms_complete_table_name('mas_jurusan'), 'mas_jurusan.id_jurusan=mhs_pkl.id_jurusan', 'left')->get($this->cms_complete_table_name('pkl'))->result(); $PHPWord = new PHPWord(); // New portrait section $section = $PHPWord->createSection(array('pageSizeH' => 20500)); // Define the TOC font style // Add title styles $styleTable = array('cellMargin' => 20); $styleTable_mhs = array('cellMargin' => 20, 'borderSize' => 6); $PHPWord->addFontStyle(1, array('size' => 16, 'color' => '333333', 'underline' => PHPWord_Style_Font::UNDERLINE_SINGLE)); $PHPWord->addFontStyle(2, array('size' => 12, 'bold' => true)); $PHPWord->addFontStyle('underline', array('size' => 11.5, 'underline' => PHPWord_Style_Font::UNDERLINE_SINGLE)); $PHPWord->addFontStyle('bold', array('size' => 11.5, 'bold' => true)); $PHPWord->addParagraphStyle('pStyle', array('align' => 'center', 'spaceAfter' => 10)); $PHPWord->addParagraphStyle('pHead', array('spaceAfter' => 0)); $PHPWord->addParagraphStyle('pTempat', array('spaceAfter' => 10, 'marginLeft' => 3000)); $PHPWord->addParagraphStyle('pStyle_footer', array('tabs' => array(new PHPWord_Style_Tab('left', 5700)), 'align' => 'center', 'spaceAfter' => 10)); $PHPWord->addParagraphStyle('pStyle_tbs', array('size' => 11, 'align' => 'left', 'spaceAfter' => 10)); $fontStyle = array('size' => 11.5); //Content foreach ($data as $d) { $section->addText('', 'pHead'); $table = $section->addTable(); $table->addRow(); $table->addCell(1250, $styleTable)->addText("", $fontStyle, 'pHead'); $table->addCell(20, $styleTable)->addText("", $fontStyle, 'pHead'); $table->addCell(9000, $styleTable)->addText("", $fontStyle, 'pHead'); $table->addRow(); $table->addCell(1250, $styleTable)->addText("Nomor", $fontStyle, 'pHead'); $table->addCell(20, $styleTable)->addText(": ", $fontStyle, 'pHead'); $table->addCell(9000, $styleTable)->addText("{$d->nomor}", $fontStyle, 'pHead'); $table->addRow(); $table->addCell(1250, $styleTable)->addText("Lamp", $fontStyle, 'pHead'); $table->addCell(20, $styleTable)->addText(": ", $fontStyle, 'pHead'); $table->addCell(9000, $styleTable)->addText("{$d->lampiran}", $fontStyle, 'pHead'); $table->addRow(); $table->addCell(1250, $styleTable)->addText("Hal", $fontStyle, 'pHead'); $table->addCell(20, $styleTable)->addText(": ", $fontStyle, 'pHead'); $table->addCell(9000, $styleTable)->addText("Permohonan PKL/Magang Mahasiswa", 'underline', 'pHead'); $section->addText('', 'pHead'); $table = $section->addTable(); $table->addRow(); $table->addCell(400, $styleTable)->addText("", $fontStyle, 'pHead'); $table->addCell(8200, $styleTable)->addText("Kepada Yth.", $fontStyle, 'pHead'); $table->addRow(); $table->addCell(400, $styleTable)->addText("", $fontStyle, 'pHead'); $table->addCell(8200, $styleTable)->addText("{$d->kepada}", 'bold', 'pHead'); $section->addText('', $fontStyle, 'pHead'); $table = $section->addTable(); $table->addRow(); $table->addCell(400, $styleTable)->addText("", $fontStyle, 'pHead'); $table->addCell(400, $styleTable)->addText("Di -", $fontStyle, 'pHead'); $table->addCell(8200, $styleTable)->addText("", $fontStyle, 'pHead'); $table->addRow(); $table->addCell(400, $styleTable)->addText("", $fontStyle, 'pHead'); $table->addCell(400, $styleTable)->addText("", $fontStyle, 'pHead'); $table->addCell(8200, $styleTable)->addText("{$d->di}", 'underline', 'pHead'); $section->addText('', $fontStyle, 'pHead'); $table = $section->addTable(); $table->addRow(); $table->addCell(400)->addText(""); $table->addCell(10000)->addText("Dengan Hormat,", $fontStyle, 'pHead'); $table->addRow(); $table->addCell(400, $styleTable)->addText("", $fontStyle, 'pHead'); $table->addCell(10000, $styleTable)->addText("Pertama sekali kami do’akan agar Bapak/Ibu senantiasa dalam keadaan sehat dan sukses selalu dalam menjalankan aktifitas, Amin.", $fontStyle, 'pHead'); $table->addRow(); $table->addCell(400)->addText(""); $table->addCell(10000)->addText("Selanjutnya kami memperkenalkan diri bahwa kami adalah Perguruan Tinggi Ilmu Komputer (STMIK-AMIK Riau) yang berlokasi di Jalan Purwodadi Indah Km. 10 Panam Pekanbaru Riau.", $fontStyle); $table->addRow(); $table->addCell(400, $styleTable)->addText("", $fontStyle, 'pHead'); $table->addCell(10000, $styleTable)->addText("Sesuai dengan kalender akademik, setiap mahasiswa Jenjang Strata I (S.1) dan Diploma III (D.3) yang akan memasuki tahap akhir diwajibkan untuk melaksanakan Praktek Kerja Lapangan (PKL) / Magang dalam rangka mengasah kemampuan mereka untuk mengenal dunia kerja yang sesungguhnya.", $fontStyle, 'pHead'); $table->addRow(); $table->addCell(400)->addText(""); $table->addCell(10000)->addText("Sebagai upaya pelaksanaan kegiatan magang tersebut, kami mohon kiranya Bapak/Ibu dapat berkenan memberikan kesempatan kepada para mahasiswa kami untuk dapat melaksanakan PKL/Magang dari tangal 01 Juli s/d 24 Agustus 2013.", $fontStyle); $table->addRow(); $table->addCell(400, $styleTable)->addText("", $fontStyle, 'pHead'); $table->addCell(10000, $styleTable)->addText("Perhatian dan binaan dari Bapak/Ibu sangat kami harapkan nantinya selama kegiatan tersebut dilaksanakan. Untuk Konfirmasi Selanjutnya Bapak/Ibu dapat menghubungi STMIK-AMIK Riau. Melalui :", $fontStyle, 'pHead'); //Kontak Dosen $section->addText('', $fontStyle, 'pHead'); $table = $section->addTable(); foreach ($cont as $cnt) { $table->addRow(); $table->addCell(400, $styleTable)->addText("", $fontStyle, 'pHead'); $table->addCell(400, $styleTable)->addText("{$no}. ", $fontStyle, 'pHead'); $table->addCell(4300, $styleTable)->addText("{$cnt->nama_dosen}", $fontStyle, 'pHead'); $table->addCell(4300, $styleTable)->addText("Hp ({$cnt->nomor_telp})", $fontStyle, 'pHead'); $no++; } $section->addText('', $fontStyle, 'pHead'); $table = $section->addTable(); $table->addRow(); $table->addCell(400, $styleTable)->addText("", $fontStyle, 'pHead'); $table->addCell(9000, $styleTable)->addText("Adapun nama-nama mahasiswa kami tersebut adalah :", $fontStyle, 'pHead'); //Nama Mahasiswa $section->addText('', $fontStyle, 'pHead'); $table = $section->addTable(); $table->addRow(); $table->addCell(400, $styleTable)->addText("", $fontStyle, 'pHead'); $table->addCell(400, $styleTable_mhs)->addText("No. ", $fontStyle, 'pHead'); $table->addCell(2600, $styleTable_mhs)->addText("Nama", $fontStyle, 'pHead'); $table->addCell(2500, $styleTable_mhs)->addText("NPM", $fontStyle, 'pHead'); $table->addCell(2500, $styleTable_mhs)->addText("Jurusan", $fontStyle, 'pHead'); foreach ($mhs as $m) { $table->addRow(); $table->addCell(400, $styleTable)->addText("", $fontStyle, 'pHead'); $table->addCell(400, $styleTable_mhs)->addText("{$no2}.", $fontStyle, 'pHead'); $table->addCell(2600, $styleTable_mhs)->addText("{$m->nama_mahasiswa}", $fontStyle, 'pHead'); $table->addCell(2500, $styleTable_mhs)->addText("{$m->npm}", $fontStyle, 'pHead'); $table->addCell(2500, $styleTable_mhs)->addText("{$m->nama_jurusan}", $fontStyle, 'pHead'); $no2++; } //Footer $section->addText('', $fontStyle); $table = $section->addTable(); $table->addRow(); $table->addCell(400)->addText("", $fontStyle); $table->addCell(8600)->addText("Besar Harapan Kami kiranya Bapak/Ibu dapat menerima mahasiswa kami tersebut, selanjutnya kami sangat mengharapkan informasi berapa orang mahasiswa kami yang dapat diterima untuk melaksanakan PKL di instansi/perusahaan yang Bapak/Ibu pimpin.", $fontStyle); $table->addRow(); $table->addCell(400)->addText("", $fontStyle); $table->addCell(8600)->addText("Atas bantuan dan kerjasama yang baik dari Bapak/Ibu kami ucapkan terima kasih.", $fontStyle, 'pHead'); $section->addTitle(''); $section->addText("\tPekanbaru, " . tanggal(date('d-m-Y')), $fontStyle, 'pStyle_footer'); $section->addText("\tAn. Ketua, ", $fontStyle, 'pStyle_footer'); $section->addTitle(''); $section->addTitle(''); $section->addText("\t{$d->ketua_jurusan}", 2, 'pStyle_footer'); $section->addText("\tKetua Jurusan {$d->nama_jurusan}", $fontStyle, 'pStyle_footer'); $section->addText("Tembusan :", 'underline', 'pStyle_tbs'); $section->addText("1. Yth. Bapak Ketua STMIK-AMIK Riau", 'pStyle_tbs'); $section->addText("2. Yth. Ibu Pembantu Ketua I", 'pStyle_tbs'); $section->addText("3. Arsip", 'pStyle_tbs'); ////open file//// $objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007'); $filename = date('d-m-Y-Hms') . '-Permohonan_PKL.docx'; $objWriter->save($filename); header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename=' . $filename); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); header('Content-Length: ' . filesize($filename)); flush(); readfile($filename); unlink($filename); // deletes the temporary file exit; } ////end of open file//// ///save file//// //$document->save('assets/docs/'.$d->nama_kar.'-'.$d->id_pegawai.'.docx'); //redirect(base_url().'assets/docs/'.$d->nama_kar.'-'.$d->id_pegawai.'.docx', 'assets/manage_pegawai'); ///end of save file//// }
$styleFirstRow = array('borderBottomSize'=>18, 'borderBottomColor'=>'0000FF', 'bgColor'=>'66BBFF'); */ // Define cell style arrays $styleCell = array('valign' => 'center'); $styleCellBTLR = array('valign' => 'center', 'textDirection' => PHPWord_Style_Cell::TEXT_DIR_BTLR); // Define font style for first row // label 的样式 $titleFontStyle = array('bold' => true, 'align' => 'center'); $valueFontStyle = array(); // $cellValueMergeStartStyle = array_merge($valueFontStyle, array('cellMerge' => 'restart')); $cellTitleMergeStartStyle = array_merge($titleFontStyle, array('cellMerge' => 'restart')); $rowTitleMergeStartStyle = array_merge($titleFontStyle, array('rowMerge' => 'restart')); define('CELL_LABEL_TITLE_WIDTH', 3500); // 标题 $PHPWord->addFontStyle('headTitleFontStyle', array('bold' => true, 'size' => 16)); $PHPWord->addParagraphStyle('headTitlePStyle', array('align' => 'center', 'spaceAfter' => 100)); $section->addText('澳 通 人 才 网 登 记 表', 'headTitleFontStyle', 'headTitlePStyle'); // 备注 $PHPWord->addFontStyle('markFontStyle', array('size' => 12)); $PHPWord->addParagraphStyle('markPStyle', array('align' => 'right', 'spaceAfter' => 100)); $section->addText('填表日期: 年 月 日', 'markFontStyle', 'markPStyle'); // 添加表格的样式 $PHPWord->addTableStyle('myOwnTableStyle', array('borderSize' => 6, 'cellMargin' => 80), array()); // 添加一个表格 $table = $section->addTable('myOwnTableStyle'); // 第一行 $table->addRow(); // Add cells $table->addCell(CELL_LABEL_TITLE_WIDTH, $styleCell)->addText('姓名', $titleFontStyle); $table->addCell(2000, $styleCell)->addText('曾繁斌', $valueFontStyle);
<?php require_once '../PHPWord.php'; // New Word Document $PHPWord = new PHPWord(); // New portrait section $section = $PHPWord->createSection(); // Add text elements $section->addText('Hello World!'); $section->addTextBreak(2); $section->addText('I am inline styled.', array('name' => 'Verdana', 'color' => '006699')); $section->addTextBreak(2); $PHPWord->addFontStyle('rStyle', array('bold' => true, 'italic' => true, 'size' => 16)); $PHPWord->addParagraphStyle('pStyle', array('align' => 'center', 'spaceAfter' => 100)); $section->addText('I am styled by two style definitions.', 'rStyle', 'pStyle'); $section->addText('I have only a paragraph style definition.', null, 'pStyle'); header('Content-Type: application/vnd.ms-word'); header('Content-Disposition: attachment;filename="myfile.docx"'); header('Cache-Control: max-age=0'); // output the file to the browser $objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007'); $objWriter->save('php://output'); exit; //you must have the exit!
public static function makePaper($questions, $subCode, $date, $time, $session, $internal, $sec) { $sem = $questions[1][1]->subject()->first()->sem; $subject = $questions[1][1]->subject()->first()->name; // Create a new PHPWord Object $PHPWord = new PHPWord(); // Every element you want to append to the word document is placed in a section. So you need a section: $section = $PHPWord->createSection(); $PHPWord->addFontStyle('myNoteStyle', array('name' => 'Calibri', 'size' => 11, 'bold' => true, 'underline' => PHPWord_Style_Font::UNDERLINE_SINGLE)); $PHPWord->addFontStyle('myOwnStyle', array('name' => 'Calibri', 'size' => 11, 'bold' => true)); $PHPWord->addParagraphStyle('myGapTStyle', array('name' => 'Calibri', 'size' => 5, 'bold' => true)); $PHPWord->addParagraphStyle('myGapPStyle', array('spaceAfter' => 0)); $PHPWord->addParagraphStyle('myHeaderStyle', array('spaceAfter' => 0)); $PHPWord->addParagraphStyle('myQuestionStyle', array('spaceAfter' => 0)); // Header $table = $section->addTable(); $table->addRow(); $table->addCell(4200)->addText('USN: [ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]', 'myOwnStyle'); $table->addCell(8000)->addText(''); $table->addCell(700)->addText($subCode, 'myOwnStyle'); $center = array('spaceAfter' => 0, 'align' => 'center'); $table_block_format = array('cellMarginTop' => -10, 'cellMarginLeft' => 30, 'valign' => 'center'); $table_block_format2 = array('cellMarginBottom' => 0, 'cellMarginLeft' => 100, 'valign' => 'center'); $questionTextStyle = array('bold' => false, 'size' => 10.5, 'name' => 'Calibri'); $cellTextStyleBigBold = array('bold' => true, 'size' => 13, 'name' => 'Calibri'); $PHPWord->addTableStyle('myTable', $table_block_format, array('align' => 'center')); $PHPWord->addTableStyle('myQuestionTable', $table_block_format, array('align' => 'center')); // $table = $section->addTable('myTable'); // $table->addRow(); // $table->addCell(10000)->addText('Semester '.$sem.', B.E Degree Examination, '.$date, $cellTextStyleBigBold, $center); // $table->addRow(); // $table->addCell(10000)->addText($subject, $cellTextStyleBigBold, $center); $section->addText('Dayananda Sagar College of Engineering, Bangalore - 78', $cellTextStyleBigBold, $center); $section->addText('Department of Computer Science & Engineering', $cellTextStyleBigBold, $center); $section->addText('Session: ' . $session, $cellTextStyleBigBold, $center); $section->addText('Internal Assessment - ' . $internal, $cellTextStyleBigBold, $center); $table = $section->addTable(); $table->addRow(); $cell = $table->addCell(6000); // $textrun = $cell->createTextRun(); $cell->addText('Semester: ' . $sem, 'myOwnStyle', 'myHeaderStyle'); $cell->addText('Subject: ' . $subject, 'myOwnStyle', 'myHeaderStyle'); $cell->addText('Time: ' . $time, 'myOwnStyle', 'myHeaderStyle'); $table->addCell(4000)->addText(''); $cell = $table->addCell(2100); // $textrun = $cell->createTextRun(); $cell->addText('Section: ' . $sec, 'myOwnStyle', 'myHeaderStyle'); $cell->addText('Date: ' . $date, 'myOwnStyle', 'myHeaderStyle'); $cell->addText('Max Marks: 50', 'myOwnStyle', 'myHeaderStyle'); // After creating a section, you can append elements: $listStyle = array('listType' => PHPWord_Style_ListItem::TYPE_NUMBER_NESTED); $section->addText('PART A', 'myOwnStyle', $center); $section->addText('Answer any 2 questions out of 3. Each question carries 20 Marks', 'myNoteStyle', $center); $table = $section->addTable('myQuestionTable'); for ($i = 1; $i <= 3; $i++) { $letter = 'a'; for ($j = 1; $j <= sizeof($questions[$i]); $j++) { $table->addRow(); if (sizeof($questions[$i]) == 1) { $table->addCell(100)->addText($i . '.'); } elseif ($j == 1) { $table->addCell(100)->addText($i . '.' . $letter++ . ")"); } else { $table->addCell(100)->addText(" " . $letter++ . ")"); } $subQuestions = preg_split('/[\\n]/', $questions[$i][$j]->question, -1, NULL); $cell = $table->addCell(9000); foreach ($subQuestions as $subQuestion) { $cell->addText($subQuestion, $questionTextStyle, 'myQuestionStyle'); } if ($questions[$i][$j]->images()->first()) { $cell->addImage('images/' . $questions[$i][$j]->images()->first()->path, array('align' => 'center')); } if ($j == sizeof($questions[$i])) { $cell->addText('', 'myGapTStyle', 'myGapPStyle'); } $table->addCell(100)->addText('(' . $questions[$i][$j]->marks . ')'); } } $section->addText('PART B', 'myOwnStyle', $center); $section->addText('Answer any 1 question out of 2. Each question carries 10 Marks', 'myNoteStyle', $center); $table = $section->addTable('myQuestionTable'); for ($i = 4; $i <= 5; $i++) { $letter = 'a'; for ($j = 1; $j <= sizeof($questions[$i]); $j++) { $table->addRow(); if (sizeof($questions[$i]) == 1) { $table->addCell(100)->addText($i . '.'); } elseif ($j == 1) { $table->addCell(100)->addText($i . '.' . $letter++ . ")"); } else { $table->addCell(100)->addText(" " . $letter++ . ")"); } $subQuestions = preg_split('/[\\n]/', $questions[$i][$j]->question, -1, NULL); $cell = $table->addCell(9000); foreach ($subQuestions as $subQuestion) { $cell->addText($subQuestion, $questionTextStyle, 'myQuestionStyle'); } if ($questions[$i][$j]->images()->first()) { $cell->addImage('images/' . $questions[$i][$j]->images()->first()->path, array('align' => 'center')); } if ($j == sizeof($questions[$i])) { $cell->addText('', 'myGapTStyle', 'myGapPStyle'); } $table->addCell(100)->addText('(' . $questions[$i][$j]->marks . ')'); } } //Footer $footer = $section->createFooter(); $footer->addPreserveText('{PAGE}/{NUMPAGES}', $center); // At last write the document to webspace: $objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007'); $objWriter->save('papers/' . $questions[1][1]->subject()->first()->name . '[' . $date . ']' . '.docx'); }
/** * Write content file to XML format * * @param PHPWord $pPHPWord * @return string XML Output * @throws Exception */ public function writeContent(PHPWord $pPHPWord = null) { // Create XML writer $objWriter = null; if ($this->getParentWriter()->getUseDiskCaching()) { $objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); } else { $objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_MEMORY); } // XML header $objWriter->startDocument('1.0', 'UTF-8'); // office:document-content $objWriter->startElement('office:document-content'); $objWriter->writeAttribute('xmlns:office', 'urn:oasis:names:tc:opendocument:xmlns:office:1.0'); $objWriter->writeAttribute('xmlns:style', 'urn:oasis:names:tc:opendocument:xmlns:style:1.0'); $objWriter->writeAttribute('xmlns:text', 'urn:oasis:names:tc:opendocument:xmlns:text:1.0'); $objWriter->writeAttribute('xmlns:table', 'urn:oasis:names:tc:opendocument:xmlns:table:1.0'); $objWriter->writeAttribute('xmlns:draw', 'urn:oasis:names:tc:opendocument:xmlns:drawing:1.0'); $objWriter->writeAttribute('xmlns:fo', 'urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0'); $objWriter->writeAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink'); $objWriter->writeAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/'); $objWriter->writeAttribute('xmlns:meta', 'urn:oasis:names:tc:opendocument:xmlns:meta:1.0'); $objWriter->writeAttribute('xmlns:number', 'urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0'); $objWriter->writeAttribute('xmlns:svg', 'urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0'); $objWriter->writeAttribute('xmlns:chart', 'urn:oasis:names:tc:opendocument:xmlns:chart:1.0'); $objWriter->writeAttribute('xmlns:dr3d', 'urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0'); $objWriter->writeAttribute('xmlns:math', 'http://www.w3.org/1998/Math/MathML'); $objWriter->writeAttribute('xmlns:form', 'urn:oasis:names:tc:opendocument:xmlns:form:1.0'); $objWriter->writeAttribute('xmlns:script', 'urn:oasis:names:tc:opendocument:xmlns:script:1.0'); $objWriter->writeAttribute('xmlns:ooo', 'http://openoffice.org/2004/office'); $objWriter->writeAttribute('xmlns:ooow', 'http://openoffice.org/2004/writer'); $objWriter->writeAttribute('xmlns:oooc', 'http://openoffice.org/2004/calc'); $objWriter->writeAttribute('xmlns:dom', 'http://www.w3.org/2001/xml-events'); $objWriter->writeAttribute('xmlns:xforms', 'http://www.w3.org/2002/xforms'); $objWriter->writeAttribute('xmlns:xsd', 'http://www.w3.org/2001/XMLSchema'); $objWriter->writeAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance'); $objWriter->writeAttribute('xmlns:rpt', 'http://openoffice.org/2005/report'); $objWriter->writeAttribute('xmlns:of', 'urn:oasis:names:tc:opendocument:xmlns:of:1.2'); $objWriter->writeAttribute('xmlns:xhtml', 'http://www.w3.org/1999/xhtml'); $objWriter->writeAttribute('xmlns:grddl', 'http://www.w3.org/2003/g/data-view#'); $objWriter->writeAttribute('xmlns:tableooo', 'http://openoffice.org/2009/table'); $objWriter->writeAttribute('xmlns:field', 'urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0'); $objWriter->writeAttribute('xmlns:formx', 'urn:openoffice:names:experimental:ooxml-odf-interop:xmlns:form:1.0'); $objWriter->writeAttribute('xmlns:css3t', 'http://www.w3.org/TR/css3-text/'); $objWriter->writeAttribute('office:version', '1.2'); // We firstly search all fonts used $_sections = $pPHPWord->getSections(); $countSections = count($_sections); if ($countSections > 0) { $pSection = 0; $numPStyles = 0; $numFStyles = 0; foreach ($_sections as $section) { $pSection++; $_elements = $section->getElements(); foreach ($_elements as $element) { if ($element instanceof PHPWord_Section_Text) { $fStyle = $element->getFontStyle(); $pStyle = $element->getParagraphStyle(); if ($fStyle instanceof PHPWord_Style_Font) { $numFStyles++; $arrStyle = array('color' => $fStyle->getColor(), 'name' => $fStyle->getName()); $pPHPWord->addFontStyle('T' . $numFStyles, $arrStyle); $element->setFontStyle('T' . $numFStyles); } elseif ($pStyle instanceof PHPWord_Style_Paragraph) { $numPStyles++; $pPHPWord->addParagraphStyle('P' . $numPStyles, array()); $element->setParagraph('P' . $numPStyles); } } } } } // office:font-face-decls $objWriter->startElement('office:font-face-decls'); $arrFonts = array(); $styles = PHPWord_Style::getStyles(); $numFonts = 0; if (count($styles) > 0) { foreach ($styles as $styleName => $style) { // PHPWord_Style_Font if ($style instanceof PHPWord_Style_Font) { $numFonts++; $name = $style->getName(); if (!in_array($name, $arrFonts)) { $arrFonts[] = $name; // style:font-face $objWriter->startElement('style:font-face'); $objWriter->writeAttribute('style:name', $name); $objWriter->writeAttribute('svg:font-family', $name); $objWriter->endElement(); } } } if (!in_array('Times New Roman', $arrFonts)) { $objWriter->startElement('style:font-face'); $objWriter->writeAttribute('style:name', 'Times New Roman'); $objWriter->writeAttribute('svg:font-family', 'Times New Roman'); $objWriter->endElement(); } } $objWriter->endElement(); $objWriter->startElement('office:automatic-styles'); $styles = PHPWord_Style::getStyles(); $numPStyles = 0; if (count($styles) > 0) { foreach ($styles as $styleName => $style) { if (preg_match('#^T[0-9]+$#', $styleName) != 0 || preg_match('#^P[0-9]+$#', $styleName) != 0) { // PHPWord_Style_Font if ($style instanceof PHPWord_Style_Font) { $objWriter->startElement('style:style'); $objWriter->writeAttribute('style:name', $styleName); $objWriter->writeAttribute('style:family', 'text'); // style:text-properties $objWriter->startElement('style:text-properties'); $objWriter->writeAttribute('fo:color', '#' . $style->getColor()); $objWriter->writeAttribute('style:font-name', $style->getName()); $objWriter->writeAttribute('style:font-name-complex', $style->getName()); $objWriter->endElement(); $objWriter->endElement(); } if ($style instanceof PHPWord_Style_Paragraph) { $numPStyles++; // style:style $objWriter->startElement('style:style'); $objWriter->writeAttribute('style:name', $styleName); $objWriter->writeAttribute('style:family', 'paragraph'); $objWriter->writeAttribute('style:parent-style-name', 'Standard'); $objWriter->writeAttribute('style:master-page-name', 'Standard'); // style:paragraph-properties $objWriter->startElement('style:paragraph-properties'); $objWriter->writeAttribute('style:page-number', 'auto'); $objWriter->endElement(); $objWriter->endElement(); } } } if ($numPStyles == 0) { // style:style $objWriter->startElement('style:style'); $objWriter->writeAttribute('style:name', 'P1'); $objWriter->writeAttribute('style:family', 'paragraph'); $objWriter->writeAttribute('style:parent-style-name', 'Standard'); $objWriter->writeAttribute('style:master-page-name', 'Standard'); // style:paragraph-properties $objWriter->startElement('style:paragraph-properties'); $objWriter->writeAttribute('style:page-number', 'auto'); $objWriter->endElement(); $objWriter->endElement(); } } $objWriter->endElement(); // office:body $objWriter->startElement('office:body'); // office:text $objWriter->startElement('office:text'); // text:sequence-decls $objWriter->startElement('text:sequence-decls'); // text:sequence-decl $objWriter->startElement('text:sequence-decl'); $objWriter->writeAttribute('text:display-outline-level', 0); $objWriter->writeAttribute('text:name', 'Illustration'); $objWriter->endElement(); // text:sequence-decl $objWriter->startElement('text:sequence-decl'); $objWriter->writeAttribute('text:display-outline-level', 0); $objWriter->writeAttribute('text:name', 'Table'); $objWriter->endElement(); // text:sequence-decl $objWriter->startElement('text:sequence-decl'); $objWriter->writeAttribute('text:display-outline-level', 0); $objWriter->writeAttribute('text:name', 'Text'); $objWriter->endElement(); // text:sequence-decl $objWriter->startElement('text:sequence-decl'); $objWriter->writeAttribute('text:display-outline-level', 0); $objWriter->writeAttribute('text:name', 'Drawing'); $objWriter->endElement(); $objWriter->endElement(); $_sections = $pPHPWord->getSections(); $countSections = count($_sections); $pSection = 0; if ($countSections > 0) { foreach ($_sections as $section) { $pSection++; $_elements = $section->getElements(); foreach ($_elements as $element) { if ($element instanceof PHPWord_Section_Text) { $this->_writeText($objWriter, $element); } elseif ($element instanceof PHPWord_Section_TextBreak) { $this->_writeTextBreak($objWriter); } else { print_r($element); echo '<br />'; } } if ($pSection == $countSections) { $this->_writeEndSection($objWriter, $section); } else { $this->_writeSection($objWriter, $section); } } } $objWriter->endElement(); $objWriter->endElement(); $objWriter->endElement(); // Return return $objWriter->getData(); }
public function process_wizard_form_one() { if ($_POST) { // Sanitize form $form = $this->toolbox('Sanitize')->form($_POST); $this->company = $form['company']; $this->url = $form['url']; $this->cosultant = $form['consultant']; $this->toolbox('session')->set('assessment_company', $form['company']); $this->toolbox('session')->set('assessment_url', $form['url']); // We want to assemble the file name here in the following format: // Intials_Web_Assess_MMDDYY // Get the first letter of each word (including hyphenated/underscored words) $corpname = preg_split("/[\\s,_ -]+/", $form['company']); $initials = ""; foreach ($corpname as $firstletter) { $initials .= $firstletter[0]; } $this->file_name = $initials . '_Web_Assess_' . date("mdY") . $this->file_extension; $this->toolbox('session')->set('assessment_file_name', $this->file_name); // Now let's create the file $file = $this->file_name; // Create a new PHPWord Object $PHPWord = new PHPWord(); // Every element you want to append to the word document is placed in a section. So you need a section: $section = $PHPWord->createSection(); // After creating a section, you can append elements: $section->addImage('http://www.dynamicartisans.com/area51/public/template/update/assets/images/dynamicartisans-logo-mobi.png', array('width' => 100, 'height' => 100, 'marginTop' => -1, 'marginLeft' => -1, 'wrappingStyle' => 'behind')); $section->addTextBreak(1); // You can directly style your text by giving the addText function an array: $section->addText('sight, sound, color, motion, and emotion.', array('name' => 'Tahoma', 'size' => 12, 'bold' => false)); // If you often need the same style again you can create a user defined style to the word document // and give the addText function the name of the style: $PHPWord->addFontStyle('date-style', array('text-align' => 'right', 'size' => 12, 'color' => '1B2232')); $section->addText(date("F d, Y"), 'date-style'); $section->addTextBreak(1); $section->addText('Contact:' . $this->company, array('bold' => true)); #$section->addText( $this->company ); $section->addText('Consultant:' . $form['consultant'], array('bold' => true)); #$section->addText( $form['consultant'] ); $section->addTextBreak(1); $section->addText('We took a moment to assess the website for ' . $this->toolbox('session')->get('assessment_company') . ' and these are the observations and recommendations from our web development team: '); // You can also putthe appended element to local object an call functions like this: //$myTextElement = $section->addText('Hello World!'); //$myTextElement->setBold(); //$myTextElement->setName('Verdana'); //$myTextElement->setSize(22); // At least write the document to webspace: $objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007'); $objWriter->save($this->draft_folder . $this->file_name); // $this->model('Assessments')->generate_tags( $this->company ); // Compile form variable tags // $this->model('Assessments')->initialize_var_tags( $this->company, $this->url, $form['consultant'], $this->file_name ); // Track network speeds $this->model('Assessments')->network_speed($this->toolbox('Performance')->check_latency_raw($this->toolbox('session')->get('assessment_url')), $this->toolbox('Performance')->check_download_speed_raw($this->toolbox('session')->get('assessment_url')), $this->company); // Autosave draft $this->save_draft($this->company, $this->file_name, time(), $this->author); // Saving wizard -- move on two step two if ($this->model('Assessments')->wizard_step_one($this->company, $this->url, $form['first_name'], $form['last_name'], $form['consultant'], $this->file_name, $this->author)) { $this->redirect('assessments/wizard/server'); } else { throw new Exception('Error processing request'); } } }
public function generatedocx() { if ($this->request->is('post')) { $sentenceId = $this->request['data']['sentenceId']; $startIndex = $this->request['data']['startIndex']; $endIndex = $this->request['data']['endIndex']; $maxLevel = $this->request['data']['maxLevel']; $tmpDocumentPath = '/tmp/IAtagger_generated.docx'; $sentenceData = Utils::getSentenceData($sentenceId); //die(print_r($sentenceData, true)); // New Word Document $PHPWord = new PHPWord(); // New portrait section $section = $PHPWord->createSection(); $PHPWord->addParagraphStyle('centering', array('align' => 'center')); $PHPWord->addFontStyle('wordsRowTextStyle', array('bold' => true)); $PHPWord->addFontStyle('tagsTextStyle', array('bold' => true, 'color' => '000066', 'align' => 'center')); $PHPWord->addFontStyle('defaultTextStyle', array('bold' => false)); $wordsRowCellStyle = array('borderTopSize' => 6, 'borderTopColor' => '006699', 'borderLeftSize' => 6, 'borderLeftColor' => '006699', 'borderRightSize' => 6, 'borderRightColor' => '006699', 'borderBottomSize' => 18, 'borderBottomColor' => '000066', 'bgColor' => 'E2F0FF', 'cellMargin' => 30, 'valign' => 'center'); $cellStyle = array('borderSize' => 6, 'borderColor' => '006699', 'cellMargin' => 30, 'valign' => 'center'); $table = $section->addTable(); // Bracket row $table->addRow(); $table->addCell(900); $wordIndex = 0; foreach ($sentenceData['sentence']['Word'] as $word) { if ($wordIndex >= $startIndex && $wordIndex < $endIndex) { $cell = $table->addCell(2000); if ($word['postposition_id']) { $cell->addImage('/var/www/html/tagging/app/webroot/img/leftBracket.png', array('width' => 40, 'height' => 15, 'align' => 'right')); } if ($word['is_postposition']) { $cell->addImage('/var/www/html/tagging/app/webroot/img/rightBracket.png', array('width' => 40, 'height' => 15, 'align' => 'left')); } } $wordIndex++; } // Words row $table->addRow(900); $table->addCell(900, $wordsRowCellStyle); $wordIndex = 0; foreach ($sentenceData['sentence']['Word'] as $word) { if ($wordIndex >= $startIndex && $wordIndex < $endIndex) { $cell = $table->addCell(2000, $wordsRowCellStyle); if ($word['split']) { $wordText = $word['stem'] . '-' . $word['suffix']; } else { $wordText = $word['text']; } $cell->addText($wordText, 'wordsRowTextStyle', 'centering'); } $wordIndex++; } // Annotation rows $legend = array(); $levelIndex = 0; foreach ($sentenceData['sentence']['WordAnnotations'] as $annotationData) { if ($levelIndex < $maxLevel) { $table->addRow(900); $wordAnnotationType = $annotationData['type']['WordAnnotationType']; // annotation name cell $cell = $table->addCell(900, $cellStyle); $cell->addText($wordAnnotationType['name'], 'defaultTextStyle', 'centering'); $wordIndex = 0; foreach ($annotationData['annotations'] as $annotation) { if ($wordIndex >= $startIndex && $wordIndex < $endIndex) { $cell = $table->addCell(900, $cellStyle); if (!empty($annotation)) { if ($wordAnnotationType['strict_choices']) { foreach ($annotation['WordAnnotationTypeChoice'] as $choice) { $cell->addText($choice['value'], 'tagsTextStyle', 'centering'); $legend[$choice['value']] = $choice['description']; } } else { $cell->addText($annotation['text_value'], 'defaultTextStyle', 'centering'); } } } $wordIndex++; } } $levelIndex++; } foreach ($sentenceData['sentence']['SentenceAnnotations'] as $annotationData) { if ($levelIndex < $maxLevel) { $table->addRow(900); $sentenceAnnotationType = $annotationData['type']['SentenceAnnotationType']; // annotation name cell $cell = $table->addCell(900, $cellStyle); $cell->addText($sentenceAnnotationType['name'], 'defaultTextStyle', 'centering'); $spanningCellStyle = $cellStyle; $spanningCellStyle['gridSpan'] = $endIndex - $startIndex; $cell = $table->addCell(900, $spanningCellStyle); $text = isset($annotationData['annotation']['text']) ? $annotationData['annotation']['text'] : ''; $cell->addText($text); } $levelIndex++; } // Legend ksort($legend); $section->addTextBreak(2); $section->addText("Legend:", array('bold' => true)); foreach ($legend as $value => $description) { $section->addListItem($value . ' - ' . $description); } // Save File $objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007'); $objWriter->save($tmpDocumentPath); $this->response->file($tmpDocumentPath, array('download' => true, 'name' => 'IAtagger_table.docx')); // Return response object to prevent controller from trying to render // a view return $this->response; } }
/************************************************/ // New Word Document $PHPWord = new PHPWord(); // New portrait section $section = $PHPWord->createSection(); // Define table style arrays $styleTable = array('borderSize' => 6, 'borderColor' => '689F3B', 'cellMargin' => 10, 'size' => 10); $styleFirstRow = array('borderBottomSize' => 5, 'borderBottomColor' => '689F3B', 'bgColor' => 'D2F4B5'); // Define cell style arrays $styleCell = array('valign' => 'center'); $styleCellBTLR = array('valign' => 'center', 'textDirection' => PHPWord_Style_Cell::TEXT_DIR_BTLR); // Define font style for first row $fontStyle = array('bold' => true, 'size' => 10, 'align' => 'center'); $paragraphStyle = array('bold' => true, 'size' => 10, 'align' => 'center'); $PHPWord->addParagraphStyle('pStyle', $paragraphStyle); $PHPWord->addFontStyle('rStyle', array('bold' => true, 'size' => 12)); $PHPWord->addParagraphStyle('pStyle', array('align' => 'center', 'spaceAfter' => 100)); $section->addText(html_entity_decode(iconv('UTF-8', 'windows-1252', 'Personnel ' . $array_departement[$id_dep]['F'])) . ' - Situation au ' . $date_situation_effectifs, 'rStyle', 'pStyle'); foreach ($tab_agents_dep as $key_agents_dep => $value_agents_dep) { $PHPWord->addTableStyle('myOwnTableStyle', $styleTable, $styleFirstRow); // Add table $table = $section->addTable('myOwnTableStyle'); $table->addRow(); $table->addCell(2000)->addText(html_entity_decode(iconv('UTF-8', 'windows-1252', $value_agents_dep['nom'] . " " . $value_agents_dep['prenom']))); if ($value_agents_dep['date_echeance_regime'] == '0000-00-00' || $value_agents_dep['date_echeance_regime'] == '00-00-0000') { $table->addCell(2000)->addText(html_entity_decode(iconv('UTF-8', 'windows-1252', $array_regime[$value_agents_dep['id_regime']]['F']))); } else { $table->addCell(2000)->addText(html_entity_decode(iconv('UTF-8', 'windows-1252', $array_regime[$value_agents_dep['id_regime']]['F'] . ' ' . $value_agents_dep['date_echeance_regime']))); } $table->addCell(1000)->addText($value_agents_dep['langue']); $table->addCell(3000)->addText(html_entity_decode(iconv('UTF-8', 'windows-1252', $array_grade[$value_agents_dep['id_grade']]['F'])));
public function generate($id = 0) { $this->load->library('PHPWord'); $this->load->helper('util'); $date = date('Y-m-d_H-i-s'); //if ($id==0); $conf = $this->db->get($this->cms_complete_table_name('konfigurasi'))->result(); $data = $this->db->where('id_ket_lulusan', $id)->get($this->cms_complete_table_name('ket_lulusan'))->result(); $ket = $this->db->where('fk_id_ket_lulusan', $id)->get($this->cms_complete_table_name('keterangan_lulusan'))->result(); $PHPWord = new PHPWord(); // New portrait section $section = $PHPWord->createSection(array('pageSizeH' => 20500)); // Define the TOC font style // Add title styles $PHPWord->addFontStyle(1, array('size' => 16, 'color' => '000', 'underline' => PHPWord_Style_Font::UNDERLINE_SINGLE)); $PHPWord->addFontStyle(2, array('size' => 12, 'color' => '000', 'bold' => true)); $PHPWord->addParagraphStyle('pStyle', array('align' => 'center', 'spaceAfter' => 10)); $PHPWord->addParagraphStyle('pStyle_footer', array('tabs' => array(new PHPWord_Style_Tab('left', 6000)), 'align' => 'center', 'spaceAfter' => 10)); $PHPWord->addParagraphStyle('pStyle_tbs', array('size' => 11, 'align' => 'left', 'spaceAfter' => 10)); $fontStyle = array('spaceAfter' => 60, 'size' => 12); //Generate Document foreach ($data as $d) { $section->addTitle(''); $section->addTitle(''); $section->addTitle(''); $section->addText('SURAT KETERANGAN LULUSAN', 1, 'pStyle'); $section->addText('No.' . $d->nomor_surat . '/B-01/STMIK-AMIK/' . $d->bulan . '/' . $d->tahun, $fontStyle, 'pStyle'); $section->addTitle(''); $section->addTitle(''); $section->addText('Yang bertanda tangan dibawah ini :', $fontStyle); //Table foreach ($conf as $c) { $table = $section->addTable(); $table->addRow(); $table->addCell(500)->addText(""); $table->addCell(1750)->addText("Nama", $fontStyle); $table->addCell(3750)->addText(": " . $c->nama_puket, $fontStyle); $table->addRow(); $table->addCell(500)->addText(""); $table->addCell(1750)->addText("Pangkat/Gol", $fontStyle); $table->addCell(3750)->addText(": " . $c->pangkat_puket, $fontStyle); $table->addRow(); $table->addCell(500)->addText(""); $table->addCell(1750)->addText("Jabatan", $fontStyle); $table->addCell(3750)->addText(": Pembantu Ketua I. Bid. Akademis", $fontStyle); } //End OfTable $section->addText('Menerangkan bahwa :', $fontStyle); //Table $table = $section->addTable(); $table->addRow(); $table->addCell(500)->addText(""); $table->addCell(1750)->addText("Nama", $fontStyle); $table->addCell(3750)->addText(": " . $d->nama_mahasiswa, $fontStyle); $table->addRow(); $table->addCell(500)->addText(""); $table->addCell(1750)->addText("NPM", $fontStyle); $table->addCell(3750)->addText(": " . $d->npm, $fontStyle); $table->addRow(); $table->addCell(500)->addText(""); $table->addCell(1750)->addText("Tempat/Tgl Lahir", $fontStyle); $table->addCell(3750)->addText(": " . $d->tempat_lahir . ", " . tanggal(date($d->tanggal_lahir)), $fontStyle); //End OfTable $section->addText('Adalah benar mahasiswa Sekolah Tinggi Manajemen Informatika & Komputer AMIK Riau (STMIK-AMIK) Riau yang telah :', $fontStyle); $section->addText(""); foreach ($ket as $k) { $section->addListItem($k->keterangan, 0, $fontStyle); } //End OfTable foreach ($conf as $c) { $section->addText('Demikian surat keterangan kelulusan ini dikeluarkan untuk dapat dipergunakan sebagaimana mestinya.', $fontStyle); $section->addTitle(''); $section->addText("\tPekanbaru, " . tanggal(date('d-m-Y')), $fontStyle, 'pStyle_footer'); $section->addTitle(''); $section->addTitle(''); $section->addTitle(''); $section->addText("\t{$c->nama_puket}", 2, 'pStyle_footer'); $section->addText("\tPuket I Bid. Akademis", $fontStyle, 'pStyle_footer'); $section->addTitle(''); $section->addTitle(''); $section->addText("Tembusan disampaikan kepada Yth :", 'pStyle_tbs'); $section->addText("1. Ketua STMIK-AMIK Riau", 'pStyle_tbs'); $section->addText("2. Arsip ……", 'pStyle_tbs'); } ////open file//// $objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007'); $filename = $d->npm . '-Ket_Lulusan.docx'; $objWriter->save($filename); header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename=' . $filename); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); header('Content-Length: ' . filesize($filename)); flush(); readfile($filename); unlink($filename); // deletes the temporary file exit; } ////end of open file//// ///save file//// //$document->save('assets/docs/'.$d->nama_kar.'-'.$d->id_pegawai.'.docx'); //redirect(base_url().'assets/docs/'.$d->nama_kar.'-'.$d->id_pegawai.'.docx', 'assets/manage_pegawai'); ///end of save file//// }
/************************************************/ // New Word Document $PHPWord = new PHPWord(); // New portrait section $section = $PHPWord->createSection(); // Define table style arrays $styleTable = array('borderSize' => 6, 'borderColor' => '689F3B', 'cellMargin' => 10, 'size' => 10); $styleFirstRow = array('borderBottomSize' => 5, 'borderBottomColor' => '689F3B', 'bgColor' => 'D2F4B5'); // Define cell style arrays $styleCell = array('valign' => 'center'); $styleCellBTLR = array('valign' => 'center', 'textDirection' => PHPWord_Style_Cell::TEXT_DIR_BTLR); // Define font style for first row $fontStyle = array('bold' => true, 'size' => 10, 'align' => 'center'); $paragraphStyle = array('bold' => true, 'size' => 10, 'align' => 'center'); $PHPWord->addParagraphStyle('pStyle', $paragraphStyle); $PHPWord->addFontStyle('rStyle', array('bold' => true, 'size' => 12)); $PHPWord->addFontStyle('gros_titre', array('bold' => true, 'size' => 12, 'color' => '689F3B', 'underline' => PHPWord_Style_Font::UNDERLINE_SINGLE)); $PHPWord->addParagraphStyle('pStyle_center', array('align' => 'center', 'spaceAfter' => 200)); $PHPWord->addParagraphStyle('pStyle_left', array('align' => 'left', 'spaceAfter' => 100)); /******************************************** Signalétique nom, prénom, date naissance ***************/ $txt = "Fiche individuelle - " . $tab_agents['nom'] . ' ' . $tab_agents['prenom']; $section->addText(html_entity_decode(iconv('UTF-8', 'windows-1252', $txt)), 'gros_titre', 'pStyle_center'); /*$txt="NOM: ".$tab_agents['nom']; $section -> addText(html_entity_decode(iconv('UTF-8', 'windows-1252',$txt)),'pStyle_left'); $txt="PRENOM: ".$tab_agents['prenom']; $section -> addText(html_entity_decode(iconv('UTF-8', 'windows-1252',$txt)),'pStyle_left');*/ $txt = "ID REGISTRE: " . $tab_agents['registre_id']; $section->addText(html_entity_decode(iconv('UTF-8', 'windows-1252', $txt)), 'pStyle_left');
break; case "11": $mes = 'Novembro'; break; case "12": $mes = 'Dezembro'; break; } require_once INTERNAL_ROOT_PORTAL . '/lib/word/PHPWord.php'; // New Word Document $PHPWord = new PHPWord(); // New portrait section $section = $PHPWord->createSection(); // Add style definitions $PHPWord->addParagraphStyle('pStyle', array('spacing' => 100, 'name' => 'Times New Roman', 'bold' => false, 'size' => 11)); $PHPWord->addFontStyle('BoldText', array('name' => 'Times New Roman', 'bold' => true, 'size' => 11)); $PHPWord->addFontStyle('texto', array('name' => 'Times New Roman', 'bold' => false, 'size' => 11)); $PHPWord->addFontStyle('assinatura', array('name' => 'Times New Roman', 'bold' => false, 'size' => 10.5)); // Add header $header = $section->createHeader(); $table = $header->addTable(); $table->addRow(); $table->addCell(4500)->addImage('C:/Diego/troncal.jpg', array('width' => 250, 'height' => 75, 'align' => 'left')); $table->addCell(4500)->addText(' '); $table->addCell(4500)->addText($documento->getCodGRD() . '/' . date("Y"), 'texto'); // Add text elements $section->addText(' Belém, ' . date("N") . ' de ' . $mes . ' de ' . date("Y") . '.', 'texto'); $section->addText('Ao Núcleo de Gerenciamento de Transporte Metropolitano - NGTM ', 'BoldText', 'Teste', 'texto'); $section->addText('Avenida Gentil Bittencourt, n.º 1539, Nazaré Belém - PA', 'texto'); $section->addText('Att.: Dra. Marilena Mácola Marques Diretora Executiva - NGTM', 'texto'); $section->addText('Ref.: Contrato Nº 002/2014-NGTM', 'texto');
$documento->setLocal(""); $documento->setCodGRD(""); } require_once '../../lib/word/PHPWord.php'; // New Word Document $PHPWord = new PHPWord(); // New portrait section $section = $PHPWord->createSection(); // Define table style arrays $styleTable = array('cellMarginLeft' => 110, 'cellMarginRight' => 110, 'borderSize' => 1); $styleCellMerged = array('valign' => 'center', 'gridSpan' => 2); $styleCellBTLR1 = array('vMerge' => 'restart', 'valign' => 'center', 'textDirection' => PHPWord_Style_Cell::TEXT_DIR_BTLR); $styleCellBTLR2 = array('vMerge' => 'fusion', 'valign' => 'center', 'textDirection' => PHPWord_Style_Cell::TEXT_DIR_BTLR); // Add style definitions $PHPWord->addParagraphStyle('pStyle', array('spacing' => 100, 'name' => 'Times New Roman', 'bold' => false, 'size' => 11, 'align' => 'center', 'spaceAfter' => 100)); $PHPWord->addFontStyle('BoldText', array('name' => 'Times New Roman', 'bold' => true, 'size' => 12)); $PHPWord->addFontStyle('texto', array('name' => 'Arial', 'bold' => false, 'size' => 11)); $PHPWord->addFontStyle('texto_sublinhado', array('name' => 'Arial', 'bold' => false, 'size' => 11, 'underline' => PHPWord_Style_Font::UNDERLINE_SINGLE)); $PHPWord->addFontStyle('titulo', array('name' => 'Thorndale', 'size' => 12, 'bold' => false, 'align' => 'center', 'spaceAfter' => 100)); // Add table style $PHPWord->addTableStyle('tbl13', $styleTable); // Add header $header = $section->createHeader(); // Add table $table = $header->addTable('tbl13'); // variaveis que recebem o texto $assunto = utf8_decode($documento->getAssunto()); $msg2 = utf8_decode("SISTEMA TRONCAL DE ÔNIBUS DA REGIÃO METROPOLITANA DE BELÉM"); $pagina = utf8_decode("Página"); $local = utf8_decode($documento->getLocal()); $observacao = utf8_decode($documento->getObservacao());
$section->addListItem('List Item 2', 0); $section->addListItem('List Item 3', 0); $section->addTextBreak(2); // Add listitem elements $section->addListItem('List Item 1', 0); $section->addListItem('List Item 1.1', 1); $section->addListItem('List Item 1.2', 1); $section->addListItem('List Item 1.3 (styled)', 1, array('bold' => true)); $section->addListItem('List Item 1.3.1', 2); $section->addListItem('List Item 1.3.2', 2); $section->addTextBreak(2); // Add listitem elements $listStyle = array('listType' => PHPWord_Style_ListItem::TYPE_NUMBER); $section->addListItem('List Item 1', 0, null, $listStyle); $section->addListItem('List Item 2', 0, null, $listStyle); $section->addListItem('List Item 3', 0, null, $listStyle); $section->addTextBreak(2); // Add listitem elements $PHPWord->addFontStyle('myOwnStyle', array('color' => 'FF0000')); $PHPWord->addParagraphStyle('P-Style', array('spaceAfter' => 95)); $listStyle = array('listType' => PHPWord_Style_ListItem::TYPE_NUMBER_NESTED); $section->addListItem('List Item 1', 0, 'myOwnStyle', $listStyle, 'P-Style'); $section->addListItem('List Item 2', 0, 'myOwnStyle', $listStyle, 'P-Style'); $section->addListItem('List Item 3', 1, 'myOwnStyle', $listStyle, 'P-Style'); $section->addListItem('List Item 4', 1, 'myOwnStyle', $listStyle, 'P-Style'); $section->addListItem('List Item 5', 2, 'myOwnStyle', $listStyle, 'P-Style'); $section->addListItem('List Item 6', 1, 'myOwnStyle', $listStyle, 'P-Style'); $section->addListItem('List Item 7', 0, 'myOwnStyle', $listStyle, 'P-Style'); // Save File $objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007'); $objWriter->save('ListItem.docx');
$misamarti = $_POST['misamarti']; $mobile = $_POST['mobile']; $email = $_POST['email']; $dawesebuleba = $_POST['txt_edu_name']; $fakulteti = $_POST['txt_edu_faculty']; $specialoba = $_POST['txt_edu_profession']; $xarisxi = $_POST['txt_edu_degree']; $periodii = $_POST['txt_edu_period']; $enebi = $_POST['txt_lang_name']; $skills = $_POST['txt_skill_name']; $organizacia = $_POST['txt_work_name']; $pozicia = $_POST['txt_work_position']; $periodi = $_POST['txt_work_period']; $PHPWord = new PHPWord(); $section = $PHPWord->CreateSection(); $PHPWord->addFontStyle('rStyle', array('bold' => true, 'size' => 16)); $PHPWord->addParagraphStyle('pStyle', array('align' => 'center', 'spaceAfter' => 100)); $section->addText('CV', 'rStyle', 'pStyle'); $section->addTextBreak(2); $section->addImage($target_file, array('width' => 210, 'height' => 210, 'align' => 'center')); $section->addTextBreak(2); $styleTable = array('borderSize' => 6, 'borderColor' => '006699', 'cellMargin' => 80); $styleCell = array('valign' => 'center'); $styleCellBTLR = array('valign' => 'center', 'textDirection' => PHPWord_Style_Cell::TEXT_DIR_BTLR); $fontStyle = array('bold' => true, 'align' => 'center'); $PHPWord->addTableStyle('myOwnTableStyle', $styleTable); $table = $section->addTable('myOwnTableStyle'); if ($name != '') { $table->addRow(2); $table->addCell(4000, $styleCell)->addText('Name', $fontStyle); $table->addCell(4000, $styleCell)->addText($name, $fontStyle);
<?php require_once '../PHPWord.php'; // New Word Document $PHPWord = new PHPWord(); // New portrait section $section = $PHPWord->createSection(); // Add style definitions $PHPWord->addParagraphStyle('pStyle', array('spacing' => 100)); $PHPWord->addFontStyle('BoldText', array('bold' => true)); $PHPWord->addFontStyle('ColoredText', array('color' => 'FF8080')); $PHPWord->addLinkStyle('NLink', array('color' => '0000FF', 'underline' => PHPWord_Style_Font::UNDERLINE_SINGLE)); // Add text elements $textrun = $section->createTextRun('pStyle'); $textrun->addText('Each textrun can contain native text or link elements.'); $textrun->addText(' No break is placed after adding an element.', 'BoldText'); $textrun->addText(' All elements are placed inside a paragraph with the optionally given p-Style.', 'ColoredText'); $textrun->addText(' The best search engine: '); $textrun->addLink('http://www.google.com', null, 'NLink'); $textrun->addText('. Also not bad: '); $textrun->addLink('http://www.bing.com', null, 'NLink'); // Save File $objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007'); $objWriter->save('Textrun.docx');
/** * Generates the DOCX question/correction form for an offlinequiz group. * * @param question_usage_by_activity $templateusage the template question usage for this offline group * @param object $offlinequiz The offlinequiz object * @param object $group the offline group object * @param int $courseid the ID of the Moodle course * @param object $context the context of the offline quiz. * @param boolean correction if true the correction form is generated. * @return stored_file instance, the generated DOCX file. */ function offlinequiz_create_docx_question(question_usage_by_activity $templateusage, $offlinequiz, $group, $courseid, $context, $correction = false) { global $CFG, $DB, $OUTPUT; $letterstr = 'abcdefghijklmnopqrstuvwxyz'; $groupletter = strtoupper($letterstr[$group->number - 1]); $coursecontext = context_course::instance($courseid); PHPWord_Media::resetMedia(); $docx = new PHPWord(); $trans = new offlinequiz_html_translator(); // Define cell style arrays. $cellstyle = array('valign' => 'center'); // Add text styles. // Normal style. $docx->addFontStyle('nStyle', array('size' => $offlinequiz->fontsize)); // Italic style. $docx->addFontStyle('iStyle', array('italic' => true, 'size' => $offlinequiz->fontsize)); // Bold style. $docx->addFontStyle('bStyle', array('bold' => true, 'size' => $offlinequiz->fontsize)); $docx->addFontStyle('brStyle', array('bold' => true, 'align' => 'right', 'size' => $offlinequiz->fontsize)); // Underline style. $docx->addFontStyle('uStyle', array('underline' => PHPWord_Style_Font::UNDERLINE_SINGLE, 'size' => $offlinequiz->fontsize)); $docx->addFontStyle('ibStyle', array('italic' => true, 'bold' => true, 'size' => $offlinequiz->fontsize)); $docx->addFontStyle('iuStyle', array('italic' => true, 'underline' => PHPWord_Style_Font::UNDERLINE_SINGLE, 'size' => $offlinequiz->fontsize)); $docx->addFontStyle('buStyle', array('bold' => true, 'underline' => PHPWord_Style_Font::UNDERLINE_SINGLE, 'size' => $offlinequiz->fontsize)); $docx->addFontStyle('ibuStyle', array('italic' => true, 'bold' => true, 'underline' => PHPWord_Style_Font::UNDERLINE_SINGLE, 'size' => $offlinequiz->fontsize)); // Header style. $docx->addFontStyle('hStyle', array('bold' => true, 'size' => $offlinequiz->fontsize + 4)); // Center style. $docx->addParagraphStyle('cStyle', array('align' => 'center', 'spaceAfter' => 100)); $docx->addParagraphStyle('cStyle', array('align' => 'center', 'spaceAfter' => 100)); $docx->addParagraphStyle('questionTab', array('tabs' => array(new PHPWord_Style_Tab("left", 360)))); // Define table style arrays. $tablestyle = array('borderSize' => 0, 'borderColor' => 'FFFFFF', 'cellMargin' => 20, 'align' => 'center'); $firstrowstyle = array('borderBottomSize' => 0, 'borderBottomColor' => 'FFFFFF', 'bgColor' => 'FFFFFF'); $docx->addTableStyle('tableStyle', $tablestyle, $firstrowstyle); $boldfont = new PHPWord_Style_Font(); $boldfont->setBold(true); $boldfont->setSize($offlinequiz->fontsize); $normalfont = new PHPWord_Style_Font(); $normalfont->setSize($offlinequiz->fontsize); // Define custom list item style for question answers. $level1 = new PHPWord_Style_Paragraph(); $level1->setTabs(new PHPWord_Style_Tabs(array(new PHPWord_Style_Tab('clear', 720), new PHPWord_Style_Tab('num', 360)))); $level1->setIndentions(new PHPWord_Style_Indentation(array('left' => 360, 'hanging' => 360))); $level2 = new PHPWord_Style_Paragraph(); $level2->setTabs(new PHPWord_Style_Tabs(array(new PHPWord_Style_Tab('left', 720), new PHPWord_Style_Tab('num', 720)))); $level2->setIndentions(new PHPWord_Style_Indentation(array('left' => 720, 'hanging' => 360))); // Create the section that will be used for all outputs. $section = $docx->createSection(); $title = offlinequiz_str_html_docx($offlinequiz->name); if (!empty($offlinequiz->time)) { if (strlen($title) > 35) { $title = substr($title, 0, 33) . ' ...'; } $title .= ": " . offlinequiz_str_html_docx(userdate($offlinequiz->time)); } else { if (strlen($title) > 40) { $title = substr($title, 0, 37) . ' ...'; } } $title .= ", " . offlinequiz_str_html_docx(get_string('group') . " {$groupletter}"); // Add a header. $header = $section->createHeader(); $header->addText($title, array('size' => 10), 'cStyle'); $header->addImage($CFG->dirroot . '/mod/offlinequiz/pix/line.png', array('width' => 600, 'height' => 5, 'align' => 'center')); // Add a footer. $footer = $section->createFooter(); $footer->addImage($CFG->dirroot . '/mod/offlinequiz/pix/line.png', array('width' => 600, 'height' => 5, 'align' => 'center')); $footer->addPreserveText($title . ' | ' . get_string('page') . ' ' . '{PAGE} / {NUMPAGES}', null, array('align' => 'left')); // Print title page. if (!$correction) { $section->addText(offlinequiz_str_html_docx(get_string('questionsheet', 'offlinequiz') . ' - ' . get_string('group') . " {$groupletter}"), 'hStyle', 'cStyle'); $section->addTextBreak(2); $table = $section->addTable('tableStyle'); $table->addRow(); $cell = $table->addCell(200, $cellstyle)->addText(offlinequiz_str_html_docx(get_string('name')) . ': ', 'brStyle'); $table->addRow(); $cell = $table->addCell(200, $cellstyle)->addText(offlinequiz_str_html_docx(get_string('idnumber', 'offlinequiz')) . ': ', 'brStyle'); $table->addRow(); $cell = $table->addCell(200, $cellstyle)->addText(offlinequiz_str_html_docx(get_string('studycode', 'offlinequiz')) . ': ', 'brStyle'); $table->addRow(); $cell = $table->addCell(200, $cellstyle)->addText(offlinequiz_str_html_docx(get_string('signature', 'offlinequiz')) . ': ', 'brStyle'); $section->addTextBreak(2); // The DOCX intro text can be arbitrarily long so we have to catch page overflows. if (!empty($offlinequiz->pdfintro)) { $blocks = offlinequiz_convert_image_docx($offlinequiz->pdfintro); offlinequiz_print_blocks_docx($section, $blocks); } $section->addPageBreak(); } // Load all the questions needed for this offline quiz group. $sql = "SELECT q.*, c.contextid, ogq.page, ogq.slot, ogq.maxmark \n FROM {offlinequiz_group_questions} ogq,\n {question} q,\n {question_categories} c\n WHERE ogq.offlinequizid = :offlinequizid\n AND ogq.offlinegroupid = :offlinegroupid\n AND q.id = ogq.questionid\n AND q.category = c.id\n ORDER BY ogq.slot ASC "; $params = array('offlinequizid' => $offlinequiz->id, 'offlinegroupid' => $group->id); // Load the questions. $questions = $DB->get_records_sql($sql, $params); if (!$questions) { echo $OUTPUT->box_start(); echo $OUTPUT->error_text(get_string('noquestionsfound', 'offlinequiz', $groupletter)); echo $OUTPUT->box_end(); return; } // Load the question type specific information. if (!get_question_options($questions)) { print_error('Could not load question options'); } // Restore the question sessions to their most recent states. // Creating new sessions where required. $number = 1; // We need a mapping from question IDs to slots, assuming that each question occurs only once. $slots = $templateusage->get_slots(); $texfilter = new filter_tex($context, array()); // Create the docx question numbering. This is only created once since we number all questions from 1...n. $questionnumbering = new PHPWord_Numbering_AbstractNumbering("Question-level", array(new PHPWord_Numbering_Level("1", PHPWord_Numbering_Level::NUMFMT_DECIMAL, "%1)", "left", $level1, $boldfont), new PHPWord_Numbering_Level("1", PHPWord_Numbering_Level::NUMFMT_LOWER_LETTER, "%2)", "left", $level2, $normalfont))); $docx->addNumbering($questionnumbering); // If shufflequestions has been activated we go through the questions in the order determined by // the template question usage. if ($offlinequiz->shufflequestions) { foreach ($slots as $slot) { $slotquestion = $templateusage->get_question($slot); $myquestion = $slotquestion->id; set_time_limit(120); $question = $questions[$myquestion]; // Either we print the question HTML. $questiontext = $question->questiontext; // Filter only for tex formulas. if (!empty($texfilter)) { $questiontext = $texfilter->filter($questiontext); } // Remove all HTML comments (typically from MS Office). $questiontext = preg_replace("/<!--.*?--\\s*>/ms", "", $questiontext); // Remove <font> tags. $questiontext = preg_replace("/<font[^>]*>[^<]*<\\/font>/ms", "", $questiontext); // Remove <script> tags that are created by mathjax preview. $questiontext = preg_replace("/<script[^>]*>[^<]*<\\/script>/ms", "", $questiontext); // Remove all class info from paragraphs because TCDOCX won't use CSS. $questiontext = preg_replace('/<p[^>]+class="[^"]*"[^>]*>/i', "<p>", $questiontext); $questiontext = $trans->fix_image_paths($questiontext, $question->contextid, 'questiontext', $question->id, 0.6, 300, 'docx'); $blocks = offlinequiz_convert_image_docx($questiontext); offlinequiz_print_blocks_docx($section, $blocks, $questionnumbering, 0); $answernumbering = new PHPWord_Numbering_AbstractNumbering("Adv Multi-level", array(new PHPWord_Numbering_Level("1", PHPWord_Numbering_Level::NUMFMT_DECIMAL, "%1.", "left", $level1, $boldfont), new PHPWord_Numbering_Level("1", PHPWord_Numbering_Level::NUMFMT_LOWER_LETTER, "%2)", "left", $level2, $normalfont))); $docx->addNumbering($answernumbering); if ($question->qtype == 'multichoice' || $question->qtype == 'multichoiceset') { // Save the usage slot in the group questions table. // $DB->set_field('offlinequiz_group_questions', 'usageslot', $slot, // array('offlinequizid' => $offlinequiz->id, // 'offlinegroupid' => $group->id, 'questionid' => $question->id)); // There is only a slot for multichoice questions. $attempt = $templateusage->get_question_attempt($slot); $order = $slotquestion->get_order($attempt); // Order of the answers. foreach ($order as $key => $answer) { $answertext = $question->options->answers[$answer]->answer; // Filter only for tex formulas. if (!empty($texfilter)) { $answertext = $texfilter->filter($answertext); } // Remove all HTML comments (typically from MS Office). $answertext = preg_replace("/<!--.*?--\\s*>/ms", "", $answertext); // Remove all paragraph tags because they mess up the layout. $answertext = preg_replace("/<p[^>]*>/ms", "", $answertext); // Remove <script> tags that are created by mathjax preview. $answertext = preg_replace("/<script[^>]*>[^<]*<\\/script>/ms", "", $answertext); $answertext = preg_replace("/<\\/p[^>]*>/ms", "", $answertext); $answertext = $trans->fix_image_paths($answertext, $question->contextid, 'answer', $answer, 0.6, 200, 'docx'); $blocks = offlinequiz_convert_image_docx($answertext); offlinequiz_print_blocks_docx($section, $blocks, $answernumbering, 1); } if ($offlinequiz->showgrades) { $pointstr = get_string('points', 'grades'); if ($question->maxgrade == 1) { $pointstr = get_string('point', 'offlinequiz'); } // Indent the question grade like the answers. $textrun = $section->createTextRun($level2); $textrun->addText('(' . ($question->maxgrade + 0) . ' ' . $pointstr . ')', 'bStyle'); } } $section->addTextBreak(); $number++; } } else { // Not shufflequestions. // We have to compute the mapping questionid -> slotnumber. $questionslots = array(); foreach ($slots as $slot) { $questionslots[$templateusage->get_question($slot)->id] = $slot; } // No shufflequestions, so go through the questions as they have been added to the offlinequiz group // We also add custom page breaks. $currentpage = 1; foreach ($questions as $question) { // Add page break if set explicitely by teacher. if ($question->page > $currentpage) { $section->addPageBreak(); $currentpage++; } set_time_limit(120); // Print the question. $questiontext = $question->questiontext; // Filter only for tex formulas. if (!empty($texfilter)) { $questiontext = $texfilter->filter($questiontext); } // Remove all HTML comments (typically from MS Office). $questiontext = preg_replace("/<!--.*?--\\s*>/ms", "", $questiontext); // Remove <font> tags. $questiontext = preg_replace("/<font[^>]*>[^<]*<\\/font>/ms", "", $questiontext); // Remove <script> tags that are created by mathjax preview. $questiontext = preg_replace("/<script[^>]*>[^<]*<\\/script>/ms", "", $questiontext); // Remove all class info from paragraphs because TCDOCX won't use CSS. $questiontext = preg_replace('/<p[^>]+class="[^"]*"[^>]*>/i', "<p>", $questiontext); $questiontext = $trans->fix_image_paths($questiontext, $question->contextid, 'questiontext', $question->id, 0.6, 300, 'docx'); $blocks = offlinequiz_convert_image_docx($questiontext); // Description questions are printed without a number because they are not on the answer form. if ($question->qtype == 'description') { offlinequiz_print_blocks_docx($section, $blocks); } else { offlinequiz_print_blocks_docx($section, $blocks, $questionnumbering, 0); } $answernumbering = new PHPWord_Numbering_AbstractNumbering("Adv Multi-level", array(new PHPWord_Numbering_Level("1", PHPWord_Numbering_Level::NUMFMT_DECIMAL, "%1.", "left", $level1), new PHPWord_Numbering_Level("1", PHPWord_Numbering_Level::NUMFMT_LOWER_LETTER, "%2)", "left", $level2))); $docx->addNumbering($answernumbering); if ($question->qtype == 'multichoice' || $question->qtype == 'multichoiceset') { $slot = $questionslots[$question->id]; // Save the usage slot in the group questions table. // $DB->set_field('offlinequiz_group_questions', 'usageslot', $slot, // array('offlinequizid' => $offlinequiz->id, // 'offlinegroupid' => $group->id, 'questionid' => $question->id)); // Now retrieve the order of the answers. $slotquestion = $templateusage->get_question($slot); $attempt = $templateusage->get_question_attempt($slot); $order = $slotquestion->get_order($attempt); // Order of the answers. foreach ($order as $key => $answer) { $answertext = $question->options->answers[$answer]->answer; // Filter only for tex formulas. if (!empty($texfilter)) { $answertext = $texfilter->filter($answertext); } // Remove all HTML comments (typically from MS Office). $answertext = preg_replace("/<!--.*?--\\s*>/ms", "", $answertext); // Remove all paragraph tags because they mess up the layout. $answertext = preg_replace("/<p[^>]*>/ms", "", $answertext); // Remove <script> tags that are created by mathjax preview. $answertext = preg_replace("/<script[^>]*>[^<]*<\\/script>/ms", "", $answertext); $answertext = preg_replace("/<\\/p[^>]*>/ms", "", $answertext); $answertext = $trans->fix_image_paths($answertext, $question->contextid, 'answer', $answer, 0.6, 200, 'docx'); $blocks = offlinequiz_convert_image_docx($answertext); offlinequiz_print_blocks_docx($section, $blocks, $answernumbering, 1); } if ($offlinequiz->showgrades) { $pointstr = get_string('points', 'grades'); if ($question->maxgrade == 1) { $pointstr = get_string('point', 'offlinequiz'); } // Indent the question grade like the answers. $textrun = $section->createTextRun($level2); $textrun->addText('(' . ($question->maxgrade + 0) . ' ' . $pointstr . ')', 'bStyle'); } $section->addTextBreak(); $number++; // End if multichoice. } } // End forall questions. } // End else no shufflequestions. $fs = get_file_storage(); $fileprefix = 'form'; if ($correction) { $fileprefix = 'correction'; } srand(microtime() * 1000000); $unique = str_replace('.', '', microtime(true) . rand(0, 100000)); $tempfilename = $CFG->dataroot . '/temp/offlinequiz/' . $unique . '.docx'; check_dir_exists($CFG->dataroot . '/temp/offlinequiz', true, true); if (file_exists($tempfilename)) { unlink($tempfilename); } // Save file. $objwriter = PHPWord_IOFactory::createWriter($docx, 'Word2007'); $objwriter->save($tempfilename); // Prepare file record object. $timestamp = date('Ymd_His', time()); $fileinfo = array('contextid' => $context->id, 'component' => 'mod_offlinequiz', 'filearea' => 'pdfs', 'filepath' => '/', 'itemid' => 0, 'filename' => $fileprefix . '-' . strtolower($groupletter) . '_' . $timestamp . '.docx'); // Delete existing old files, should actually not happen. if ($oldfile = $fs->get_file($fileinfo['contextid'], $fileinfo['component'], $fileinfo['filearea'], $fileinfo['itemid'], $fileinfo['filepath'], $fileinfo['filename'])) { $oldfile->delete(); } // Create a Moodle file from the temporary file. $file = $fs->create_file_from_pathname($fileinfo, $tempfilename); // Remove all temporary files. unlink($tempfilename); $trans->remove_temp_files(); return $file; }