本文整理汇总了PHP中PHPWord::createSection方法的典型用法代码示例。如果您正苦于以下问题:PHP PHPWord::createSection方法的具体用法?PHP PHPWord::createSection怎么用?PHP PHPWord::createSection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PHPWord
的用法示例。
在下文中一共展示了PHPWord::createSection方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: test
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);
}
示例2: generate
public function generate($xml_file)
{
if (!file_exists($xml_file)) {
throw new Exception("XML-file '{$xml_file}' NOT exosts.");
}
$xml = new SimpleXMLElement(file_get_contents($xml_file));
// Create a new PHPWord Object
$objPHPWord = new PHPWord();
// Every element you want to append to the word document is placed in a section. So you need a section:
$section = $objPHPWord->createSection();
foreach ($xml->body->p as $p) {
$section->addText((string) $p);
dbg::write((string) $p);
}
header('Content-Type: application/vnd.ms-word');
header('Content-Disposition: attachment;filename="' . (string) $xml->body['title'] . '.doc"');
header('Cache-Control: max-age=0');
$objWriter = PHPWord_IOFactory::createWriter($objPHPWord, 'Word2007');
$objWriter->save('php://output');
exit;
}
示例3: generateResume
public function generateResume($id = NULL)
{
//Проверяем, зарегестрированн ли пользователь и его роль
if (isset($this->session->userdata['id'])) {
$user = Doctrine::getTable('User')->findOneBy('id', $this->session->userdata['id']);
if ($user->getRole() == 'applicant') {
echo json_encode(array('status' => false, 'msg' => 'Скачивать резюме могут только работодатели и агентства!'));
exit;
}
} else {
echo json_encode(array('status' => false, 'msg' => 'Скачивать резюме могут только зарегестрированные пользователи!'));
exit;
}
if (empty($id)) {
echo json_encode(array('status' => false));
exit;
}
$resume = Doctrine::getTable('Resume')->findOneBy('id', $id);
if (empty($resume)) {
echo json_encode(array('status' => false));
exit;
}
//Папка для хранения файлов
$path = str_replace('system/', '', BASEPATH) . 'downloads/resumes/';
//Создаем ее, если она была созданна ранее
if (!file_exists($path)) {
mkdir($path, 0, true);
}
//Имя файла с резюме
$file_name = 'resume_' . $id . '.docx';
//Если такой файл уже есть, то проверяем дату его создания
if (file_exists($path . $file_name)) {
if ($resume->modification_date != NULL and $resume->modification_date >= date('Y-m-d H:i:s', filectime($path . $file_name))) {
echo json_encode(array('status' => true, 'url' => site_url() . 'downloads/resumes/' . $file_name));
exit;
} else {
unlink($path . $file_name);
}
}
$this->load->library('PHPWord');
$word = new PHPWord();
$section = $word->createSection();
$section->addText('Резюме от: ' . date('Y.m.d', $resume->getPlacementDate()), array('name' => 'Verdana', 'color' => '006699'));
$section->addText($resume->formatName('s n p'), array('name' => 'Verdana', 'bold' => true, 'size' => 20));
$section->addImage($resume->getRealImagePath(), array('align' => 'left'));
$section->addTextBreak();
$bold = array('bold' => true);
$grey = array('bgColor' => 'dcdcdc', 'valign' => 'center');
$center = array('valign' => 'center');
$styleTable = array('borderSize' => 4, 'borderColor' => 'dcdcdc');
$word->addTableStyle('myOwnTableStyle', $styleTable);
$table = $section->addTable('myOwnTableStyle');
$data = array('Возраст:' => $resume->getResumeAuthorAge(), 'Пол:' => $resume->gender->getDescription(), 'Семейное положение:' => $resume->family_state->getValue(), 'Наличие детей:' => $resume->getChilds(), 'Город проживания:' => $resume->getCity(), 'Район проживания:' => $resume->getArea(), 'Национальность:' => $resume->getNationality(), 'E-mail:' => $resume->getContactEmail(), 'Контактный телефон:' => $resume->getContactPhone());
foreach ($data as $key => $value) {
$table->addRow();
$table->addCell(3000, $grey)->addText($key, $bold, array('spaceAfter' => 0));
$table->addCell(6000, $center)->addText($value, array(), array('spaceAfter' => 0));
}
$section->addTextBreak();
//Желаемая должность
$section->addText(trim($resume->getDesiredPosition()) == '' ? 'Точная информация о интересующей должности не указанна' : $resume->getDesiredPosition(), array('name' => 'Verdana', 'bold' => true, 'size' => 16));
//Дополнительно рассматриваемые должности
if (count($resume->getPositions()) > 0) {
$section->addText('Также рассматриваются:', array('name' => 'Verdana', 'bold' => true, 'size' => 12));
foreach ($resume->getPositions() as $position_id) {
$position = Doctrine::getTable('Position')->findOneBy('id', $position_id);
$section->addText($position->getName());
}
}
$table = $section->addTable('myOwnTableStyle');
$table->addRow();
$table->addCell(3000, $grey)->addText("Квалификация:", $bold);
$cell = $table->addCell('3000', $center);
foreach ($resume->getQualificationForWord() as $item) {
$cell->addText($item);
}
$data = array('Описание опыта работы:' => $resume->getExperienceDescription(), 'Период опыта работы:' => $resume->experience->getValue(), 'Наличие рекомендаций:' => $resume->getGuidanceAvailability());
foreach ($data as $key => $value) {
$table->addRow();
$table->addCell(3000, $grey)->addText($key, $bold, array('spaceAfter' => 0));
$table->addCell(6000, $center)->addText($value, array(), array('spaceAfter' => 0));
}
$section->addTextBreak();
$section->addText('Образование', array('name' => 'Verdana', 'color' => '006699', 'bold' => true, 'size' => 16));
$table = $section->addTable('myOwnTableStyle');
$table->addRow();
$table->addCell(3000, $grey)->addText("Образование:", $bold, array('spaceAfter' => 0));
$table->addCell(6000, $center)->addText($resume->education->getValue(), array(), array('spaceAfter' => 0));
$table->addRow();
$table->addCell(3000, $grey)->addText("Специальность:", $bold, array('spaceAfter' => 0));
$table->addCell(6000, $center)->addText($resume->getSpeciality(), array(), array('spaceAfter' => 0));
$section->addTextBreak();
$section->addText('Пожелания к работе', array('name' => 'Verdana', 'color' => '006699', 'bold' => true, 'size' => 16));
$table = $section->addTable('myOwnTableStyle');
$data = array('Регион работы:' => $resume->getWorkRegion()->getValue(), 'Работа с проживанием в семье:' => (int) $resume->getHomestay() == 1 ? 'Да' : 'Нет', 'Вид занятости:' => $resume->getOperatingSchedulesText(), 'График работы:' => $resume->getWorkTimetable(), 'Заработная плата:' => $resume->getPaymentDetails());
foreach ($data as $key => $value) {
$table->addRow();
$table->addCell(3000, $grey)->addText($key, $bold, array('spaceAfter' => 0));
$table->addCell(6000, $center)->addText($value, array(), array('spaceAfter' => 0));
}
//.........这里部分代码省略.........
示例4: save
public function save($html, $dir)
{
import("@.ORG.htmltodocx.documentation.support_functions");
$phpword_object = new PHPWord();
$section = $phpword_object->createSection();
// HTML Dom object:
$html_dom = new simple_html_dom();
$html_dom->load('<html><body>' . $html . '</body></html>');
// Note, we needed to nest the html in a couple of dummy elements.
// Create the dom array of elements which we are going to work on:
$html_dom_array = $html_dom->find('html', 0)->children();
// We need this for setting base_root and base_path in the initial_state array
// (below). We are using a function here (derived from Drupal) to create these
// paths automatically - you may want to do something different in your
// implementation. This function is in the included file
// documentation/support_functions.inc.
$paths = htmltodocx_paths();
// Provide some initial settings:
$initial_state = array('phpword_object' => &$phpword_object, 'base_root' => $paths['base_root'], 'base_path' => $paths['base_path'], 'current_style' => array('size' => '11'), 'parents' => array(0 => 'body'), 'list_depth' => 0, 'context' => 'section', 'pseudo_list' => TRUE, 'pseudo_list_indicator_font_name' => 'Wingdings', 'pseudo_list_indicator_font_size' => '7', 'pseudo_list_indicator_character' => 'l ', 'table_allowed' => TRUE, 'treat_div_as_paragraph' => TRUE, 'style_sheet' => htmltodocx_styles_example());
// Convert the HTML and put it into the PHPWord object
htmltodocx_insert_html($section, $html_dom_array[0]->nodes, $initial_state);
// Clear the HTML dom object:
$html_dom->clear();
unset($html_dom);
// Save File
$str = explode(".", $h2d_file_uri);
$h2d_file_uri = $dir . "wordtemp/" . time() . ".docx";
if (!file_exists($dir . "wordtemp/")) {
$this->createFolders($dir . "wordtemp/");
//判断目标文件夹是否存在
}
$objWriter = PHPWord_IOFactory::createWriter($phpword_object, 'Word2007');
$objWriter->save($h2d_file_uri);
return $h2d_file_uri;
}
示例5: generate_docx
function generate_docx($html, $file_path, &$file_takeout_tmp_files)
{
$phpword_object = new PHPWord();
$section = $phpword_object->createSection();
$html_dom = new simple_html_dom();
$html_dom->load($html);
$html_dom_array = $html_dom->find('html', 0)->children();
$paths = htmltodocx_paths();
$initial_state = array('phpword_object' => &$phpword_object, 'base_root' => $paths['base_root'], 'base_path' => $paths['base_path'], 'current_style' => array('size' => '11'), 'parents' => array(0 => 'body'), 'list_depth' => 0, 'context' => 'section', 'pseudo_list' => TRUE, 'pseudo_list_indicator_font_name' => 'Wingdings', 'pseudo_list_indicator_font_size' => '7', 'pseudo_list_indicator_character' => 'l ', 'table_allowed' => TRUE, 'treat_div_as_paragraph' => FALSE, 'style_sheet' => htmltodocx_styles(), 'download_img_path' => elgg_get_data_path(), 'download_img_tmp' => &$file_takeout_tmp_files);
htmltodocx_insert_html($section, $html_dom_array[0]->nodes, $initial_state);
$html_dom->clear();
unset($html_dom);
$objWriter = PHPWord_IOFactory::createWriter($phpword_object, 'Word2007');
// Word2007 is the only option :-(
$objWriter->save($file_path);
}
示例6: display
function display()
{
//declare variables
global $db;
$fileName = "TestTour.docx";
$PHPWord = new PHPWord();
$section = $PHPWord->createSection(array("marginTop" => "0", "marginLeft" => "0"));
/* $tour = new Tour();
$record = isset($_GET["record"]) ? htmlspecialchars($_GET["record"]) : '';
$sql = " SELECT t.id,t.name,t.tour_code,t.picture,
t.duration,t.transport2, t.operator,t.description,
t.deleted,t.tour_code,t.from_place,t.to_place,
t.start_date,t.end_date,t.division,contract_value,currency_id,
currency,u.first_name,u.last_name
FROM tours t
INNER JOIN users u
ON t.assigned_user_id = u.id
WHERE t.id = '" . $record . "' AND t.deleted = 0 AND u.deleted = 0 ";
$result = $db->query($sql);
$row = $db->fetchByAssoc($result);*/
//create word ile
// $section->addImage('C:\xampp\htdocs\carnival\modules\Tours\views\carnival_header.jpg', array("align" => "center"));
//$section->addText("haha");
$section->addImage('modules\\Tours\\views\\carnival_header.jpg', array("width" => 793, "height" => 125, "align" => "center"));
//save file
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, "Word2007");
$objWriter->save($fileName);
//return word file
if (!$fileName) {
die("file not found");
}
ob_end_clean();
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename={$fileName}");
header("Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document");
header("Content-Transfer-Encoding: binary");
readfile($fileName);
//unlink($fileName);
exit;
}
示例7: _initDoc
/**
*
*/
protected function _initDoc()
{
$this->_word = new PHPWord();
$sectionStyle = array('orientation' => $this->_orientation, 'marginLeft' => 900, 'marginRight' => 900, 'marginTop' => 900, 'marginBottom' => 900);
$this->_mainSection = $this->_word->createSection($sectionStyle);
}
示例8: PHPWord
<?php
require_once '../PHPWord.php';
// New Word Document
$PHPWord = new PHPWord();
// New portrait section
$section = $PHPWord->createSection(array('borderColor' => '00FF00', 'borderSize' => 12));
$section->addText('I am placed on a default section.');
// New landscape section
$section = $PHPWord->createSection(array('orientation' => 'landscape'));
$section->addText('I am placed on a landscape section. Every page starting from this section will be landscape style.');
$section->addPageBreak();
$section->addPageBreak();
// New portrait section
$section = $PHPWord->createSection(array('marginLeft' => 600, 'marginRight' => 600, 'marginTop' => 600, 'marginBottom' => 600));
$section->addText('This section uses other margins.');
// Save File
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007');
$objWriter->save('Section.docx');
示例9: repStrPHPword
/**
* @Title: repStrPHPword
* @Description: todo(模板标签文件和数据进行替换,然后到处word)
* @param 模板标签文件地址 $docfile
* @param 生成的最新文件目录 $causedir
* @param 导出的数据源数组 $bookNamearr
* @param 生成的最新文件名 $fileName
* @param 导出的文件类型,默认为word $type
* @author 王昭侠
* @date 2015-6-29 下午4:54:45
* @throws
*/
public function repStrPHPword($docfile, $causedir, $bookNamearr, $fileName, $type = "word", $export = 'word')
{
set_time_limit(0);
//验证模板标签文件是否存在
if (!file_exists($docfile)) {
$this->error("模板文件不存在,请检查");
}
//验证最新文件目录是否存在
if (!file_exists($causedir)) {
//不存在则生成最新文件目录
$this->createFolders($causedir);
//判断目标文件夹是否存在
}
import('@.ORG.PHPWord', '', $ext = '.php');
$PHPWord = new PHPWord();
$filepath = pathinfo($docfile);
$filenameGBK = $causedir . '/' . $fileName . '.' . $filepath['extension'];
$filenameUTF8 = iconv("UTF-8", "GBK", $filenameGBK);
$document = $PHPWord->loadTemplate($docfile);
$document->clearAllBiaoji();
foreach ($bookNamearr as $k => $v) {
if ($v["is_datatable"]) {
$data = array();
$data["showname"] = $v["showname"];
$data["value"] = $v["value"];
$data["showtype"] = $v["showtype"] !== NULL ? $v["showtype"] : 0;
$data["showtitle"] = $v["showtitle"] !== NULL ? $v["showtitle"] : 0;
$data["zihao"] = $v["zihao"];
$data["hangjianju"] = $v["hangjianju"];
$data["ziti"] = $v["ziti"];
if (isset($v["colORrow"])) {
$data["colORrow"] = $v["colORrow"];
}
//title_none 如果等于1表示去掉hearder头部
if (is_array($v["value"]) && !isset($v["colORrow"]) && $v['title_none'] != 1) {
foreach ($v["value"] as $kk => $vv) {
$data["titleArr"][] = empty($vv["showname"]) ? "" : $vv["showname"];
$data["fieldwidth"][] = $v["fieldwidth"][$vv["name"]];
}
}
$document->setValue($v["name"], $data);
} else {
$document->setValue($v["name"], $v);
}
}
if (!empty($_SESSION["htmltodocx_img"])) {
$content = $document->getStr();
$document->clearTemplateTag();
$document->save($filenameUTF8);
// New portrait section
$section = $PHPWord->createSection();
// Add image elements
foreach ($_SESSION["htmltodocx_img"] as $v => $k) {
$section->addImage($k["src"], $k["style"]);
$section->addTextBreak(1);
}
// Save File
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007');
$imgurl = UPLOAD_SampleWord . 'Image.docx';
$objWriter->save($imgurl);
unset($_SESSION["htmltodocx_img"]);
$documentImg = $PHPWord->loadTemplate($imgurl);
$documentImg->setStr($content);
$documentImg->save($filenameUTF8);
unlink($imgurl);
} else {
$document->clearTemplateTag();
$document->save($filenameUTF8);
}
if ($export == 'swf') {
//生成PDF
$HttpSoctetIOAction = A('Http');
$filenamePDFUTF8 = $HttpSoctetIOAction->createPDF($causedir, $filenameUTF8);
$swfurl = str_replace("pdf", "swf", $filenamePDFUTF8);
$swfurl = preg_replace("/^([\\s\\S]+)\\/Public\\//", "", $swfurl);
if ($type == "pdf") {
$filenameUTF8 = $filenamePDFUTF8;
}
}
//导出后,就修改版本信息
$savewordmodel = M('mis_system_template_saveword');
$filenameUTF8Quan = preg_replace("/^([\\s\\S]+)\\/Public\\//", "", $filenameUTF8);
//获取参数
$id = $_REQUEST['id'];
$saveWordId = $_REQUEST['fileid'];
$modelname = $this->getActionName();
$wordMap['modelid'] = $id;
$wordMap['modelname'] = $modelname;
//.........这里部分代码省略.........
示例10: makePaper
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'));
//.........这里部分代码省略.........
示例11: PHPWord
<?php
require_once 'PHPWord.php';
// New Word Document
$PHPWord = new PHPWord();
// New portrait section
$section = $PHPWord->createSection(array('orientation' => 'landscape', 'marginLeft' => 600, 'marginRight' => 600, 'marginTop' => 200, 'marginBottom' => 200));
// Define table style arrays
$styleTable = array('borderSize' => 1, 'borderColor' => 'black', 'cellMargin' => 5);
$styleFirstRow = array('borderBottomSize' => 5, 'borderBottomColor' => '0000FF', 'bgColor' => 'lavender');
// Define cell style arrays
$styleCell = array('valign' => 'center');
$styleCellBTLR = array('valign' => 'right', 'textDirection' => PHPWord_Style_Cell::TEXT_DIR_BTLR);
// Define font style for first row
$fontStyle = array('bold' => false, 'align' => 'right', 'size' => 7);
// Add table style
$PHPWord->addTableStyle('myOwnTableStyle', $styleTable, $styleFirstRow);
$section->addText('LAPORAN KWITANSI', 'rStyle', 'pStyle');
$section->addText(' ' . $periode . '', array('name' => 'Arial'), 'pStyle');
// Add table
$table = $section->addTable('myOwnTableStyle');
// Add row
$table->addRow(900);
// Add cells
$table->addCell(300, $styleCell)->addText('No', array('align' => 'center'));
$table->addCell(1900, $styleCell)->addText('No KW', $fontStyle);
$table->addCell(1600, $styleCell)->addText('Tgl KW', $fontStyle);
$table->addCell(1600, $styleCell)->addText('No.Kontrak', $fontStyle);
$table->addCell(2000, $styleCell)->addText('Asuransi', $fontStyle);
$table->addCell(2000, $styleCell)->addText('Tertanggung', $fontStyle);
$table->addCell(2000, $styleCell)->addText('Surveyor', $fontStyle);
示例12: PHPWord
<?php
require_once '../PHPWord.php';
// New Word Document
$PHPWord = new PHPWord();
// New portrait section
$section = $PHPWord->createSection();
// Add text elements
$section->addText('You can open this OLE object by double clicking on the icon:');
$section->addTextBreak(2);
// Add object
$section->addObject('_sheet.xls');
// Save File
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007');
$objWriter->save('Object.docx');
示例13: downloadApprovalNotice
/**
* @return boolean
*/
function downloadApprovalNotice()
{
$phpword_object = new PHPWord();
$section = $phpword_object->createSection();
$header = $section->createHeader();
$footer = $section->createFooter();
// Replace the keys by the values of the proposal
$this->_replaceHTMLs($this->sectionEditorSubmission);
// Convert the HTML and put it into the PHPWord object
$headerDomArray = $this->_getHtmlDomArray($this->header);
$headerDomArray = $headerDomArray[0];
$bodyDomArray = $this->_getHtmlDomArray($this->body);
$bodyDomArray = $bodyDomArray[0];
$footerDomArray = $this->_getHtmlDomArray($this->footer);
$footerDomArray = $footerDomArray[0];
htmltodocx_insert_html($header, $headerDomArray->nodes, $this->_getSettings('header'));
htmltodocx_insert_html($section, $bodyDomArray->nodes, $this->_getSettings());
htmltodocx_insert_html($footer, $footerDomArray->nodes, $this->_getSettings('footer'));
// Always include the page number in the footer
$footer->addPreserveText(Locale::translate('submission.approvalNotice.pageNumberOfTotalPages.page') . ' {PAGE} ' . Locale::translate('submission.approvalNotice.pageNumberOfTotalPages.of') . ' {NUMPAGES}', null, array('size' => 6, 'align' => 'center'));
// Save File
$h2d_file_uri = tempnam('', 'htd');
$objWriter = PHPWord_IOFactory::createWriter($phpword_object, 'Word2007');
$objWriter->save($h2d_file_uri);
// Download the file:
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=' . $this->fileName . '.docx');
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($h2d_file_uri));
ob_clean();
flush();
$status = readfile($h2d_file_uri);
unlink($h2d_file_uri);
return true;
}
示例14: generatedocx
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);
//.........这里部分代码省略.........
示例15: generate
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
//.........这里部分代码省略.........