PHPSpreadsheet provides a rich API that allows you to set up lots of cell and document properties, including styles, images, dates, functions, etc. You can use it in any Excel spreadsheet you want.

When debugging your setup, make sure that the correct files are introduced and instantiated.

use PhpOfficePhpSpreadsheetSpreadsheet;

$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet(); 

The font

The first line sets the A7 through B7 cells to bold, Arial, 10-point font; Line 2 sets the B1 cell to bold.



Set the text color to red.


The picture

You can load images into Excel.

$drawing = new PhpOfficePhpSpreadsheetWorksheetDrawing();

Column width

Set the width of column A to 30 characters.


If you want to automatically calculate column widths, you can do this:


Set the default column width to 12.


Line height

Set the height of row 10 to 100pt.


Sets the default row height.



Set the A1 cell to be horizontally centered.

$styleArray = [
    'alignment' => [
        'horizontal' => PhpOfficePhpSpreadsheetStyleAlignment::HORIZONTAL_CENTER,


Merge A18 through E22 into a single cell.


Break up

Split the merged cells.


A border

Add a red border between B2 and G8.

$styleArray = [
    'borders' => [
        'outline' => [
            'borderStyle' => PhpOfficePhpSpreadsheetStyleBorder::BORDER_THICK,
            'color' => ['argb' => 'FFFF0000'],

Sheet title

Sets the current sheet title.



Set the date format.

    ->setCellValue('D1', '2018-06-15');


A newline

Use n to wrap a cell, equivalent to (Alt +”Enter”).



Set the cell to hyperlink form.

$spreadsheet->getActiveSheet()->setCellValue('E6', '');

Using the function

Calculate the SUM of cells between B5 and C5 using SUM. The same applies to other functions: MAX, MIN, AVERAGE.

    ->setCellValue('B7', '=SUM(B5:C5)'); 

Set document properties

You can set Excel document properties.

$Spreadsheet ->getProperties() ->setCreator(" HelloWeba ") // Author ->setLastModifiedBy("Yuegg") // Last Modifier ->setTitle("Office" 2007 XLSX Test Document") // Title -> SetSubject ("Office 2007 XLSX Test Document") // Subtitle -> SetDescription ("Test Document for" Office 2007 XLSX, Generated using PHP classes.") and set keyword ("office 2007 openxml PHP "); / / classification

PHPSpreadshee also offers CSV, PDF, HTML and XML file processing interfaces in addition to Excel.

Use more set document please refer to website: