相关疑难解决方法(0)

使用 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';
}
Run Code Online (Sandbox Code Playgroud)

如何将文本格式添加到单元格值中以粗体、斜体、字体大小等,我已尝试如上所示,但它不起作用

php phpword

4
推荐指数
1
解决办法
2万
查看次数

标签 统计

php ×1

phpword ×1