【问题标题】:phpword insert bullet list in a tablephpword 在表格中插入项目符号列表
【发布时间】:2017-05-08 15:17:57
【问题描述】:

首先很抱歉我的英语不好(我是意大利人)。 嗨,我对 phpword 库有疑问: 我会在单元格中插入一个项目符号列表,但我只是不知道该怎么做。 这是我的代码:

<?php
include_once 'vendor/autoload.php';
include ('session_admin.php');
$class = $_SESSION['n_classe'];
include ('../conn_serv.php');

$phpWord = new \PhpOffice\PhpWord\PhpWord();

$section = $phpWord->addSection();

$sectionStyle = $section->getStyle();

$sectionStyle->setMarginRight(\PhpOffice\PhpWord\Shared\Converter::cmToTwip(1));
$sectionStyle->setMarginLeft(\PhpOffice\PhpWord\Shared\Converter::cmToTwip(1));
$sectionStyle->setMarginTop(\PhpOffice\PhpWord\Shared\Converter::cmToTwip(1));
$sectionStyle->setMarginBottom(\PhpOffice\PhpWord\Shared\Converter::cmToTwip(1));


$fontStyle = new \PhpOffice\PhpWord\Style\Font();
$fontStyle->setBold(true);
$fontStyle->setName('Tahoma');
$fontStyle->setSize(12);
$myTextElement = $section->addText('RELAZIONE FINALE VISITA O VIAGGIO D ISTRUZIONE');
$myTextElement->setFontStyle($fontStyle);

$fancyTableStyleName = 'Fancy Table';
$fancyTableStyle = array('borderSize' => 1, 'borderColor' => 'd2d2d2', 'cellMargin' => 40, 'width' => 200 , 'alignment'  => \PhpOffice\PhpWord\SimpleType\JcTable::CENTER);
$fancyTableCellStyle = array('valign' => 'center');
$fancyTableFontStyle = array('bold' => true);
$phpWord->addTableStyle($fancyTableStyleName, $fancyTableStyle, $fancyTableFirstRowStyle);
$table = $section->addTable($fancyTableStyleName);

$table->addRow();
$table->addCell(20000)->addText('Classe/i ___________ sez. ____________');
$table->addRow();
$table->addCell(20000)->addText('Visita guidata/Viaggio d istruzione a:                                                              del: ');
$table->addRow();
$table->addCell(20000)->addText('Docente referente:');
$table->addRow();
$table->addCell(20000)->addText('Docenti accompagnatori:');
$table->addRow();



$table->addCell(20000)->addText('Realizzazione dell iniziativa: ');
//i would insert in this cell ^ the bullet list here below
$section->addListItem("secondo le previsioni");
$section->addListItem("parzialmente realizzata (motivare)");
$section->addListItem("non realizzata (motivare)");

$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
$objWriter->save('Prova.docx');



//header("Location: stampa_proposte.php");?>

The result that I will get is this

谢谢大家。

【问题讨论】:

    标签: php phpword


    【解决方案1】:

    只需按照向单元格添加文本的方式进行操作,而不是当前代码:

    $table->addCell(20000)->addText('Realizzazione dell iniziativa: ');
    //i would insert in this cell ^ the bullet list here below
    $section->addListItem("secondo le previsioni");
    $section->addListItem("parzialmente realizzata (motivare)");
    $section->addListItem("non realizzata (motivare)");
    

    您可以通过这种方式在表格单元格中插入列表项:

    $table_cell = $table->addCell(20000);//assign cell a variable
    //add elements to cell. For square bullets refer documentation
    $table_cell->addText('Realizzazione dell iniziativa: '); 
    $table_cell->addListItem("secondo le previsioni",0);//0 is the list level
    $table_cell->addListItem("parzialmente realizzata (motivare)",0);
    $table_cell->addListItem("non realizzata (motivare)",0);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-03-10
      • 2019-06-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-09
      • 1970-01-01
      相关资源
      最近更新 更多