2015-10-16 15 views
0

我正在嘗試使用PHPWord創建word文件。我已經設置了一些字體樣式和段落樣式。即使沒有給出文本打破,我在行1和行2之間得到6行空白。有什麼建議?抑制PHPWord中兩行文本之間的空白

這裏是我的代碼

$this->word->addFontStyle('titleStyle', array('bold' => true, 'size' => 16, 'name'=>'Calibri')); 
    $this->word->addFontStyle('lineStyle', array('align'=>'left','size' => 10, 'name'=>'Calibri')); 
    $this->word->addParagraphStyle('pStyle', array('align' => 'center', 'spaceBefore' => 0, 'spaceAfter' => 0, 'spacing' => 0)); 

    $section = $this->word->createSection(array('breakType'=>'continuous')); 

    // Simple text 
    $section->addText('Text Document','titleStyle','pStyle'); 

    $section->addText('Line1 : ','lineStyle');  
    $section->addText('Line2 : ','lineStyle');  
    $section->addText('Line3 : ','lineStyle');   
    $section->addText('Line4 : ','lineStyle');   


    $filename='NewDoc.docx'; //save our document as this file name 
    header('Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document'); //mime type 
    header('Content-Disposition: attachment;filename="'.$filename.'"'); //tell browser what's the file name 
    header('Cache-Control: max-age=0'); //no cache 

    $objWriter = PHPWord_IOFactory::createWriter($this->word, 'Word2007'); 
    $objWriter->save('php://output'); 

任何幫助將不勝感激。

以下是我正在生成的輸出文件。 enter image description here

回答

0

您定義的段落樣式不適用於任何添加的文本。

如果你想你的定義段落樣式應用到所添加的文本,您需要將域名(或定義)添加爲參數:

$section->addText('Line 1 : '.$line1,'lineStyle', 'pStyle'); 

,或者如果你希望創建全球款的風格,將被自動地使用無處不在:

$phpWord->setDefaultParagraphStyle(array('align'=>'left','size' => 10, 'name'=>'Calibri')); 
+0

你的問題中的代碼片段(當用一些常量字符串替換$ line1等)沒有爲我創建任何額外的空格或行。你的變量中是否有可能導致多餘行的內容? – ejuhjav

+0

那麼,現在我已經刪除了所有的變量,並使用簡單的常量字符串,如你已經嘗試過。但我仍然遇到同樣的問題。我已經更新了我的代碼。可能是我正在使用不同版本的PHPWord比你。我從gitHUb下載了一個。 – KloppForKop

+0

是的,我使用0.12.0這不是最新的 - 所以如果你使用的0.13.0版本可能會有一些差異... – ejuhjav

相關問題