Introduction
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, with no Microsoft Excel or Office automation dependency. It is a structural port of the existing Aspose.Cells FOSS for .NET library, exposed through the Aspose\Cells_FOSS namespace and built around the same Workbook, Worksheet, Cells, and Cell objects.
The library is MIT-licensed and requires only PHP’s own zip, dom, simplexml, and mbstring extensions — no native Office libraries and no compiled dependencies. It is used by cloning the repository directly and requiring its bundled autoload.php — no package manager or build step is involved.
What’s Included
Workbook creation and loading
Create a new Workbook or load an existing .xlsx file. LoadOptions exposes TryRepairPackage and TryRepairXml for loading a possibly-damaged file, and Workbook->LoadDiagnostics reports whether the load carried a data-loss risk.
use Aspose\Cells_FOSS\LoadOptions;
use Aspose\Cells_FOSS\Workbook;
$loadOptions = new LoadOptions();
$loadOptions->TryRepairPackage = true;
$loadOptions->TryRepairXml = true;
$workbook = new Workbook('input.xlsx', $loadOptions);
if ($workbook->LoadDiagnostics->HasDataLossRisk) {
echo 'Potential data loss risk detected during load.' . PHP_EOL;
}
Cell values and formulas
Read and write cell values with Cells["A1"]->PutValue(...), and write formula strings (e.g. =SUM(B2:B3)) that are stored verbatim in the saved file.
$sheet->Cells['A1']->PutValue('Product');
$sheet->Cells['B4']->Formula = '=SUM(B2:B3)';
Styling
Apply fonts, fill colors, and fill patterns through the Style, Font, Color, and FillPattern classes. Read a cell’s current style with GetStyle(), modify it, and reapply it with SetStyle().
use Aspose\Cells_FOSS\Color;
use Aspose\Cells_FOSS\FillPattern;
$headerStyle = $sheet->Cells['A1']->GetStyle();
$headerStyle->Font->IsBold = true;
$headerStyle->Pattern = FillPattern::Solid;
$headerStyle->ForegroundColor = Color::FromArgb(255, 34, 120, 212);
$sheet->Cells['A1']->SetStyle($headerStyle);
Page setup
Configure margins, orientation, scaling, fit-to-width/height, and print area through PageSetupModel.
Quick Start
git clone https://github.com/aspose-cells-foss/Aspose.Cells-FOSS-for-PHP.git
cd Aspose.Cells-FOSS-for-PHP
composer installuse 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');
Supported Formats
| Format | Extension | Read | Write |
|---|---|---|---|
| Excel Workbook | xlsx | ✓ | ✓ |
The library targets .xlsx only — there is no formula calculation engine (formula strings are stored, not evaluated), and no PDF, HTML, or image export in the current release.
Open Source & Licensing
Aspose.Cells FOSS for PHP is released under the MIT License. The source code is available on GitHub, and commercial use is permitted under the license terms.