Working with Core API
Overview
Workbook is the entry point for every task in Aspose.Cells FOSS for PHP: create or
load one, reach its worksheets and cells, then save.
Creating and Saving a Workbook
<?php
require __DIR__ . '/vendor/autoload.php';
use Aspose\Cells_FOSS\Workbook;
$workbook = new Workbook();
$sheet = $workbook->Worksheets[0];
$sheet->Name = 'Report';
$sheet->Cells['A1']->PutValue('Revenue');
$workbook->Save('report.xlsx');Loading an Existing Workbook with Repair Options
<?php
require __DIR__ . '/vendor/autoload.php';
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;
}Typed Values and Formulas
Cell::PutValue() stores a typed value; the Formula property stores a formula string
(not evaluated by this library):
$sheet->Cells['A2']->PutValue(1.99);
$sheet->Cells['B4']->Formula = '=SUM(B2:B3)';Styling
Cell::GetStyle() returns the cell’s current Style; mutate its Font, Pattern, and
ForegroundColor, then write it back with Cell::SetStyle():
use Aspose\Cells_FOSS\Color;
use Aspose\Cells_FOSS\FillPattern;
$style = $sheet->Cells['A1']->GetStyle();
$style->Font->IsBold = true;
$style->Font->Color = Color::FromArgb(255, 255, 255, 255);
$style->Pattern = FillPattern::Solid;
$style->ForegroundColor = Color::FromArgb(255, 34, 120, 212);
$sheet->Cells['A1']->SetStyle($style);Tips and Best Practices
Cell::GetStyle()returns a copy, not a live reference — always callSetStyle()with the mutated object to apply changes.- Saving only supports
.xlsx.
Common Issues
| Issue | Cause | Fix |
|---|---|---|
| Load fails on a questionable file | Corrupt ZIP or malformed XML | Set TryRepairPackage/TryRepairXml to true on LoadOptions, then check LoadDiagnostics |
| Formula shows a stale result | This library does not calculate formulas | Open the file in Excel/LibreOffice, which recalculates on open |
FAQ
Does PutValue() accept any PHP type?
PutValue() accepts the typed values confirmed in the API surface (strings, numbers,
booleans); consult the API reference for
the exact overload set on Cell.
Why doesn’t my formula show a computed result?
Aspose.Cells FOSS for PHP stores the formula text only — it does not include a calculation engine. Open the saved file in a spreadsheet application to see the computed value.
API Reference Summary
| Class/Method | Description |
|---|---|
Workbook | Entry point; represents an Excel workbook |
Workbook::Save($path) | Writes the workbook as .xlsx |
Cell::PutValue($value) | Stores a typed value |
Cell->Formula | Formula text stored on a cell |
Cell::GetStyle() / Cell::SetStyle($style) | Reads/writes cell formatting |
LoadOptions->TryRepairXml / TryRepairPackage | Enables repair during load |