Skip to main content

PhpSpreadsheet

A powerful pure PHP library for reading and writing spreadsheet files. Work with Excel, OpenDocument, CSV, and more — all from your PHP code.

Quick Start

Get up and running with PhpSpreadsheet in minutes

1

Install via Composer

Install PhpSpreadsheet using Composer:
composer require phpoffice/phpspreadsheet
2

Create your first spreadsheet

Create a new PHP file and add the following code:
<?php
require 'vendor/autoload.php';

use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;

$spreadsheet = new Spreadsheet();
$activeWorksheet = $spreadsheet->getActiveSheet();
$activeWorksheet->setCellValue('A1', 'Hello World!');

$writer = new Xlsx($spreadsheet);
$writer->save('hello_world.xlsx');
3

Run and verify

Execute your PHP script and open the generated hello_world.xlsx file. You should see “Hello World!” in cell A1.
PhpSpreadsheet requires PHP 8.1 or newer. Check your PHP version with php -v.

Key Features

Everything you need to work with spreadsheets in PHP

Multiple File Formats

Read and write Excel (XLSX, XLS), OpenDocument (ODS), CSV, HTML, and more

Formula Engine

Built-in calculation engine with 450+ Excel formula functions

Rich Formatting

Apply styles, fonts, colors, borders, and conditional formatting

Charts & Graphics

Create and embed charts, images, and drawings

Memory Efficient

Optimized for large files with chunked reading and caching

Data Operations

Autofilters, tables, data validation, and defined names

Popular Examples

Common use cases and code examples

Hello World

Create your first spreadsheet

Reading Spreadsheets

Load and parse existing files

Styling Cells

Apply formatting and styles

Working with Formulas

Add and calculate formulas

Creating Charts

Generate charts and graphs

Data Validation

Add input validation rules

Ready to get started?

Install PhpSpreadsheet via Composer and start working with spreadsheets in your PHP application today.

View Quickstart Guide

Build docs developers (and LLMs) love