We live in open source world... So, let it be same for knowledge !!
Note :- The implementations and code snippets are from my learning and knowledge repository. I am putting in public domain to be used by anyone. See creative commons License for more details.

Pages

Wednesday, April 25, 2012

Report Generation in Excel (.xlsx) - Example

Following is an example fo building an excel sheet through C#. I have taken excel sheet as this been a very rich feature in office with we are building a tabular report. The report generated in excel is really easy to work with. Building an excel required building different objects individually and integrating it. Once done then write data in it. After saving the excel releasing all the resources is a key which we seldom forget.

During this implementation I came across an issue that once the excel get genetated and after closing the excel everythign is fine. But when shutting down the PC pop up came for saving excel which is not present in the desktop. That time realized that the objects of excel created through code are still open and active even though there is no excel instance on desktop. For that at reason end added code to release the resources and calling GC.

This example shows building an Excel (.xlsx) report which will diaplay data from list List<string[]> ListGeneratedSize; String[] has array size of 7. This example has following aspects:

Merging cells

Setting cell color

Setting cell label

Setting cell font

Assigning excel worksheet features like autofit etc.

Releasing resources at the end

My opinion is that even though it would be bit complicated building a report in excel but this adds a lot of value to the report.