本文整理汇总了PHP中PhpOffice\PhpWord\PhpWord::setDefaultFontName方法的典型用法代码示例。如果您正苦于以下问题:PHP PhpWord::setDefaultFontName方法的具体用法?PHP PhpWord::setDefaultFontName怎么用?PHP PhpWord::setDefaultFontName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PhpOffice\PhpWord\PhpWord
的用法示例。
在下文中一共展示了PhpWord::setDefaultFontName方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testSetGetDefaultFontName
/**
* Test set/get default font name
*/
public function testSetGetDefaultFontName()
{
$phpWord = new PhpWord();
$fontName = 'Times New Roman';
$this->assertEquals(PhpWord::DEFAULT_FONT_NAME, $phpWord->getDefaultFontName());
$phpWord->setDefaultFontName($fontName);
$this->assertEquals($fontName, $phpWord->getDefaultFontName());
}
示例2: testWriteContent
/**
* Test write content
*/
public function testWriteContent()
{
$imageSrc = __DIR__ . "/../../../_files/images/PhpWord.png";
$objectSrc = __DIR__ . "/../../../_files/documents/sheet.xls";
$expected = 'Expected';
$phpWord = new PhpWord();
$docProps = $phpWord->getDocumentProperties();
$docProps->setCustomProperty('Company', 'PHPWord');
$phpWord->setDefaultFontName('Verdana');
$phpWord->addFontStyle('Font', array('size' => 11));
$phpWord->addParagraphStyle('Paragraph', array('align' => 'center'));
$phpWord->addTableStyle('tblStyle', array('width' => 100));
$section = $phpWord->addSection(array('colsNum' => 2));
$section->addText($expected);
$section->addText('Test font style', 'Font');
$section->addText('Test paragraph style', null, 'Paragraph');
$section->addLink('http://test.com', 'Test link');
$section->addTitle('Test title', 1);
$section->addTextBreak();
$section->addPageBreak();
$section->addListItem('Test list item');
$section->addImage($imageSrc, array('width' => 50));
$section->addObject($objectSrc);
$section->addTOC();
$textrun = $section->addTextRun();
$textrun->addText('Test text run');
$table = $section->addTable(array('width' => 50));
$cell = $table->addRow()->addCell();
$cell = $table->addRow()->addCell();
$cell->addText('Test');
$cell->addLink('http://test.com', 'Test link');
$cell->addTextBreak();
$cell->addListItem('Test list item');
$cell->addImage($imageSrc);
$cell->addObject($objectSrc);
$textrun = $cell->addTextRun();
$textrun->addText('Test text run');
$footer = $section->addFooter();
$footer->addPreserveText('{PAGE}');
$table = $section->addTable('tblStyle')->addRow()->addCell();
$doc = TestHelperDOCX::getDocument($phpWord, 'ODText');
$element = "/office:document-content/office:body/office:text/text:section/text:p";
$this->assertEquals($expected, $doc->getElement($element, 'content.xml')->nodeValue);
}
示例3: testWriteContent
/**
* Test write content
*/
public function testWriteContent()
{
$imageSrc = __DIR__ . '/../../../_files/images/PhpWord.png';
$objectSrc = __DIR__ . '/../../../_files/documents/sheet.xls';
$expected = 'Expected';
$phpWord = new PhpWord();
$docProps = $phpWord->getDocInfo();
$docProps->setCustomProperty('Company', 'PHPWord');
$phpWord->setDefaultFontName('Verdana');
$phpWord->addFontStyle('Font', array('size' => 11));
$phpWord->addParagraphStyle('Paragraph', array('alignment' => Jc::CENTER));
$phpWord->addTableStyle('tblStyle', array('width' => 100));
$section = $phpWord->addSection(array('colsNum' => 2));
$section->addText(htmlspecialchars($expected, ENT_COMPAT, 'UTF-8'));
$section->addText(htmlspecialchars('Test font style', ENT_COMPAT, 'UTF-8'), 'Font');
$section->addText(htmlspecialchars('Test paragraph style', ENT_COMPAT, 'UTF-8'), null, 'Paragraph');
$section->addLink('https://github.com/PHPOffice/PHPWord', htmlspecialchars('PHPWord on GitHub', ENT_COMPAT, 'UTF-8'));
$section->addTitle(htmlspecialchars('Test title', ENT_COMPAT, 'UTF-8'), 1);
$section->addTextBreak();
$section->addPageBreak();
$section->addListItem(htmlspecialchars('Test list item', ENT_COMPAT, 'UTF-8'));
$section->addImage($imageSrc, array('width' => 50));
$section->addObject($objectSrc);
$section->addTOC();
$textrun = $section->addTextRun();
$textrun->addText(htmlspecialchars('Test text run', ENT_COMPAT, 'UTF-8'));
$table = $section->addTable(array('width' => 50));
$cell = $table->addRow()->addCell();
$cell = $table->addRow()->addCell();
$cell->addText(htmlspecialchars('Test', ENT_COMPAT, 'UTF-8'));
$cell->addLink('https://github.com/PHPOffice/PHPWord', htmlspecialchars('PHPWord on GitHub', ENT_COMPAT, 'UTF-8'));
$cell->addTextBreak();
$cell->addListItem(htmlspecialchars('Test list item', ENT_COMPAT, 'UTF-8'));
$cell->addImage($imageSrc);
$cell->addObject($objectSrc);
$textrun = $cell->addTextRun();
$textrun->addText(htmlspecialchars('Test text run', ENT_COMPAT, 'UTF-8'));
$footer = $section->addFooter();
$footer->addPreserveText(htmlspecialchars('{PAGE}', ENT_COMPAT, 'UTF-8'));
$table = $section->addTable('tblStyle')->addRow()->addCell();
$doc = TestHelperDOCX::getDocument($phpWord, 'ODText');
$element = '/office:document-content/office:body/office:text/text:section/text:p';
$this->assertEquals($expected, $doc->getElement($element, 'content.xml')->nodeValue);
}
示例4: export
public function export($path)
{
$phpWord = new PhpWord();
$phpWord->setDefaultFontName('Times New Roman');
$phpWord->setDefaultFontSize(12);
$phpWord->addTitleStyle(1, ['size' => 26, 'bold' => true], []);
$phpWord->addTitleStyle(2, ['size' => 22, 'bold' => true], []);
$phpWord->addTitleStyle(3, ['size' => 18, 'bold' => true], []);
$phpWord->addTitleStyle(4, ['size' => 16, 'bold' => true], []);
$phpWord->addFontStyle('f_timeAndPlace', ['size' => 16, 'bold' => false]);
$phpWord->addFontStyle('f_bold', ['bold' => true]);
$phpWord->addFontStyle('f_italic', ['italic' => true]);
$phpWord->addFontStyle('f_label', []);
$phpWord->addFontStyle('f_chairName', []);
$phpWord->addFontStyle('f_chairOrganisation', []);
$phpWord->addFontStyle('f_presentationAuthor', ['bold' => true]);
$phpWord->addFontStyle('f_presentationOrganisation', []);
$phpWord->addFontStyle('f_presentationName', ['italic' => true]);
$phpWord->addFontStyle('f_contributionPaperLabel', []);
$phpWord->addParagraphStyle('p_contributionPaperLabel', ['lineHeight' => 1]);
$phpWord->addParagraphStyle('p_presentation', ['lineHeight' => 1]);
$phpWord->addParagraphStyle('p_presentationContributionPaper', ['lineHeight' => 1, 'basedOn' => 'presentation']);
$phpWord->addParagraphStyle('p_chairs', []);
$phpWord->addParagraphStyle('p_timeAndPlace', []);
$section = $phpWord->addSection();
$section->addTitle($this->text('Research Network / Research Stream Sessions'));
foreach ($this->getTypes() as $type) {
if (!$this->isExportType($type)) {
continue;
}
$section->addTitle($this->text(sprintf('%s - %s', $type, static::$typeNames[$type])), 2);
foreach ($this->getSessions($type) as $session) {
$start = new \DateTime($session['start']);
$end = new \DateTime($session['end']);
$timeAndPlace = sprintf('%s - %s / %s / %s', $start->format('H:i'), $end->format('H:i'), $start->format('jS l'), $session['room']);
$section->addText($timeAndPlace, 'f_timeAndPlace', 'p_timeAndPlace');
$section->addTitle($this->text(sprintf('%s / %s', $session['short'], $session['title'])), 3);
$chairs = $this->getChairs($session);
if ($chairs) {
$textRun = $section->addTextRun('p_chairs');
$text = count($chairs) == 1 ? 'Chair: ' : 'Chairs: ';
$textRun->addText($this->text($text), 'f_label', null);
foreach ($chairs as $chair) {
$textRun->addText($this->text(sprintf('%s ', $chair['name'])), 'f_chairName', null);
$textRun->addText($this->text(sprintf('(%s)', $chair['organisation'])), 'f_chairOrganisation', null);
}
}
$presentations = $this->getPresentations($session['id']);
$contributingPapers = array_filter($presentations, function ($p) {
return $p['acceptance'] === 'Contributing Paper';
});
$otherPresentations = array_filter($presentations, function ($p) {
return $p['acceptance'] !== 'Contributing Paper';
});
foreach ($otherPresentations as $presentation) {
$textRun = $section->addTextRun('p_presentation');
foreach ($this->getAuthors($presentation) as $author) {
$textRun->addText($this->text(sprintf('%s ', $author['name'])), 'f_presentationAuthor');
$textRun->addText($this->text(sprintf('(%s)', $author['organisation'])), 'f_presentationOrganisation');
$textRun->addText(', ');
}
$textRun->addText($this->text($presentation['title']), 'f_presentationName');
}
if ($contributingPapers) {
$section->addText('Contributed papers', 'f_contributionPaperLabel', 'p_contributionPaperLabel');
foreach ($contributingPapers as $presentation) {
$textRun = $section->addTextRun('p_presentationContributionPaper');
foreach ($this->getAuthors($presentation) as $author) {
$textRun->addText($this->text(sprintf('%s ', $author['name'])), 'f_presentationAuthor');
$textRun->addText($this->text(sprintf('(%s)', $author['organisation'])), 'f_presentationOrganisation');
$textRun->addText(', ');
}
$textRun->addText($this->text($presentation['title']), 'f_presentationName');
}
}
}
$section->addPageBreak();
}
$phpWord->save($path);
}