This is the solution I arrived at:
I created as directory structure at the same level of the application and system directory (outside the public html)
assets\templates\receipt_template.docx
assets\receipts\
In my model:
Code:
// delete any previous files created and downloaded, first
$this->delete_receipt('../assets/receipts');
//create TemplateProcessor object with word doc
$templateProcessor = new \PhpOffice\PhpWord\TemplateProcessor('../assets/templates/receipt_template.docx');
// make substitutions
$templateProcessor->setValue('name', htmlspecialchars('Elementary School Teachers Federtion of Ontario', ENT_COMPAT, 'UTF-8'));
$templateProcessor->setValue('amount', htmlspecialchars('35.50', ENT_COMPAT, 'UTF-8'));
// generate file name and save in receipts directory
$datetime = date('Y_M_d_G_i');
$filename = 'receipt_' . $datetime . '.docx';
$templateProcessor->saveAs('../assets/receipts/' . $filename);
//download
force_download('../assets/receipts/' . $filename, NULL, TRUE);