PHPOffice / PHPWord

A pure PHP library for reading and writing word processing documents
https://phpoffice.github.io/PHPWord/
Other
7.27k stars 2.7k forks source link

How can I read and write to a docx file with PHPWord? #2365

Open richardsonoge opened 1 year ago

richardsonoge commented 1 year ago

Here is my problem with PHPWord::

At first I wanted to convert my doc file to docx. Now I found a copy() function that gives me the possibility to transform it into a docx file. Now I would like to take the content of this file, translate it and write the url of my site at the beginning of the file. I have found many scripts that tell me what to do. But every time I try to use these scripts, they give me an error. For example, I wanted to convert my document to a docx file, but it gives me this error:

Steps to Reproduce

Please provide a code sample that reproduces the issue.

$fileUrl = '../docs.bloggors.com/docs/bb8bee21e252e84820e0c9308a36bc09.doc';

require_once 'vendor/autoload.php';

if (is_readable($fileUrl)) {
    echo 'The file is available for readinge';
} else {
    echo 'The file is not accessible for reading !';
}

$templateProcessor = new \PhpOffice\PhpWord\TemplateProcessor($fileUrl);
$templateProcessor->setValue('name', 'myvar');
$templateProcessor->saveAs('oge.docx');

This is what I expect from you guys

Can you help me to be able to transform a doc file into a docx file or to write, modify and add text correctly in the file I created and transformed with the copy() function please?

Please fill in your environment information:

MarkBaker commented 1 year ago

Pull the file to the local filesystem, and then open it. PhpWord works from the filesystem, not from remote streamed files, because remote streaming doesn't support seek()