Skip to content

Commit

Permalink
Merge pull request #13 from NanoFabricFX/master
Browse files Browse the repository at this point in the history
修复Datatable 列的顺序和DTO的顺序不一致 导致数据放错列
  • Loading branch information
xin-lai authored Nov 20, 2019
2 parents 6eb9bde + 0b3c1d7 commit 615d992
Showing 1 changed file with 15 additions and 12 deletions.
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

0 comments on commit 615d992

Please sign in to comment.