PHPackages                             firebrandhq/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. firebrandhq/silverstripe-excel-export

ActiveSilverstripe-vendormodule

firebrandhq/silverstripe-excel-export
=====================================

Silverstripe module offering DataFormatters to export DataObjects in Excel format.

0.2.2(5y ago)82.9k14[2 issues](https://github.com/firebrandhq/excel-export/issues)MITPHP

Since Sep 21Pushed 5y ago3 watchersCompare

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

READMEChangelog (2)Dependencies (2)Versions (7)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;=3.1
- [phpoffice/phpexcel](https://github.com/PHPOffice/PHPExcel) &gt;=1.8

Suggestions
-----------

[](#suggestions)

- [silverstripe/restfulserver](https://github.com/silverstripe/silverstripe-restfulserver) &gt;=3.1

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

[](#installation)

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

```
composer require firebrandhq/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.

### Call via the SilverStripe RestfulServer Module

[](#call-via-the-silverstripe-restfulserver-module)

The [SilverStripe RestfulServer Module](https://github.com/silverstripe/silverstripe-restfulserver) allows you to turn any SilverStripe website into a RESTFul Server.

If you use the *SilverStripe RestfulServer Module* in conjunction with the *Silverstripe Excel Export module*, you'll be able to dynamically export any DataObject set just by entering the right URL in your browser.

#### Access control

[](#access-control)

Obviously, you don't want everyone to be able to download any data off your website. The SilverStripe RestfulServer Module will only return results for DataObject with the `$api_access` property set.

```
private static $api_access = true;

```

Additionally, access to individual DataObjects is controlled by the `canView` function.

[Configuration the SilverStripe RestfulServer Module ](https://github.com/silverstripe/silverstripe-restfulserver#configuration)

#### Getting to the data

[](#getting-to-the-data)

Exporting your data is just as easy as entering a URL.

- Get a list of all Pages in Excel 2007: **
- Get a list of all Pages in Excel 5: **
- Get a list of all Pages in CSV: **
- Limit the list to 10 results: **
- Return a single record: **
- Drill down into relationships: **

[SilverStripe RestfulServer Module Supported operations](https://github.com/silverstripe/silverstripe-restfulserver#supported-operations)

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);

```

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance15

Infrequent updates — may be unmaintained

Popularity29

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 75% of commits — single point of failure

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

Every ~443 days

Total

5

Last Release

2113d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/eb656fdb4734a2490b0b88295b5d35f59e0ee709611ed7b7b0fdbc33eaad2c82?d=identicon)[firebrandhq](/maintainers/firebrandhq)

---

Top Contributors

[![maxime-rainville](https://avatars.githubusercontent.com/u/1168676?v=4)](https://github.com/maxime-rainville "maxime-rainville (9 commits)")[![marc-firebrand](https://avatars.githubusercontent.com/u/33405402?v=4)](https://github.com/marc-firebrand "marc-firebrand (1 commits)")[![mark-a-j-adriano](https://avatars.githubusercontent.com/u/11882563?v=4)](https://github.com/mark-a-j-adriano "mark-a-j-adriano (1 commits)")[![sanderha](https://avatars.githubusercontent.com/u/6941043?v=4)](https://github.com/sanderha "sanderha (1 commits)")

### Embed Badge

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

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

###  Alternatives

[silvershop/core

Provides an ecommerce product catalog, shopping cart, and order management system

11340.0k42](/packages/silvershop-core)[silverstripe-terraformers/gridfield-rich-filter-header

Rich filter header component for GridField

1325.7k1](/packages/silverstripe-terraformers-gridfield-rich-filter-header)[sunnysideup/ecommerce

Silverstripe E-commerce Application

257.2k79](/packages/sunnysideup-ecommerce)[silverstripe/superglue

102.2k](/packages/silverstripe-superglue)

PHPackages © 2026

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