Create your Holiday Cards with OfficeWriter, The Sequel

seasonsgreetingsThe holiday season is back! Stores are stocking their shelves with the season’s must-haves and calendars are quickly filling up with travel and office parties. With all the hustle, bustle and festivities, occasionally remember to send out those holiday cards and thank-you notes gets lost in the tinsel and taffeta. Well, you’re in luck, because this year we’ve put together a project for you to easily send out holiday thank-you notes and cards the nostalgic, old-fashioned way.

Last year, Sam showed us how to Automate Your Holiday Cards with OfficeWriter, and this year we’ve added thank-you notes to the mix. So you can spend less time on holiday prep and more time on the things that matter most – friends and family.

Using a few built-in tools with the .NET Framework, OfficeWriter, and templates, you can personalize every card for each one of your friends and family. See the example below. Then make your own by following these steps:

STEP 1 – DOWNLOAD OFFICEWRITER:

To get started, you will need to have OfficeWriter installed in order to be able to use the sample code below. In my solution, I used OfficeWriter and its built-in WordTemplate functionality to do a server-side mail merge. If you do not have OfficeWriter, you can download a free evaluation here.

STEP 2 – DOWNLOAD SAMPLE CODE:

Next, you will need the sample code. Download the sample solution here. This solution comes bundled with:

  • Sample code
  • Easily modifiable templates for holiday cards, mailing labels, and thank-you letters.
  • Dummy data from a Gmail Contact Export

Open the solution, run the generator, and you can see the three items:

SAMPLE OUTPUT:

SAMPLE CODE:

OfficeWriter makes it easy to generate the finished holiday cards, labels, and thank-you cards. With about 5 lines of OfficeWriter code for each template, within minutes you can go from nothing to a finished, picture-perfect file. The sample code below is a simple way to parameterize the code to handle all of our template files.

<br />
        private void GenerateCards()<br />
        {<br />
            GenerateOutput(&quot;\\Templates\\HolidayCards.in.docx&quot;, DataGenerator.GetContacts(), &quot;GreetingCards.docx&quot;, false);<br />
        }</p>
<p>        private void GenerateLabels()<br />
        {<br />
            GenerateOutput(&quot;\\Templates\\Labels.in.docx&quot;, DataGenerator.GetContacts(), &quot;Labels.docx&quot;, false);<br />
        }</p>
<p>        private void GenerateThankYouCards()<br />
        {<br />
            GenerateOutput(&quot;\\Templates\\ThankYouCards.in.docx&quot;, ThankYouCardManager.GetThankYouCardData(), &quot;ThankYouCards.docx&quot;, false);<br />
        }</p>
<p>        private void GenerateOutput(String templateFileName, DataTable templateData, String outputFileName, bool useNextFields)<br />
        {<br />
            WordTemplate wt = new WordTemplate(); //Create Word Template<br />
            wt.EnableNEXTFields = useNextFields; // Need to enable this for the labels<br />
            wt.Open(Page.MapPath(templateFileName)); //Open Template File<br />
            wt.SetMailMerge(templateData); //Read in Data and Perform a Mail Merge<br />
            wt.Process(); //Process the file<br />
            wt.Save(Page.Response, outputFileName, false); //Save it back to the context stream so the user is prompted to save the file<br />
        }<br />
}<br />

holidaycards2013

STEP 3 – CUSTOMIZING THE SAMPLE APPLICATION:

CUSTOMIZE THE TEMPLATES:

While I have worked with OfficeWriter for some time, my background is in programming, not design. The great feature of OfficeWriter is that it is able to find where to put the data wherever they are in the document, so I encourage you to make the forms prettier than what I have provided. You can navigate to the Templates folder in the solution and modify any of:

  • the HolidayCards.in.docx
  • the Labels.in.docx
  • the ThankYouCards.in.docx

USING YOUR OWN DATA:

The code this year imports from a Comma Separated Values file, produced from Gmail. With minimal modification you can use your own CSV files. Some common applications that let you export to .CSV files are Outlook, Gmail (use the Outlook CSV file format from Gmail), and many other email and contact management clients. More instructions are built into the application for easy reference.

MORE IDEAS AND WAYS TO USE THIS CODE:

In my solution I used .CSV files to store my contacts, but if you are a company this code can easily be expanded to read your data from your company’s database and easily help you automate many parts of your company – think offer letters, contracts, invoices, newsletters or training/award certificates. The list goes on and on.

Stay tuned for a video coming soon of a behind-the-scenes look at how we put this all together!

Related posts: