Documentation for new ListItem feature
This commit is contained in:
parent
39a5e8c51e
commit
297eeaadf0
@ -207,10 +207,14 @@ Lists
|
|||||||
|
|
||||||
To add a list item use the function ``addListItem``.
|
To add a list item use the function ``addListItem``.
|
||||||
|
|
||||||
|
Basic usage:
|
||||||
|
|
||||||
.. code-block:: php
|
.. code-block:: php
|
||||||
|
|
||||||
$section->addListItem($text, [$depth], [$fontStyle], [$listStyle], [$paragraphStyle]);
|
$section->addListItem($text, [$depth], [$fontStyle], [$listStyle], [$paragraphStyle]);
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
|
||||||
- ``$text`` Text that appears in the document.
|
- ``$text`` Text that appears in the document.
|
||||||
- ``$depth`` Depth of list item.
|
- ``$depth`` Depth of list item.
|
||||||
- ``$fontStyle`` See "Font style" section.
|
- ``$fontStyle`` See "Font style" section.
|
||||||
@ -219,6 +223,40 @@ To add a list item use the function ``addListItem``.
|
|||||||
PHPWord\_Style\_ListItem.
|
PHPWord\_Style\_ListItem.
|
||||||
- ``$paragraphStyle`` See "Paragraph style" section.
|
- ``$paragraphStyle`` See "Paragraph style" section.
|
||||||
|
|
||||||
|
Advanced usage:
|
||||||
|
|
||||||
|
You can also create your own numbering style by changing the ``$listStyle`` parameter
|
||||||
|
with the name of your numbering style.
|
||||||
|
|
||||||
|
.. code-block:: php
|
||||||
|
|
||||||
|
$phpWord->addNumberingStyle(
|
||||||
|
'multilevel',
|
||||||
|
array('type' => 'multilevel', 'levels' => array(
|
||||||
|
array('format' => 'decimal', 'text' => '%1.', 'left' => 360, 'hanging' => 360, 'tabPos' => 360),
|
||||||
|
array('format' => 'upperLetter', 'text' => '%2.', 'left' => 720, 'hanging' => 360, 'tabPos' => 720),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$section->addListItem('List Item I', 0, null, 'multilevel');
|
||||||
|
$section->addListItem('List Item I.a', 1, null, 'multilevel');
|
||||||
|
$section->addListItem('List Item I.b', 1, null, 'multilevel');
|
||||||
|
$section->addListItem('List Item II', 0, null, 'multilevel');
|
||||||
|
|
||||||
|
Level styles:
|
||||||
|
|
||||||
|
- ``start`` Starting value
|
||||||
|
- ``format`` Numbering format bullet|decimal|upperRoman|lowerRoman|upperLetter|lowerLetter
|
||||||
|
- ``restart`` Restart numbering level symbol
|
||||||
|
- ``suffix`` Content between numbering symbol and paragraph text tab|space|nothing
|
||||||
|
- ``text`` Numbering level text e.g. %1 for nonbullet or bullet character
|
||||||
|
- ``align`` Numbering symbol align left|center|right|both
|
||||||
|
- ``left`` See paragraph style
|
||||||
|
- ``hanging`` See paragraph style
|
||||||
|
- ``tabPos`` See paragraph style
|
||||||
|
- ``font`` Font name
|
||||||
|
- ``hint`` See font style
|
||||||
|
|
||||||
Tables
|
Tables
|
||||||
------
|
------
|
||||||
|
|
||||||
|
|||||||
@ -221,9 +221,11 @@ class Word2007 extends AbstractReader implements ReaderInterface
|
|||||||
// Section properties
|
// Section properties
|
||||||
if ($xmlReader->elementExists('w:pPr/w:sectPr', $node)) {
|
if ($xmlReader->elementExists('w:pPr/w:sectPr', $node)) {
|
||||||
$settingsNode = $xmlReader->getElement('w:pPr/w:sectPr', $node);
|
$settingsNode = $xmlReader->getElement('w:pPr/w:sectPr', $node);
|
||||||
$settings = $this->readSectionStyle($xmlReader, $settingsNode);
|
if (!is_null($settingsNode)) {
|
||||||
$section->setSettings($settings);
|
$settings = $this->readSectionStyle($xmlReader, $settingsNode);
|
||||||
$this->readHeaderFooter($filename, $settings, $section);
|
$section->setSettings($settings);
|
||||||
|
$this->readHeaderFooter($filename, $settings, $section);
|
||||||
|
}
|
||||||
$section = $this->phpWord->addSection();
|
$section = $this->phpWord->addSection();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -268,7 +270,9 @@ class Word2007 extends AbstractReader implements ReaderInterface
|
|||||||
$pStyle = $this->readParagraphStyle($xmlReader, $node);
|
$pStyle = $this->readParagraphStyle($xmlReader, $node);
|
||||||
$fStyle = $this->readFontStyle($xmlReader, $node);
|
$fStyle = $this->readFontStyle($xmlReader, $node);
|
||||||
if (empty($fStyle)) {
|
if (empty($fStyle)) {
|
||||||
$this->phpWord->addParagraphStyle($name, $pStyle);
|
if (is_array($pStyle)) {
|
||||||
|
$this->phpWord->addParagraphStyle($name, $pStyle);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
$this->phpWord->addFontStyle($name, $fStyle, $pStyle);
|
$this->phpWord->addFontStyle($name, $fStyle, $pStyle);
|
||||||
}
|
}
|
||||||
@ -634,8 +638,9 @@ class Word2007 extends AbstractReader implements ReaderInterface
|
|||||||
} elseif ($rowNode->nodeName == 'w:tc') { // Cell
|
} elseif ($rowNode->nodeName == 'w:tc') { // Cell
|
||||||
$cellWidth = $xmlReader->getAttribute('w:w', $rowNode, 'w:tcPr/w:tcW');
|
$cellWidth = $xmlReader->getAttribute('w:w', $rowNode, 'w:tcPr/w:tcW');
|
||||||
$cellStyle = null;
|
$cellStyle = null;
|
||||||
if ($xmlReader->elementExists('w:tcPr', $rowNode)) {
|
$cellStyleNode = $xmlReader->getElement('w:tcPr', $rowNode);
|
||||||
$cellStyle = $this->readCellStyle($xmlReader, $xmlReader->getElement('w:tcPr', $rowNode));
|
if (!is_null($cellStyleNode)) {
|
||||||
|
$cellStyle = $this->readCellStyle($xmlReader, $cellStyleNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
$cell = $row->addCell($cellWidth, $cellStyle);
|
$cell = $row->addCell($cellWidth, $cellStyle);
|
||||||
@ -786,6 +791,9 @@ class Word2007 extends AbstractReader implements ReaderInterface
|
|||||||
if ($domNode->nodeName == 'w:hyperlink') {
|
if ($domNode->nodeName == 'w:hyperlink') {
|
||||||
$domNode = $xmlReader->getElement('w:r', $domNode);
|
$domNode = $xmlReader->getElement('w:r', $domNode);
|
||||||
}
|
}
|
||||||
|
if (is_null($domNode)) {
|
||||||
|
return $style;
|
||||||
|
}
|
||||||
if ($xmlReader->elementExists('w:rPr', $domNode)) {
|
if ($xmlReader->elementExists('w:rPr', $domNode)) {
|
||||||
if ($xmlReader->elementExists('w:rPr/w:rStyle', $domNode)) {
|
if ($xmlReader->elementExists('w:rPr/w:rStyle', $domNode)) {
|
||||||
$style = $xmlReader->getAttribute('w:val', $domNode, 'w:rPr/w:rStyle');
|
$style = $xmlReader->getAttribute('w:val', $domNode, 'w:rPr/w:rStyle');
|
||||||
|
|||||||
@ -34,7 +34,7 @@ class Style
|
|||||||
*/
|
*/
|
||||||
public static function addParagraphStyle($styleName, $styles)
|
public static function addParagraphStyle($styleName, $styles)
|
||||||
{
|
{
|
||||||
self::setStyleValues($styleName, $styles, new Paragraph());
|
self::setStyleValues($styleName, new Paragraph(), $styles);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -46,7 +46,7 @@ class Style
|
|||||||
*/
|
*/
|
||||||
public static function addFontStyle($styleName, $styleFont, $styleParagraph = null)
|
public static function addFontStyle($styleName, $styleFont, $styleParagraph = null)
|
||||||
{
|
{
|
||||||
self::setStyleValues($styleName, $styleFont, new Font('text', $styleParagraph));
|
self::setStyleValues($styleName, new Font('text', $styleParagraph), $styleFont);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -57,7 +57,7 @@ class Style
|
|||||||
*/
|
*/
|
||||||
public static function addLinkStyle($styleName, $styles)
|
public static function addLinkStyle($styleName, $styles)
|
||||||
{
|
{
|
||||||
self::setStyleValues($styleName, $styles, new Font('link'));
|
self::setStyleValues($styleName, new Font('link'), $styles);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -65,11 +65,11 @@ class Style
|
|||||||
*
|
*
|
||||||
* @param string $styleName
|
* @param string $styleName
|
||||||
* @param array $styleTable
|
* @param array $styleTable
|
||||||
* @param array $styleFirstRow
|
* @param array|null $styleFirstRow
|
||||||
*/
|
*/
|
||||||
public static function addTableStyle($styleName, $styleTable, $styleFirstRow = null)
|
public static function addTableStyle($styleName, $styleTable, $styleFirstRow = null)
|
||||||
{
|
{
|
||||||
self::setStyleValues($styleName, null, new Table($styleTable, $styleFirstRow));
|
self::setStyleValues($styleName, new Table($styleTable, $styleFirstRow), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -81,7 +81,7 @@ class Style
|
|||||||
*/
|
*/
|
||||||
public static function addTitleStyle($titleCount, $styleFont, $styleParagraph = null)
|
public static function addTitleStyle($titleCount, $styleFont, $styleParagraph = null)
|
||||||
{
|
{
|
||||||
self::setStyleValues("Heading_{$titleCount}", $styleFont, new Font('title', $styleParagraph));
|
self::setStyleValues("Heading_{$titleCount}", new Font('title', $styleParagraph), $styleFont);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -94,7 +94,7 @@ class Style
|
|||||||
*/
|
*/
|
||||||
public static function addNumberingStyle($styleName, $styleValues)
|
public static function addNumberingStyle($styleName, $styleValues)
|
||||||
{
|
{
|
||||||
self::setStyleValues($styleName, $styleValues, new Numbering());
|
self::setStyleValues($styleName, new Numbering(), $styleValues);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -156,13 +156,13 @@ class Style
|
|||||||
* Set style values and put it to static style collection
|
* Set style values and put it to static style collection
|
||||||
*
|
*
|
||||||
* @param string $styleName
|
* @param string $styleName
|
||||||
* @param array $styleValues
|
|
||||||
* @param Paragraph|Font|Table|Numbering $styleObject
|
* @param Paragraph|Font|Table|Numbering $styleObject
|
||||||
|
* @param array|null $styleValues
|
||||||
*/
|
*/
|
||||||
private static function setStyleValues($styleName, $styleValues, $styleObject)
|
private static function setStyleValues($styleName, $styleObject, $styleValues = null)
|
||||||
{
|
{
|
||||||
if (!array_key_exists($styleName, self::$styles)) {
|
if (!array_key_exists($styleName, self::$styles)) {
|
||||||
if (is_array($styleValues)) {
|
if (!is_null($styleValues) && is_array($styleValues)) {
|
||||||
foreach ($styleValues as $key => $value) {
|
foreach ($styleValues as $key => $value) {
|
||||||
$styleObject->setStyleValue($key, $value);
|
$styleObject->setStyleValue($key, $value);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,7 +10,6 @@
|
|||||||
namespace PhpOffice\PhpWord\Style;
|
namespace PhpOffice\PhpWord\Style;
|
||||||
|
|
||||||
use PhpOffice\PhpWord\Style;
|
use PhpOffice\PhpWord\Style;
|
||||||
use PhpOffice\PhpWord\Style\Numbering;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List item style
|
* List item style
|
||||||
@ -92,7 +91,7 @@ class ListItem extends AbstractStyle
|
|||||||
/**
|
/**
|
||||||
* Get numbering style name
|
* Get numbering style name
|
||||||
*
|
*
|
||||||
* @return integer
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getNumStyle()
|
public function getNumStyle()
|
||||||
{
|
{
|
||||||
@ -108,7 +107,7 @@ class ListItem extends AbstractStyle
|
|||||||
{
|
{
|
||||||
$this->numStyle = $value;
|
$this->numStyle = $value;
|
||||||
$numStyleObject = Style::getStyle($this->numStyle);
|
$numStyleObject = Style::getStyle($this->numStyle);
|
||||||
if (!is_null($numStyleObject)) {
|
if ($numStyleObject instanceof Numbering) {
|
||||||
$this->numId = $numStyleObject->getIndex();
|
$this->numId = $numStyleObject->getIndex();
|
||||||
$numStyleObject->setNumId($this->numId);
|
$numStyleObject->setNumId($this->numId);
|
||||||
}
|
}
|
||||||
@ -234,6 +233,7 @@ class ListItem extends AbstractStyle
|
|||||||
// Populate style and register to global Style register
|
// Populate style and register to global Style register
|
||||||
$style = $listTypeStyles[$this->listType];
|
$style = $listTypeStyles[$this->listType];
|
||||||
foreach ($style['levels'] as $key => $value) {
|
foreach ($style['levels'] as $key => $value) {
|
||||||
|
$level = array();
|
||||||
$levelProperties = explode(', ', $value);
|
$levelProperties = explode(', ', $value);
|
||||||
$level['level'] = $key;
|
$level['level'] = $key;
|
||||||
for ($i = 0; $i < count($properties); $i++) {
|
for ($i = 0; $i < count($properties); $i++) {
|
||||||
|
|||||||
@ -115,7 +115,7 @@ class NumberingLevel extends AbstractStyle
|
|||||||
*/
|
*/
|
||||||
public function getLevel()
|
public function getLevel()
|
||||||
{
|
{
|
||||||
return $level->level;
|
return $this->level;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -421,17 +421,4 @@ class Template
|
|||||||
}
|
}
|
||||||
return substr($this->documentXML, $startPosition, ($endPosition - $startPosition));
|
return substr($this->documentXML, $startPosition, ($endPosition - $startPosition));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Delete a block of text
|
|
||||||
*
|
|
||||||
* @param string $blockname
|
|
||||||
* @param string $replacement
|
|
||||||
* @deprecated
|
|
||||||
* @codeCoverageIgnore
|
|
||||||
*/
|
|
||||||
public function deleteTemplateBlock($blockname, $replacement = '')
|
|
||||||
{
|
|
||||||
$this->deleteBlock($blockname);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -15,7 +15,6 @@ use PhpOffice\PhpWord\Style;
|
|||||||
use PhpOffice\PhpWord\Style\Font;
|
use PhpOffice\PhpWord\Style\Font;
|
||||||
use PhpOffice\PhpWord\Style\Paragraph;
|
use PhpOffice\PhpWord\Style\Paragraph;
|
||||||
use PhpOffice\PhpWord\Style\Table;
|
use PhpOffice\PhpWord\Style\Table;
|
||||||
use PhpOffice\PhpWord\Style\Numbering;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Word2007 styles part writer
|
* Word2007 styles part writer
|
||||||
@ -54,7 +53,6 @@ class Styles extends Base
|
|||||||
if ($styleName == 'Normal') {
|
if ($styleName == 'Normal') {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$styleClass = str_replace('PhpOffice\\PhpWord\\Style\\', '', get_class($style));
|
|
||||||
|
|
||||||
// Font style
|
// Font style
|
||||||
if ($style instanceof Font) {
|
if ($style instanceof Font) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user