Skip to content

Commit fc40ae5

Browse files
committed
完善批注
1 parent e8e9c1f commit fc40ae5

File tree

4 files changed

+19
-6
lines changed

4 files changed

+19
-6
lines changed

src/Magicodes.ExporterAndImporter.Excel/Utility/ImportHelper.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,15 @@ protected virtual void LabelingError(ExcelPackage excelPackage)
131131
//标注数据错误
132132
foreach (var item in ImportResult.RowErrors)
133133
{
134-
var col = ImporterHeaderInfos.First(p => p.ExporterHeader.Name == item.FieldErrors.First().Key);
135-
var cell = worksheet.Cells[item.RowIndex, col.ExporterHeader.ColumnIndex];
136-
cell.Style.Font.Color.SetColor(Color.Red);
137-
cell.Style.Font.Bold = true;
138-
cell.AddComment(string.Join(",", item.FieldErrors.Values), col.ExporterHeader.Author);
134+
foreach (var field in item.FieldErrors)
135+
{
136+
var col = ImporterHeaderInfos.First(p => p.ExporterHeader.Name == field.Key);
137+
var cell = worksheet.Cells[item.RowIndex, col.ExporterHeader.ColumnIndex];
138+
cell.Style.Font.Color.SetColor(Color.Red);
139+
cell.Style.Font.Bold = true;
140+
cell.AddComment(string.Join(",", item.FieldErrors.Values), col.ExporterHeader.Author);
141+
}
142+
139143
}
140144
var ext = Path.GetExtension(FilePath);
141145
excelPackage.SaveAs(new FileInfo(FilePath.Replace(ext, "_" + Guid.NewGuid().ToString("N") + ext)));

src/Magicodes.ExporterAndImporter.Tests/ExcelImporter_Tests.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,19 @@ public async Task RowDataError_Test()
116116
result.TemplateErrors.Count.ShouldBe(0);
117117
result.RowErrors.ShouldContain(p => p.RowIndex == 2 && p.FieldErrors.ContainsKey("产品名称"));
118118
result.RowErrors.ShouldContain(p => p.RowIndex == 3 && p.FieldErrors.ContainsKey("产品名称"));
119+
120+
result.RowErrors.ShouldContain(p => p.RowIndex == 7 && p.FieldErrors.ContainsKey("产品代码"));
121+
119122
result.RowErrors.ShouldContain(p => p.RowIndex == 3 && p.FieldErrors.ContainsKey("重量(KG)"));
120-
result.RowErrors.ShouldContain(p => p.RowIndex == 3 && p.FieldErrors.ContainsKey("公式测试"));
121123
result.RowErrors.ShouldContain(p => p.RowIndex == 4 && p.FieldErrors.ContainsKey("公式测试"));
122124
result.RowErrors.ShouldContain(p => p.RowIndex == 5 && p.FieldErrors.ContainsKey("公式测试"));
123125
result.RowErrors.ShouldContain(p => p.RowIndex == 6 && p.FieldErrors.ContainsKey("公式测试"));
126+
result.RowErrors.ShouldContain(p => p.RowIndex == 7 && p.FieldErrors.ContainsKey("公式测试"));
127+
128+
result.RowErrors.ShouldContain(p => p.RowIndex == 3 && p.FieldErrors.ContainsKey("身份证"));
129+
result.RowErrors.ShouldContain(p => p.RowIndex == 4 && p.FieldErrors.ContainsKey("身份证"));
130+
result.RowErrors.ShouldContain(p => p.RowIndex == 5 && p.FieldErrors.ContainsKey("身份证"));
131+
124132
result.RowErrors.Count.ShouldBeGreaterThan(0);
125133
}
126134
}

src/Magicodes.ExporterAndImporter.Tests/Models/ImportProductDto.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ public class ImportProductDto
8080
public DateTime FormulaTest { get; set; }
8181

8282
[ImporterHeader(Name = "身份证")]
83+
[RegularExpression(@"(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)", ErrorMessage = "身份证号码无效!")]
8384
public string IdNo { get; set; }
8485

8586
[Display(Name = "性别")]
Binary file not shown.

0 commit comments

Comments
 (0)