refactor: improve BOM library matching logic with column-name-based lookup
All checks were successful
NTFY Notification / notify (push) Successful in 3s
All checks were successful
NTFY Notification / notify (push) Successful in 3s
- Add BOM library column name constants (名称, 编码, 数量, etc.) - Add GetBOMConditionFields() and IsConditionField() utility functions - Refactor ExtractMaterialInfo to use column names instead of hardcoded positions - Refactor ExtractSingleSubComponent to use column names for 接头/弹性元件 - Refactor ExtractComponentInfo to use column names - Improve MatchAllMaterialTypes to iterate all worksheets dynamically - Add debug logging for troubleshooting This fix resolves issues where worksheets with non-standard column counts (like 表壳, 罩壳) could not extract material information properly. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -54,6 +54,45 @@ Public Const BOMLIB_SHEET_MOVEMENT As String = "机芯"
|
||||
Public Const BOMLIB_SHEET_COMPONENT As String = "部件"
|
||||
Public Const BOMLIB_SHEET_EDGE As String = "边"
|
||||
|
||||
' BOM库物料列名常量
|
||||
Public Const BOMLIB_COL_NAME As String = "名称"
|
||||
Public Const BOMLIB_COL_CODE As String = "编码"
|
||||
Public Const BOMLIB_COL_QTY As String = "数量"
|
||||
Public Const BOMLIB_COL_JOINT_NAME As String = "接头名称"
|
||||
Public Const BOMLIB_COL_JOINT_CODE As String = "接头编码"
|
||||
Public Const BOMLIB_COL_JOINT_QTY As String = "接头数量"
|
||||
Public Const BOMLIB_COL_ELEMENT_NAME As String = "弹性元件名称"
|
||||
Public Const BOMLIB_COL_ELEMENT_CODE As String = "弹性元件编码"
|
||||
Public Const BOMLIB_COL_ELEMENT_QTY As String = "弹性元件数量"
|
||||
|
||||
' BOM库条件字段列表(所有可能的条件字段)
|
||||
Public Function GetBOMConditionFields() As Variant
|
||||
GetBOMConditionFields = Array( _
|
||||
"azxs", "bkxs", "gclj", "jycz", "lcdw", "lcfw", _
|
||||
"fjgn", "btcy", "bp", "dskd", "nqlc", "bptx", _
|
||||
"jddj", "cpdm", "tsjz", "tsyq", "bpts", "kdxh" _
|
||||
)
|
||||
End Function
|
||||
|
||||
' 检查列名是否为条件列
|
||||
Public Function IsConditionField(ByVal colName As String) As Boolean
|
||||
Dim fields As Variant
|
||||
fields = GetBOMConditionFields()
|
||||
|
||||
Dim i As Long
|
||||
Dim lowerColName As String
|
||||
lowerColName = LCase(Trim(colName))
|
||||
|
||||
For i = LBound(fields) To UBound(fields)
|
||||
If lowerColName = LCase(fields(i)) Then
|
||||
IsConditionField = True
|
||||
Exit Function
|
||||
End If
|
||||
Next i
|
||||
|
||||
IsConditionField = False
|
||||
End Function
|
||||
|
||||
' 获取表头排序索引 (越小越靠前)
|
||||
Public Function GetHeaderPriority(key As String) As Long
|
||||
Dim vList As Variant
|
||||
|
||||
Reference in New Issue
Block a user