Document Generation

Nonprofits often have to generate a large amount of thank you mail. Sending a response to a donation increases the likelihood of the donor giving again, so being able to send an acknowledgement accurately and quickly is an important business consideration.

I worked at such an organization, and the process for generating those thank-yous was painful. It consisted of mail-merging in Microsoft Word, with some prep work in Excel to get things lined up. To complicate things, different donations had different thank you messages. Gifts in kind had to reference the gift, scheduled donations had to be skipped, and many other nuanced and specific rules. It was all done by hand. A human had to take all of the donation data, sift through the pieces, organize them, export different files per template type, then go through the process of loading each into Word and printing them. At one point, that human was me.

Honey I Built a Tool Again

So I built a tool in C# that bypassed the whole thing. It takes in a CSV of donation data, straight from the CRM. This CSV contains all of the fields necessary to perform the logic required to determine what template a donation should associate with. I developed an XML schema (I know - but I promise it's friendly to non-techies) that allows users to define rules. These rules are sorted such that the most important template type triggers first, falling through to the default if none of the rules are met. It even supports defining aliases for mapping from the CSV field to the {Template} in the source document - so instead of {Billing State/Province} in your template, you can alias that field to just {State}.

The result? Given a CSV, in a few seconds you are presented with an output folder with both the envelope Word document as well as the thank-you document, sorted in the same order and ready to print-fold-and-ship.

The Software

  • C#/.Net 5
  • DocX (non-FOSS library for OpenXML manip.)
    • Ultimately I'd probably either find a FOSS thing or write a library to do just enough for what I need

Lessons Learned

I got to work with C#, which was an interesting experience. It's definitely more verbose in some ways, but it has a really convenient parallelization mechanism that I was able to leverage essentially for free to speed up large batches.

The DocX dependency not being freely available was the biggest sticking point for this project. Its not too expensive to license from them, but I wasn't going to bother with selling this anyway. Despite being a huge speed improvement over the original process, I know that things could be faster and I suspect that more optimization could be done, possibly with a homegrown (and libre) OpenXML library.

All in all it was a good run. My contact with the organization left shortly after I finished the tool, so I didn't have the same foot in to introduce it. I might revisit it someday, but it's not the most interesting problem - there are a ton of template tools. However, it was really rewarding to be able to eliminate a huge amount of busy work that I was subjected to with a tool that I built.