3
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();          
        }
    }

只是尝试这个库ClosedXML.dll,它会引发异常,无法弄清楚可能是什么问题。我_fNamesavefiledialog. 任何人的想法?

4

2 回答 2

8

以为会删除这篇文章,但将来可能会对某人有所帮助....我所要做的就是再引用一个 DLL DocumentFormat.OpenXml.dll 。现在完美运行!

于 2012-12-05T21:47:29.597 回答
0

更新 closedXML 库后,我修复了同样的错误。换句话说,如果 ClosedXML 和 OpenXML 是更新包,则不会发生此错误。

于 2019-05-09T06:36:59.440 回答