Back

BLOG • DIGITAL INSIGHTS

Customizing the Built-in Sitefinity Excel Export

Sitefinity's built-in Excel export can be extended to include custom data. This post shows how to use IoC to replace the default ExcelExporter and add item owner information to every exported row, with working code for both the bootstrap step and the custom exporter class.

Sitefinity CMS

Motivation

Every now and then we need to export some content type from Sitefinity to Excel. Sitefinity allows content item exporting for dynamic content types. However, not many people know this can also be extended to include custom data. In this short post I will show you how to export items along with their owner information.

The Solution

Sitefinity uses IoC, and luckily the default exporter is registered - so extending and replacing it is straightforward.

The interface we need to implement is IDataItemExporter. However, in this case it is easier to extend the class Sitefinity provides rather than implementing everything from scratch. That class is ExcelExporter, found in the Telerik.Sitefinity.Data.Utilities.Exporters namespace.

Step 1 - Bootstrap in Global.asax.cs

As usual, we start with the bootstrapped event handling in Global.asax.cs:

Step 2 - Implement the Custom Exporter Class

Next, implement the class itself:

The built-in Sitefinity exporter exposes a few methods - the two we care about are:

  • CreateHeadersCells - creates the column headers.
  • CreateContentRow - creates a row for each data item.

Build the project and run it. If you now go to the Sitefinity backend, navigate to Administration - Module Builder, and click Actions - Export content for any module, you will see the owner of each item included in the exported Excel file.

Things to Note

  1. This will run for any content type. We use the IOwnership interface check to make sure the content type has an Owner property - which should be true for all dynamic content items, but it is good practice to ensure your code has everything it needs.
  2. If you want to apply this only for a specific type, you can add a type check and fall back to the base functionality for types you are not interested in.
  3. It is absolutely critical that headers and rows have the same number of columns - remember all those Excel and CSV files where things just don't match!

Read More

Explore more insights and case studies from our team.