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.
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
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.
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.
I had the same problem. I downloaded Library on github from
https://github.com/PHPOffice/PhpSpreadsheet
and made a few changes
changed its namespaces
used autoload.php file
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
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');
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.
Related
I am attempting to use the FPDF (http://www.fpdf.org/) PHP addon for my website that uses Laravel. I want to be able to dynamically create a PDF.
I have stored the libraries' files in the folder: '/public/vendor'.
This is what I have so far:
require $_SERVER['DOCUMENT_ROOT'] . '/vendor/fpdf/fpdf.php';
which works fine. However when I try to use the FPDF class using:
$pdf = new FPDF('P', 'pt', array(500,233));
I get the error: Class "'App\Console\Commands\FPDF' not found"
How can I fix this to use the library. I do not have access to command line so I have to manually import any folders or files.
Any help is greatly appreciated.
Update:: I do not have any access to the console so i cannot use composer. Any way to still do this?
Ideally if using Laravel, you should load it via composer the get it to work correctly.
If you do not have access to composer on the server, you could download the project, make sure you are running the same version of PHP as the server and run composer install fpdf/fpdf. Re-upload the composer.json, composer.lock and vendor folder.
https://packagist.org/packages/fpdf/fpdf
Try following code:
$pdf = new \Fpdf\Fpdf('P', 'pt', array(500,233));
FPDF is in the root namespace and you are within another namespace.
Highly recommend using https://github.com/mccarlosen/laravel-mpdf which can be installed via composer
It supports blade views and you can pass variables to it just like in view()
I have a requirement to fetch data from an excel file through a widget (i.e) moonlandsoft/phpexcel/Excel in YII2. For testing, I am trying to place the file in the appropriate view directory (Where I have the below coding in the view file) and test the code. But an error saying
file doesn't exist
is occurring. Its because I don't know the exact location where the widget trying to fetch data. Where should I place the excel file ( test.ods ) to test?
<?php
use moonland\phpexcel\Excel;
$filename = "test.ods";
$data = Excel::import(
$filename, [
'setFirstRecordAsKeys' => true
]
);
print_r($data);
exit;
You need to place the file inside the web directory and not in the views directory as web folder is the place which is publically accessible and includes the entry script index.php.
So place your file in the web directory if you are using
yii2-app-basic YOUR_PROJECT_ROOT/web
yii2-advance-app YOUR_PROJECT_ROOT/frontend/web or YOUR_PROJECT_ROOT/backend/web
and your script will start working and you can see the array printed.
Apart from getting it working, my opinion is you should not use this extension because
It is using the PHPExcel which is deprecated and replaced by PHPSpreadsheet you can see the message on the console when you install this extension for the first time
Package phpoffice/phpexcel is abandoned, you should avoid using it.
Use phpoffice/phpspreadsheet instead.
PhpSpreadsheet is the next version of PHPExcel. It breaks compatibility to dramatically improve the code base quality (namespaces, PSR compliance, use of latest PHP language features, etc.).
Because all efforts have shifted to PhpSpreadsheet, PHPExcel will no longer be maintained. All contributions for PHPExcel, patches and new features, should target PhpSpreadsheet develop branch.
And above all the extension is abandoned and no more maintained since 2016 there are several pull request that was never merged including the update to PHPSpreadsheet but nothing.
A better alternative could be arieslee/yii2-phpspreadsheet which is a modified version of the same extension you are using and upgraded to PHPSpreadsheet, you won't need to change anything in the code its the same extension with same methods.
I'm new to mpdf and I'm having a problem implementing it on my project. I saw a link in Facebook that has a tutorial for mpdf, I read and followed all the instructions but unfortunately there is still an error about some deprecated value.
Here is the link I followed : http://codesquery.com/convert-html-pdf-codeiniter-using-mpdf/
And here is the screenshot of the problem:
I hope you guys can help me.
I guess you use php 7. You must change names of function. In old php for example 5.19 the same name of function and class means that this function is a constructor. In PHP 7 it must be for example:
public function __construct(mPDF $mpdf){}
Click here to see a list of all modification
You can easily install mpdf by using composer in codeigniter. This is how I implemented composer in CodeIgniter 3.It is very easy. You have to install composer on your machine download it from https://getcomposer.org/. After installing composer in your pc,
Copy and paste composer.json file in the project folder to application folder.
In the config.php file $config['composer_autoload'] = TRUE;
Now you have composer in your project. Now i will saw you how to install mpdf using composer
Open cmd and direct to application folder
Inside application directory Type composer require mpdf/mpdf
Now a vendor folder will be created inside application folder and inside vendor folder you can see all your packages downloaded by composer.
Now since you autoloaded composer now you can just use the code given by mpdf official manual like in your controllers.
function m_pdf(){
$mpdf = new mPDF();
// Write some HTML code:
$mpdf->WriteHTML('Hello World');
// Output a PDF file directly to the browser
$mpdf->Output();
}
Remember you don't need to type require_once APPPATH.'/vendor/mpdf/mpdf/mpdf.php'; since you already autoloader composer. If not prefer to autoload composer you must type require_once APPPATH.'/vendor/mpdf/mpdf/mpdf.php' at the beginning of each controllers where you use the mpdf vendor libraries. If you encountered any problems please comment below.
Good afternoon, I will start off by saying that I've never included a composer project in my projects unless it was a composer package for the Laravel framework. Where you "require" it and add it to the providers array and aliases if needed.
Now, the problem. I have a composer package I'm trying to play around with https://github.com/WHAnonymous/Chat-API the problem is i dont know how to include it into myu project since its not really made "for" laravel. So I'm trying to use plain php without a framework but I have no idea how to "load" the package in, tried googling and only found information regarding building a package.
To clarify: I can install the package fine, its the php part of "loading" the package in my index.php file that im struggling with, pretend the index.php file is empty.
Can someone please help me?
After installing the package with composer, the composer has generated an autoloader that you can include with:
require_once 'vendor/autoload.php';
Then you can use the classes of the package without further includes. In your example this might be:
// Create an instance of WhatsProt.
$w = new WhatsProt($username, $nickname, $debug);
(taken from https://github.com/WHAnonymous/Chat-API/blob/master/examples/exampleRegister.php)
Note that this line from the example is not necessary, when you use the composer autoloader:
require_once('../src/whatsprot.class.php');
Assuming you have composer installed and have gone through the basics in the link posted by Paul.
You would run the following
~/composer install (same directory your composer.json file resides in).
Contents of composer.json file would be:
{
"require" : {
"whatsapp/chat-api" : "2.5.4"
}
}
i'm trying to convert some html to pdf.
After some google search i find dompdf but when i try to convert i retrieve
PHP-font-lib must either be installed via composer or copied to lib/php-font-lib
This is what i'm trying to do:
require 'pdf/dompdf.php';
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
$dompdf->stream("sample.pdf");
How can i solve? Thanks!
Dompdf moved recently to Github, and we also added Composer support. For this, we removed the reference to the required external library php-font-lib.
Note: If you are using composer to install dompdf (and php-font-lib), you need to put define("DOMPDF_ENABLE_AUTOLOAD", false); in dompdf_config.custom.inc.php. This will then allow composer to autoload php-font-lib which is installed through dompdf's composer.json file. Otherwise, you may still get an error. (See this issue)
If you are not using composer and want to use the latest edition of dompdf with this library: (source)
Get the latest dompdf release from Github and extract it into a directory.
Download the library release also from Github
Create the dompdf/lib/php-font-lib/classes/ directory.
In the zip file, take the contents of the src/FontLib/ folder and paste that into your newly created directory.
While my edit is being reviewed, I'll post the details here for the latest dompdf 0.6.1
If you are using composer to install dompdf (and php-font-lib), you need to put define("DOMPDF_ENABLE_AUTOLOAD", false); in dompdf_config.custom.inc.php. This will then allow composer to autoload php-font-lib which is installed through dompdf's composer.json file. Otherwise, you may still get an error. (See this Issue #636)
If you are not using composer and want to use the latest edition of dompdf, you will need to manually install php-font-lib: (https://stackoverflow.com/a/24505929/3854385)
Get the latest dompdf release from Github and extract it into a directory.
Download the library release also from Github
Create the dompdf/lib/php-font-lib/classes/ directory.
In the zip file, take the contents of the src/FontLib/ folder and paste that into your newly created directory.
Another trick, to avoid the change of automated downloaded files from Composer, is define the DOMPDF_ENABLE_AUTOLOAD and after reload the config file:
// Disable DOMPDF's internal autoloader if you are using Composer
define('DOMPDF_ENABLE_AUTOLOAD', false);
require_once CONFIG_DIR . 'vendor/dompdf/dompdf/dompdf_config.inc.php';
$dompdf = new \DOMPDF;