drb88830 2016-02-01 07:48
浏览 31
已采纳

表忽略给定的格式

I'm trying to add some tables to a document, which after lot of work, it's showing right. Generated with PHPWord. The issue is that whatever I add in the table,row or cell style, it doesn't modify the table.

I've already tried: $table->addRow(15), $table->addRow(array('height'=>15)) and as is shown in the code below.

Also, there is no documentation on how to add a cell with two lines of text, because below 'Sign' I have to add 'Name'.

//TABLE1
$table = $section->addTable(array('width'=>100, 'borderSize'=> 1, 'borderColor'=>'000000'));
$table->addRow(15,array('height'=>15));
$table->addCell(array('width'=>150))->addText('COMPANY', $smallBoldFont);
$table->addRow();
$table->addCell()->addText('');
$table->addRow();
$table->addCell()->addText('');
//TABLE1
$section->addTextBreak(2);
//TABLE2
$table2 = $section->addTable(array('borderSize'=> 1, 'borderColor'=>'000000'));
$table2->addRow(100,array('height'=>80));
$table2->addCell(150,array('width'=>800))->addText('Recibed', $smallFont8);
$table2->addRow();
$table2->addCell()->addText('Time:', $smallFont8);
$table2->addCell()->addText('Sign:', $smallFont8);
//TABLE2

Is there a reason why PHPWord ignores my format style to tables? Is there any other way of doing it better?

Desired output:

enter image description here

Actual output:

enter image description here

  • 写回答

1条回答 默认 最新

  • dongmaijie5200 2016-02-01 08:38
    关注

    In documentation is all. Just to read it deeply. Here is section how to create tables, including creation of tables with multicolumn cells

    I don't know if PHPWord has some pre-defined units for case if you miss to use them. But it seems you need to set units for width. But you should test units and numbers as you need.

    Order to create multicolumn cell is gridSpan(). So line for creation of the first row of the second table (probably) should be:

    $table2->addCell(150,array('width'=>800))->gridSpan(2) ->addText('Recibed', $smallFont8);
    

    PHPWord uses twip as default unit. And all cells have to match its width. The smallest cell is taken for entire column.

    For convertion from twips to other units may be used EndMemo (Topography Conversion Online).

    250 pixels are 3750 twips.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部