PHPSpreadsheet installation and basic usage | Make an Excel File in PHP | PHPSpreadsheet Tutorial #1

PHPSpreadsheet installation and basic usage | Make an Excel File in PHP | PHPSpreadsheet Tutorial #1


Hi everyone. Welcome to my php tutorial video. in this video, i’m about to explain how to use PHP Spreadsheet to generate excel file in PHP. So what is the difference with the PHP Excel library? In fact, this library are made by the same creator of PHP Excel. As the readme says, PHP Spreadsheet is simply the next version of PHP Excel which breaks compatibility to improve the code base quality. and because all efforts have shifted to PHP Spreadsheet, PHP Excel will no longer be maintained. So you should start consider using this library instead of old PHP Excel for your next project. let’s take a look at the documentation. this library supported more file format and also able to make a pdf file out of spreadsheet. You need php version 5.6 or newer to run this library. And also some php extension. For the installation, this library needs composer to manage it’s dependency. For those who are not familiar with composer, composer is a dependency manager for PHP. At it’s getting started page, you can see how to install composer on linux by using the installer. either locally or globally. Or in windows, you can download the executable installer, run it, and it will take care of the rest. Composer is a text-based program so you need to run it from command terminal. In my machine, i already have composer. Before proceeding, make sure that composer is already up and running in your local machine. Now, let’s make a new directory in the root directory. From your terminal, change the current working directory to our new directory by using cd command followed by the path. We can install PHP Spreadsheet by using it’s repo name. The repo name format should looks like the lower-cased github url. For now, let’s just paste the composer command. Composer will make a new json file which contain package name installed in our project. Then composer will try to download the required packages required by PHP Spreadsheet. Looks like we’re encountering a problem here. if we read the message carefully, we’ll see that one of our package requires an php extension called fileinfo, which somehow is not available in my machine. Now let’s make it available. Open the php configuration file. Usually called php.ini find the text “fileinfo”. It seems that the fileinfo extension is commented out in my configuration. So let’s fix it. You may also run through same problem but with different extension in your machine. If that happens, just do a quick google search on how to enable the required extension in your PHP. if nothing goes wrong, the required dependency will be installed without any error. you can also see here that PHPSpreadsheet recommends you to install libraries to handle pdf and render chart. there is a vendor directory created by composer. inside, you will find all package installed in this project and all dependencies. there is a file called autoload. we just need to call this autoload in our script in order to use PHPSpreadsheet. the good thing of using composer is you can add libraries like fpdf, domPDF, or tcpdf with just one command. and use the same autoload file in order to use it in your script. in order to use this library, you can use autoload.php or directly call Bootstrap.php inside PHPSpreadsheet src directory. basically both does the same thing, which is calling the autoload. i recommend you to use autoload.php. so let’s make the spreadsheet script i named it simple1.php. first, just call the autoload file. then to use the spreadsheet library, we call them here using : use PhpOfficePhpSpreadsheetSpreadsheet. for now, let’s just see the getting started page and copy the hello world script there. now let me explain what this codes does. first we call the autoload script. then load the PHPSpreadsheet library by it’s namespace. and also the xlsx writer class to make an excel file. you can read more about php namespace in the link i’ve put in description. then we make a new spreadsheet object. get the current active sheet, which is first sheet. set the value of cell A1 to “Hello World !” next, make an xlsx object with the spreadsheet we’ve just created. save it into a file named hello world dot xlsx in the server. now let’s execute the script in our browser. sorry, seems like i forgot to start the apache server. see there’s nothing happening in browser. because as i’ve said before, the file result is saved in server. now what if instead of saved in the server, i want this file to be downloaded in the browser. to do that, we can simply redirect the page to our file after generation is done. but i don’t recommend this way. let’s just try it out for now. looks like i forgot the semicolon and the name is somewhat wrong. as i have said, i don’t recommend this way. now, the recommended way is to use IOFactory class which came with PHPSpreadsheet. IOFactory are built-in class which allows us to read from and write into files. IOFactory are also shipped with another PHPOffice libraries such as PHPWord and PHPPresentation. now let’s copy our script into a new one. let’s just remove the writing part and use IOFactory instead. we will use createWriter method of IOFactory. also do not forget to load the IOFactory class in our script. we don’t need to save the excel as a file, so we save it directly to PHP output. let’s try it out. it looks scrambled. just alot of strange character. this is not what we expected. this is because what we do is making an excel binary file, yet the server and browser treats it as a normal text file. let’s tell the browser and the server to treat this file as an excel file by changing the header. let’s do google’s magic to see what’s the excel header look like. let’s copy the content type header to define the content type as an excel file. it’s now working. but the file name is somewhat wrong for an excel file. let’s add something to the header. and now it’s working as expected. this concludes this chapter of tutorial. i put the link to the source codes in the description. feel free to ask anything in the comment section. please kindly like my video and subscribe to my channel. see you in the next chapter.

