Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
718946f
Update RTF.php - Support for ListTable
rasamassen Sep 3, 2025
190a58a
Update Header.php - Initial Commit for List support
rasamassen Sep 3, 2025
b1f2b1d
Update Header.php - Write listtable and listoverridetable
rasamassen Sep 4, 2025
000efe4
Update ListItem.php - RTF Writer needs to access the NumberingStyle
rasamassen Sep 4, 2025
73cb2ba
Update ListItem.php - Make writer work for basic lists
rasamassen Sep 4, 2025
7e5f31a
Update ListItem.php - Accidentally rmoved function
rasamassen Sep 4, 2025
ffd4dd2
Update Header.php - Minor fixes
rasamassen Sep 4, 2025
07ff047
Update ListItem.php - format fix
rasamassen Sep 4, 2025
c311204
Update Header.php - Formatting fixes
rasamassen Sep 4, 2025
f73a09d
Update Header.php - Fix formatting
rasamassen Sep 4, 2025
42e94f2
Update Header.php - Fix formatting
rasamassen Sep 4, 2025
1db3452
Update ListItem.php - ensure $style instanceof ListItem
rasamassen Sep 5, 2025
4530e1b
Update ListItem.php - ensure $style instanceof ListItem additional
rasamassen Sep 5, 2025
5f590b3
Update Header.php - Make Bullet Lists work properly
rasamassen Sep 5, 2025
4ff9eed
Update ListItem.php - Address CS Fixer Issue
rasamassen Sep 5, 2025
19bc087
Update ListItem.php - Fix Static Analysis error
rasamassen Sep 5, 2025
4a800d1
Update Header.php - ListTable Fixes, Improvements, and Additions
rasamassen Sep 13, 2025
6479292
Update 1.5.0.md - Changelog for Pull 2821
rasamassen Sep 13, 2025
9f16198
Update Header.php - Minor Fixes
rasamassen Sep 13, 2025
d727be7
Update Header.php - Fix
rasamassen Sep 13, 2025
0f4bb94
Update Header.php - Fixing Static
rasamassen Sep 13, 2025
f68a534
Update ListItem.php - CS Fix
rasamassen Sep 13, 2025
a453cbd
Update Header.php - Static Fix
rasamassen Sep 13, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/changes/1.x/1.5.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
### Bug fixes

- Set writeAttribute return type by [@radarhere](https://github.com/radarhere) fixing [#2204](https://github.com/PHPOffice/PHPWord/issues/2204) in [#2776](https://github.com/PHPOffice/PHPWord/pull/2776)
- Writer RTF: Support listItem, including listTable by [@rasamassen](https://github.com/rasamassen) in [#2821](https://github.com/PHPOffice/PHPWord/pull/2821), fixing [#1106](https://github.com/PHPOffice/PHPWord/issues/1106)

### Miscellaneous

Expand All @@ -16,4 +17,4 @@

### BC Breaks

### Notes
### Notes
18 changes: 17 additions & 1 deletion src/PhpWord/Style/ListItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
namespace PhpOffice\PhpWord\Style;

use PhpOffice\PhpWord\Style;
use PhpOffice\PhpWord\Style\Numbering as NumberingStyle;

/**
* List item style.
Expand Down Expand Up @@ -115,6 +116,21 @@ public function getNumStyle()
return $this->numStyle;
}

/**
* Get numbering style.
*
* @return ?NumberingStyle
*/
public function getNumberingStyle()
{
$numStyleObject = Style::getStyle($this->numStyle);
if ($numStyleObject instanceof NumberingStyle) {
return $numStyleObject;
}

return null;
}

/**
* Set numbering style name.
*
Expand All @@ -126,7 +142,7 @@ public function setNumStyle($value)
{
$this->numStyle = $value;
$numStyleObject = Style::getStyle($this->numStyle);
if ($numStyleObject instanceof Numbering) {
if ($numStyleObject instanceof NumberingStyle) {
$this->numId = $numStyleObject->getIndex();
$numStyleObject->setNumId($this->numId);
}
Expand Down
10 changes: 10 additions & 0 deletions src/PhpWord/Writer/RTF.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,16 @@ public function getColorTable()
return $this->getWriterPart('Header')->getColorTable();
}

/**
* Get list table.
*
* @return array
*/
public function getListTable()
{
return $this->getWriterPart('Header')->getListTable();
}

/**
* Get last paragraph style.
*
Expand Down
44 changes: 44 additions & 0 deletions src/PhpWord/Writer/RTF/Element/ListItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,48 @@
*/
class ListItem extends Text
{
/**
* Write list item element.
*/
public function write()
{
/** @var \PhpOffice\PhpWord\Element\Text $element Type hint */
$element = $this->element;
if (!$element instanceof \PhpOffice\PhpWord\Element\ListItem) {
return '';
}

$this->getStyles();

$depth = (int) $element->getDepth();
$style = $element->getStyle();
$text = $element->getTextObject();

// Bullet List
$content = '';
$content .= $this->writeOpening();
if ($style instanceof \PhpOffice\PhpWord\Style\ListItem) {
$numStyle = $style->getNumberingStyle();
$levels = $numStyle->getLevels();
$content .= '\ilvl' . $element->getDepth();
$content .= '\ls' . $style->getNumId();
$content .= '\tx' . $levels[$depth]->getTabPos();
$hanging = $levels[$depth]->getLeft() + $levels[$depth]->getHanging();
$left = 0 - $levels[$depth]->getHanging();
$content .= '\fi' . $left;
$content .= '\li' . $hanging;
$content .= '\lin' . $hanging;
}
$content .= $this->writeFontStyle(); // Doesn't work. Don't know why. Probalby something to do with \PphOffice\PhpWord\Element\ListItem storing styles in a textObject type \PphOffice\PhpWord\Element\Text rather than within the Element itself
$content .= PHP_EOL;
/* $content .= '{\listtext\f2 \\\'b7\tab }'; // Not sure if needed for listItemRun
$content .= PHP_EOL; */
$content .= '{';
$content .= $this->writeText($element->getText());
$content .= '}';
$content .= PHP_EOL;
$content .= $this->writeClosing();

return $content;
}
}
Loading
Loading