-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TemplateProcessor generates an invalid Word file #2320
Labels
Comments
I have the same problem but when using use PhpOffice\PhpWord\TemplateProcessor;
$vars = ["name" => "Name & Breaking"];
$templateProcessor = new TemplateProcessor();
$templateProcessor->setValues($vars);
$templateProcessor->saveAs('file.docx'); The & char breaks the file when trying to opening it. If I remove |
Hi Alarai, use PhpOffice\PhpWord\TemplateProcessor;
use PhpOffice\PhpWord\PhpWord;
require '../vendor/autoload.php';
$templateProcessor = new TemplateProcessor('absence.docx');
$templateProcessor->setValues(
[
'name'=> 'Bahaa',
'address'=> 'Cairo',
]);
$FullFileName = 'absence.docs';
// Save the document to a temporary file
$filename = tempnam(sys_get_temp_dir(),'absence') . '.docx';
$templateProcessor->saveAs($filename);
// Set the appropriate headers for Word document download
header('Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document');
header('Content-Disposition: attachment;filename='.$FullFileName);
header('Cache-Control: max-age=0');
// Output the document content
readfile($filename);
// Delete the temporary file
unlink($filename);
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Describe the Bug
The following test file when saved is building a file that could not be opened back in Word.
Steps to Reproduce
Just trying to open/save the file with the Template Processor.
Please use this sample file : absence.docx
Expected Behavior
The saved file should open properly in Word.
Current Behavior
The file does not open in Word.
![image](https://user-images.githubusercontent.com/7099355/198547875-cb99e03f-0eef-4a4b-87eb-af1de81df989.png)
Context
Please fill in your environment information:
The text was updated successfully, but these errors were encountered: