Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The type initializer for 'ClosedXML.Excel.XLWorkbook' threw an exception

Tags:

c#

using ClosedXML.Excel;

class XLSXWriter : BExporter
    {
        private readonly string _fName;

        public XLSXWriter(string fileName)
        {
            _fName = fileName;
        }

        public override void Export(IEnumerable<AnimalData> animals)
        {
            var workBook = new XLWorkbook(); <---Throws an exception

            var workSheet = workBook.Worksheets.Add("MySheet");

            workSheet.Cell("A1").Value = "Hello World";            

            FileStream fs = new FileStream(_fName, FileMode.Create);
            workBook.SaveAs(fs);
            fs.Close();          
        }
    }

Just trying this library ClosedXML.dll, and it throws an exception can't figure out what could be the problem. I get the _fName from the savefiledialog. Ideas anybody?

like image 565
smons Avatar asked Oct 12 '25 15:10

smons


1 Answers

Thought would delete this post, but might help someone in future....All i had to do was reference one more DLL DocumentFormat.OpenXml.dll . Works perfectly now!

like image 65
smons Avatar answered Oct 14 '25 11:10

smons



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!