Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Table/cell styles applied to odt file #1363

Open
1 of 3 tasks
marcin-solvenet opened this issue May 2, 2018 · 1 comment
Open
1 of 3 tasks

Table/cell styles applied to odt file #1363

marcin-solvenet opened this issue May 2, 2018 · 1 comment

Comments

@marcin-solvenet
Copy link

marcin-solvenet commented May 2, 2018

This is:

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

out_docs.zip

@bastien70
Copy link

Hello, the problem is still the same. No update from 2018 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants