Skip to content

Commit ff3c4c1

Browse files
committed
fix: 修复 获取真实错误位置
1 parent 7a63a0a commit ff3c4c1

File tree

14 files changed

+101
-63
lines changed

14 files changed

+101
-63
lines changed

src/Bing.Offices.Abstractions/Bing/Offices/Metadata/Excels/ICell.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ public interface ICell
3535
/// </summary>
3636
int RowIndex { get; }
3737

38+
/// <summary>
39+
/// 物理行索引
40+
/// </summary>
41+
int PhysicalRowIndex { get; }
42+
3843
/// <summary>
3944
/// 结束列索引
4045
/// </summary>

src/Bing.Offices.Abstractions/Bing/Offices/Metadata/Excels/IRange.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ public interface IRange
4141
/// <param name="cells">单元格列表</param>
4242
void AddRow(int rowIndex, IEnumerable<ICell> cells);
4343

44+
/// <summary>
45+
/// 添加单元行
46+
/// </summary>
47+
/// <param name="rowIndex">行索引</param>
48+
/// <param name="physicalRowIndex">物理行索引</param>
49+
/// <param name="cells">单元格列表</param>
50+
void AddRow(int rowIndex, int physicalRowIndex, IEnumerable<ICell> cells);
51+
4452
/// <summary>
4553
/// 清空单元行
4654
/// </summary>

src/Bing.Offices.Abstractions/Bing/Offices/Metadata/Excels/IRow.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ public interface IRow
1212
/// </summary>
1313
int RowIndex { get; set; }
1414

15+
/// <summary>
16+
/// 物理行索引
17+
/// </summary>
18+
int PhysicalRowIndex { get; set; }
19+
1520
/// <summary>
1621
/// 是否有效
1722
/// </summary>

src/Bing.Offices.Abstractions/Bing/Offices/Metadata/Excels/IWorkSheet.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,13 @@ public interface IWorkSheet
8181
/// <param name="cells">单元格集合</param>
8282
void AddBodyRow(IEnumerable<ICell> cells);
8383

84+
/// <summary>
85+
/// 添加正文
86+
/// </summary>
87+
/// <param name="cells">单元格集合</param>
88+
/// <param name="physicalRowIndex">物理行索引</param>
89+
void AddBodyRow(IEnumerable<ICell> cells, int physicalRowIndex);
90+
8491
/// <summary>
8592
/// 添加页脚
8693
/// </summary>

src/Bing.Offices.Core/Bing/Offices/Extensions/WorkbookExtensions.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@ public static IEnumerable<ValidateResult> Validate(this IWorkbook workbook)
4444
var list = new List<ValidateResult>();
4545
foreach (var sheet in workbook.Sheets)
4646
{
47-
// 由于需要真实行数,因此需要增加1
48-
list.AddRange(sheet.GetBody().Where(x => !x.Valid).Select(row => new ValidateResult()
49-
{RowIndex = row.RowIndex + 1, ErrorMsg = row.ErrorMsg, SheetName = sheet.Name}));
47+
list.AddRange(sheet.GetBody().Where(x => !x.Valid).Select(row => new ValidateResult {RowIndex = row.PhysicalRowIndex + 1, ErrorMsg = row.ErrorMsg, SheetName = sheet.Name}));
5048
}
5149
return list;
5250
}

src/Bing.Offices.Core/Bing/Offices/Helpers/ExpressionMapper.cs

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -114,40 +114,6 @@ private static MemberBinding GetMapperBinding(PropertyInfo prop, MethodInfo firs
114114
return Expression.Bind(prop, expr);
115115
}
116116

117-
///// <summary>
118-
///// 变更类型
119-
///// </summary>
120-
///// <param name="value">值</param>
121-
///// <param name="type">类型</param>
122-
//public static object ChangeType(string value, Type type)
123-
//{
124-
// object obj = null;
125-
// var nullableType = Nullable.GetUnderlyingType(type);
126-
// try
127-
// {
128-
// if (nullableType != null)
129-
// {
130-
// if (value == null)
131-
// obj = null;
132-
// else
133-
// obj = OtherChangeType(value, type);
134-
// }
135-
// else if (typeof(Enum).IsAssignableFrom(type))
136-
// {
137-
// obj = Enum.Parse(type, value);
138-
// }
139-
// else
140-
// {
141-
// obj = Convert.ChangeType(value, type);
142-
// }
143-
// return obj;
144-
// }
145-
// catch
146-
// {
147-
// return default;
148-
// }
149-
//}
150-
151117
/// <summary>
152118
/// 变更类型
153119
/// </summary>

src/Bing.Offices.Core/Bing/Offices/Metadata/Excels/Cell.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,17 @@ public int RowIndex
7878
}
7979
}
8080

81+
/// <summary>
82+
/// 物理行索引
83+
/// </summary>
84+
public int PhysicalRowIndex {
85+
get
86+
{
87+
Row.CheckNull(nameof(Row));
88+
return Row.PhysicalRowIndex;
89+
}
90+
}
91+
8192
/// <summary>
8293
/// 结束列索引
8394
/// </summary>

src/Bing.Offices.Core/Bing/Offices/Metadata/Excels/Range.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,22 @@ public void AddRow(int rowIndex, IEnumerable<ICell> cells)
9999
AddCell(row, cell, rowIndex);
100100
}
101101

102+
/// <summary>
103+
/// 添加单元行
104+
/// </summary>
105+
/// <param name="rowIndex">行索引</param>
106+
/// <param name="physicalRowIndex">物理行索引</param>
107+
/// <param name="cells">单元格列表</param>
108+
public void AddRow(int rowIndex, int physicalRowIndex, IEnumerable<ICell> cells)
109+
{
110+
if (cells == null)
111+
return;
112+
var row = CreateRow(rowIndex);
113+
row.PhysicalRowIndex = physicalRowIndex;
114+
foreach (var cell in cells)
115+
AddCell(row, cell, rowIndex);
116+
}
117+
102118
/// <summary>
103119
/// 创建单元行
104120
/// </summary>

src/Bing.Offices.Core/Bing/Offices/Metadata/Excels/Row.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ public class Row : IRow
2525
/// </summary>
2626
public int RowIndex { get; set; }
2727

28+
/// <summary>
29+
/// 物理行索引
30+
/// </summary>
31+
public int PhysicalRowIndex { get; set; }
32+
2833
/// <summary>
2934
/// 是否有效
3035
/// </summary>

src/Bing.Offices.Core/Bing/Offices/Metadata/Excels/WorkSheet.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,20 @@ public void AddBodyRow(IEnumerable<ICell> cells)
220220
ResetFirstColumnSpan();
221221
}
222222

223+
/// <summary>
224+
/// 添加正文
225+
/// </summary>
226+
/// <param name="cells">单元格集合</param>
227+
/// <param name="physicalRowIndex">物理行索引</param>
228+
public void AddBodyRow(IEnumerable<ICell> cells, int physicalRowIndex)
229+
{
230+
if (cells == null)
231+
return;
232+
GetBodyRange().AddRow(_rowIndex, physicalRowIndex, cells);
233+
_rowIndex++;
234+
ResetFirstColumnSpan();
235+
}
236+
223237
/// <summary>
224238
/// 获取正文单元范围
225239
/// </summary>

0 commit comments

Comments
 (0)