php - how to fill in table on template file from phpword?
Get the solution ↓↓↓How to insert table from database employee to my template document as above? I successfully filled company field.
code like bellow
require_once APPPATH.'libraries/autoload.php';
use PhpOffice\PhpWord\PhpWord;
public function cetaksurat()
{
$templateProcessor = new \PhpOffice\PhpWord\TemplateProcessor('source.docx');
$templateProcessor->setValues([
'company' => 'my company',
//how to insert employee table from my database array result?
//.....
]);
header("Content-Disposition: attachment; filename=result.docx");
$templateProcessor->saveAs('php://output');
}
thank you
Answer
Solution:
in my case I would use:
$news2 = $this->phpword_model->get_employe(); //
foreach($news2 as $key=>$values) {
$array_values1 = $values['id'];
$array_values2 = $values['name'];
}
$templateProcessor->setValue('id', $array_values1);
$templateProcessor->setValue('name', $array_values2);
$templateProcessor->saveAs($filename);
/// the first example is for a single record. now this example is for multiple records.
$news7 = $this->phpword_model->get_employes();
$templateProcessor->cloneRow('id', count($news7));
$i=1;
foreach($news7 as $key=>$values) {
$templateProcessor->setValue('id#'.$i++, $values['id']);
}
$i2=1;
foreach($news7 as $key=>$values) {
$templateProcessor->setValue('name#'.$i2++, $values['name']);
}
$templateProcessor->saveAs($filename);
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: unable to determine current zabbix database version: the table "dbversion" was not found.
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.