36

According to the PhpSpreadsheet Doc it's neccessary to install it with composer. In my case I just have a webspace without Terminal but Plesk. Is it anyway possible to use PhpSpreadsheet, like it is with PHPExcel where you just have to place the files in any location? What do I have to do to get it run? I found no further information how to with only FTP webserver access.

MaggusK
  • 605
  • 1
  • 8
  • 12

6 Answers6

48

In your case there are two options for you!

Answer: 1

Alternative method without terminal

Run composer with a PHP script in browser

Answer: 2

Third party sites, which allow to download composer packages online. get PHPspreadsheet latest version.

https://php-download.com/package/phpoffice/phpspreadsheet

Bonus You can download almost any composer packages @ https://php-download.com

Shahnawaz Kadari
  • 1,423
  • 1
  • 12
  • 20
  • 4
    You guided me to the best solution. It's in the first link where @Sven gives the hint just to install composer and additionally software locally and afterwards upload it. – MaggusK Feb 14 '18 at 08:02
  • 1
    So this really worked. Was easy. The only trouble was to get all required php extension installed until PhpSpreadsheet could be installed locally without errors. After installing **_php7.0-cli_** I had to install also: * php7.0-gd * php7.0-zip * php7.0-mbstring Afterward I could install PhpSpreadsheet like in the [Doc](https://phpspreadsheet.readthedocs.io/en/develop/#installation) And just put the generated folders and files with ftp on the webspace. The hello World excample worked at once. – MaggusK Feb 14 '18 at 17:09
  • Hey @Smartpal, you just linked the doc I linked before :-)) Of course I read it, but guess: there is a difference between enabling and installing ;-) – MaggusK Feb 16 '18 at 09:17
  • When I try and unzip the file from **Answer 3**, I get this error (Windows 7): `Windows cannot complete the extraction. The Compressed (zipped) Folder 'C:\...phpspreadsheet.zip' is invalid.` Could someone re-zip and upload again? – ban-geoengineering Jun 27 '18 at 12:44
  • 1
    Have now managed to successfully unzip it using the 7-Zip application: https://7-zip.org/ – ban-geoengineering Jun 27 '18 at 12:53
  • 22
    thank you very much! I can't stand the "composer" crap. PHP libraries should be included by including a single .php file in your main script and that's it – Gianluca Ghettini Sep 05 '18 at 13:42
  • @Smartpal I’ve gone through that page over and over. I keep getting exceptions that the pdf libraries (tcpdf or mpdf) cannot be found. I installed without composer and now I cannot find a single example of how to save to pdf – Christopher Smit Nov 08 '18 at 09:40
  • @ChristopherSmit, you are having troubles because you don't use composer. You **really** should use it. Believe or not, using composer make your life simpler for install and update of packages. It will only get more messy for you with newer versions of PhpSpreadsheet if you don't use composer. – PowerKiKi Jan 22 '19 at 00:04
  • @MaggusK Any chance you can zip up the folder needed without composer? Thank you! – SeaBass Apr 28 '19 at 03:43
  • 5
    I dont understand why people force composer horsesh!t, I never could install it under windows7 nor 10 – user7082181 Feb 19 '20 at 12:22
  • I like it; but, how can you confidently say it will be 100% secure way, there will be the chance of malicious code in the package that can steal your confidential. – Lokendra Parihar Nov 26 '20 at 16:57
  • Answer 2, using the download there and doing a `require('/phpspeadsheets/vendor/autoload.php');` I'm still getting a fatal error due to PhpSpreadsheets not finding one of their own classes: `PHP Fatal error: Uncaught Error: Class "ZipArchive" not found in /var/project/code/5158/thirdparty/PhpSpreadsheet/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Reader/Xlsx.php:82` – Bing Mar 23 '21 at 15:15
11

Have you considered installing composer locally, running it as instructed, and then just sending the generated files to the server via normal FTP? You install composer on your computer and run it there, then upload via FTP/SFP...

Composer is not "necessarily" intended to run live while the user is downloading the pages, it is intended to be run "mainly" on your local computer and generating the files and dependencies that later on you upload to the server. It can update the files on your server, but that is a convenience not a necessity.

PowerKiKi
  • 4,539
  • 4
  • 39
  • 47
FrancescoMM
  • 2,845
  • 1
  • 18
  • 29
  • 2
    While this might be the most practical solution, you have to keep in mind that it completely bybass the PHP extension requirements check on the production system. So you'll have to be extra careful to manually check that manually. – PowerKiKi May 24 '18 at 01:59
  • 1
    @PowerKiKi yes, it checks for all the extension requirements and dependencies locally, so you have to be sure to upload all of them. When you upload you just have to upload the whole folder, if in doubt, and you are safe. On the other hand I don't trust things to update automatically without me knowing. I totally prefere to be the one uploading updates if I think they are necessary and stable. – FrancescoMM Jan 19 '19 at 09:13
2

By registering custom autoloader and PSR simplecache autoloader it is possible to fully workaround composer installation - see:

https://github.com/PHPOffice/PhpSpreadsheet/issues/31#issuecomment-354502740

Please note, that installation via composer is currently the only officially supported solution.

lubosdz
  • 4,210
  • 2
  • 29
  • 43
2

I had the same problem. I downloaded Library on github from https://github.com/PHPOffice/PhpSpreadsheet and made a few changes

  1. changed its namespaces
  2. used autoload.php file
  3. It worked

the Library without the need of Composer is in this link https://github.com/YoloZoloo/PhpSpreadSheet/tree/master

You can change the folder name to any folder you like. Load [AnyFolder]->table.php from your server and press 「ダウンロード」.

Hit back to me if you encounter any issues

YoloZoloo
  • 41
  • 4
  • 1
    Not up-to-date. Better install via [php-download.com](https://php-download.com), rename 'vendor' directory to 'phpspreadsheet' and copy that directory to /usr/local/share/php/ (macOS) or /usr/share/php/ (CentOS/Fedora). Load it in your PHP script via `require 'phpspreadsheet/autoload.php';` – MrMacvos Apr 25 '22 at 11:49
  • @MrMacvos, that php-download.com looks fishy. It says it has a trial but one has to subscribe and give credit card data first. It also needs a paypal account, even when one chooses the "credit card" options. – osiris Jun 21 '23 at 11:22
  • True, it wasn't up to date. I just updated it. Should be much more useful now. – YoloZoloo Aug 05 '23 at 06:10
-3

Smartpal, thanks for your pack, it works fine!

Also it possible to replace folder:

/phpspreadsheet/vendor/phpoffice/phpspreadsheet/src/

in Smartpal's archive with more fresh sources from phpspreadsheet github and it also will work.

PS: If you have issues with reading xls files saved in encoding other than CP1252, you have to seek literals CP1252 in file ./src/PhpSpreadsheet/Reader/Xls.php and replace them with other value that you need or some named constant or even mb_detect_encoding(). Then it will read such xls correctly.

Kenny Horna
  • 13,485
  • 4
  • 44
  • 71
ManiaC
  • 1
  • 2
    It is a terrible idea to replace some files with new one, it **will** fail at some point in the future, when a file is renamed or a new file is introduced. You really should use composer. – PowerKiKi Jan 22 '19 at 00:00
-3

sample code

require 'vendor/autoload.php'; 
use PhpOffice\PhpSpreadsheet\Spreadsheet; 
use PhpOffice\PhpSpreadsheet\Writer\Xlsx; 
$spreadsheet = new Spreadsheet(); 
$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue('A1', 'Hello World !');

$writer = new Xlsx($spreadsheet);
$writer->save('hello world.xlsx');
B Varma
  • 85
  • 1
  • 2