本文整理汇总了PHP中PhpOffice\PhpWord\PhpWord::addSection方法的典型用法代码示例。如果您正苦于以下问题:PHP PhpWord::addSection方法的具体用法?PHP PhpWord::addSection怎么用?PHP PhpWord::addSection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PhpOffice\PhpWord\PhpWord
的用法示例。
在下文中一共展示了PhpWord::addSection方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: generateDOC
public function generateDOC($html)
{
$objPHPWord = new PhpWord();
// Create new PHPWord object
$section = $objPHPWord->addSection();
Html::addHtml($section, $html, true);
$objWriter = IOFactory::createWriter($objPHPWord, 'Word2007');
ob_start();
$objWriter->save('php://output');
$contents = ob_get_clean();
return $contents;
}
示例2: createDocx
/**
* Create word file using phpWord library
*
* @param array $text
* @param $file
* @return string
* @throws \PhpOffice\PhpWord\Exception\Exception
*/
public function createDocx(array $text, $file)
{
$file_path = public_path($file);
$phpWord = new PhpWord();
foreach ($text as $page) {
$section = $phpWord->addSection();
$page = $this->escape($page);
Html::addHtml($section, $page);
}
$objWriter = IOFactory::createWriter($phpWord, 'Word2007');
$objWriter->save($file_path);
return $file_path;
}
示例3: read
/**
* Read document.xml
*
* @param \PhpOffice\PhpWord\PhpWord $phpWord
*/
public function read(PhpWord &$phpWord)
{
$xmlReader = new XMLReader();
$xmlReader->getDomFromZip($this->docFile, $this->xmlFile);
$nodes = $xmlReader->getElements('w:body/*');
if ($nodes->length > 0) {
$section = $phpWord->addSection();
foreach ($nodes as $node) {
switch ($node->nodeName) {
case 'w:p':
// Paragraph
// Page break
// @todo <w:lastRenderedPageBreak>
if ($xmlReader->getAttribute('w:type', $node, 'w:r/w:br') == 'page') {
$section->addPageBreak();
// PageBreak
}
// Paragraph
$this->readParagraph($xmlReader, $node, $section, 'document');
// Section properties
if ($xmlReader->elementExists('w:pPr/w:sectPr', $node)) {
$settingsNode = $xmlReader->getElement('w:pPr/w:sectPr', $node);
if (!is_null($settingsNode)) {
$settings = $this->readSectionStyle($xmlReader, $settingsNode);
$section->setSettings($settings);
if (!is_null($settings)) {
$this->readHeaderFooter($settings, $section);
}
}
$section = $phpWord->addSection();
}
break;
case 'w:tbl':
// Table
$this->readTable($xmlReader, $node, $section, 'document');
break;
case 'w:sectPr':
// Last section
$settings = $this->readSectionStyle($xmlReader, $node);
$section->setSettings($settings);
if (!is_null($settings)) {
$this->readHeaderFooter($settings, $section);
}
break;
}
}
}
}
示例4: read
/**
* Read content.xml
*
* @param \PhpOffice\PhpWord\PhpWord $phpWord
*/
public function read(PhpWord &$phpWord)
{
$xmlReader = new XMLReader();
$xmlReader->getDomFromZip($this->docFile, $this->xmlFile);
$nodes = $xmlReader->getElements('office:body/office:text/*');
if ($nodes->length > 0) {
$section = $phpWord->addSection();
foreach ($nodes as $node) {
// $styleName = $xmlReader->getAttribute('text:style-name', $node);
switch ($node->nodeName) {
case 'text:h':
// Heading
$depth = $xmlReader->getAttribute('text:outline-level', $node);
$section->addTitle($node->nodeValue, $depth);
break;
case 'text:p':
// Paragraph
$section->addText($node->nodeValue);
break;
case 'text:list':
// List
$listItems = $xmlReader->getElements('text:list-item/text:p', $node);
foreach ($listItems as $listItem) {
// $listStyleName = $xmlReader->getAttribute('text:style-name', $listItem);
$section->addListItem($listItem->nodeValue);
}
break;
}
}
}
}
示例5: testSavePhpOutput
/**
* Save php output
*
* @todo Haven't got any method to test this
*/
public function testSavePhpOutput()
{
$phpWord = new PhpWord();
$section = $phpWord->addSection();
$section->addText('Test');
$writer = new ODText($phpWord);
$writer->save('php://output');
}
示例6: load
/**
* Loads PhpWord from file
*
* @param string $docFile
*
* @throws \Exception
*
* @return \PhpOffice\PhpWord\PhpWord
*/
public function load($docFile)
{
$phpWord = new PhpWord();
if ($this->canRead($docFile)) {
$section = $phpWord->addSection();
HTMLParser::addHtml($section, file_get_contents($docFile), true);
} else {
throw new \Exception("Cannot read {$docFile}.");
}
return $phpWord;
}
示例7: getDocFileStr
/**
* 生成简历文件字符串
* @param $sp_id 快照主键
* @param string $type 类型 doc/doc_no_contact(隐藏了联系方式)
*/
public function getDocFileStr($id, $type = 'doc_no_contact')
{
$sp_model = new ResumeSnapshot();
$sp_info = $sp_model->getResumeSnapshotInfoById($id);
//根据简历快照生成word
$phpWord = new PhpWord();
// New portrait section
$section = $phpWord->addSection();
// Add header for all other pages //todo logo图片需传到线上
$subsequent = $section->addHeader();
$subsequent->addText(htmlspecialchars('51CTO高招-中高端IT人才的招聘平台'));
$subsequent->addImage('http://job.51cto.com/pic/logo_s.jpg', array('width' => 80, 'height' => 80, 'align' => 'right'));
//// $section = $phpWord->addSection();
// $html = '<h1>Adding element via HTML</h1>';
// $html .= '<p>Some well formed HTML snippet needs to be used</p>';
// $html .= '<p>With for example <strong>some<sup>1</sup> <em>inline</em> formatting</strong><sub>1</sub></p>';
// $html .= '<p>Unordered (bulleted) list:</p>';
// $html .= '<ul><li>Item 1</li><li>Item 2</li><ul><li>Item 2.1</li><li>Item 2.1</li></ul></ul>';
// $html .= '<p>Ordered (numbered) list:</p>';
// $html .= '<ol><li>Item 1</li><li>Item 2</li></ol>';
//
// \PhpOffice\PhpWord\Shared\Html::addHtml($section, $html);
$section = $phpWord->addSection();
$header = array('size' => 16, 'bold' => true);
//1.Use EastAisa FontStyle
$section->addText(htmlspecialchars('邵燕'), array('name' => '微软雅黑', 'size' => '二号', 'color' => '1B2232'));
$section->addText(htmlspecialchars('邵燕'), array('name' => '微软雅黑', 'size' => '二号', 'color' => '1B2232'));
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
$rand = time() . rand(10000, 99999);
$file = WEB_ROOT . "/runtime/{$rand}.docx";
//临时文件
$file = WEB_ROOT . "/runtime/test.docx";
//临时文件
$objWriter->save($file, 'Word2007', true);
// $file_str = file_get_contents($file);
// unlink($file);//删除文件
//
// return $file_str;
}
示例8: testConstruct
/**
* Test construct
*/
public function testConstruct()
{
$file = __DIR__ . '/../../_files/mpdf.pdf';
$phpWord = new PhpWord();
$section = $phpWord->addSection();
$section->addText(htmlspecialchars('Test 1', ENT_COMPAT, 'UTF-8'));
$rendererName = Settings::PDF_RENDERER_MPDF;
$rendererLibraryPath = realpath(PHPWORD_TESTS_BASE_DIR . '/../vendor/mpdf/mpdf');
Settings::setPdfRenderer($rendererName, $rendererLibraryPath);
$writer = new PDF($phpWord);
$writer->save($file);
$this->assertTrue(file_exists($file));
unlink($file);
}
示例9: testConstruct
/**
* Test construct
*/
public function testConstruct()
{
$file = __DIR__ . "/../../_files/tcpdf.pdf";
$phpWord = new PhpWord();
$section = $phpWord->addSection();
$section->addText('Test 1');
$rendererName = Settings::PDF_RENDERER_TCPDF;
$rendererLibraryPath = realpath(PHPWORD_TESTS_BASE_DIR . '/../vendor/tecnick.com/tcpdf');
Settings::setPdfRenderer($rendererName, $rendererLibraryPath);
$writer = new PDF($phpWord);
$writer->save($file);
$this->assertTrue(file_exists($file));
unlink($file);
}
示例10: testConstruct
/**
* Test construct
*/
public function testConstruct()
{
define('DOMPDF_ENABLE_AUTOLOAD', false);
$file = __DIR__ . "/../../_files/temp.pdf";
$phpWord = new PhpWord();
$section = $phpWord->addSection();
$section->addText('Test 1');
$rendererName = Settings::PDF_RENDERER_DOMPDF;
$rendererLibraryPath = realpath(PHPWORD_TESTS_BASE_DIR . '/../vendor/dompdf/dompdf');
Settings::setPdfRenderer($rendererName, $rendererLibraryPath);
$writer = new PDF($phpWord);
$writer->save($file);
$this->assertTrue(file_exists($file));
unlink($file);
}
示例11: testWriteFootnotes
/**
* Write footnotes
*/
public function testWriteFootnotes()
{
$phpWord = new PhpWord();
$phpWord->addParagraphStyle('pStyle', array('align' => 'left'));
$section = $phpWord->addSection();
$section->addText(htmlspecialchars('Text', ENT_COMPAT, 'UTF-8'));
$footnote1 = $section->addFootnote('pStyle');
$footnote1->addText(htmlspecialchars('Footnote', ENT_COMPAT, 'UTF-8'));
$footnote1->addTextBreak();
$footnote1->addLink('https://github.com/PHPOffice/PHPWord');
$footnote2 = $section->addEndnote(array('align' => 'left'));
$footnote2->addText(htmlspecialchars('Endnote', ENT_COMPAT, 'UTF-8'));
$doc = TestHelperDOCX::getDocument($phpWord);
$this->assertTrue($doc->elementExists('/w:document/w:body/w:p/w:r/w:footnoteReference'));
$this->assertTrue($doc->elementExists('/w:document/w:body/w:p/w:r/w:endnoteReference'));
}
示例12: testWriteFootnotes
/**
* Write footnotes
*/
public function testWriteFootnotes()
{
$phpWord = new PhpWord();
$phpWord->addParagraphStyle('pStyle', array('align' => 'left'));
$section = $phpWord->addSection();
$section->addText('Text');
$footnote1 = $section->addFootnote('pStyle');
$footnote1->addText('Footnote');
$footnote1->addTextBreak();
$footnote1->addLink('http://google.com');
$footnote2 = $section->addEndnote(array('align' => 'left'));
$footnote2->addText('Endnote');
$doc = TestHelperDOCX::getDocument($phpWord);
$this->assertTrue($doc->elementExists("/w:document/w:body/w:p/w:r/w:footnoteReference"));
$this->assertTrue($doc->elementExists("/w:document/w:body/w:p/w:r/w:endnoteReference"));
}
示例13: readWPNode
/**
* Read w:p node
*
* @param \PhpOffice\PhpWord\Shared\XMLReader $xmlReader
* @param \DOMElement $node
* @param \PhpOffice\PhpWord\Element\Section $section
*
* @todo <w:lastRenderedPageBreak>
*/
private function readWPNode(XMLReader $xmlReader, \DOMElement $node, Section &$section)
{
// Page break
if ($xmlReader->getAttribute('w:type', $node, 'w:r/w:br') == 'page') {
$section->addPageBreak();
// PageBreak
}
// Paragraph
$this->readParagraph($xmlReader, $node, $section);
// Section properties
if ($xmlReader->elementExists('w:pPr/w:sectPr', $node)) {
$sectPrNode = $xmlReader->getElement('w:pPr/w:sectPr', $node);
if ($sectPrNode !== null) {
$this->readWSectPrNode($xmlReader, $sectPrNode, $section);
}
$section = $this->phpWord->addSection();
}
}
示例14: 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);
}
示例15: 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);
}