<?php include_once 'Sample_Header.php'; // New Word document echo date('H:i:s'), ' Create new PhpWord object', EOL; $phpWord = new \PhpOffice\PhpWord\PhpWord(); // New section $section = $phpWord->addSection(); // Define styles $fontStyle12 = array('spaceAfter' => 60, 'size' => 12); $fontStyle10 = array('size' => 10); $phpWord->addTitleStyle(1, array('size' => 20, 'color' => '333333', 'bold' => true)); $phpWord->addTitleStyle(2, array('size' => 16, 'color' => '666666')); $phpWord->addTitleStyle(3, array('size' => 14, 'italic' => true)); $phpWord->addTitleStyle(4, array('size' => 12)); // Add text elements $section->addText('Table of contents 1'); $section->addTextBreak(2); // Add TOC #1 $toc = $section->addTOC($fontStyle12); $section->addTextBreak(2); // Filler $section->addText('Text between TOC'); $section->addTextBreak(2); // Add TOC #1 $section->addText('Table of contents 2'); $section->addTextBreak(2); $toc2 = $section->addTOC($fontStyle10); $toc2->setMinDepth(2); $toc2->setMaxDepth(3); // Add Titles
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'); }
$section->addText("TERİMLER, SİMGELER VE KISALTMALAR", 'rIcBasStyle', 'pBasStyle'); $space75Left = array('align' => 'both', 'spaceBefore' => 0, 'spaceAfter' => 0, 'spacing' => 75); if ($terim[0] != null) { foreach ($terim[0] as $row) { $textrun = $section->createTextRun($space75Left); $textrun->addText($row["TERIM_ADI"] . ": ", 'rIcBasStyle'); $textrun->addText($row["TERIM_ACIKLAMA"], 'rIcStyle'); } $section->addText('ifade eder.', 'rIcStyle', array('align' => 'both')); } //Terimler Son $section = $phpWord->createSection(array('orientation' => 'portrait')); $section->addText('İÇİNDEKİLER', 'rIcBasStyle', 'pBasStyle'); //**********************************İÇİNDEKİLER**********************************************************// //Önemli: İçindekiler Kısmı yok. Yapılacak ins. $phpWord->addTitleStyle(1, array('name' => 'Times New Roman', 'size' => 12, 'bold' => true), array('align' => 'both', 'spaceBefore' => 150, 'spaceAfter' => 0, 'spacing' => 150)); $phpWord->addTitleStyle(2, array('name' => 'Times New Roman', 'size' => 12, 'bold' => true), array('align' => 'both', 'spaceBefore' => 150, 'spaceAfter' => 0, 'spacing' => 150)); $fontStyleIcindekiler = array('spaceAfter' => 60, 'size' => 12); $section->addTOC($fontStyle, $fontStyle); //**********************************İÇİNDEKİLER**********************************************************// //Giriş $section = $phpWord->createSection(array('orientation' => 'portrait')); $section->addTitle('1. GİRİŞ', 1); $section->addText(FormFactory::ucwordsTR($data["STANDART_ADI"]) . " (" . $data["SEVIYE_ADI"] . ") ulusal meslek standardı 5544 sayılı Mesleki Yeterlilik Kurumu (MYK) Kanunu ile anılan Kanun uyarınca çıkartılan \"Ulusal Meslek Standartlarının Hazırlanması Hakkında Yönetmelik\" ve \"Mesleki Yeterlilik Kurumu Sektör Komitelerinin Kuruluş, Görev, Çalışma Usul ve Esasları Hakkında Yönetmelik\" hükümlerine göre MYK'nın görevlendirdiği " . FormFactory::ucWordsLeaveConjunction($kurulusAd) . " tarafından hazırlanmıştır.", 'rIcStyle', array('align' => 'both')); $section->addText(FormFactory::ucwordsTR($data["STANDART_ADI"]) . " (" . $data["SEVIYE_ADI"] . ") ulusal meslek standardı, sektördeki ilgili kurum ve kuruluşların görüşleri alınarak değerlendirilmiş, " . $sektor . " tarafından incelendikten sonra MYK Yönetim Kurulunca onaylanmıştır.", 'rIcStyle', array('align' => 'both')); //Giriş SON //Meslek Tanıtımı $space75Both = array('align' => 'both', 'spaceBefore' => 0, 'spaceAfter' => 0, 'spacing' => 75); $space150Both = array('align' => 'both', 'spaceBefore' => 150, 'spaceAfter' => 0, 'spacing' => 150); $section = $phpWord->createSection(array('orientation' => 'portrait')); $section->addTitle('2. MESLEK TANITIMI', 1);
$section->addListItem(htmlspecialchars('List Item 2', ENT_COMPAT, 'UTF-8'), 0, 'myOwnStyle', $predefinedMultilevel, 'P-Style'); $section->addListItem(htmlspecialchars('List Item 3', ENT_COMPAT, 'UTF-8'), 1, 'myOwnStyle', $predefinedMultilevel, 'P-Style'); $section->addListItem(htmlspecialchars('List Item 4', ENT_COMPAT, 'UTF-8'), 1, 'myOwnStyle', $predefinedMultilevel, 'P-Style'); $section->addListItem(htmlspecialchars('List Item 5', ENT_COMPAT, 'UTF-8'), 2, 'myOwnStyle', $predefinedMultilevel, 'P-Style'); $section->addListItem(htmlspecialchars('List Item 6', ENT_COMPAT, 'UTF-8'), 1, 'myOwnStyle', $predefinedMultilevel, 'P-Style'); $section->addListItem(htmlspecialchars('List Item 7', ENT_COMPAT, 'UTF-8'), 0, 'myOwnStyle', $predefinedMultilevel, 'P-Style'); $section->addTextBreak(2); $section->addText(htmlspecialchars('List with inline formatting.', ENT_COMPAT, 'UTF-8')); $listItemRun = $section->addListItemRun(); $listItemRun->addText(htmlspecialchars('List item 1', ENT_COMPAT, 'UTF-8')); $listItemRun->addText(htmlspecialchars(' in bold', ENT_COMPAT, 'UTF-8'), array('bold' => true)); $listItemRun = $section->addListItemRun(); $listItemRun->addText(htmlspecialchars('List item 2', ENT_COMPAT, 'UTF-8')); $listItemRun->addText(htmlspecialchars(' in italic', ENT_COMPAT, 'UTF-8'), array('italic' => true)); $listItemRun = $section->addListItemRun(); $listItemRun->addText(htmlspecialchars('List item 3', ENT_COMPAT, 'UTF-8')); $listItemRun->addText(htmlspecialchars(' underlined', ENT_COMPAT, 'UTF-8'), array('underline' => 'dash')); $section->addTextBreak(2); // Numbered heading $phpWord->addNumberingStyle('headingNumbering', array('type' => 'multilevel', 'levels' => array(array('pStyle' => 'Heading1', 'format' => 'decimal', 'text' => '%1'), array('pStyle' => 'Heading2', 'format' => 'decimal', 'text' => '%1.%2'), array('pStyle' => 'Heading3', 'format' => 'decimal', 'text' => '%1.%2.%3')))); $phpWord->addTitleStyle(1, array('size' => 16), array('numStyle' => 'headingNumbering', 'numLevel' => 0)); $phpWord->addTitleStyle(2, array('size' => 14), array('numStyle' => 'headingNumbering', 'numLevel' => 1)); $phpWord->addTitleStyle(3, array('size' => 12), array('numStyle' => 'headingNumbering', 'numLevel' => 2)); $section->addTitle(htmlspecialchars('Heading 1', ENT_COMPAT, 'UTF-8'), 1); $section->addTitle(htmlspecialchars('Heading 2', ENT_COMPAT, 'UTF-8'), 2); $section->addTitle(htmlspecialchars('Heading 3', ENT_COMPAT, 'UTF-8'), 3); // Save file echo write($phpWord, basename(__FILE__, '.php'), $writers); if (!CLI) { include_once 'Sample_Footer.php'; }
<?php include_once 'Sample_Header.php'; // New Word Document echo date('H:i:s'), ' Create new PhpWord object', EOL; $phpWord = new \PhpOffice\PhpWord\PhpWord(); $phpWord->addFontStyle('rStyle', array('bold' => true, 'italic' => true, 'size' => 16, 'allCaps' => true, 'doubleStrikethrough' => true)); $phpWord->addParagraphStyle('pStyle', array('alignment' => \PhpOffice\PhpWord\SimpleType\Jc::CENTER, 'spaceAfter' => 100)); $phpWord->addTitleStyle(1, array('bold' => true), array('spaceAfter' => 240)); // New portrait section $section = $phpWord->addSection(); // Simple text $section->addTitle(htmlspecialchars('Welcome to PhpWord', ENT_COMPAT, 'UTF-8'), 1); $section->addText(htmlspecialchars('Hello World!', ENT_COMPAT, 'UTF-8')); // Two text break $section->addTextBreak(2); // Defined style $section->addText(htmlspecialchars('I am styled by a font style definition.', ENT_COMPAT, 'UTF-8'), 'rStyle'); $section->addText(htmlspecialchars('I am styled by a paragraph style definition.', ENT_COMPAT, 'UTF-8'), null, 'pStyle'); $section->addText(htmlspecialchars('I am styled by both font and paragraph style.', ENT_COMPAT, 'UTF-8'), 'rStyle', 'pStyle'); $section->addTextBreak(); // Inline font style $fontStyle['name'] = 'Times New Roman'; $fontStyle['size'] = 20; $textrun = $section->addTextRun(); $textrun->addText(htmlspecialchars('I am inline styled ', ENT_COMPAT, 'UTF-8'), $fontStyle); $textrun->addText(htmlspecialchars('with ', ENT_COMPAT, 'UTF-8')); $textrun->addText(htmlspecialchars('color', ENT_COMPAT, 'UTF-8'), array('color' => '996699')); $textrun->addText(htmlspecialchars(', ', ENT_COMPAT, 'UTF-8')); $textrun->addText(htmlspecialchars('bold', ENT_COMPAT, 'UTF-8'), array('bold' => true)); $textrun->addText(htmlspecialchars(', ', ENT_COMPAT, 'UTF-8'));
require_once 'src/php_libs/return_demographic.php'; \PhpOffice\PhpWord\Autoloader::register(); function establish_mysql_connection() { try { $db = new PDO("mysql:host=localhost;dbname=NHS;charset=utf8", "portal_user", ""); } catch (PDOException $ex) { die("Failed to connect to the database: " . $ex->getMessage()); } return $db; } // New Word Document $phpWord = new \PhpOffice\PhpWord\PhpWord(); $phpWord->addFontStyle('rStyle', array('bold' => true, 'italic' => true, 'size' => 16, 'allCaps' => true, 'doubleStrikethrough' => true)); $phpWord->addParagraphStyle('pStyle', array('align' => 'center', 'spaceAfter' => 100)); $phpWord->addTitleStyle(1, array('bold' => true), array('align' => 'center')); // New portrait section $section = $phpWord->addSection(); // Simple text $section->addTitle(htmlspecialchars(date('d F Y H:i:s')), 1); $section->addTitle(htmlspecialchars(return_demographic($_SESSION['pid'], 0)), 1); $section->addTitle(htmlspecialchars(return_demographic($_SESSION['pid'], 1)), 1); $section->addTitle(htmlspecialchars(return_demographic($_SESSION['pid'], 3)), 1); $section->addTitle(htmlspecialchars(return_demographic($_SESSION['pid'], 2)), 1); // Two text break $section->addTextBreak(2); $data = array(); for ($i = 1; isset($_POST['select' . $i]); $i++) { if (!isset($data[$_POST['box' . $i]])) { $data[$_POST['box' . $i]] = array(); }
// } ############################################## // New Word Document // echo date('H:i:s'), ' Create new PhpWord object', EOL; $phpWord = new \PhpOffice\PhpWord\PhpWord(); // $PHPWord->addParagraphStyle('pJustify', array('align' => 'both', 'spaceBefore' => 0, 'spaceAfter' => 0, 'spacing' => 0)); // //add this style then append it to text below // $section->addText('something', 'textstyle', 'pJustify'); // //the text behind this will be justified and will be in a new line, not in a new paragraph // $section->addText('behind', 'textstyle', 'pJustify'); //----Style---- // $phpWord->addTitleStyle(1, array('size' => 16), array('numStyle' => 'hNum', 'numLevel' => 0)); // $phpWord->addTitleStyle(2, array('size' => 14), array('numStyle' => 'hNum', 'numLevel' => 1)); // $phpWord->addTitleStyle(3, array('size' => 12), array('numStyle' => 'hNum', 'numLevel' => 2)); //------------- $phpWord->addTitleStyle(2, array('name' => 'Times New Roman', 'size' => 18, 'color' => '000000', 'bold' => true)); //h2 $phpWord->addTitleStyle(3, array('name' => 'Times New Roman', 'size' => 12, 'color' => '000000', 'bold' => true)); //h3 $phpWord->addTitleStyle(4, array('name' => 'Times New Roman', 'size' => 12, 'color' => '000000')); //h4 $section = $phpWord->addSection(); //------------------Header n Footer----------------------- // Add header for all other pages $subsequent = $section->addHeader(); // $subsequent->addText(htmlspecialchars('Subsequent pages in Section 1 will Have this!', ENT_COMPAT, 'UTF-8')); // Add footer $footer = $section->addFooter(); $footer->addPreserveText(htmlspecialchars('Page {PAGE} of {NUMPAGES}.', ENT_COMPAT, 'UTF-8'), null, array('alignment' => 'center')); //----------------------------------------- // $normalFont['name'] = 'Times New Roman';
<?php include_once 'Sample_Header.php'; // New Word document echo date('H:i:s'), ' Create new PhpWord object', EOL; $phpWord = new \PhpOffice\PhpWord\PhpWord(); $phpWord->addTitleStyle(1, array('size' => 14, 'bold' => true)); $section = $phpWord->addSection(); // Arc $section->addTitle(htmlspecialchars('Arc', ENT_COMPAT, 'UTF-8'), 1); $section->addShape('arc', array('points' => '-90 20', 'frame' => array('width' => 120, 'height' => 120), 'outline' => array('color' => '#333333', 'weight' => 2, 'startArrow' => 'oval', 'endArrow' => 'open'))); // Curve $section->addTitle(htmlspecialchars('Curve', ENT_COMPAT, 'UTF-8'), 1); $section->addShape('curve', array('points' => '1,100 200,1 1,50 200,50', 'connector' => 'elbow', 'outline' => array('color' => '#66cc00', 'weight' => 2, 'dash' => 'dash', 'startArrow' => 'diamond', 'endArrow' => 'block'))); // Line $section->addTitle(htmlspecialchars('Line', ENT_COMPAT, 'UTF-8'), 1); $section->addShape('line', array('points' => '1,1 150,30', 'outline' => array('color' => '#cc00ff', 'line' => 'thickThin', 'weight' => 3, 'startArrow' => 'oval', 'endArrow' => 'classic'))); // Polyline $section->addTitle(htmlspecialchars('Polyline', ENT_COMPAT, 'UTF-8'), 1); $section->addShape('polyline', array('points' => '1,30 20,10 55,20 75,10 100,40 115,50, 120,15 200,50', 'outline' => array('color' => '#cc6666', 'weight' => 2, 'startArrow' => 'none', 'endArrow' => 'classic'))); // Rectangle $section->addTitle(htmlspecialchars('Rectangle', ENT_COMPAT, 'UTF-8'), 1); $section->addShape('rect', array('roundness' => 0.2, 'frame' => array('width' => 100, 'height' => 100, 'left' => 1, 'top' => 1), 'fill' => array('color' => '#FFCC33'), 'outline' => array('color' => '#990000', 'weight' => 1), 'shadow' => array())); // Oval $section->addTitle(htmlspecialchars('Oval', ENT_COMPAT, 'UTF-8'), 1); $section->addShape('oval', array('frame' => array('width' => 100, 'height' => 70, 'left' => 1, 'top' => 1), 'fill' => array('color' => '#33CC99'), 'outline' => array('color' => '#333333', 'weight' => 2), 'extrusion' => array())); // Save file echo write($phpWord, basename(__FILE__, '.php'), $writers); if (!CLI) { include_once 'Sample_Footer.php'; }
/** * */ public function exportMemberProfile($id) { $user = User::find($id); if (!$user) { return Redirect::route('members')->with('mError', 'Cet utilisateur est introuvable !'); } $phpWord = new \PhpOffice\PhpWord\PhpWord(); $phpWord->addTitleStyle(1, array('name' => 'Tahoma', 'size' => 30, 'bold' => true), array('align' => 'center', 'spaceBefore' => true, 'spaceAfter' => true)); $phpWord->addTitleStyle(2, array('name' => 'Tahoma', 'size' => 14, 'color' => '666666', 'bold' => true), array('align' => 'center', 'spaceBefore' => true, 'spaceAfter' => true)); $phpWord->addFontStyle('defaultText', array('name' => 'Tahoma', 'size' => 12, 'spaceBefore' => true, 'spaceAfter' => true)); $section = $phpWord->addSection(array('marginTop' => \PhpOffice\PhpWord\Shared\Converter::cmToTwip(1), 'marginLeft' => \PhpOffice\PhpWord\Shared\Converter::cmToTwip(1), 'marginRight' => \PhpOffice\PhpWord\Shared\Converter::cmToTwip(1))); $textrun = $section->addTextRun('Heading1'); $textrun->addText($user->fullname); $section->addTextBreak(); $textrun = $section->addTextRun('Heading2'); $textrun->addText(htmlspecialchars($user->bio_short)); $section->addTextBreak(); $table = $section->addTable(); $table->addRow(); $cell1 = $table->addCell(\PhpOffice\PhpWord\Shared\Converter::cmToTwip(14)); foreach (explode("\n", htmlspecialchars($user->bio_long)) as $line) { $cell1->addText($line, 'defaultText'); } $cell1->addTextBreak(); if ($user->phone) { $cell1->addText(htmlspecialchars(sprintf('Tél: %s', $user->phoneFmt)), 'defaultText', array('align' => 'right')); } $cell1->addText(htmlspecialchars(sprintf('Email: %s', $user->email)), 'defaultText', array('align' => 'right')); if ($user->website) { $cell1->addText(htmlspecialchars($user->website), 'defaultText', array('align' => 'right')); } $cell2 = $table->addCell(\PhpOffice\PhpWord\Shared\Converter::cmToTwip(5)); $image_url = $user->largeAvatarUrl; $image_url = preg_replace('!^(.+)\\?.+$!', '$1', $image_url); if (false === strpos($image_url, 'http')) { $image_url = public_path() . $image_url; } $cell2->addImage($image_url, array('width' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(5))); $filename = sprintf('%s.docx', Str::slug($user->fullname)); $objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007'); $objWriter->save($filename); $content = file_get_contents($filename); unlink($filename); $headers = array("Content-Description" => "File Transfer", "Content-Transfer-Encoding" => "binary", "Content-type" => "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "Content-Disposition" => "attachment; filename=" . $filename); return Response::make($content, 200, $headers); }
$obj = json_decode($json); $file = $obj->title . '.docx'; header("Content-Description: File Transfer"); header('Content-Disposition: inline; filename="' . $file . '"'); 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"); \PhpOffice\PhpWord\Settings::setOutputEscapingEnabled(true); // New Word document // New section $section = $phpWord->addSection(); // Define styles $phpWord->addTitleStyle(1, array('size' => 35, 'bold' => true, 'color' => '#e83d84')); // Adding Text element with font customized using named font style... $pStyle = 'p'; $phpWord->addFontStyle($pStyle, array('name' => 'Arial', 'size' => 16, 'color' => '757575', 'bold' => false)); // Arc $section->addTitle($obj->title, 1); //$section->addText(htmlspecialchars_decode(strip_tags($obj->body)), $pStyle); WaffleHtml::addHtml($section, $obj->body); if ($obj->sidebar) { $sidebar = $phpWord->addSection(); $sidebar->addTitle("Sidebar", 1); //$sidebar->addText(strip_tags($obj->sidebar), $pStyle); WaffleHtml::addHtml($sidebar, $obj->sidebar); } $nav = $phpWord->addSection(); $nav->addTitle("Navigation", 1);
<?php include_once 'Sample_Header.php'; use PhpOffice\PhpWord\Shared\Converter; // New Word document echo date('H:i:s'), ' Create new PhpWord object', EOL; $phpWord = new \PhpOffice\PhpWord\PhpWord(); // Define styles $phpWord->addTitleStyle(1, array('size' => 14, 'bold' => true), array('keepNext' => true, 'spaceBefore' => 240)); $phpWord->addTitleStyle(2, array('size' => 14, 'bold' => true), array('keepNext' => true, 'spaceBefore' => 240)); // 2D charts $section = $phpWord->addSection(); $section->addTitle('2D charts', 1); $section = $phpWord->addSection(array('colsNum' => 2, 'breakType' => 'continuous')); $chartTypes = array('pie', 'doughnut', 'bar', 'column', 'line', 'area', 'scatter', 'radar'); $twoSeries = array('bar', 'column', 'line', 'area', 'scatter', 'radar'); $threeSeries = array('bar', 'line'); $categories = array('A', 'B', 'C', 'D', 'E'); $series1 = array(1, 3, 2, 5, 4); $series2 = array(3, 1, 7, 2, 6); $series3 = array(8, 3, 2, 5, 4); foreach ($chartTypes as $chartType) { $section->addTitle(ucfirst($chartType), 2); $chart = $section->addChart($chartType, $categories, $series1); $chart->getStyle()->setWidth(Converter::inchToEmu(2.5))->setHeight(Converter::inchToEmu(2)); if (in_array($chartType, $twoSeries)) { $chart->addSeries($categories, $series2); } if (in_array($chartType, $threeSeries)) { $chart->addSeries($categories, $series3); }
define('SCRIPT_FILENAME', basename($_SERVER['SCRIPT_FILENAME'], '.php')); define('IS_INDEX', SCRIPT_FILENAME == 'index'); Autoloader::register(); Settings::loadConfig(); // Set writers $writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf', 'HTML' => 'html', 'PDF' => 'pdf'); if (null === Settings::getPdfRendererPath()) { $writers['PDF'] = null; } if (CLI) { return; } $phpWord = new \PhpOffice\PhpWord\PhpWord(); $phpWord->addFontStyle('rStyle', array('bold' => true, 'italic' => true, 'size' => 16, 'allCaps' => true, 'doubleStrikethrough' => true)); $phpWord->addParagraphStyle('pStyle', array('align' => 'center', 'spaceAfter' => 100)); $phpWord->addTitleStyle(1, array('bold' => true), array('spaceAfter' => 240)); $phpWord->addTitleStyle(2, array('bold' => true), array('spaceAfter' => 240), array('align' => 'center')); $section = $phpWord->addSection(); $section->addText(htmlspecialchars('exXXX公司工作汇报与总结'), array('size' => 16, 'name' => '宋体'), array('align' => 'center', 'bold' => true)); $section->addTextBreak(1); $styleTable = array('borderSize' => 6, 'borderColor' => '000000', 'cellMargin' => 80); $styleFirstRow = array('borderBottomSize' => 18, 'borderBottomColor' => '0000FF', 'bgColor' => 'ffffff'); $styleCell = array('valign' => 'center'); $styleCellBTLR = array('valign' => 'center', 'textDirection' => \PhpOffice\PhpWord\Style\Cell::TEXT_DIR_BTLR); $fontSizeStyle = array('size' => 14, 'name' => '宋体'); $fontStyle = array('bold' => true, 'align' => 'center'); $phpWord->addTableStyle('Fancy Table', $styleTable, $styleFirstRow); $table = $section->addTable('Fancy Table'); $table->addRow(900); $table->addCell(1200, $styleCell)->addText(htmlspecialchars('姓名'), $fontSizeStyle, $fontStyle); $table->addCell(2100, $styleCell)->addText(htmlspecialchars($data->name), $fontSizeStyle, $fontStyle);
public function actionWord() { $data = $this->getData(); $searchModel = $data['searchModel']; $dataProvider = $data['dataProvider']; $title = $data['title']; $modelName = $data['modelName']; $fields = $this->getFieldsKeys($searchModel->exportFields()); $phpWord = new \PhpOffice\PhpWord\PhpWord(); $section = $phpWord->addSection(); $sectionStyle = $section->getSettings(); $sectionStyle->setLandscape(); $sectionStyle->setBorderTopColor('C0C0C0'); $sectionStyle->setMarginTop(300); $sectionStyle->setMarginRight(300); $sectionStyle->setMarginBottom(300); $sectionStyle->setMarginLeft(300); $phpWord->addTitleStyle(1, ['name' => 'HelveticaNeueLT Std Med', 'size' => 16], ['align' => 'center']); //h $section->addTitle('<p style="font-size: 24px; text-align: center;">' . $title ? $title : $modelName . '</p>'); $table = $section->addTable(['name' => 'Tahoma', 'align' => 'center', 'cellMarginTop' => 30, 'cellMarginRight' => 30, 'cellMarginBottom' => 30, 'cellMarginLeft' => 30]); $table->addRow(300, ['exactHeight' => true]); foreach ($fields as $one) { $table->addCell(1500, ['bgColor' => 'eeeeee', 'valign' => 'center', 'borderTopSize' => 5, 'borderRightSize' => 5, 'borderBottomSize' => 5, 'borderLeftSize' => 5])->addText($searchModel->getAttributeLabel($one), ['bold' => true, 'size' => 10], ['align' => 'center']); } foreach ($dataProvider->getModels() as $model) { $table->addRow(300, ['exactHeight' => true]); foreach ($searchModel->exportFields() as $one) { if (is_string($one)) { $table->addCell(1500, ['valign' => 'center', 'borderTopSize' => 1, 'borderRightSize' => 1, 'borderBottomSize' => 1, 'borderLeftSize' => 1])->addText($model[$one], ['bold' => false, 'size' => 10], ['align' => 'right']); } else { $table->addCell(1500, ['valign' => 'center', 'borderTopSize' => 1, 'borderRightSize' => 1, 'borderBottomSize' => 1, 'borderLeftSize' => 1])->addText($one($model), ['bold' => false, 'size' => 10], ['align' => 'right']); } } } header('Content-Type: application/vnd.ms-word'); $filename = $modelName . '_' . time() . ".docx"; header('Content-Disposition: attachment;filename=' . $filename . ' '); header('Cache-Control: max-age=0'); $objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007'); $objWriter->save('php://output'); }
public function gera_word() { $this->load->library('word2'); // 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 (CLI) { // return; //} // Set titles and names //$pageHeading = str_replace('_', ' ', SCRIPT_FILENAME); $pageHeading = "page heading"; //$pageTitle = IS_INDEX ? 'Welcome to ' : "{$pageHeading} - "; $pageTitle = "titulo da pagina"; //$pageTitle .= 'PHPWord'; //$pageHeading = IS_INDEX ? '' : "<h1>{$pageHeading}</h1>"; // Populate samples $files = ''; if ($handle = opendir('.')) { while (false !== ($file = readdir($handle))) { if (preg_match('/^Sample_\\d+_/', $file)) { $name = str_replace('_', ' ', preg_replace('/(Sample_|\\.php)/', '', $file)); $files .= "<li><a href='{$file}'>{$name}</a></li>"; } } closedir($handle); } //include_once 'Sample_Header.php'; require_once APPPATH . "third_party/PHPWord2/PhpWord.php"; // New Word Document echo date('H:i:s'), " Create new PhpWord object"; $phpWord = new \PhpOffice\PhpWord\PhpWord(); $phpWord->addFontStyle('rStyle', array('bold' => true, 'italic' => true, 'size' => 16, 'allCaps' => true, 'doubleStrikethrough' => true)); $phpWord->addParagraphStyle('pStyle', array('align' => 'center', 'spaceAfter' => 100)); $phpWord->addTitleStyle(1, array('bold' => true), array('spaceAfter' => 240)); // New portrait section $section = $phpWord->addSection(); // Simple text $section->addTitle('Welcome to PhpWord', 1); $section->addText('Hello World!'); // Two text break $section->addTextBreak(2); // Defined style $section->addText('I am styled by a font style definition.', 'rStyle'); $section->addText('I am styled by a paragraph style definition.', null, 'pStyle'); $section->addText('I am styled by both font and paragraph style.', 'rStyle', 'pStyle'); $section->addPageBreak(); // Inline font style $fontStyle['name'] = 'Times New Roman'; $fontStyle['size'] = 20; $fontStyle['bold'] = true; $fontStyle['italic'] = true; $fontStyle['underline'] = 'dash'; $fontStyle['strikethrough'] = true; $fontStyle['superScript'] = true; $fontStyle['color'] = 'FF0000'; $fontStyle['fgColor'] = 'yellow'; $fontStyle['smallCaps'] = true; $section->addText('I am inline styled.', $fontStyle); $section->addTextBreak(); // Link $section->addLink('http://www.google.com', 'Google'); $section->addTextBreak(); // Image //$section->addImage('resources/_earth.jpg', array('width'=>18, 'height'=>18)); // Save file //echo write($phpWord, basename(__FILE__, '.php'), $writers); //if (!CLI) { //include_once 'Sample_Footer.php'; // } // Save file echo $this->write($phpWord, basename(__FILE__, '.php'), $writers); if (!CLI) { //include_once 'Sample_Footer.php'; } }