PHPOffice/PhpSpreadsheet · error · PhpOffice\PhpSpreadsheet\Exception
Can only get pseudo-border for supervisor.
Error message
Can only get pseudo-border for supervisor.
What it means
Borders::getAllBorders() returns the 'allBorders' pseudo-border, which exists only on a supervisor Borders instance — the one attached to a Style used through $sheet->getStyle(...). A standalone (non-supervisor) Borders object, e.g. from new Style() or new Borders(), has no worksheet/range context to fan operations out to, so the getter throws 'Can only get pseudo-border for supervisor.'
Source
Thrown at src/PhpSpreadsheet/Style/Borders.php:257
{
return $this->bottom;
}
/**
* Get Diagonal.
*/
public function getDiagonal(): Border
{
return $this->diagonal;
}
/**
* Get AllBorders (pseudo-border). Only applies to supervisor.
*/
public function getAllBorders(): Border
{
if (!$this->isSupervisor) {
throw new PhpSpreadsheetException('Can only get pseudo-border for supervisor.');
}
return $this->allBorders;
}
/**
* Get Outline (pseudo-border). Only applies to supervisor.
*/
public function getOutline(): Border
{
if (!$this->isSupervisor) {
throw new PhpSpreadsheetException('Can only get pseudo-border for supervisor.');
}
return $this->outline;
}
/**View on GitHub (pinned to 65b080eef4)
Solutions
- Work through the supervisor route: $spreadsheet->getActiveSheet()->getStyle('A1')->getBorders()->getAllBorders().
- On standalone Borders, set the four concrete sides individually (top/bottom/left/right) or applyFromArray per side.
- To apply all/outline/inside borders to a range, call $sheet->getStyle($range)->applyFromArray(['borders' => ['allBorders' => [...]]]) which operates in supervisor mode.
Example fix
// before
$borders = new \PhpOffice\PhpSpreadsheet\Style\Borders();
$borders->getAllBorders()->setBorderStyle(...); // throws
// after
$sheet->getStyle('A1:D10')->applyFromArray([
'borders' => [
'allBorders' => ['borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN],
],
]); Defensive patterns
Strategy: validation
Validate before calling
// Only call pseudo-border getters on a supervisor obtained via getStyle()
$style = $sheet->getStyle('A1:D10');
$allBorders = $style->getBorders()->getAllBorders(); // OK: supervisor
$allBorders->applyFromArray(['borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN]); Type guard
/** No public isSupervisor flag exists — narrow by origin instead. */
function bordersAreSupervisor(\PhpOffice\PhpSpreadsheet\Worksheet\Worksheet $sheet, string $range, \PhpOffice\PhpSpreadsheet\Style\Borders $b): bool
{
// supervisor Borders are exactly those reached via $sheet->getStyle($range)->getBorders()
return $b === $sheet->getStyle($range)->getBorders();
} Try / catch
try {
$borders->getAllBorders()->applyFromArray($arr);
} catch (\PhpOffice\PhpSpreadsheet\Exception $e) {
// non-supervisor: set each concrete side instead
foreach (['Top', 'Bottom', 'Left', 'Right'] as $side) {
$borders->{"get$side"()}->applyFromArray($arr);
}
} Prevention
- Always obtain styles via $sheet->getStyle($range) before touching pseudo-borders.
- Never construct Style/Borders with new for range-level operations.
- Prefer applyFromArray() with 'allBorders'/'outline'/'inside' keys at the range level.
When it happens
Trigger: (new \PhpOffice\PhpSpreadsheet\Style\Borders())->getAllBorders(); (new Style())->getBorders()->getAllBorders(); reaching into a cloned/detached style component (e.g. via getStyle()->getBorders() on an unattached Style) and then calling getAllBorders(); same for getOutline()/getInside().
Common situations: Building Style objects by hand to pass into applyFromArray and accidentally chaining pseudo-border getters; inspection/reflection code that iterates every style sub-object; porting snippets that assumed the object came from getStyle().
Related errors
- Cannot get shared component for a pseudo-border.
- No default style found for this workbook
- CellXf index is out of bounds.
- CellStyleXf index is out of bounds.
- Text rotation {$angleInDegrees} should be a value between -9
AI-assisted analysis of PHPOffice/PhpSpreadsheet@65b080eef4 (2026-08-17).
Data as JSON: /api/errors/211b8a1cdef1f18a.
Report an issue: GitHub.