最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - How using phpword delete personal data left in word template when generate file? - Stack Overflow

programmeradmin0浏览0评论

When generating a file from a word template, is it possible to delete personal data left in the template? For example, the author's name.

I checked if the author's name is left in the template, in the new files received based on this template, this author's name is copied, which is not correct, because is personal data.

I have a lot of templates and it’s problematic to manually delete personal data from them; they are also often edited and sometimes you forget to delete this data from them.

When generating a file from a word template, is it possible to delete personal data left in the template? For example, the author's name.

I checked if the author's name is left in the template, in the new files received based on this template, this author's name is copied, which is not correct, because is personal data.

I have a lot of templates and it’s problematic to manually delete personal data from them; they are also often edited and sometimes you forget to delete this data from them.

Share Improve this question edited Feb 6 at 10:59 Dmitriy asked Feb 5 at 11:33 DmitriyDmitriy 95 bronze badges 5
  • 2 Isn't that what the setCreator method is for? phpoffice.github.io/PHPWord/docs/classes/… – C3roe Commented Feb 5 at 11:42
  • @C3roe No! As I wrote above, I use "word" templates to generate word files. So i use TemplateProcessor class, that only allows you to change the body and the header of the document. Why are you downvoting the question? – Dmitriy Commented Feb 6 at 9:53
  • 1 Don't expect people to automatically know what exactly you are doing, when you don't show any code. No one here can know, if you meant "template" literally, or just used the term liberally. (That's why you are supposed to show some code when asking here to begin with, minimal reproducible example.) Not my downvote though. – C3roe Commented Feb 6 at 9:59
  • @C3roe I wrote what I do!, using the phpword class, I take a word file template and generate a file based on it. What code should be presented here if it is minimal in my question. $templateProcessor = new TemplateProcessor($templateFileLink); $templateProcessor->saveAs($resultFileLink); That all of code. – Dmitriy Commented Feb 6 at 10:14
  • @C3roe thank you, based on your answer I was able to make a working version of what I needed – Dmitriy Commented Feb 6 at 10:49
Add a comment  | 

1 Answer 1

Reset to default 0

I found answer based on comment from @C3roe:

$templateProcessor = new TemplateProcessor($templateFileLink);
$templateProcessor->saveAs($resultFileLink);

$objReader = \PhpOffice\PhpWord\IOFactory::createReader('Word2007');
/** @var PhpWord $phpWord */
$phpWord = $objReader->load($resultFileLink); // instance of \PhpOffice\PhpWord\PhpWord
/** @var DocInfo $properties */
$properties = $phpWord->getDocInfo();
$properties->setCreator('');
$properties->setModified(false);
$properties->setLastModifiedBy('');
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
$objWriter->save($resultFileLink);

发布评论

评论列表(0)

  1. 暂无评论