1
votes

I am using File Helpers and I am unsure how to take my data and export it to an excel file.

I see a tutorial forextracting records but not creating a excel file.

I tried to do this

ExcelStorage provider = new ExcelStorage(typeof(Img));

provider.StartRow = 2;
provider.StartColumn = 1;

provider.FileName = "Customers.xls";

provider.HeaderRows = 6;

provider.InsertRecords(imgs.ToArray()); // imgs was a list before

System.IO.FileNotFoundException was unhandled by user code
Message=Could not load file or assembly 'Interop.Excel, Version=1.3.0.0, Culture=neutral, PublicKeyToken=3e0c08d59cc3d657' or one of its dependencies. The system cannot find the file specified.
Source=FileHelpers.ExcelStorage FileName=Interop.Excel, Version=1.3.0.0, Culture=neutral, PublicKeyToken=3e0c08d59cc3d657
FusionLog==== Pre-bind state information === LOG: User = LOG: DisplayName = Interop.Excel, Version=1.3.0.0, Culture=neutral, PublicKeyToken=3e0c08d59cc3d657 (Fully-specified) LOG: Appbase = LOG: Initial PrivatePath = Calling assembly : FileHelpers.ExcelStorage, Version=2.9.9.0, Culture=neutral, PublicKeyToken=3e0c08d59cc3d657. === LOG: This bind starts in default load context. LOG: Using application configuration file: web.config LOG: Using host configuration file: LOG: Using machine configuration file from machine.config. LOG: Post-policy reference: Interop.Excel, Version=1.3.0.0, Culture=neutral, PublicKeyToken=3e0c08d59cc3d657 LOG: Attempting download of new URL file: LOG: Attempting download of new URL file:Interop.Excel.DLL. LOG: Attempting download of new URL file:Interop.Excel.DLL. LOG: Attempting download of new URL file:Interop.Excel.DLL. LOG: Attempting download of new URL file:Interop.Excel.EXE. LOG: Attempting download of new URL file:Interop.Excel.EXE. LOG: Attempting download of new URL file:Interop.Excel.EXE. LOG: Attempting download of new URL file:Interop.Excel.EXE.

StackTrace: at FileHelpers.DataLink.ExcelStorage.InitExcel() at FileHelpers.DataLink.ExcelStorage.InsertRecords(Object[] records) at Index() in Controller.cs:line 37 at lambda_method(Closure , ControllerBase , Object[] ) at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary2 parameters) at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary2 parameters) at System.Web.Mvc.ControllerActionInvoker.<>c_DisplayClass15.b_12() at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation)
InnerException:

2
Are you referencing the office assembly in your project?Mike Perrenoud
From the FileHelpers website ExcelStorage class doc... ExcelStorage Class This class implements the DataStorage for Microsoft Excel Files. WARNING you need to have installed Microsoft Excel 2000 or newer to use this feature. To use this class you need to reference the FileHelpers.ExcelStorage.dll file.dbugger
Yes, They came when I downloaded filehelpers from nuget (Interop.Excel v1.3.0.0, Interop.Office v2.1.0.0)chobo2
@dbugger - I have FileHelpers.ExcelStorage(2.9.9.0) and I have Excel 2010 on my computer.chobo2
@dbugger is probably right but I'm betting - because of the backwards compatibility - if you just reference the COM library it will work.Mike Perrenoud

2 Answers

8
votes

You need to set 'Embed Interop Types' to 'false' for the Interop.Excel and Interop.Office references which will automatically set copy local to true and it will all work.

2
votes

I think you just need to add a reference to the Excel assembly in your project - it's a dependency for the software you're using to export it to Excel. You can find those assemblies under the COM tab, and here is a link that lists their names so you can find them. You may not have the same version as that link but they'll be named relatively the same.

Let me know if you need more help.