c# - 如何使用 FileHelpers 导出到 excel 文件

标签 c# .net filehelpers

我正在使用 File Helpers 而且我不确定如何获取我的数据并将其导出到 Excel 文件。

我看到了 extracting records 的教程但不创建 excel 文件。

我试过了

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:

最佳答案

您需要将 Interop.Excel 和 Interop.Office 引用的“Embed Interop Types”设置为“false”,这将自动将复制本地设置为 true,并且一切正常。

关于c# - 如何使用 FileHelpers 导出到 excel 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9729979/

相关文章:

c# - 状态栏大红叉出现

c# - 我怎样才能在 <li> 标签内获取复选框文本并在 jQuery 的另一个标签中显示它?

C#正则表达式麻烦

c# - FileHelpers:读取文件时如何处理引用的字段

c# - FileHelpers:混合分隔和固定长度记录

c# - 如何在 C# 中使用像 exists() 这样的 XPath 函数?

c# - 如何将 C# 'single case union type' 类对象序列化为其基础值并返回?

c# - 如何在仅具有模数和私有(private)指数 (D) 参数的 C# 中解密数据?

c# - C# 的 Actors 有什么好的实现吗?

c# - FluentNHibernate SubClassMap 问题 : Discriminator fail