feat(error-analysis): add configurable header row for report layout

Add OUTPUT_HEADER_ROW constant (row 10) to allow space above error report:
- Preserves rows 1-9 for title, instructions, or summary information
- Error report header now starts at row 10
- Only clears data from header row downwards (preserves upper content)
- Removed AutoFit to maintain custom column widths

This provides flexibility for report formatting and allows
additional context to be added above the error analysis data.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Misaka_Company
2026-03-26 16:48:39 +08:00
parent 1e995b5485
commit c597a6cf75

View File

@@ -8,6 +8,8 @@ Option Explicit
' 提取条件配置 ' 提取条件配置
Private Const CONDITION_CONFIG = "azxs,安装形式|bkxs,表壳形式|gclj,过程连接|jycz,接液材质|lcfw,量程范围|fjgn,附加功能" Private Const CONDITION_CONFIG = "azxs,安装形式|bkxs,表壳形式|gclj,过程连接|jycz,接液材质|lcfw,量程范围|fjgn,附加功能"
' 指定输出[BOM匹配异常报表]的表头所在行号
Private Const OUTPUT_HEADER_ROW As Long = 10
'===================================================================== '=====================================================================
' 过程: GenerateErrorAnalysisReport ' 过程: GenerateErrorAnalysisReport
@@ -437,21 +439,21 @@ Private Sub WriteOutputHeader(ws As Worksheet)
Dim col As Long Dim col As Long
col = 1 col = 1
ws.Cells(1, col).value = "总排号": col = col + 1 ws.Cells(OUTPUT_HEADER_ROW, col).value = "总排号": col = col + 1
ws.Cells(1, col).value = "生产订单号": col = col + 1 ws.Cells(OUTPUT_HEADER_ROW, col).value = "生产订单号": col = col + 1
ws.Cells(1, col).value = "产品型号": col = col + 1 ws.Cells(OUTPUT_HEADER_ROW, col).value = "产品型号": col = col + 1
Dim configs() As String Dim configs() As String
configs = Split(CONDITION_CONFIG, "|") configs = Split(CONDITION_CONFIG, "|")
Dim i As Long Dim i As Long
For i = LBound(configs) To UBound(configs) For i = LBound(configs) To UBound(configs)
ws.Cells(1, col).value = Trim(Split(configs(i), ",")(1)) ws.Cells(OUTPUT_HEADER_ROW, col).value = Trim(Split(configs(i), ",")(1))
col = col + 1 col = col + 1
Next i Next i
ws.Cells(1, col).value = "未匹配参数": col = col + 1 ws.Cells(OUTPUT_HEADER_ROW, col).value = "未匹配参数": col = col + 1
ws.Cells(1, col).value = "未匹配参数值": col = col + 1 ws.Cells(OUTPUT_HEADER_ROW, col).value = "未匹配参数值": col = col + 1
ws.Cells(1, col).value = "提取备注": col = col + 1 ws.Cells(OUTPUT_HEADER_ROW, col).value = "提取备注": col = col + 1
End Sub End Sub
'===================================================================== '=====================================================================
@@ -518,7 +520,8 @@ Private Sub WriteBatchData(ws As Worksheet, outputData As Collection)
Next j Next j
Next i Next i
ws.Range("A2").Resize(rowCount, colCount).value = resultData ' 数据从表头的下一行开始写入
ws.Cells(OUTPUT_HEADER_ROW + 1, 1).Resize(rowCount, colCount).value = resultData
End Sub End Sub
'===================================================================== '=====================================================================
@@ -548,13 +551,14 @@ Private Function CreateErrorOutputSheet() As Worksheet
Set CreateErrorOutputSheet = ThisWorkbook.Worksheets.Add Set CreateErrorOutputSheet = ThisWorkbook.Worksheets.Add
CreateErrorOutputSheet.Name = wsName CreateErrorOutputSheet.Name = wsName
Else Else
CreateErrorOutputSheet.Cells.Clear ' 只清空表头及其以下的数据,保留表头以上的可能存在的内容
CreateErrorOutputSheet.Rows(OUTPUT_HEADER_ROW & ":" & CreateErrorOutputSheet.Rows.count).Clear
End If End If
End Function End Function
Private Sub FormatOutputSheet(ws As Worksheet) Private Sub FormatOutputSheet(ws As Worksheet)
On Error Resume Next On Error Resume Next
With ws.Rows(1) With ws.Rows(OUTPUT_HEADER_ROW)
.Font.Bold = True .Font.Bold = True
.Interior.Color = RGB(244, 176, 132) ' 橙色背景,突出异常属性 .Interior.Color = RGB(244, 176, 132) ' 橙色背景,突出异常属性
.HorizontalAlignment = xlCenter .HorizontalAlignment = xlCenter
@@ -562,7 +566,7 @@ Private Sub FormatOutputSheet(ws As Worksheet)
' 将"未匹配参数"列和"未匹配参数值"列加粗显示,颜色标红 ' 将"未匹配参数"列和"未匹配参数值"列加粗显示,颜色标红
Dim unmatchValCol As Long Dim unmatchValCol As Long
unmatchValCol = ws.Cells(1, ws.Columns.count).End(xlToLeft).Column - 1 unmatchValCol = ws.Cells(OUTPUT_HEADER_ROW, ws.Columns.count).End(xlToLeft).Column - 1
Dim unmatchParamCol As Long Dim unmatchParamCol As Long
unmatchParamCol = unmatchValCol - 1 unmatchParamCol = unmatchValCol - 1
@@ -573,7 +577,6 @@ Private Sub FormatOutputSheet(ws As Worksheet)
ws.Columns(unmatchValCol).Font.Bold = True ws.Columns(unmatchValCol).Font.Bold = True
End If End If
ws.Columns.AutoFit
On Error GoTo 0 On Error GoTo 0
End Sub End Sub