Using Open XML SDK v2.0 on Windows Azure
Join the DZone community and get the full member experience.
Join For Freegenerating 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 "))))); worddocument.maindocumentpart.document.save(); worddocument.close(); }
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.
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.
Published at DZone with permission of Sudheendra Kovalam. See the original article here.
Opinions expressed by DZone contributors are their own.
Trending
-
What Is mTLS? How To Implement It With Istio
-
How To Design Reliable IIoT Architecture
-
An Overview of Kubernetes Security Projects at KubeCon Europe 2023
-
What Is Test Pyramid: Getting Started With Test Automation Pyramid
Comments