PHPWord - addListItem в ячейку таблицы, которая распознала стиль абзаца элемента списка

У меня есть ячейка таблицы, где я хотел бы разместить несколько элементов списка. Ниже мой код.

По сути, у меня определена целая куча стилей, а затем я добавляю строки и ячейки. Внутри одной из ячеек я добавляю неупорядоченный список.

Примечание. Если вам интересно, почему у меня здесь «точный» параметр, $table->addRow(250, "exact"); это потому, что я использовал это исправление для управления высотой строки таблицы.

// Table
$styleTable = array(    'borderSize'        =>  7,
                        'cellMarginTop'     =>  0,
                        'cellMarginLeft'    =>  100,
                        'valign'            =>  'center',
                        'spaceAfter'        =>  0
                                                        );

$styleCell = array(     'spaceAfter'        =>  0               
                                                        );


$cellTextStyle = array(     'bold'  =>  false, 
                            'size'  =>  10, 
                            'name'  =>  'Calibri'
                                                        );

$cellTextStyleBold = array( 'bold'  =>  true, 
                            'size'  =>  10, 
                            'name'  =>  'Calibri'   
                                                        );

$listStyleText = array(     'spaceAfter'    =>  0,
                            'spaceBefore'   =>  0,
                            'spacing'       =>  0,
                            'size'          =>  10       
                                                                );  

$listStyle = array(         'spaceAfter'    =>  0,
                            'spaceBefore'   =>  0,
                            'spacing'       =>  0
                                                                );  

$listStyleParagraph = array(        'spaceAfter'    =>  0,
                                    'spaceBefore'   =>  0,
                                    'spacing'       =>  0       
                                                                );          

$PHPWord->addTableStyle('myTable', $styleTable);

$table = $section->addTable('myTable');
$table->addRow(250, "exact");
$table->addCell(5760, $styleCell)->addText('Type:', $cellTextStyleBold);
$table->addCell(5760, $styleCell)->addText('Kazvin', $cellTextStyle);

$table->addRow(250, "null");
$table->addCell(5760, $styleCell)->addText('Description:', $cellTextStyleBold);
$cell = $table->addCell(5760, $styleCell);

// Add listitem elements inside table cell
$PHPWord->addParagraphStyle('listStyle', array('spaceAfter'=>0));
$cell->addListItem('100% wool pile on a cotton foundation', 0, null, null, 'listStyle');
$cell->addListItem('Semi-open ivory field', 0, null, null, 'listStyle');
$cell->addListItem('Coral and powder blue floral medallion', 0, null, null, 'listStyle');
$cell->addListItem('Formal coral, powder blue and ivory border', 0, null, null, 'listStyle');

Проблема в том, что стиль абзаца элемента списка не используется при выполнении чего-то вроде $cell->addListItem....

Если бы я использовал $section-> вместо $cell->

// Add listitem elements inside table cell
$PHPWord->addParagraphStyle('listStyle', array('spaceAfter'=>0));
$section->addListItem('100% wool pile on a cotton foundation', 0, null, null, 'listStyle');
$section->addListItem('Semi-open ivory field', 0, null, null, 'listStyle');
$section->addListItem('Coral and powder blue floral medallion', 0, null, null, 'listStyle');
$section->addListItem('Formal coral, powder blue and ivory border', 0, null, null, 'listStyle');

Тогда 'spaceAfter' => 0 работает нормально. Однако неупорядоченный список отображается за пределами ячейки таблицы.

Я несколько дней пытался найти способ применить стиль абзаца 'spaceAfter' => 0 к элементам списка внутри ячейки таблицы, но безуспешно.

Кто-нибудь знает, как можно реализовать что-то подобное?


person Raphael Rafatpanah    schedule 17.12.2013    source источник


Ответы (1)


Внесите изменения в Cell.php.

Заменять :

public function addListItem($text, $depth = 0, $styleText = null, $styleList = null) {
    $text = utf8_encode($text);
    $listItem = new PHPWord_Section_ListItem($text, $depth, $styleText, $styleList, $styleParagraph);
    $this->_elementCollection[] = $listItem;
    return $listItem;
}

By :

public function addListItem($text, $depth = 0, $styleText = null, $styleList = null, $styleParagraph = null) {
    $text = utf8_encode($text);
    $listItem = new PHPWord_Section_ListItem($text, $depth, $styleText, $styleList, $styleParagraph);
    $this->_elementCollection[] = $listItem;
    return $listItem;
}

Работай как шарм для меня!

person I. Ahounou    schedule 01.05.2014