本文整理汇总了PHP中PhpOffice\PhpWord\PhpWord::save方法的典型用法代码示例。如果您正苦于以下问题:PHP PhpWord::save方法的具体用法?PHP PhpWord::save怎么用?PHP PhpWord::save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PhpOffice\PhpWord\PhpWord
的用法示例。
在下文中一共展示了PhpWord::save方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: write
/**
* Write documents
*
* @param \PhpOffice\PhpWord\PhpWord $phpWord
* @param string $filename
* @param array $writers
*
* @return string
*/
function write($phpWord, $filename, $writers)
{
$result = '';
// Write documents
foreach ($writers as $format => $extension) {
$result .= date('H:i:s') . " Write to {$format} format";
if (null !== $extension) {
$targetFile = __DIR__ . "/results/{$filename}.{$extension}";
$phpWord->save($targetFile, $format);
} else {
$result .= ' ... NOT DONE!';
}
$result .= EOL;
}
$result .= getEndingNotes($writers);
return $result;
}
示例2: write
/**
* Write documents
*
* @param \PhpOffice\PhpWord\PhpWord $phpWord
* @param string $filename
* @param array $writers
*
* @return string
*/
function write($phpWord, $filename, $writers)
{
// $result = '';
// Write documents
foreach ($writers as $format => $extension) {
// $result .= date('H:i:s') . " Write to {$format} format";
if (null !== $extension) {
// $targetFile = __DIR__ . "/results/{$filename}.{$extension}";
$targetFile = generateRealPathDocxFileLocation() . "{$filename}.{$extension}";
$phpWord->save($targetFile, $format);
}
// else {
// $result .= ' ... NOT DONE!';
// }
// $result .= EOL;
}
// $result .= getEndingNotes($writers);
// return $result;
return '';
}
示例3: testSave
/**
* Test save
*/
public function testSave()
{
$phpWord = new PhpWord();
$section = $phpWord->addSection();
$section->addText('Hello world!');
$this->assertTrue($phpWord->save('test.docx', 'Word2007', true));
}
示例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);
}