Is there a way to use PHPExcel in view of Laravel? - php

PHPExcel is a library to generate MS Excel file using PHP (and so far the best one I have used in supporting Chinese output). It works fine in Laravel. However, unlike libraries for generating email or PDF files, in PHPExcel (and many other libraries used for generating Excel file) the file can only be generated by calling PHP functions instead of converting HTML into Excel, so the code has to be put in controller / classes.
I feel a little uncomfortable to put codes that mainly for views into controller, and it is a group project so readability is also a concern. Is there a way I can put the code generating Excel file into view in Laravel?

You have to install "maatwebsite/excel" package, and then you can use the functionality of PHPExcel. Go: here to get basic information regarding package installation, and here to get detail tutorial, on how to use this package.
See, if that helps.

Laravel 5 allows you to place your classes anywhere in the app folder, given the appropriate PSR-4 compliance.
Therefore, you can create a class which is solely responsible for containing all codes pertaining to the creation of your Excel files.
Then you can call the method, from your controller whenever appropriate.

Related

PHPExcel for laravel 5

I want to use my PHPExcel Laravel application. I installed the library in the vendor directory. What is the method to call my controller and thereby implement this example: http://g-ernaelsten.developpez.com/tutoriels/excel2007/?page=fondements#L2.1
In the posts I read it just had to write to the header
use PHPExcel;
use PHPExcel_IOFactory;
It's not sufficient
Who can help me start with this library? and integrate it into my project Laravel. Thank
Maatwebsite made a built a Laravel package for PHPExcel. You can find it here https://github.com/Maatwebsite/Laravel-Excel together with the documentation for it.
If for any reasons you prefer to not use this, you need to
include '/vendor/PHPExcel/PHPExcel';
include '/vendor/PHPExcel/PHPExcel/Writer/Excel5.php';

Symfony2 editing PDF

I have a problem when trying to edit existing PDF. In non-symfony part of code I've used FPDI library and I could just open existing pdf as:
$pdf->setSourceFile('example.pdf');
Now in the symfony part of the project we're using White october bundle for symfony2 which is basically wrapper around TCPDF library.
But the problem is TCPDF does not have any option to open existing file as template. So is there any way I could edit existing pdf file without including another bundle? Since I don't want to have multiple bundles doing almost exact same thing.
According to the documentation of TCPDF library, you can use the import method.
If your library doesn't allow it, use another one ?
Edit: KnpSnappy doesn't allow editing. Only generating.

php includes inside other includes

So my login check I have split into two sections that I tried putting in two different files and including them. First I will show the original code then the split code. I think my problem is with the link to the include. I try to use an absolute path. But it seems to be failing. My whole App is modular so I have global files set up outside of the rest of the App structure and I call the files as needed. I have also thought of just loading the functions through _autoload() but I don't know that this would solve my issue.
<?
//Inventory index.php
include$_SERVER['DOCUMENT_ROOT'].'/Globals/db_connect.php';
include$_SERVER['DOCUMENT_ROOT'].'/Globals/functions.php';
sec_session_start();if(login_check($mysqli)==true){?>
/////Html and or more php code to be executed. Usualy a mix of both.
<?}else{
echo ("You are not authorized to access this page, please login. <br/>");}?>
here is what I am trying to do....P.S. I know my code is kinda hard to read I am trying to format it for easier reading but I can process clumps better than I can spaced code. Not sure why.
<?
//Inventory index.php
include$_SERVER['DOCUMENT_ROOT'].'/Globals/auth1.php';?>
/////Html and or more php code to be executed. Usualy a mix of both.
<?}else{include$_SERVER['DOCUMENT_ROOT'].'/Globals/auth2.php';?>
What I think is happening is the includes in Auth1 are failing. are my absolute paths failing? Am I better off using _autoload().
You should always choose "autoloading" in favor of manual includes for multiple reasons.
Readable structure -- one class for each file and one folder for each namespace segment allows you to find anything in the directory structure of your project very fast.
Easy maintenance -- if you change the folder structure/position of your files (as well as their namespaces) you're done, no paths to be rewritten and verified.
Compatibility with other projects for example using PSR-0 or PSR-4. PSR-0 is meant for covering legacy code, PSR-4 should be used for new libraries.
Compatibility with package management software -- which expect some kind of predictable conventions to be respected. For example Composer expects either PSR-0 or PSR-4 and it enables autoloads for you.
On the subject of coding standards and formatting the same applies:
familiar structures are easier to recognize.
The decision is perfectly arbitrary; it's always your (or your team') choice. Either will work fine -- you will get used to any one of them.
Consistence is important, PSR-1 and PSR-2 are the lingua franca of both Symfony & friends as well as many other projects which use composer as their package management (and others).
I can suggest to use composer and it's autoloader which support different types of files loading. For production you can use --optimize option to make autoloading works better (as I remember composer scan all folders and build array of existing files)

Using Laravel bundle with CodeIgniter

I want to use Laravel Bootstrapper bundle http://bundles.laravel.com/bundle/bootstrapper with my CodeIgniter application.
How can i utilize autoloader functionality to use Bootstrapper bundle code in CodeIgniter in native PHP 5 fashion.
Button::make('Abc')->with_icon('ok');
Do you suggest to convert Bootstrapper bundle in CodeIgniter library or we can use it as it is.
I am using bootstrap for creating views, thus already including bootstrap specific css, js & images.
Please help, so that the bundle can be used with CodeIgniter
Why? It's not designed to work with CI, you'll probably have to mess about alot to get it working. See one of the many versions available for CI here https://github.com/vesparny/codeigniter-html5boilerplate-twitter-bootstrap.
Further more, I dont see any great advantage of having a bootstrap CI integration, if you do then go for it but I just use my own customised bootstrap and load it in as normal in template/view files. Works just fine and keeps all those UI/view bits and pieces separate for designers/Front-end coders who panic at the sight of php.
All this work trying to keep design, function and layout separate and people go to great effort to ruin it with something like this.

generation of multiple reports and zipping in codeigniter php

I want to generate multiple pdf reports on click of single print button and zip all the pdf's and store it in a folder.
Any help please. I need this functionality in my project.
According to https://stackoverflow.com/questions/560583/which-is-the-best-pdf-library-for-php
, the best pdf php library is FPDF.
They also mention that Zend has a nice PDF Lib. If you are using CodeIgniter you may wish to use the Zend library, as Zend libraries work nicely inside of CodeIgniter. (A simple Google search will show up several tutorials on using Zend libs as CI libs).
Someone on the CI Forums has instructions on using FPDF with CodeIgniter:
http://codeigniter.com/forums/viewthread/45365/
As for the second part of your question, wrapping data in a zip file is easily done with with CodeIgniter Zip Encoding library as detailed in the user guide.

Categories