1. Overview
This sample shows how you can create a custom export provider that overrides the built-in Excel provider to customize or extend it, as an alternative to providing an entirely separate implementation. You can adapt this sample to use any of the methods described below to accomplish your own custom functionality.
2. Getting started
This sample relies on capabilities added to Custom Analytics starting in version 26.4 and requires this version or higher.
The following prerequisites must be installed on your computer to build the provided sample without modifications:
- Visual Studio 2026 or higher
- Microsoft .NET 10 or higher
You can modify the sample project to target different versions of .NET if preferred depending on the version used by your Custom Analytics instance.
The Dundas BI NuGet packages referenced as dependencies are initially set to version 26.4. If your version of Custom Analytics is newer and the APIs you are using may have changed, you can update the version of these package references.
This sample also references assemblies such as Dundas.BI.Export.StandardExportProviders found within the App_Data folder of your installed instance: App_Data\Extensions\Dundas.StdExport\bin\netcore.
2.1. Download the sample solution
To download the sample solution, click here.
2.2. Open the solution
Extract LogoExcelExportProvider.zip to a folder and open the solution in Microsoft Visual Studio, which is used to build the extension.
To use the option to publish directly to your Custom Analytics instance, run Visual Studio as an administrator before opening the solution. For example, you can right-click Visual Studio in the start menu and find the Run as administrator option.
The solution file is named LogoExcelExportProvider.slnx.
3. The project
The project is a class library.
- LogoExcelExportProvider.csproj - The project file, which will need to be edited before building as described below.
- PublishExtensionTemplate.props - Used for auto publishing the extension after the build succeeds, and defines extension properties and files.
- LogoExcelExportProvider.cs - This class contains the custom export provider.
- LogoExcelExportProviderPackage.cs - This class contains the package information about the extension package.
- Resources\logo.png - This is the image rendered into Excel by this sample.
3.1. Dundas BI bin directory
This sample project needs to be pointed to the location of the standard export provider extension binary included in your Custom Analytics instance:
- Locate the App_Data\Extensions\Dundas.StdExport\bin\netcore subfolder of your Custom Analytics installation, which should contain Dundas.BI.Export.StandardExportProviders.dll.
- If your development machine is different than the server where Custom Analytics is deployed, copy Dundas.BI.Export.StandardExportProviders.dll to your development machine.
- Right-click the project in Visual Studio (e.g., LogoExcelExportProvider) and click Edit Project File.
- Edit the <DundasBIBinDir> element's contents to point to the location on the same machine containing Dundas.BI.Export.StandardExportProviders.dll.
- When the project file is saved, confirm the assembly is listed in the Solution Explorer window without a warning icon under the project > Dependencies > Assemblies.
3.2. Publish Extension Template Props
This sample has a mechanism to automatically publish the extension when building, which is the Dundas.BI.PublishExtension NuGet package. When this package is added to the project, it creates a PublishExtensionTemplate.props file containing MSBuild property and item groups, which define how to create and publish the extension.
When the DtFilePath property is set to the file path of the dt tool of a Custom Analytics instance, it will then publish the extension directly to that instance when you build the solution. It will also touch the web.config file to force the web application to reset.
If the DtFilePath property is not set, it will create a .zip file you can add to your Custom Analytics instance using the Extensions screen in the administration UI. After building the solution with default settings and the solution configuration set to Release, this .zip file can be found in the bin\Release\net10.0 subfolder of your solution.
For more details on using this package to automate publishing extensions, see Using the Dundas.BI.PublishExtension NuGet package.
3.3. Overriding methods
The sample project overrides the following method for the purposes of inserting a logo and some text at the top of the exported worksheet. This is just an example, and there are many more methods you can override, described in the next section.
/// <summary>
/// Adds the logo to the top of the worksheet, before the first adapter is rendered on it. The adapters are rendered below it.
/// </summary>
protected override void StartOfWorksheetRendering(Worksheet worksheet, ExportRequest request, AdapterDataInfo info)
{
// The first row that is free below the logo. Without a logo the text starts at the top.
uint nextRow = 1;
byte[] png = GetLogoPng();
if (png != null)
{
// The image is kept by the drawing until the workbook is written, so it is not disposed here.
MagickImage image = new MagickImage(png);
worksheet.AddDrawing(new Drawing
{
Worksheet = worksheet,
ColumnIndex = 0,
RowIndex = 0, // Drawing anchors are zero-based, so this is the top left cell.
BitmapSource = image,
});
// The rows that the image covers, which is how the worksheet measures the rows that a drawing uses.
nextRow = (uint)Math.Floor(image.Height / Dundas.BI.Export.StandardExportProviders.Xlsx.Constants.DefaultRowHeightInPixel) + 2;
}
this.AddText(worksheet, nextRow, "Exported By: " + (Engine.Current.Session?.AccountDisplayName ?? string.Empty));
this.AddText(worksheet, nextRow + 1, "Exported On: " + DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture) + " UTC");
}
4. Virtual methods
The following can be overridden by a class inheriting from Dundas.BI.Export.StandardExportProviders.ExcelProvider, as the LogoExcelExportProvider class does in this sample:
| Member/Method | Purpose |
|---|---|
protected virtual uint SharedWorksheetRowGap |
Number of empty rows between adapters that share a worksheet. |
protected virtual void RenderDocument(Document, IEnumerable<AdapterDataInfo>, ExportRequest, IExtensionLogger, Stopwatch) |
Top-level hook for the whole export. An override should call the base to render the adapters. It can add its own content to the document or pass different adapters to the base. |
protected virtual IEnumerable<AdapterDataInfo> SortAdapterInfos(IEnumerable<AdapterDataInfo>, ExportRequest) |
Sets the render order of the adapters, which is also the worksheet order. The default sorts by adapter name. An adapter left out of the result isn’t exported. |
protected virtual void StartOfWorksheetRendering(Worksheet, ExportRequest, AdapterDataInfo) |
Runs once per worksheet, before its first adapter. Content added here appears above the adapters. |
protected virtual void EndOfWorksheetRendering(Worksheet, ExportRequest, IReadOnlyList<AdapterDataInfo>) |
Runs once per worksheet, after all its adapters. Content added here appears below them. It isn’t called if the export is cancelled. |
protected virtual void StartOfAdapterRendering(Worksheet, ExportRequest, AdapterDataInfo) |
Runs for each adapter before it renders. It isn’t called for adapters skipped because they have nothing to export. |
protected virtual void EndOfAdapterRendering(Worksheet, ExportRequest, AdapterDataInfo) |
Runs for each adapter that rendered something, after it renders. It isn’t called if the export is cancelled. |
protected internal virtual string GetWorksheetName(Document, string, ExportRequest, AdapterDataInfo info = null) |
Chooses which worksheet an adapter renders on. Adapters that map to the same name share a sheet. |
You can also refer to the sample export provider class code. It overrides these members even when unnecessary, for the purposes of documenting the same information.