Skip to content
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

Help wanted to create document using template. #1449

Open
theenescresta opened this issue Aug 11, 2018 · 6 comments
Open

Help wanted to create document using template. #1449

theenescresta opened this issue Aug 11, 2018 · 6 comments

Comments

@theenescresta
Copy link

I am using PHPword to generate the word documents. I want to generate multiple documents so that I want to use the template. I tried this code in the controller
$templateProcessor = new TemplateProcessor('resources/Sample_07_TemplateCloneRow.docx');
$templateProcessor->setValue('Name', 'John Doe');
$templateProcessor->setValue(array('City', 'Street'), array('Detroit', '12th Street'));
and following error is displayed:
copy(resources/Sample_07_TemplateCloneRow.docx): failed to open stream: No such file or directory

at :
// Template file cloning
if (false === copy($documentTemplate, $this->tempDocumentFilename)) {
throw new CopyFileException($documentTemplate, $this->tempDocumentFilename);
}

What is the default directory of Template Processor? or we have to give location manually. Please help!

  • PHP version:7.0 laravel 5.5
  • PHPWord version: 0.14
@adlanarifzr
Copy link

Can you try something like this?

...
$templateProcessor = new TemplateProcessor('resources/Sample_07_TemplateCloneRow.docx');
$templateProcessor->setValue('Name', 'John Doe');
$templateProcessor->setValue(array('City', 'Street'), array('Detroit', '12th Street'));

$export_file = public_path('filename.docx');

$templateProcessor->saveAs($export_file);
return response()->download($export_file)->deleteFileAfterSend(true);

@theenescresta
Copy link
Author

I tried but it says.
copy(resources/Sample_07_TemplateCloneRow.docx): failed to open stream: No such file or directory
Which directory TemplateProcessor Access or we have to link controller and resources folder .?

@adlanarifzr
Copy link

Remove the copy(resources/Sample_07_TemplateCloneRow.docx) line.. Just use exactly as my sample.

@theenescresta
Copy link
Author

I tried same Please have a look.
image
image

@adlanarifzr
Copy link

Please change your Sample_07_TemplateCloneRow.docx to be inside /storage directory instead. And use this line:

$templateProcessor = new TemplateProcessor(storage_path('Sample_07_TemplateCloneRow.docx'));

@cwilby
Copy link

cwilby commented Mar 30, 2019

Try using the resource_path helper.

$templateProcessor = new TemplateProcessor(resource_path('Sample_07_TemplateCloneRow.docx'))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants