FileHelpers icon indicating copy to clipboard operation
FileHelpers copied to clipboard

The type initializer for 'NPOI.OpenXmlFormats.ExtendedPropertiesDocument' threw an exception.

Open michaelakin opened this issue 8 years ago • 1 comments

I created the following program and it will not save for the newer excel "xlsx" file extensions, but it will for "xls".

using System.Collections.Generic;
using FileHelpers;
using FileHelpers.ExcelNPOIStorage;

namespace TestXlSXSave
{
    class Program
    {

        [DelimitedRecord("|")]
        public  class TestFile
        {
            public string Name;
            public string Address;
        }

        static void Main(string[] args)
        {
            // add records to a list
            var myList = new List<TestFile>();
            myList.Add(new TestFile() {Name = "Michael", Address = "123 N Somewhere"});
            myList.Add(new TestFile() { Name = "Marcos", Address = "456 S Somewhere Else" });

            // set up FileHelpers Excel Engine
            var engine = new ExcelNPOIStorage(typeof(TestFile), 0, 0)
            {
                FileName = @"u:\test.xlsx",
                OverrideFile = true,
                SheetName = "Test"
            };

            // Column Headers
            var headers = new List<string>();
            headers.Add("Name");
            headers.Add("Address");

            // Save 
            engine.ColumnsHeaders = headers;
            engine.InsertRecords(myList.ToArray());

        }
    }
}

michaelakin avatar Jun 08 '16 22:06 michaelakin

I had the same problem. My solution was getting the FileHelpers source code and rebuild (Debug) and used separated Dlls. FileHelpers.ExcelNPOIStorage.dll was about 13KB instead of 5035KB. Of course, you have to install NPOI package. It seems that the Release build had missed something.

siquylee avatar Jul 08 '16 05:07 siquylee