Welcome to MSDN Blogs Sign in | Join | Help
How can I export an Office Accounting report to Excel in code

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?

Posted: Friday, April 11, 2008 5:35 PM by Jorn

Comments

cbospikes said:

Seriously ... your awesome.  

Perfect solution to my issue of rendering reports on the client machine.

Once I started working with the objects I found the reportdocument has view that is bindable to a gridview.  

.Net is awesome, this SDK is awesome!

# April 14, 2008 9:23 PM

tudor said:

Jorn,

I really want to implement office accounting 2008 pro... but one of our basic requirements is to be able to import original bank receipts and payments into MOA (the originals, not the reconciliation files). If we can't do that, we're sunk.

I've been struggling with the SDK - probably because I'm a noob to the product and the terminology (documents, lines, transactions) isn't clear to me...

Do you have any simple examples of how I can import bank deposits and payments? We do the bulk of our payments and receipts processing on another system (in-house custom stuff w SQLServer backend). We want to use MOA to process our accounts, but our sales team need to process bank receipts and payments on our other system, and then we want to import those into MOA for reconciliation.

I really hope you can help... :)

# May 5, 2008 4:31 AM

nikodes said:

Hi Jorn,

which section of the template do i write those codes on?

niko

# September 30, 2008 3:19 AM

Jorn said:

Hi

I'm not sure I understand the question, can you clarify?

Jorn

# September 30, 2008 12:26 PM

nikodes said:

Hi Jorn,

Sorry to ask you an unclear question as i am new to this coding.

the code above (export to excel), where should i write those code in my native report template? should i create a new method? or stick it in one of the method in native report tempate?  or stick it in driverAddIn section?

regards,

Niko

# September 30, 2008 7:16 PM

Jorn said:

Hmm, well what are you trying to do?

You don’t need this code for the user to be able to export your report to Excel, that is build in.

You would use this code if you want to run and export a report from your own program, in this case you would put the code in your program, not in the INativeReport implementation.

Does that make sense?

Jorn

# October 1, 2008 12:33 PM

nikodes said:

Hi jorn,

I am sorry for the confiusion, i was trying to export when the code has not been finished. but it can export to excel when i finally finish it. thank you so much for your reply.

I have another a quick question. How to enable chart on the report?

regards,

Nikodemus

# October 3, 2008 12:26 AM
Anonymous comments are disabled
Page view tracker