【问题标题】:PHPWord - addListItem into Table Cell that recognized List Item Paragraph StylePHPWord - 将ListItem添加到识别列表项段落样式的表格单元格中
【发布时间】:2013-12-17 17:26:24
【问题描述】:

我有一个表格单元格,我想在其中放置一些列表项。下面是我的代码。

基本上,我定义了一大堆样式,然后添加行和单元格。在其中一个单元格中,我添加了一个无序列表。

注意:如果您想知道为什么我在这里有“精确”参数,$table->addRow(250, "exact"); 这是因为我使用了this fix for controlling table row height

// 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 段落样式应用于表格单元格内的列表项,但没有成功。

有谁知道这样的事情是如何实现的?

【问题讨论】:

    标签: php ms-word phpword


    【解决方案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;
    }
    

    作者:

    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;
    }
    

    工作对我来说就像一个魅力!

    【讨论】:

      猜你喜欢
      • 2021-01-24
      • 1970-01-01
      • 2012-08-02
      • 1970-01-01
      • 1970-01-01
      • 2020-05-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多