Can't instantiate new workbook

Aug 29, 2012 at 2:54 PM

ClosedXML looks like it will be a life saver for me, but I can't even get the first step to work.  I have the DLL added as a reference in my project (Winforms C# 2010, .NET 3.5) and I have

using ClosedXML.Excel;
at the top of the class.  Everything compiles fine, but when I call that method it fails on
var workbook = new XLWorkbook();

The error it gives is the following:

System.TypeInitializationException was unhandled
  Message=The type initializer for 'ClosedXML.Excel.XLWorkbook' threw an exception.
I'm really at a loss, because the samples in the documentation seem to indicate that this is all that should be necessary, but it's not working. 

Aug 29, 2012 at 4:28 PM

Do you have the 3.5 dll? Did you reference DocumentFormat.OpenXml.dll?

Aug 29, 2012 at 9:30 PM

I did have the 3.5 DLL for ClosedXML, but did not have the other DLL you mentioned.  I added it and it works now.  Is that listed in the documentation?  Because I couldn't find it mentioned anywhere. 

While we're at it, is there a way to load the data into Excel for display without saving it to a file?  I haven't found a command to open Excel once the data is added to the workbook.

Aug 29, 2012 at 9:37 PM
Edited Aug 29, 2012 at 9:38 PM

Check out the documentation page where it says:


To use ClosedXML you must reference the following DLL: DocumentFormat.OpenXml.dll (part of MS Open XML SDK 2.0)


To display a file in Excel you need to use Interop which defeats the purpose of using this library in the first place.