Over a million developers have joined DZone.

Using Open XML SDK v2.0 on Windows Azure

DZone's Guide to

Using Open XML SDK v2.0 on Windows Azure

· ·
Free Resource

Generating Word/Excel reports is a fairly common requirement. Now that we intend to migrate our application to the cloud, we realize that on Windows Azure you do not have  Office DLLs or in fact, any other (unnecessary from Azure’s perspective) DLLs available to you. You can always package Office DLLs with your app deployment package and use them in your application on Windows Azure (You can find articles on the blogosphere about how this can be done).

I opted for using Open XML SDK v2.0 available here. I Can generate Word / Excel reports on the fly.

Here’s a sample code to write to create a Word Document

//Using Statements Required
using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Wordprocessing;      

//Code to Create a Word Document at the provided File Path
using (WordprocessingDocument wordDocument =
    	WordprocessingDocument.Create(filepath, WordprocessingDocumentType.Document))
   			mainPart.Document = new Document(
   				new Body(
   					new Paragraph(
   						new Run(
   							new Text("Report Generated by Open XML SDK ")))));

Now that we have everything in place we want to deploy this “Report Generation Solution” to the cloud, but first we'll run it locally on the compute Emulator.

Everything seems to be working, Next step is to deploy your application to your Azure account.

This blog post talks about a known issue on using Open XML SDK in  .NET 4 Roles on Windows Azure.

When you right click your solution to do a publish...


Windows Azure would ask you for the Hosted service where you want to deploy the solution, If you have not already set that up, the dialog box also has a provision to do that for you.


Please Remember to UnCheck, (you read that right) “UNCHECK” Enable IntelliTrace for .NET 4 roles.

You may want to argue that Intellitrace helps us in historical debugging in an event  of a fatal crash, but for now you will have to live with the Windows Azure Diagnostics Logging for now.

The reason, why this needs to be disabled is, “Enabling Intellitrace for .NET 4 roles when using the OPEN XML SDK seems to freeze your web/worker role.”

I Learnt this the hard way (after being billed for a week for a Extra Large VM (Frozen, just because I Enabled Intellitrace and am using Open XML SDK in my azure app). In other words, that’s a lot of money. Crying faceCrying faceCrying face 

Keep reading this space for such posts to come. I am working on Windows Azure now, so I am sure there are many such topics on which I can post. Smile


Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}