COM & Interop Hell: To Excel or to EPPLUS?

business-intelligence-that-rescues-you-from-excell-hellScrolling through a lot of questions on StackOverflow, CodeProject and other sites I often come across questions like how do I create an ExcelSheet, or how to close Excel after saving a document… Most of these questions stem from the problems of working with the COM/Interop model of EXCEL. It’s dirty, it’s messy and resource intensive.

But there is an alternative: a project called EPPLUS, which has several benefits.

  • You don’t need a local Excel copy installed on the machine you’re running your code. Great for server work, or when you have users that only have Office365 or no locally installed Excel on their machine!
  • It uses a simplified API model without compromising powerful features as it can: from basic reading/writing to cells and ranges, coloring, adding worksheets, saving to adding complex object, images and a lot more… The official website sums up that it supports:
    • Cell Ranges, Cell styling (Border, Color, Fill, Font, Number, Alignments)
    • Charts, Pivot tables, tables
    • Pictures, Shapes
    • Comments
    • Protection, Encryption
    • Data validation
    • Conditional formatting
    • VBA
    • Formula calculation
    • Many more…
  • Did I already mention simplified API, what I really mean is you don’t have to bother interfacing with the EXCEL COM API, and manage the different lifecycles, or write your own custom wrapper… In EPPLUS all objects that need to be closed and use resources that need to be cleaned up implement IDisposable, and a ssuch you can write code inside a using block, e.g.:
  • Free, open source & it’s actively maintained, the last commit on time of writing was 2017 February 17th on their codeplex repository.

At least give it a try (nugetcodeplex) and look into it. It’ll save you headaches from COMplicated API calls to the Excel Interop ;-)…- pun inteded.