Junior PHP Developer

Junior PHP Developer


I’m Alex, Co-Founder
of Campaign Amp and CTO. The biggest thing I think
that our developers love is the variety. We’re working on over 100
different APIs connections. We’re working in cool
industries like entertainment publishing all sorts
of live events. And the variety you
get with working in these different
industries is huge. The great thing about
being a developer is that you don’t
necessarily have to know the syntax of a
particular programming language to understand development. And they’re the
kind of people we want those passionate
problem solvers. They’re the guys
who, if they don’t know a particular piece of
code, they’ll go and learn it. And they’re the people that
we’re really keen to get into our team.

PHP Inbox System Introducing

PHP Inbox System Introducing


How to create PHP Inbox System from scratch,
we’ll use HTML,PHP,Jquery,CSS People who don’t know much about PHP don’t worry I’ll
try to explain it more Here i’m showing only 5 messages on the page, and i have pagination
moving throught messages Also i’m showing on the table the message “ID”, “From”, “Email”,
“Subjec”t, “Message”, “Sent time” and the “message” is opened or not, we will take a look to the
database i created a Database i called it “Messages” I created table inside it and called it “Messages” the “messages” table contains “ID”, “From”, “Email”, “Subject”, “Message Content”, “Date”, “Time”, “Open” And If message is opened it will be 1, if not it will be 0, here i’m showing
inside every message “From”, “Email”, “Date”, “Time” Time Format is like Facebook, Also you can
Delete The Message Watch Part 1 of this tutorials now.

02 – FizzBuzz rules for TDD on php course – zeroToMasters

02 – FizzBuzz rules for TDD on php course – zeroToMasters


You are going to be given a number. Ok, and depending on that number, you will need to return a different output so let’s say you are given a number which is divisble by 3 in that case you need to return Fizz If it’s divisible by 5 then you need to return you need to return Buzz Any other number, you need to return the number itself However what happen when that number is divisible by 3 and 5 In that case, you need to return FizzBuzz good. It’s very basic but let me throw some examples there. Just to be sure we are all on the same page So if we are given 1, we need to return 1. Because it’s not divisible by 3 neither by 5 If we are given 2, we need to return 2 Again. It’s not divisible by 3 neither by 5 If we are given 3, it’s divisible by 3 so we return Fizz 4 is not divisible by 3 or 5, so 4 5 we need to return Buzz because it’s divisible by 5 6 is divisible by 3, so we need to return Fizz and we can keep going and going until we get to the number 15 which is the first one divisible by 3 and 5 and in that case we need to return FizzBuzz

Configuring Nginx to support PHP on Debian/Ubuntu (nginx + php-fpm)

Configuring Nginx to support PHP on Debian/Ubuntu (nginx + php-fpm)


In this video I will explain how to configure the Nginx server to support PHP on the Debian/Ubuntu operating system Usually, the main configuration file nginx.conf is located in the /etc/nginx directory In it, one can distinguish block and simple directives that relate to a specific Nginx module This file contains global settings (basic, SSL, logging, Gzip) that can be redefined for a specific virtual host, which are loaded at the very end This directive includes website configuration files, for example with the name example.com.conf This directive includes virtual hosts (server blocks) through symbolic links, for example with the name example.com The configuration files that describe your domains should be located in the /etc/nginx/sites-available directory The /etc/nginx/sites-enabled directory should contain symbolic links to the active virtual hosts Let’s look at the default server configuration /etc/nginx/sites-available/default In this file, the listen directive sets the listening port 80 (HTTP) for IPv4 and IPv6 connections The root directive sets the root directory for requests, i.e. directory where all the files of your sites will be located By default, index.html, index.htm, index.nginx-debian.html files are used as the index The server name is not specified Before setting up Nginx to work with the PHP handler, we find out its version by running the command in the terminal Install PHP by running the command in the terminal Edit the server configuration file /etc/nginx/sites-available/default, adding PHP support Save the changes and close the file Check the configuration for validity by running the command in the terminal Now apply the configuration changes by running the command in the terminal Let’s verify that Nginx correctly transfers files with the .php extension to our PHP handler Create a test file that will return information about our server by running the command in the terminal Let’s make sure that the Nginx server correctly displays the content generated by the PHP script by opening this page in the browser If you correctly configured Nginx for PHP support, a similar page will be displayed After checking for security reasons, you need to delete this file by running the command in the terminal