FileHelpers
FileHelpers copied to clipboard
The type initializer for 'NPOI.OpenXmlFormats.ExtendedPropertiesDocument' threw an exception.
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());
}
}
}
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.