Hello,
could somebody tell me, how to set the Checkbox value in a template file with the TemplateProcessor .php.
Thank's
Beys
Frank D枚rsam
Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.
Not possible for now. I'm also waiting this feature for a long time.
Thanks for the quick answer.
I have already seen in xml the check box with Value = 0.
Could you tell me, how i can access the node in the xml structure ?
You can get a check box like this.
$checked = '<w:sym w:font="Wingdings" w:char="F0FE"/>';
$unChecked = '<w:sym w:font="Wingdings" w:char="F0A8"/>';
And use 'setValue()' replace the $value
such as
$templateProcessor->setValue("name",$checked);
$templateProcessor->setValue("hello",$unChecked);
And you will get a checkedbox on ${name} ,ge an unchecked box on ${hello}
@myskies's solution doesn't work for me, so I'd like to up this issue, fix required
@myskies solution worked for me. thanks
@luistheone for which version you tried?
@ozilion i use the v0.13.0 with yii2 framework
@luistheone thanks and can you share your TemplateProcessor.php file with us who can't made it to work :)
@ozilion
This was my first test file:
` public function actionFolha(){
$templateProcessor = new \PhpOffice\PhpWord\TemplateProcessor(\Yii::$app->basePath . '\web\templates\template_grupo.docx' );
$checked = '<w:sym w:font="Wingdings" w:char="F0FE"/>';
$unChecked = '<w:sym w:font="Wingdings" w:char="F0A8"/>';
$templateProcessor->setValue('data','04-3-17');
$templateProcessor->setValue('horario','17:00 脿s 20:00');
$templateProcessor->setValue('grupo','GrupoX');
$templateProcessor->setValue('rec',$checked);
$templateProcessor->setValue('ava',$unChecked);
$templateProcessor->setValue('sumario','sd asdkasj daskjd hask dhaksd <w:br/> sadsakdhasd hkas dhasdk <w:br/>nsadjaskj dasld asl
<w:br/>skdhsakjdhaskd haksd <w:br/> asdhaskjdhaskdhaskdh');
$temp_file = tempnam(sys_get_temp_dir(), 'PHPWord');
$templateProcessor->saveAs($temp_file);
header("Pragma: public");
header('Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document');
header('Content-Disposition: attachment;filename="'.basename('myFile.docx').'"');
header('Cache-Control: max-age=0');
header('Content-Length: '.filesize($temp_file));
ob_clean();
flush();
$chunksize = 1*(1024*1024); // how many bytes per chunk
$buffer = '';
$handle = fopen($temp_file, 'rb');
if ($handle === false) {
return false;
}
while (!feof($handle)) {
$buffer = fread($handle, $chunksize);
print $buffer;
}
unlink($temp_file);
return fclose($handle);
}`
and it worked as expected
Thanks for the sample code. I got it to work but actually it isnot really the checkbox we need. That code puts just small picture of checkbox not field one. You cannot interact with it later if you need. So this is just a temporary solutionat least for me.
its a Wingdings symbol, i just need that way to print the docs, its not a real checkbox. Sorry it was not what you want
Still needed very much. Could someone do anything else about to set checkbox value in template?
See also https://github.com/PHPOffice/PHPWord/issues/1187 with working code
Most helpful comment
@ozilion
This was my first test file:
` public function actionFolha(){
$templateProcessor = new \PhpOffice\PhpWord\TemplateProcessor(\Yii::$app->basePath . '\web\templates\template_grupo.docx' );
and it worked as expected