From b412c556544c23e6754f72eb7de2bcdf02f2f7c1 Mon Sep 17 00:00:00 2001 From: Misaka_Company Date: Tue, 3 Feb 2026 09:45:28 +0800 Subject: [PATCH] refactor: update output fields in MainModule MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add 生产订单号 field from column A of [产品订单] sheet - Remove 表头型号 field from output - Reorder columns to place 生产订单号 as first column - Update ProcessSingleModel and CreateOutputRowArray signatures Co-Authored-By: Claude Sonnet 4.5 --- VBA/Modules/MainModule.bas | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/VBA/Modules/MainModule.bas b/VBA/Modules/MainModule.bas index a7aa96b..babaee0 100644 --- a/VBA/Modules/MainModule.bas +++ b/VBA/Modules/MainModule.bas @@ -73,13 +73,15 @@ Public Sub ProcessProductModels() ' 假设产品型号在第1列,从第2行开始 For i = 2 To lastRow + Dim orderNumber As String + orderNumber = Trim(inputSheet.Cells(i, 1).value) ' A列:生产订单号 modelString = Trim(inputSheet.Cells(i, 2).value) Dim componentPriority As String componentPriority = Trim(inputSheet.Cells(i, 5).value) ' E列:部件优先 If modelString <> "" Then ' 处理单个型号,收集数据 - ProcessSingleModel modelString, componentPriority, BomExtractor, outputData + ProcessSingleModel orderNumber, modelString, componentPriority, BomExtractor, outputData processedCount = processedCount + 1 End If Next i @@ -111,12 +113,14 @@ End Sub '===================================================================== ' 过程: ProcessSingleModel ' 功能: 处理单个产品型号,将数据添加到输出集合 -' 参数: modelString - 产品型号字符串 +' 参数: orderNumber - 生产订单号 +' modelString - 产品型号字符串 ' componentPriority - 部件优先标志("是"或"否") ' bomExtractor - BOM提取器对象 ' outputData - 输出数据集合 '===================================================================== -Private Sub ProcessSingleModel(modelString As String, _ +Private Sub ProcessSingleModel(orderNumber As String, _ + modelString As String, _ componentPriority As String, _ BomExtractor As BomExtractor, _ outputData As collection) @@ -140,7 +144,7 @@ Private Sub ProcessSingleModel(modelString As String, _ If Not parser.Parse(modelString) Then ' 解析失败 extractNote = "解析失败: " & parser.ErrorMessage - outputData.Add CreateOutputRowArray(modelString, "", parser.Conditions, extractNote, Nothing) + outputData.Add CreateOutputRowArray(orderNumber, modelString, parser.Conditions, extractNote, Nothing) Exit Sub End If @@ -161,7 +165,7 @@ Private Sub ProcessSingleModel(modelString As String, _ If extractNote = "" Then extractNote = "未匹配到任何物料" End If - outputData.Add CreateOutputRowArray(modelString, parser.HeaderModel, parser.Conditions, extractNote, Nothing) + outputData.Add CreateOutputRowArray(orderNumber, modelString, parser.Conditions, extractNote, Nothing) Else ' 输出每个匹配的物料 Dim item As BomItem @@ -179,10 +183,10 @@ Private Sub ProcessSingleModel(modelString As String, _ End If If isFirst Then - outputData.Add CreateOutputRowArray(modelString, parser.HeaderModel, parser.Conditions, itemNote, item) + outputData.Add CreateOutputRowArray(orderNumber, modelString, parser.Conditions, itemNote, item) isFirst = False Else - outputData.Add CreateOutputRowArray("", "", parser.Conditions, itemNote, item) + outputData.Add CreateOutputRowArray("", modelString, parser.Conditions, itemNote, item) End If Next item End If @@ -197,8 +201,8 @@ Private Sub WriteOutputHeader(ws As Worksheet) Dim col As Long col = 1 + ws.Cells(1, col).value = "生产订单号": col = col + 1 ws.Cells(1, col).value = "产品型号": col = col + 1 - ws.Cells(1, col).value = "表头型号": col = col + 1 ' 写入条件字段表头 Dim Conditions() As String @@ -225,15 +229,15 @@ End Sub '===================================================================== ' 函数: CreateOutputRowArray ' 功能: 创建输出行数据的数组 -' 参数: FullModel - 完整型号 -' HeaderModel - 表头型号 +' 参数: orderNumber - 生产订单号 +' FullModel - 完整型号 ' Conditions - 条件字典 ' note - 备注 ' item - BOM项(可为Nothing) ' 返回: Variant() - 行数据数组 '===================================================================== -Private Function CreateOutputRowArray(FullModel As String, _ - HeaderModel As String, _ +Private Function CreateOutputRowArray(orderNumber As String, _ + FullModel As String, _ Conditions As Object, _ note As String, _ item As BomItem) As Variant() @@ -252,9 +256,9 @@ Private Function CreateOutputRowArray(FullModel As String, _ Dim col As Long col = 1 - ' 产品型号和表头型号 + ' 生产订单号和产品型号 + rowData(col) = orderNumber: col = col + 1 rowData(col) = FullModel: col = col + 1 - rowData(col) = HeaderModel: col = col + 1 ' 写入条件值 Dim i As Long