Tag: reflection

Microsoft.Office.Interop.Excel.Range的Type.GetProperties返回空数组

我想使用下面的代码获取Microsoft.Office.Interop.Excel.Range接口的属性列表: using Excel = Microsoft.Office.Interop.Excel; PropertyInfo[] info = typeof(Excel.Range).GetProperties(); 但结果是一个空的数组:System.Reflection.PropertyInfo [0] 我错过了什么吗?

Excel连接pipe理器的EzApi问题

EzApi是用来创buildSSIS包的,包通过oledb连接pipe理器读取excel文件(microsoft.ace.oledb.12.0)当我在读取excel文件的数据stream之后创buildEzExecSQLTask对象时, 我得到了exception: object does not match the target type 在debuggingEzApi代码后,我发现下面一行是生成exception host.Properties["TimeOut"].SetValue(host, value); 似乎当属性通过reflection设置时,它不会find目标对象。 代码在widows xp机器上工作正常,但在Windows Server 2012上造成这个问题。 堆栈跟踪 at System.Reflection.RuntimeMethodInfo.CheckConsistency(Object target) at System.Reflection.RuntimeMethodInfo.InvokeArgumentsCheck(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo […]

使用reflection过滤/删除EF5导航属性

我有下面的代码来获得通过的所有通用实体的属性。我认为这样的属性将成为一个excel报告的伟大标题。 但是当我使用它时,我得到了一些“导航”属性。 我想过滤它们,因为他们搞乱了报告。 这里是一些代码… DataTable dataTable = new DataTable(typeof(TEntity).Name); //Get properties / field names PropertyInfo[] Props = typeof(TEntity).GetProperties(BindingFlags.Public | BindingFlags.Instance); //Add props to datatable foreach (PropertyInfo prop in Props) dataTable.Columns.Add(prop.Name); 所以代码继续将其他行添加到数据表中,然后我使用它将数据发送到出色的NPOI免费的Excel导出工具。 有理想的BindingFlags属性,将允许我忽略这些东西 | !BindingFlags.Navigation 我也不一定需要其他2,因为我看到它们似乎有或没有他们相同的细节。 如果没有BindingFlags属性,有没有办法扩展它。 如果没有,那么有没有其他的标准方法可靠地检测它们,所以我可以过滤掉它们。 我听说其中一些包含“导航”作为前缀,或几乎总是虚拟的,但虽然我的虚拟似乎“几乎”部分担心我。 这就是为什么我不想做这样的事情: PropertyInfo[] Props = typeof(TEntity).GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(p => !p.GetGetMethod().IsVirtual && !p.GetGetMethod().IsFinal).ToArray(); 不过,我没有“导航”的前缀,我可以看到,但如果他们这样做,我不相信这也会给我正确的方式。 也许我对上述两个人是错误的,或者没有在正确的地方寻找。 我也完成了一些生成连接到repo的“ViewModel”的行,以从模型中获取数据并填充ViewModel。 然后发送到我的报告引擎。 这似乎更灵活,因为我可以使用它有点像预览如果我附加一个视图。 这听起来像正确的路要走吗? […]

将DataTable列表与string列表进行比较

所以我试图从Excel导入创build数据表然后用于其他事情。 我知道电子表格的名字,所以我在我的文档顶部创build了我的数据表: private DataTable Version,Pi_PROCESSPi_PMLIFEPROFILE,PIAPPLICATION,PIRUGGEDISING,ELECTRONICCOMPONENT,HFANDRFCOMPONENTS,HYBRIDANDMULTICHIPMODULE,COTSBOARDS, VARIOUSSUBASSEMBLIES,PARTCOUNT, FAMILYCOUNT; 然后,当读取电子表格时,我将有一个列表和一个for循环,将spreadhseet名称分配给该列表 List<string>ExcelSheets = new List<string>(); Excel电子表格列表和数据表单具有相同的名称 我有一个函数读取Excel电子表格基于给定的表名,所以我想能够做一些像(伪代码): foreach ExcelSheets{ Datatable = dt.ReadFunction() } 使用DataTable作为文件顶部的声明数据表。 所以我想对列表中的每个表格说一声,运行函数并将结果赋给相应的数据表 编辑:代码参考: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.IO; using System.Web; using System.Xml; using DocumentFormat.OpenXml; using DocumentFormat.OpenXml.Packaging; using DocumentFormat.OpenXml.Spreadsheet; using System.Data.OleDb; using System.Reflection; […]

C#创buildexcel表单后期限

使用winforms,C#FW4.5打开一个excel表单,具有这样的后缀: objExcel = CreateObject("Excel.Application") 现在我想使用InvokeMember方法,但是我不知道所有可以调用的excel成员。 例如,我知道我可以这样调用它: InvokeMember("Close",…为了closuresexcel,但是我在哪里可以find我可以调用的所有成员的列表以及每个成员都做了什么?