2014-03-22 10:06:08 +04:00
|
|
|
<?php
|
|
|
|
|
/**
|
2014-05-05 13:06:53 +04:00
|
|
|
* This file is part of PHPWord - A pure PHP library for reading and writing
|
|
|
|
|
* word processing documents.
|
|
|
|
|
*
|
|
|
|
|
* PHPWord is free software distributed under the terms of the GNU Lesser
|
|
|
|
|
* General Public License version 3 as published by the Free Software Foundation.
|
|
|
|
|
*
|
|
|
|
|
* For the full copyright and license information, please read the LICENSE
|
|
|
|
|
* file that was distributed with this source code. For the full list of
|
|
|
|
|
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
|
2014-03-22 10:06:08 +04:00
|
|
|
*
|
2014-03-27 23:55:06 +07:00
|
|
|
* @link https://github.com/PHPOffice/PHPWord
|
2014-05-05 12:38:31 +04:00
|
|
|
* @copyright 2010-2014 PHPWord contributors
|
2014-05-04 21:03:28 +04:00
|
|
|
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
2014-03-22 10:06:08 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
namespace PhpOffice\PhpWord;
|
|
|
|
|
|
2014-05-05 00:26:02 +07:00
|
|
|
use PhpOffice\PhpWord\Collection\Endnotes;
|
|
|
|
|
use PhpOffice\PhpWord\Collection\Footnotes;
|
|
|
|
|
use PhpOffice\PhpWord\Collection\Titles;
|
2014-04-08 00:23:49 +07:00
|
|
|
use PhpOffice\PhpWord\Element\Section;
|
2014-05-04 21:03:28 +04:00
|
|
|
use PhpOffice\PhpWord\Exception\Exception;
|
2014-03-22 10:06:08 +04:00
|
|
|
|
2014-03-24 00:26:10 +07:00
|
|
|
/**
|
2014-03-26 16:33:20 +07:00
|
|
|
* PHPWord main class
|
2014-03-24 00:26:10 +07:00
|
|
|
*/
|
2014-03-22 10:06:08 +04:00
|
|
|
class PhpWord
|
|
|
|
|
{
|
|
|
|
|
/**
|
2014-05-15 22:13:03 +07:00
|
|
|
* Default font settings
|
2014-03-22 10:06:08 +04:00
|
|
|
*
|
2014-05-15 22:13:03 +07:00
|
|
|
* @const string|int
|
|
|
|
|
* @deprecated 0.11.0 Use Settings constants
|
2014-03-22 10:06:08 +04:00
|
|
|
*/
|
2014-05-15 22:13:03 +07:00
|
|
|
const DEFAULT_FONT_NAME = Settings::DEFAULT_FONT_NAME;
|
|
|
|
|
const DEFAULT_FONT_SIZE = Settings::DEFAULT_FONT_SIZE;
|
|
|
|
|
const DEFAULT_FONT_COLOR = Settings::DEFAULT_FONT_COLOR;
|
|
|
|
|
const DEFAULT_FONT_CONTENT_TYPE = Settings::DEFAULT_FONT_CONTENT_TYPE;
|
2014-03-22 10:06:08 +04:00
|
|
|
|
|
|
|
|
/**
|
2014-03-24 00:26:10 +07:00
|
|
|
* Document properties object
|
|
|
|
|
*
|
2014-04-02 11:02:56 +07:00
|
|
|
* @var DocumentProperties
|
2014-03-22 10:06:08 +04:00
|
|
|
*/
|
2014-04-03 10:13:13 +07:00
|
|
|
private $documentProperties;
|
2014-03-22 10:06:08 +04:00
|
|
|
|
2014-05-04 00:57:44 +07:00
|
|
|
/**
|
|
|
|
|
* Collection of sections
|
|
|
|
|
*
|
|
|
|
|
* @var \PhpOffice\PhpWord\Element\Section[]
|
|
|
|
|
*/
|
|
|
|
|
private $sections = array();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Collection of titles
|
|
|
|
|
*
|
|
|
|
|
* @var \PhpOffice\PhpWord\Collection\Titles
|
|
|
|
|
*/
|
|
|
|
|
private $titles;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Collection of footnotes
|
|
|
|
|
*
|
|
|
|
|
* @var \PhpOffice\PhpWord\Collection\Footnotes
|
|
|
|
|
*/
|
|
|
|
|
private $footnotes;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Collection of endnotes
|
|
|
|
|
*
|
|
|
|
|
* @var \PhpOffice\PhpWord\Collection\Endnotes
|
|
|
|
|
*/
|
|
|
|
|
private $endnotes;
|
|
|
|
|
|
2014-03-24 00:26:10 +07:00
|
|
|
/**
|
|
|
|
|
* Create new
|
|
|
|
|
*/
|
2014-03-22 10:06:08 +04:00
|
|
|
public function __construct()
|
|
|
|
|
{
|
2014-04-03 10:13:13 +07:00
|
|
|
$this->documentProperties = new DocumentProperties();
|
2014-05-04 00:57:44 +07:00
|
|
|
$this->titles = new Titles();
|
|
|
|
|
$this->footnotes = new Footnotes();
|
|
|
|
|
$this->endnotes = new Endnotes();
|
2014-03-22 10:06:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2014-03-24 00:26:10 +07:00
|
|
|
* Get document properties object
|
|
|
|
|
*
|
2014-04-02 11:02:56 +07:00
|
|
|
* @return DocumentProperties
|
2014-03-22 10:06:08 +04:00
|
|
|
*/
|
|
|
|
|
public function getDocumentProperties()
|
|
|
|
|
{
|
2014-04-03 10:13:13 +07:00
|
|
|
return $this->documentProperties;
|
2014-03-22 10:06:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2014-03-24 00:26:10 +07:00
|
|
|
* Set document properties object
|
|
|
|
|
*
|
2014-04-08 16:09:31 +07:00
|
|
|
* @param DocumentProperties $documentProperties
|
|
|
|
|
* @return self
|
2014-03-22 10:06:08 +04:00
|
|
|
*/
|
|
|
|
|
public function setDocumentProperties(DocumentProperties $documentProperties)
|
|
|
|
|
{
|
2014-04-03 10:13:13 +07:00
|
|
|
$this->documentProperties = $documentProperties;
|
2014-03-22 10:06:08 +04:00
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-04 00:57:44 +07:00
|
|
|
/**
|
|
|
|
|
* Get all sections
|
|
|
|
|
*
|
|
|
|
|
* @return \PhpOffice\PhpWord\Element\Section[]
|
|
|
|
|
*/
|
|
|
|
|
public function getSections()
|
|
|
|
|
{
|
|
|
|
|
return $this->sections;
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-22 10:06:08 +04:00
|
|
|
/**
|
2014-03-24 00:26:10 +07:00
|
|
|
* Create new section
|
|
|
|
|
*
|
2014-06-08 16:44:46 +07:00
|
|
|
* @param array $style
|
2014-04-16 17:22:30 +04:00
|
|
|
* @return \PhpOffice\PhpWord\Element\Section
|
2014-03-22 10:06:08 +04:00
|
|
|
*/
|
2014-06-08 16:44:46 +07:00
|
|
|
public function addSection($style = null)
|
2014-03-22 10:06:08 +04:00
|
|
|
{
|
2014-06-08 16:44:46 +07:00
|
|
|
$section = new Section(count($this->sections) + 1, $style);
|
2014-05-04 00:57:44 +07:00
|
|
|
$section->setPhpWord($this);
|
2014-04-03 10:13:13 +07:00
|
|
|
$this->sections[] = $section;
|
2014-03-22 10:06:08 +04:00
|
|
|
|
|
|
|
|
return $section;
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-04 00:57:44 +07:00
|
|
|
/**
|
|
|
|
|
* Get titles
|
|
|
|
|
*
|
|
|
|
|
* @return \PhpOffice\PhpWord\Collection\Titles
|
|
|
|
|
*/
|
|
|
|
|
public function getTitles()
|
|
|
|
|
{
|
|
|
|
|
return $this->titles;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Add new title
|
|
|
|
|
*
|
|
|
|
|
* @param \PhpOffice\PhpWord\Element\Title $title
|
|
|
|
|
* @return int
|
|
|
|
|
*/
|
|
|
|
|
public function addTitle($title)
|
|
|
|
|
{
|
|
|
|
|
return $this->titles->addItem($title);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get footnotes
|
|
|
|
|
*
|
|
|
|
|
* @return \PhpOffice\PhpWord\Collection\Footnotes
|
|
|
|
|
*/
|
|
|
|
|
public function getFootnotes()
|
|
|
|
|
{
|
|
|
|
|
return $this->footnotes;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Add new footnote
|
|
|
|
|
*
|
|
|
|
|
* @param \PhpOffice\PhpWord\Element\Footnote $footnote
|
|
|
|
|
* @return int
|
|
|
|
|
*/
|
|
|
|
|
public function addFootnote($footnote)
|
|
|
|
|
{
|
|
|
|
|
return $this->footnotes->addItem($footnote);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get endnotes
|
|
|
|
|
*
|
|
|
|
|
* @return \PhpOffice\PhpWord\Collection\Endnotes
|
|
|
|
|
*/
|
|
|
|
|
public function getEndnotes()
|
|
|
|
|
{
|
|
|
|
|
return $this->endnotes;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Add new endnote
|
|
|
|
|
*
|
|
|
|
|
* @param \PhpOffice\PhpWord\Element\Endnote $endnote
|
|
|
|
|
* @return int
|
|
|
|
|
*/
|
|
|
|
|
public function addEndnote($endnote)
|
|
|
|
|
{
|
|
|
|
|
return $this->endnotes->addItem($endnote);
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-22 10:06:08 +04:00
|
|
|
/**
|
2014-03-24 00:26:10 +07:00
|
|
|
* Get default font name
|
|
|
|
|
*
|
2014-03-22 10:06:08 +04:00
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function getDefaultFontName()
|
|
|
|
|
{
|
2014-05-15 22:13:03 +07:00
|
|
|
return Settings::getDefaultFontName();
|
2014-03-22 10:06:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2014-03-24 00:26:10 +07:00
|
|
|
* Set default font name
|
|
|
|
|
*
|
2014-03-22 10:06:08 +04:00
|
|
|
* @param string $fontName
|
|
|
|
|
*/
|
|
|
|
|
public function setDefaultFontName($fontName)
|
|
|
|
|
{
|
2014-05-15 22:13:03 +07:00
|
|
|
Settings::setDefaultFontName($fontName);
|
2014-03-22 10:06:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2014-03-24 00:26:10 +07:00
|
|
|
* Get default font size
|
|
|
|
|
*
|
2014-04-03 10:13:13 +07:00
|
|
|
* @return integer
|
2014-03-22 10:06:08 +04:00
|
|
|
*/
|
|
|
|
|
public function getDefaultFontSize()
|
|
|
|
|
{
|
2014-05-15 22:13:03 +07:00
|
|
|
return Settings::getDefaultFontSize();
|
2014-03-22 10:06:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2014-03-24 00:26:10 +07:00
|
|
|
* Set default font size
|
|
|
|
|
*
|
2014-03-22 10:06:08 +04:00
|
|
|
* @param int $fontSize
|
|
|
|
|
*/
|
|
|
|
|
public function setDefaultFontSize($fontSize)
|
|
|
|
|
{
|
2014-05-15 22:13:03 +07:00
|
|
|
Settings::setDefaultFontSize($fontSize);
|
2014-03-22 10:06:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set default paragraph style definition to styles.xml
|
|
|
|
|
*
|
|
|
|
|
* @param array $styles Paragraph style definition
|
2014-05-18 11:13:38 +07:00
|
|
|
* @return \PhpOffice\PhpWord\Style\Paragraph
|
2014-03-22 10:06:08 +04:00
|
|
|
*/
|
|
|
|
|
public function setDefaultParagraphStyle($styles)
|
|
|
|
|
{
|
2014-05-18 11:13:38 +07:00
|
|
|
return Style::setDefaultParagraphStyle($styles);
|
2014-03-22 10:06:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Adds a paragraph style definition to styles.xml
|
|
|
|
|
*
|
2014-04-03 10:13:13 +07:00
|
|
|
* @param string $styleName
|
|
|
|
|
* @param array $styles
|
2014-05-18 11:13:38 +07:00
|
|
|
* @return \PhpOffice\PhpWord\Style\Paragraph
|
2014-03-22 10:06:08 +04:00
|
|
|
*/
|
|
|
|
|
public function addParagraphStyle($styleName, $styles)
|
|
|
|
|
{
|
2014-05-18 11:13:38 +07:00
|
|
|
return Style::addParagraphStyle($styleName, $styles);
|
2014-03-22 10:06:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Adds a font style definition to styles.xml
|
|
|
|
|
*
|
2014-04-03 10:13:13 +07:00
|
|
|
* @param string $styleName
|
2014-05-01 14:37:58 +07:00
|
|
|
* @param mixed $fontStyle
|
|
|
|
|
* @param mixed $paragraphStyle
|
2014-05-18 11:13:38 +07:00
|
|
|
* @return \PhpOffice\PhpWord\Style\Font
|
2014-03-22 10:06:08 +04:00
|
|
|
*/
|
2014-05-01 14:37:58 +07:00
|
|
|
public function addFontStyle($styleName, $fontStyle, $paragraphStyle = null)
|
2014-03-22 10:06:08 +04:00
|
|
|
{
|
2014-05-18 11:13:38 +07:00
|
|
|
return Style::addFontStyle($styleName, $fontStyle, $paragraphStyle);
|
2014-03-22 10:06:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Adds a table style definition to styles.xml
|
|
|
|
|
*
|
2014-03-24 00:26:10 +07:00
|
|
|
* @param string $styleName
|
|
|
|
|
* @param mixed $styleTable
|
|
|
|
|
* @param mixed $styleFirstRow
|
2014-05-18 11:13:38 +07:00
|
|
|
* @return \PhpOffice\PhpWord\Style\Table
|
2014-03-22 10:06:08 +04:00
|
|
|
*/
|
|
|
|
|
public function addTableStyle($styleName, $styleTable, $styleFirstRow = null)
|
|
|
|
|
{
|
2014-05-18 11:13:38 +07:00
|
|
|
return Style::addTableStyle($styleName, $styleTable, $styleFirstRow);
|
2014-03-22 10:06:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2014-05-18 11:13:38 +07:00
|
|
|
* Adds a numbering style
|
2014-03-22 10:06:08 +04:00
|
|
|
*
|
2014-05-18 11:13:38 +07:00
|
|
|
* @param string $styleName
|
|
|
|
|
* @param mixed $styles
|
|
|
|
|
* @return \PhpOffice\PhpWord\Style\Numbering
|
2014-03-22 10:06:08 +04:00
|
|
|
*/
|
2014-05-18 11:13:38 +07:00
|
|
|
public function addNumberingStyle($styleName, $styles)
|
2014-03-22 10:06:08 +04:00
|
|
|
{
|
2014-05-18 11:13:38 +07:00
|
|
|
return Style::addNumberingStyle($styleName, $styles);
|
2014-03-22 10:06:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Adds a hyperlink style to styles.xml
|
|
|
|
|
*
|
2014-03-24 00:26:10 +07:00
|
|
|
* @param string $styleName
|
|
|
|
|
* @param mixed $styles
|
2014-05-18 11:13:38 +07:00
|
|
|
* @return \PhpOffice\PhpWord\Style\Font
|
2014-03-22 10:06:08 +04:00
|
|
|
*/
|
|
|
|
|
public function addLinkStyle($styleName, $styles)
|
|
|
|
|
{
|
2014-05-18 11:13:38 +07:00
|
|
|
return Style::addLinkStyle($styleName, $styles);
|
2014-03-22 10:06:08 +04:00
|
|
|
}
|
|
|
|
|
|
2014-04-11 16:16:22 +07:00
|
|
|
/**
|
2014-05-18 11:13:38 +07:00
|
|
|
* Adds a heading style definition to styles.xml
|
2014-04-11 16:16:22 +07:00
|
|
|
*
|
2014-05-18 11:13:38 +07:00
|
|
|
* @param int $depth
|
|
|
|
|
* @param mixed $fontStyle
|
|
|
|
|
* @param mixed $paragraphStyle
|
|
|
|
|
* @return \PhpOffice\PhpWord\Style\Font
|
2014-04-11 16:16:22 +07:00
|
|
|
*/
|
2014-05-18 11:13:38 +07:00
|
|
|
public function addTitleStyle($depth, $fontStyle, $paragraphStyle = null)
|
2014-04-11 16:16:22 +07:00
|
|
|
{
|
2014-05-18 11:13:38 +07:00
|
|
|
return Style::addTitleStyle($depth, $fontStyle, $paragraphStyle);
|
2014-04-11 16:16:22 +07:00
|
|
|
}
|
|
|
|
|
|
2014-03-22 10:06:08 +04:00
|
|
|
/**
|
2014-03-24 00:26:10 +07:00
|
|
|
* Load template by filename
|
|
|
|
|
*
|
2014-03-22 10:06:08 +04:00
|
|
|
* @param string $filename Fully qualified filename.
|
2014-04-02 11:02:56 +07:00
|
|
|
* @return Template
|
2014-04-16 17:22:30 +04:00
|
|
|
* @throws \PhpOffice\PhpWord\Exception\Exception
|
2014-03-22 10:06:08 +04:00
|
|
|
*/
|
|
|
|
|
public function loadTemplate($filename)
|
|
|
|
|
{
|
2014-04-05 22:53:39 +07:00
|
|
|
if (file_exists($filename)) {
|
2014-03-22 10:06:08 +04:00
|
|
|
return new Template($filename);
|
|
|
|
|
} else {
|
|
|
|
|
throw new Exception("Template file {$filename} not found.");
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-04-02 11:02:56 +07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Create new section
|
|
|
|
|
*
|
2014-04-03 11:34:06 +07:00
|
|
|
* @param array $settings
|
2014-04-16 17:22:30 +04:00
|
|
|
* @return \PhpOffice\PhpWord\Element\Section
|
2014-04-11 19:04:53 +07:00
|
|
|
* @deprecated 0.10.0
|
2014-04-03 11:34:06 +07:00
|
|
|
* @codeCoverageIgnore
|
2014-04-02 11:02:56 +07:00
|
|
|
*/
|
|
|
|
|
public function createSection($settings = null)
|
|
|
|
|
{
|
|
|
|
|
return $this->addSection($settings);
|
|
|
|
|
}
|
2014-03-23 17:37:26 +07:00
|
|
|
}
|