PHPOffice / PHPWord

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

Doesn't find files #1522

Open cagatayy94 opened 5 years ago

cagatayy94 commented 5 years ago

I am just triying to open vendor/phpoffice/phpword/samples/ but it says

"Fatal error: Uncaught Exception: Could not find file '/autoload.php'. It is generated by Composer. Use 'install --prefer-source' or 'update --prefer-source' Composer commands to move forward. in C:\xampp\htdocs\word\vendor\phpoffice\phpword\bootstrap.php:22 Stack trace: #0 C:\xampp\htdocs\word\vendor\phpoffice\phpword\samples\Sample_Header.php(2): require_once() #1 C:\xampp\htdocs\word\vendor\phpoffice\phpword\samples\index.php(2): include_once('C:\xampp\htdocs...') #2 {main} thrown in C:\xampp\htdocs\word\vendor\phpoffice\phpword\bootstrap.php on line 22"

when I try to open vendor/phpoffice/phpword/tests/PhpWord/Reader/MsDocTest.php it says

Fatal error: Class 'PHPUnit\Framework\TestCase' not found in C:\xampp\htdocs\word\vendor\phpoffice\phpword\tests\PhpWord\Reader\MsDocTest.php on line 28

I couldn't get it to work properly.

This my json file might be help { "require": { "phpoffice/phpword": "v0.14.*" } }

my php version is 7.2.12 is this matter ? What should I do ?

xenofx commented 4 years ago

I have same problem.

vincent1890 commented 4 years ago

me too same problem. There is a step-by-step tutorial after installing apache2 and php extension?

xenofx commented 4 years ago

I solved the problem. I Changed $vendorDirPath in bootstrap.php file.

I use composer and my general autoload.php under the main vendor folder, but phpword folder under the vendor/x/x/x/phpword. So you must change vendorDirPath variable like this :

$vendorDirPath = realpath(DIR . '../../../../vendor');

BrunoFischerGermany commented 1 month ago

i changed the bootstrap.php

$vendorDirPath = realpath(__DIR__); $normalizedPath = str_replace(['/', '\\'], DIRECTORY_SEPARATOR, $vendorDirPath);

$toRemove = DIRECTORY_SEPARATOR . 'phpoffice' . DIRECTORY_SEPARATOR . 'phpword'; $newPath = str_replace($toRemove, '', $normalizedPath);

$vendorDirNewPath = rtrim($newPath, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;

if (file_exists($vendorDirPath . '/autoload.php')) { require $vendorDirPath . '/autoload.php'; } elseif (file_exists($vendorDirNewPath . '/autoload.php')) { require $vendorDirNewPath . '/autoload.php'; } else {

Now it's working for me

Atticus29 commented 2 days ago

Is there any update to this? And/or I'm curious why Bruno's PR was closed without comment.