Table/cell styles applied to odt file
Author: marcin-solvenetCreated May 2, 2018Updated Aug 25, 2026
LabelsBug ReportOpen Document (ODT)
This is:
- a bug report
- a feature request
- not a usage question (ask them on https://stackoverflow.com/questions/tagged/phpword)
Expected Behavior
When export to ODT file expected behaviour is apply styles to table/cell elements.
Current Behavior
Cell/Table styles are not applied
Failure Information
I used newest version PHPWord 0.14.0. I tried to open docx file with MS Word and styles were applied correctly. Then by using LibreOffice either opening odt or docx file result in styles not applied.
How to Reproduce
Please provide a code sample that reproduces the issue.
<?php
require __DIR__ . '/vendor/autoload.php';
$phpWord = new \PhpOffice\PhpWord\PhpWord();
// Styles
$phpWord->addTableStyle('mainTableStyle', ['width' => 100, 'unit' => 'pct', 'borderSize' => 1, 'borderColor' => '#000000', 'cellMargin' => 100], null);
$phpWord->addFontStyle('fontHeading1', ['size' => 16, 'bold' => true]);
$section = $phpWord->addSection();
$section->addText('Text using font style' , 'fontHeading1');
$section->addText('Default text style');
$table = $section->addTable('mainTableStyle');
$items = ['ITEM 1', 'ITEM 2', 'ITEM 3'];
foreach ($items as $item) {
$cellStyle = ['gridSpan' => 2, 'valign' => 'center', 'bgColor' => '#FFC000'];
$row = $table->addRow();
$cell = $row->addCell(\PhpOffice\PhpWord\Shared\Converter::cmToTwip(20), $cellStyle);
$cell->addText($item);
}
$docxWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
$docxWriter->save('out_' . date('Ymd_His') . '.docx');
$odtWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'ODText');
$odtWriter->save('out_' . date('Ymd_His') . '.odt');
Context
- PHP version: PHP 5.6.30
- PHPWord version: 0.14
Source: PHPOffice/PHPWord