2013-08-02 193 views
2

我具有低於使用PHPWord格式化表格單元格中的文本粗體,字體,大小等

//create a new word document 

    $word= new PHPWord(); 

    //create potrait orientation 
    $section=$word->createSection(); 


    $table = $section->addTable(); 
    $word->addFontStyle('rStyle', array('bold'=>true, 'italic'=>true, 'size'=>16)); 
    //header row 
    $table->addRow(400, array('bgColor'=>'dbdbdb')); 
    $table->addCell(2000, array('bgColor'=>'dbdbdb'))->addText('Cell 1','rStyle'); 
    $table->addCell(3500, array('bgColor'=>'dbdbdb'))->addText('Cell 1'); 
    $table->addCell(1500, array('bgColor'=>'dbdbdb'))->addText('Cell 1','rStyle'); 
    $table->addCell(2000, array('bgColor'=>'dbdbdb'))->addText('Cell 1');  

    // Save File 
    $objWriter = PHPWord_IOFactory::createWriter($word, 'Word2007'); 
    $objWriter->save('Text.docx'); 
    echo 'Text.docx created successfully'; 
} 

我怎樣才能文本格式添加到單元格值以粗體,斜體,字體大小等等的代碼片段,我試圖如上所示,但它確實不是爲我工作

回答

0

以下工作:

$tdwidth = 1440 * 3; 
$table 
    ->addCell($tdwidth) 
    ->addText(
    "TO", 
    array(
     'size' => 12, 
     'bold' => true, 
     'underline' => PHPWord_Style_Font::UNDERLINE_SINGLE 
    ) 
); 
$table 
    ->addCell($tdwidth, array('align'=>'left')) 
    ->addText(
    "FROM", 
    array(
     'size' => 12, 
     'bold' => true, 
     'underline' => PHPWord_Style_Font::UNDERLINE_SINGLE, 
    ) 
); 

唯一的差異是 - 我傳遞一個陣列,而不是一個風格DEFN ...

HTH

2
$myFontStyle = array('bold' => true, 'align' => 'center'); 

$table->addCell(1750)->addText("Testing", $myFontStyle, array('align' => 'center')); 
0

這應做到:

$word->addFontStyle('rStyle', array('bold'=>true, 'italic'=>true, 'size'=>16)); 
$centered= array('align'=>'center'); 

//header row 
$table->addRow(400, array('bgColor'=>'dbdbdb')); 
$table->addCell(2000, array('bgColor'=>'dbdbdb'))->addText('Cell 1','rStyle', $centered); 
相關問題