2016-08-23 56 views
0

我目前已经有很大的困难,可以从表格中正确放置一些文本。

我想文字是这样的:
“从计算机分析
计算机名”PHPWord如何将文本分解到表格单元格中?

,它会显示这样的单元格内: “从计算机计算机名解析”

这里我当前的代码:

$table = $section->addTable('myTable'); 

$table->addRow(300); 
$table->addCell(4000)->addImage('logo_sat.png',array ('width'=>100,'align'=>'center')); 
$table->addCell(6400, $styleVertical)->addText("Analyse from computer \n $computername", $styleFirstHeader, $styleCenter); 
$table->addCell(4000, $styleVertical)->addText("SAT" , $styleFirstHeader, $styleCenter); 
$table->addRow(30); 
$table->addCell(4000, $styleVertical)->addText("ADR $chantier_code/$analyse_id" , $styleFirstHeader, $styleCenter); 
$table->addCell(5200, $styleVertical)->addText("Indice : $indice Date : $analyse_datemaj " , $styleFirstHeader, $styleCenter); 
$table->addCell(5200, $styleVertical)->addText("Page : " , $styleFirstHeader, $styleCenter); 

我见过$section->addTextBreak([$breakCount], [$fontStyle], [$paragraphStyle]); 的文件内,但它那eems与表格单元格不兼容。

任何想法,我们可以使这个作品?

+0

您是否尝试过加入'CHAR(10)'(回车键)? – WillardSolutions

+0

@EatPeanutButter我在\ n的地方添加了它,它只是写了CHAR(10) – BackTrack57

回答

0

在phpword中添加一个换行符困扰了我,我finnaly发现解决方案,无意中,所以这里是:这证明文本。

$PHPWord->addParagraphStyle('pJustify', array('align' => 'both', 'spaceBefore' => 0, 'spaceAfter' => 0, 'spacing' => 0)); 
//add this style then append it to text below 
$section->addText('something', 'textstyle', 'pJustify'); 
//the text behind this will be justified and will be in a new line, not in a new paragraph 
$section->addText('behind', 'textstyle', 'pJustify'); 

这将输出:

+0

我尝试了你的代码,文本在表格之外。我不确定我是否正确使用它,或者它根本不适用于表格和单元格。 – BackTrack57

+0

尝试根据您的需要设置样式。 –

+0

对不起,我无法让它与我的表一起工作。你可以请一个表格和你的答案中的一些单元格的例子吗? – BackTrack57

相关问题