Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DataTable导出没有列名,这段代码将DataTable的属性与传入的DataTable列名比较导到获取不到列名 #15

Closed
anlem12 opened this issue Nov 29, 2019 · 2 comments

Comments

@anlem12
Copy link

anlem12 commented Nov 29, 2019

DataTable导出没有列名,这段代码将DataTable的属性与传入的DataTable数据列名比较导到获取不到列名

https://github.com/xin-lai/Magicodes.IE/blob/master/src/Magicodes.ExporterAndImporter.Excel/ExcelExporter.cs

///


/// 获取头部定义
///

///
///
///
///

`
private static bool GetExporterHeaderInfoList(out List exporterHeaderList,
DataColumnCollection dataColumns)
{
exporterHeaderList = new List();
var objProperties = typeof(T).GetProperties();
if (objProperties == null || objProperties.Length == 0)
return true;
var index = 0;
for (var k = 0; k < dataColumns.Count; k++)
for (var i = 0; i < objProperties.Length; i++)
if (dataColumns[k].ColumnName.Equals(objProperties[i].Name))
{
index += 1;
exporterHeaderList.Add(new ExporterHeaderInfo
{
Index = index,
PropertyName = objProperties[i].Name,
ExporterHeader =
(objProperties[i].GetCustomAttributes(typeof(ExporterHeaderAttribute), true) as
ExporterHeaderAttribute[])?.FirstOrDefault()
});
}
return false;
}

`

@xin-lai

@xin-lai
Copy link
Collaborator

xin-lai commented Nov 30, 2019

@geffzhang
找张队 哈哈哈。。。

@geffzhang
Copy link
Collaborator

geffzhang commented Dec 1, 2019

是基于DTO,DataTable 也一样是基于DTO的,必须指定你使用的DTO, DataTable 的列名和DTO的属性一致,这不是bug,这是一个特性。
而且这个方法是私有的,内部用的

@xin-lai xin-lai closed this as completed Dec 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants