Released in OfficeWriter 8.6.1 – IEnumerable Feature

In OfficeWriter 8.6.1, we added a new feature that may have been flying under your radar, and I wanted to let you in on the story of how it came about.

When I first arrived at SoftArtisans I went through training of our entire product line.  As I was reviewing the training material, I came across the ExcelWriter Template section. I saw how to add data markers to my spreadsheet, and it seemed intuitive, so I went ahead and tried it:

ienumerable

At that moment, I was thinking “This is pretty slick. Now, I can just pass things into the spreadsheet!”  I’m not the greatest at reading documentation; I just like to learn by doing, so I opened Visual Studio and started writing code:


class Expense

{

double Amount { get; set; }

string Description = "";

bool Approved { get { return (Amount > 1000); } }

}

 

for (int i=0; i<1000; i++)

expenses.Add(new Expense(i));

 

Looking good so far.  What I did next, however, was my downfall:


ExcelTemplate xlt = new ExcelTemplate();

xlt.BindData(expenses);

Woops! I received an error. I was looking for a way to enumerate using the OfficeWriter API. After some design discussions, late nights of coding, and extensive peer review I’m proud to say this is now a part of the API!

Now there are a few things you should know before you dive right in and start using it. I’ll start off with what we do support: 

  • The new API accepts an IEnumerable<T> in place of a DataTable, DataReader, or array.
  • Public properties and fields (both static and instance) are available for data markers.
  • Public properties and fields of base classes (again, for static and instance) are available for data markers.

Now for what we don’t support: 

  • We don’t expose non-public properties and fields to the end user. (We don’t want your top secret data getting out!)
  • We don’t YET support nested properties (%%=expenses.Description.Location), but we hope to do so in the future

So go forth and enumerate my friends!

Related posts:

Leave a Reply

Your email address will not be published. Required fields are marked *