PHPackages                             atwx/silverstripe-excel-export - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [File &amp; Storage](/categories/file-storage)
4. /
5. atwx/silverstripe-excel-export

ActiveSilverstripe-vendormodule[File &amp; Storage](/categories/file-storage)

atwx/silverstripe-excel-export
==============================

Silverstripe module offering DataFormatters to export DataObjects in Excel format.

v0.1.0(7mo ago)071[1 PRs](https://github.com/atwx/excel-export/pulls)MITPHP

Since Sep 24Pushed 7mo agoCompare

[ Source](https://github.com/atwx/excel-export)[ Packagist](https://packagist.org/packages/atwx/silverstripe-excel-export)[ RSS](/packages/atwx-silverstripe-excel-export/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (2)Versions (2)Used By (0)

Silverstripe Excel Export module
================================

[](#silverstripe-excel-export-module)

This Silverstripe module makes it easy to export a set of Silverstripe DataObjects to:

- Excel 2007 (XLSX)
- Excel 5 (XLS)
- CSV

This module is built by extending the standard [SilverStripe DataFormatter](http://api.silverstripe.org/3.1/class-DataFormatter.html).

Requirements
------------

[](#requirements)

- [silverstripe/cms](https://github.com/silverstripe/silverstripe-cms) &gt;=6.0
- [phpoffice/phpspreadsheet](https://github.com/PHPOffice/PhpSpreadsheet) &gt;=5.1.0

Installation
------------

[](#installation)

Install the module through [composer](http://getcomposer.org):

```
composer require atwx/silverstripe-excel-export
```

Exporting your DataObjects
--------------------------

[](#exporting-your-dataobjects)

There's 3 ways you can export your data to a spread sheet.

### Programmatically by calling the DataFormatter directly

[](#programmatically-by-calling-the-dataformatter-directly)

3 DataFormatters are provided:

- ExcelDataFormatter for XLSX
- OldExcelDataFormatter for XLS
- CsvDataFormatter for CSV

You can manually instantiate them to convert a list of DataObjects or a single DataObject.

```
$formatter = new ExcelDataFormatter();

// Will return an Excel Spreadsheet as a string for a single user
$filedata = $formatter->convertDataObject($user);

// Will return an Excel Spreadsheet as a string for a list of user
$filedata = $formatter->convertDataObjectSet(Member::get());

```

`convertDataObjectSet()` and `convertDataObject()` will automatically set the *Content-Type* HTTP header to an appropriate Mime Type.

You can also retrieve the underlying *PHPExcel* object and export your DataObject set to whatever format supported by *PHPExcel*.

```
// Get your Data
$formatter = new ExcelDataFormatter();
$excel = $formatter->getPhpExcelObject(SiteTree::get());

// Set up a writer
$writer = PHPExcel_IOFactory::createWriter($excel, 'HTML');

// Save the file somewhere on the server
$writer->save('/tmp/sitetree_list.html');

// Output the results back to the browser
$writer->save('php://output');

// Output the file to a variable
ob_start();
$writer->save('php://output');
$fileData = ob_get_clean();

```

### Add the GridFieldExcelExportButton to a GridField

[](#add-the-gridfieldexcelexportbutton-to-a-gridfield)

The `GridFieldExcelExportButton` allows your CMS users to easily export the data from a GridField to a spreadsheet.

```
$rowEntryConfig = GridFieldConfig_RecordEditor::create();
$rowEntryConfig->addComponent(new GridFieldExcelExportButton());
$rowEntryDataGridField = new GridField(
    "ContentRow",
    "Content Row Entry",
    $this->ContentRow(),
    $rowEntryConfig
);
$fields->addFieldToTab('Root.Main', $rowEntryDataGridField);

```

The above code snippet will display a split button allowing the user to export the GridField list to the format of their choice.

Unlike the SilverStripe [GridFieldExportButton](http://api.silverstripe.org/3.1/class-GridFieldExportButton.html), the `GridFieldExcelExportButton` will export all the fields of the provided DataObjects ... not just the summary fields.

You can also use the `GridFieldExcelExportAction` component. This button is added to each row and allows you to export individual records one at a time. Out of the box, `GridFieldExcelExportAction` will export to *xlsx*, but you can get it to export to *xls* or *csv* (e.g.: `new GridFieldExcelExportAction('csv')`).

`GridFieldExcelExportAction` and `GridFieldExcelExportButton` can be used in conjunction if you want to give both options to your users.

Customising the output
----------------------

[](#customising-the-output)

There's 2 ways you can control the output:

- Choose which fields to output ;
- Choose to use field label instead of fields names in the headers.

### Choose which fields to output

[](#choose-which-fields-to-output)

Because the `ExcelDataFormatter` extends [DataFormatter](http://api.silverstripe.org/3.3/class-DataFormatter.html), you can use methods like `setCustomFields()`, `setCustomAddFields()` or `setRemoveFields()` to control what fields will be present in the spread sheet.

```
$formatter = new ExcelDataFormatter();

// This formatter instead of returning every field of a DataObject, will only return 3 fields.
$formatter->setCustomFields(['ID', 'Title', 'LastEdited']);

// If youe DataObject has dynamic properties, you can reference them using setCustomAddFields().
$formatter->setCustomAddFields(['ChildrenCount']);

```

#### Defining a default column set

[](#defining-a-default-column-set)

You can customise the default column set that will be return for a specific DataObject class by defining a `getExcelExportFields()` method on your DataOject class.

This `getExcelExportFields()` method should return an array of fields following the same format used by `DataObject::inheritedDatabaseFields()`:

```
return [
    'ID' => 'Int',
    'Name' => 'Varchar',
    'Address' => 'Text'
];

```

You may also reference relationships in this array or dynamic properties:

```
return [
    'Owner.Name' => 'Varchar',
    'Category.Title' => 'Varchar',
    'ChildrenCount' => 'Int',
];

```

This will also allow you to control the order the fields appear in the Spread Sheet. Note that ID will always be the first field and cannot be removed.

This behavior can be overriden for specific instances of `ExcelDataFormatter` by calling the `setCustomFields()` method.

Use field labels or field names as column headers
-------------------------------------------------

[](#use-field-labels-or-field-names-as-column-headers)

Out of the box, the actual field names will be used as column header. (e.g.: `FirstName` rather than `First Name`).

You can customise this behavior and use the Field Labels as define on your DataObject class instead. When generating the header row, `ExcelDataFormatter` will call the `fieldLabel()` method on your Data Object to decide what string to use in each header.

### Change the default for all `ExcelDataFormatter`

[](#change-the-default-for-all-exceldataformatter)

In you YML config, you can use the following syntax to change the default headers.

```
ExcelDataFormatter:
  UseLabelsAsHeaders: true

```

### Override the default for a specific instance

[](#override-the-default-for-a-specific-instance)

You may change the default behavior for a specific instance.

```
$formatter->setUseLabelsAsHeaders(true);

```

### Thanks to

[](#thanks-to)

Thanks to [Firebrand](https://firebrand.nz/) who originally developed this module. This version adds compatibility for silverstripe 6.

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance66

Regular maintenance activity

Popularity5

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity25

Early-stage or recently created project

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

227d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/64d979993815fa2d2ea95b3fd72b4f43e95a631ce569f4f1c0330786971b5fc2?d=identicon)[adiwidjaja](/maintainers/adiwidjaja)

![](https://www.gravatar.com/avatar/63d164bab71fc011430a89319c7e170995fa494d7d122feaed5a370f39c89d12?d=identicon)[HenrikBormann](/maintainers/HenrikBormann)

---

Top Contributors

[![maxime-rainville](https://avatars.githubusercontent.com/u/1168676?v=4)](https://github.com/maxime-rainville "maxime-rainville (9 commits)")[![ss-koshala](https://avatars.githubusercontent.com/u/65384702?v=4)](https://github.com/ss-koshala "ss-koshala (9 commits)")[![HenrikBormann](https://avatars.githubusercontent.com/u/88386045?v=4)](https://github.com/HenrikBormann "HenrikBormann (4 commits)")[![Zazama](https://avatars.githubusercontent.com/u/7694808?v=4)](https://github.com/Zazama "Zazama (3 commits)")[![sanderha](https://avatars.githubusercontent.com/u/6941043?v=4)](https://github.com/sanderha "sanderha (1 commits)")

### Embed Badge

![Health badge](/badges/atwx-silverstripe-excel-export/health.svg)

```
[![Health](https://phpackages.com/badges/atwx-silverstripe-excel-export/health.svg)](https://phpackages.com/packages/atwx-silverstripe-excel-export)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
