It has been a while since my last post and I have gotten a few questions. One question was related to exporting reports to Excel.

 

This is actually pretty simple; you may have noticed the IReportExportToExcelV2 interface. This is the key to this task.

Basically the system report executor implements this interface and therefore you can use it to export.

 

Time for an example:

 

// First we need the engine

ISbaObjects sbaObjects = loader.GetSbaObjects(.........);

ISmallBusinessInstance instance

    = (ISmallBusinessInstance)sbaObjects.SmallBusinessInstance;

IReportEngineV2 reportEngine

    = (IReportEngineV2)sbaObjects.ReportEngine;

 

// Get a report descriptor

IReportDescriptorV2 reportDescriptor

    = reportEngine.ReportDescriptorView

          .GetByName("CustomerTransactionHistory");

 

// Use the report descriptor to create a report executor

INativeReportExecutorV2 reportExecutor

    = (INativeReportExecutorV2)reportEngine

           .GetReportExecutor(reportDescriptor);

 

// Let's change a filter on the report

// just to show that you can modify the report before exporting

IReportFilterDateV2 filterDate

    = (IReportFilterDateV2)reportExecutor.ReportProperties

    .ReportFilters.GetFilter(ReportFilterEnum.DateFilter);

filterDate.DateFilter = DateFilter.Today;

 

// Now everything is ready and we can cast the

// executor to an IReportExportToExcelV2

IReportExportToExcelV2 exportToExcel

    = reportExecutor as IReportExportToExcelV2;

if (exportToExcel != null)

    exportToExcel.ExportToExcel();

 

Pretty easy eh?