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 列的顺序和DTO的顺序不一致 导致数据放错列 #13

Merged
merged 2 commits into from
Nov 20, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 15 additions & 12 deletions src/Magicodes.ExporterAndImporter.Excel/ExcelExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -384,29 +384,32 @@ private static bool GetExporterHeaderInfoList<T>(out List<ExporterHeaderInfo> ex
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="exporterHeaderList"></param>
/// <param name="dataColumns"></param>
/// <returns></returns>
private static bool GetExporterHeaderInfoList<T>(out List<ExporterHeaderInfo> exporterHeaderList,DataColumnCollection dataColumns)
private static bool GetExporterHeaderInfoList<T>(out List<ExporterHeaderInfo> exporterHeaderList, DataColumnCollection dataColumns)
{
exporterHeaderList = new List<ExporterHeaderInfo>();
var objProperties = typeof(T).GetProperties();
if (objProperties == null || objProperties.Length == 0)
return true;

int index = 0;
for (var i = 0; i < objProperties.Length; i++)
for (var k = 0; k < dataColumns.Count; k++)
{
if (dataColumns.Contains(objProperties[i].Name))
for (var i = 0; i < objProperties.Length; i++)
{
index += 1;
exporterHeaderList.Add(new ExporterHeaderInfo
if (dataColumns[k].ColumnName.Equals(objProperties[i].Name))
{
Index = index,
PropertyName = objProperties[i].Name,
ExporterHeader =
(objProperties[i].GetCustomAttributes(typeof(ExporterHeaderAttribute), true) as
ExporterHeaderAttribute[])?.FirstOrDefault()
});

index += 1;
exporterHeaderList.Add(new ExporterHeaderInfo
{
Index = index,
PropertyName = objProperties[i].Name,
ExporterHeader =
(objProperties[i].GetCustomAttributes(typeof(ExporterHeaderAttribute), true) as
ExporterHeaderAttribute[])?.FirstOrDefault()
});
}
}
}
return false;
Expand Down