1. Products
  2.   Aspose.Cells
  3.   Aspose.Cells FOSS for PHP

Aspose.Cells FOSS for PHP

Create, load, modify, and save Excel .xlsx workbooks from PHP — free and open-source, zero Microsoft Office dependency.

Open-Source PHP Library for Excel Spreadsheets

Aspose.Cells FOSS for PHP is a free, open-source library for creating, loading, modifying, and saving Excel workbooks in .xlsx format from PHP 8.1+ applications, without requiring Microsoft Excel or any Office automation dependency. The library is a structural port of the established Aspose.Cells FOSS for .NET codebase, exposed through a clean object API built around Workbook, Worksheet, Cells, and Cell — the same core objects developers already know from Aspose’s other Cells FOSS libraries. Create a new workbook or load an existing one, write and read cell values and formulas, apply fonts, fills, borders, and alignment through the Style class, and configure page setup (margins, orientation, scaling, print area) through PageSetupModel. The library is MIT-licensed and requires only PHP’s own zip, dom, simplexml, and mbstring extensions — no native Office libraries, no COM automation, no compiled dependencies. Install it by cloning the repository and requiring its bundled autoload.php directly — no build step or package manager is involved (see the Quick Start example below). For the enterprise product family, see Aspose.Cells — Enterprise Product Family.

Create, Load, and Save Excel Workbooks

  • XLSX read/write: Create a new Workbook or load an existing .xlsx file.
  • Cell access: Read and write values with Cells["A1"]->PutValue(...) bracket-style indexing.
  • Formulas: Write formula strings (e.g. =SUM(B2:B3)) stored verbatim in the saved file.
  • Load repair options: LoadOptions exposes TryRepairPackage and TryRepairXml to recover from a damaged source file before it is fully parsed.
  • Load diagnostics: Workbook->LoadDiagnostics reports data-loss risk discovered while loading.

Where Aspose.Cells FOSS for PHP Can Be Used

  • Data export: Generate .xlsx reports directly from PHP application data.
  • Report generation: Build styled, branded spreadsheets without Office or LibreOffice installed.
  • Data repair pipelines: Load a possibly-damaged workbook with repair options enabled and re-save a clean copy.
  • CI/CD automation: Generate test-result or build-artifact spreadsheets inside PHP-based Docker containers.

Styling and Page Setup

  • Font and fill: Apply bold, color, and fill pattern through Style, Font, Color, and FillPattern.
  • Style retrieval: Read a cell’s current style with GetStyle() before modifying and reapplying it with SetStyle().
  • Page setup: Configure margins, orientation, scaling, fit-to-width/height, and print area via PageSetupModel.
  • Validation: Validation-related classes model cell-level data validation rules.

Developer Experience

Aspose.Cells FOSS for PHP requires PHP 8.1 or later and the zip, dom, simplexml, and mbstring extensions — all either built into standard PHP distributions or widely available. Install it by cloning the repository and requiring its bundled autoload.php directly (see the Quick Start example below); no build step or compiled dependency is involved.

The library is a structural port of Aspose.Cells FOSS for .NET, so method names follow the same PascalCase convention as that library rather than typical PHP camelCase. It is MIT-licensed, hosted on GitHub, and accepts bug reports and pull requests.

Create a Styled Workbook and Save It

Create a new Workbook, write values and a formula to cells, apply a bold white-on-blue header style, and save the result as .xlsx. This example was run against the real library as part of this launch’s verification.

git clone https://github.com/aspose-cells-foss/Aspose.Cells-FOSS-for-PHP.git
cd Aspose.Cells-FOSS-for-PHP
composer install
use Aspose\Cells_FOSS\Color;
use Aspose\Cells_FOSS\FillPattern;
use Aspose\Cells_FOSS\Workbook;

$workbook = new Workbook();
$sheet = $workbook->Worksheets[0];

$sheet->Name = 'Products';
$sheet->Cells['A1']->PutValue('Product');
$sheet->Cells['B1']->PutValue('Price');
$sheet->Cells['A2']->PutValue('Apple');
$sheet->Cells['B2']->PutValue(2.99);
$sheet->Cells['A3']->PutValue('Orange');
$sheet->Cells['B3']->PutValue(1.99);
$sheet->Cells['B4']->Formula = '=SUM(B2:B3)';

$headerStyle = $sheet->Cells['A1']->GetStyle();
$headerStyle->Font->IsBold = true;
$headerStyle->Font->Color = Color::FromArgb(255, 255, 255, 255);
$headerStyle->Pattern = FillPattern::Solid;
$headerStyle->ForegroundColor = Color::FromArgb(255, 34, 120, 212);

$sheet->Cells['A1']->SetStyle($headerStyle);
$sheet->Cells['B1']->SetStyle($headerStyle);

$workbook->Save('products.xlsx');

Load a Workbook with Repair Options Enabled

Load an existing .xlsx file with package- and XML-level repair enabled, check the load diagnostics for data-loss risk, then modify and re-save it. This example was also run against the real library as part of this launch’s verification.

use Aspose\Cells_FOSS\LoadOptions;
use Aspose\Cells_FOSS\Workbook;

$loadOptions = new LoadOptions();
$loadOptions->TryRepairPackage = true;
$loadOptions->TryRepairXml = true;
$loadOptions->StrictMode = false;

$workbook = new Workbook('input.xlsx', $loadOptions);

if ($workbook->LoadDiagnostics->HasDataLossRisk) {
    echo 'Potential data loss risk detected during load.' . PHP_EOL;
}

$workbook->Worksheets[0]->Cells['A1']->PutValue('Updated');
$workbook->Save('updated.xlsx');

Frequently Asked Questions

What PHP version is required?

PHP 8.1 or later, with the zip, dom, simplexml, and mbstring extensions enabled.

Are there any native dependencies?

No. The library is pure PHP; no native extensions beyond the standard ones listed above.

How do I install it?

git clone https://github.com/aspose-cells-foss/Aspose.Cells-FOSS-for-PHP.git — see the Installation Guide for the full steps: clone the repository and require the bundled autoload.php.

Which formats can be read and written?

Only .xlsx (Excel Open XML). There is no .xls, .csv, or .ods support in this release.

Does the library calculate formulas?

No. The Formula property on Cell stores the formula text as-is; the value is recalculated by Excel or another spreadsheet application when the file is opened.

Is a license key required?

No. Aspose.Cells FOSS for PHP is distributed under the MIT License (the license text is included in the repository) with no license key or activation step required to use the library.

What should I do if a file fails to load?

Pass a LoadOptions instance with TryRepairPackage and TryRepairXml set to true to the Workbook constructor, then check $workbook->LoadDiagnostics->HasDataLossRisk after loading.

  

Support and Learning Resources