Documentation for new ListItem feature

This commit is contained in:
Ivan Lanin 2014-04-11 17:59:48 +07:00
parent 39a5e8c51e
commit 297eeaadf0
7 changed files with 66 additions and 35 deletions

View File

@ -207,10 +207,14 @@ Lists
To add a list item use the function ``addListItem``.
Basic usage:
.. code-block:: php
$section->addListItem($text, [$depth], [$fontStyle], [$listStyle], [$paragraphStyle]);
Parameters:
- ``$text`` Text that appears in the document.
- ``$depth`` Depth of list item.
- ``$fontStyle`` See "Font style" section.
@ -219,6 +223,40 @@ To add a list item use the function ``addListItem``.
PHPWord\_Style\_ListItem.
- ``$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
------

View File

@ -221,9 +221,11 @@ class Word2007 extends AbstractReader implements ReaderInterface
// 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);
$this->readHeaderFooter($filename, $settings, $section);
}
$section = $this->phpWord->addSection();
}
break;
@ -268,7 +270,9 @@ class Word2007 extends AbstractReader implements ReaderInterface
$pStyle = $this->readParagraphStyle($xmlReader, $node);
$fStyle = $this->readFontStyle($xmlReader, $node);
if (empty($fStyle)) {
if (is_array($pStyle)) {
$this->phpWord->addParagraphStyle($name, $pStyle);
}
} else {
$this->phpWord->addFontStyle($name, $fStyle, $pStyle);
}
@ -634,8 +638,9 @@ class Word2007 extends AbstractReader implements ReaderInterface
} elseif ($rowNode->nodeName == 'w:tc') { // Cell
$cellWidth = $xmlReader->getAttribute('w:w', $rowNode, 'w:tcPr/w:tcW');
$cellStyle = null;
if ($xmlReader->elementExists('w:tcPr', $rowNode)) {
$cellStyle = $this->readCellStyle($xmlReader, $xmlReader->getElement('w:tcPr', $rowNode));
$cellStyleNode = $xmlReader->getElement('w:tcPr', $rowNode);
if (!is_null($cellStyleNode)) {
$cellStyle = $this->readCellStyle($xmlReader, $cellStyleNode);
}
$cell = $row->addCell($cellWidth, $cellStyle);
@ -786,6 +791,9 @@ class Word2007 extends AbstractReader implements ReaderInterface
if ($domNode->nodeName == 'w:hyperlink') {
$domNode = $xmlReader->getElement('w:r', $domNode);
}
if (is_null($domNode)) {
return $style;
}
if ($xmlReader->elementExists('w:rPr', $domNode)) {
if ($xmlReader->elementExists('w:rPr/w:rStyle', $domNode)) {
$style = $xmlReader->getAttribute('w:val', $domNode, 'w:rPr/w:rStyle');

View File

@ -34,7 +34,7 @@ class Style
*/
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)
{
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)
{
self::setStyleValues($styleName, $styles, new Font('link'));
self::setStyleValues($styleName, new Font('link'), $styles);
}
/**
@ -65,11 +65,11 @@ class Style
*
* @param string $styleName
* @param array $styleTable
* @param array $styleFirstRow
* @param array|null $styleFirstRow
*/
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)
{
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)
{
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
*
* @param string $styleName
* @param array $styleValues
* @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 (is_array($styleValues)) {
if (!is_null($styleValues) && is_array($styleValues)) {
foreach ($styleValues as $key => $value) {
$styleObject->setStyleValue($key, $value);
}

View File

@ -10,7 +10,6 @@
namespace PhpOffice\PhpWord\Style;
use PhpOffice\PhpWord\Style;
use PhpOffice\PhpWord\Style\Numbering;
/**
* List item style
@ -92,7 +91,7 @@ class ListItem extends AbstractStyle
/**
* Get numbering style name
*
* @return integer
* @return string
*/
public function getNumStyle()
{
@ -108,7 +107,7 @@ class ListItem extends AbstractStyle
{
$this->numStyle = $value;
$numStyleObject = Style::getStyle($this->numStyle);
if (!is_null($numStyleObject)) {
if ($numStyleObject instanceof Numbering) {
$this->numId = $numStyleObject->getIndex();
$numStyleObject->setNumId($this->numId);
}
@ -234,6 +233,7 @@ class ListItem extends AbstractStyle
// Populate style and register to global Style register
$style = $listTypeStyles[$this->listType];
foreach ($style['levels'] as $key => $value) {
$level = array();
$levelProperties = explode(', ', $value);
$level['level'] = $key;
for ($i = 0; $i < count($properties); $i++) {

View File

@ -115,7 +115,7 @@ class NumberingLevel extends AbstractStyle
*/
public function getLevel()
{
return $level->level;
return $this->level;
}
/**

View File

@ -421,17 +421,4 @@ class Template
}
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);
}
}

View File

@ -15,7 +15,6 @@ use PhpOffice\PhpWord\Style;
use PhpOffice\PhpWord\Style\Font;
use PhpOffice\PhpWord\Style\Paragraph;
use PhpOffice\PhpWord\Style\Table;
use PhpOffice\PhpWord\Style\Numbering;
/**
* Word2007 styles part writer
@ -54,7 +53,6 @@ class Styles extends Base
if ($styleName == 'Normal') {
continue;
}
$styleClass = str_replace('PhpOffice\\PhpWord\\Style\\', '', get_class($style));
// Font style
if ($style instanceof Font) {