2

First of all sorry for my vary bad english (i'm Italian). Hi, i have a problem with phpword library: i would insert a bullet list in a cell but I just do not know how to do it. This is my code:

<?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

Thanks to all.

1 Answer 1

1

just do it the way you add text to cell, so instead of current code:

$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)");

You can insert list items in table-cell this way:

$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);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.