How to export to excel file with FileHelpers

元气小坏坏 提交于 2019-12-13 17:44:02

问题


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:


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/9729979/how-to-export-to-excel-file-with-filehelpers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!