Alternative for PHP_excel

Alternative for PHP_excel

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

Alternatives to php-excel for Customized XLSX Export

The default behavior of libraries like php-excel often falls short when you need granular control over cell styling, merged ranges, or complex conditional formatting. Relying on a single package to handle everything frequently leads to brittle code that is difficult to maintain once the requirements outgrow simple CSV-like structures. The core challenge isn't just generating a binary file; it's doing so while preserving the rich formatting properties of Microsoft Excel without forcing a dependency on the proprietary OOXML schema directly or using heavy-weight dependencies like PhpSpreadsheet if you are looking for lighter alternatives.

When evaluating options, the landscape splits primarily between two approaches: leveraging existing robust libraries that offer extensive feature sets versus utilizing raw PHP to construct the Open XML format manually. The former provides stability but can introduce significant bloat. The latter offers maximum flexibility and minimal overhead but requires a deep understanding of how Excel files are structured internally.

For developers working within the Laravel ecosystem, https://laravelcompany.com often highlights the importance of choosing the right stack for performance-critical tasks; sometimes, avoiding heavy dependencies is exactly what keeps an application responsive. If you need php-excel-level functionality without the overhead, PhpSpreadsheet remains the industry standard. However, if your goal is strictly custom formatting and you want to avoid the massive footprint of a full library, constructing the file manually using PHP's built-in functions is a viable strategy.

The Manual Open XML Approach

Excel files (.xlsx) are essentially ZIP archives containing XML documents. Each XML file within the archive defines a specific part of the spreadsheet: styles, sheets, shared strings, or relationships. To export data with custom formatting without external libraries, you must replicate this structure programmatically.

The process involves creating a temporary directory, populating it with specific XML files that define your content and styles, zipping them up, and renaming the result to .xlsx. The critical part is defining the <style> elements within the styles.xml file. Here, you map attributes like bgColor, fontColor, or borderBottom directly to the cells in your output.

While this approach eliminates the need for Composer dependencies, it requires careful handling of namespaces and XML schemas. A common pitfall is failing to properly escape special characters within the XML strings or misaligning cell references with their corresponding row/column indices. This method is ideal for highly specific formatting needs where you want total control over every byte written to the disk.

Leveraging PhpSpreadsheet for Complex Needs

If your customization requirements involve complex formulas, data validation, or intricate conditional formatting rules that are difficult to encode in raw XML, PhpSpreadsheet is the pragmatic choice. It abstracts the Open XML complexity into a clean API while retaining full access to the underlying structure when necessary.

You can instantiate a Spreadsheet object and append sheets as needed. To apply custom formatting, you work with cell style objects:

$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();

// Define a style for bold text with a specific background color
$style = [
    'font' => ['bold' => true, 'name' => 'Arial'],
    'fill' => ['fillType' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID, 'color' => ['argb' => 'FFD3D3D3']],
    'alignment' => ['horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER]
];

// Apply style to a range of cells (e.g., A1:C5)
$sheet->getStyle('A1:C5')->applyFromArray($style);

// Write data
$sheet->setCellValue('A1', 'Custom Header');
$sheet->fromArray($yourDataArray, null, 'A2');

// Save the file with custom filename
$writer = \PhpOffice\PhpSpreadsheet\Writer\Xlsx::create($spreadsheet);
$writer->save('/path/to/file.xlsx');

This pattern allows you to mix simple data writing with sophisticated styling logic. The trade-off is memory usage; loading large datasets into a Spreadsheet object can strain resources if not processed in chunks or managed carefully.

Conclusion on Library Selection

Choosing between a manual implementation and a library like PhpSpreadsheet depends entirely on the complexity of your formatting rules and your tolerance for dependency size. If you need to generate thousands of reports with identical, complex layouts, the initial setup cost of configuring styles might be amortized over volume. Conversely, for one-off exports or dynamic user-generated reports, the flexibility of a library that handles the XML schema internally usually outweighs the performance hit.

Our network