我定期需要从 Agile PLM 服务器下载给定 BOM 中的所有项目,并将它们保存在以其 Agile 项目编号命名的单独文件夹中,手动执行此操作非常繁琐且耗时。
有什么方法可以通过 Python 实现自动化吗?我在网上查看的所有地方都导致了死胡同的 python 包,这些包据称是用于与 Agile PLM 接口的,但没有文档,也没有明确的实际使用方法。
到目前为止,我见过的唯一可能的选择是像 Selenium 这样通过无头浏览器与 Agile servlet 交互,但这对于我的低技能水平的人来说似乎是一场噩梦。
虽然我更喜欢 python,但如果有其他更好的方法来自动执行此任务,我非常愿意接受建议。然而,我对敏捷服务器端没有任何控制权。
我在目前的工作中也遇到了同样的问题。但这就是我的做法。
供您参考。这是我的 PDXParser VBA 宏代码。 子解析 PDXXMLFile() 将 xmlDoc 变暗为对象 Dim xmlNode 作为对象 将 itemIdentifier 变暗为字符串 将附件名称变暗为字符串 暗淡的文件标识符作为字符串 暗淡文件用途作为字符串 暗淡 rowNum As Long 昏暗的工作表 暗淡单元作为范围 昏暗的附件单元格作为范围 昏暗目的单元格作为范围
' Load the XML file
Set xmlDoc = CreateObject("MSXML2.DOMDocument")
xmlDoc.async = False
xmladdress = InputBox("Enter the address")
xmlDoc.Load (xmladdress & "\pdx.xml") ' Replace with the path to your PDX XML file
' Check for XML parsing errors
If xmlDoc.parseError.ErrorCode <> 0 Then
MsgBox "Error parsing XML: " & xmlDoc.parseError.reason
Exit Sub
End If
' Set initial row number for writing data
rowNum = 2
' Set reference to the first worksheet
Set ws = ActiveSheet
' Loop through each <Item> node in the XML document
For Each xmlNode In xmlDoc.SelectNodes("//Item")
' Get the value of the itemIdentifier attribute
itemIdentifier = xmlNode.getAttribute("itemIdentifier")
' Write the itemIdentifier to the worksheet and make it bold
Set cell = ws.Cells(rowNum, 1)
cell.Value = itemIdentifier
cell.Font.Bold = True
Set purposeCell = ws.Cells(rowNum, 2)
purposeCell.Value = "Master"
' Increment row number
rowNum = rowNum + 1
' Loop through each <Attachment> node within the <Item> node
For Each attachmentNode In xmlNode.SelectNodes("Attachments/Attachment")
filePurpose = ""
' Get the value of the universalResourceIdentifier attribute
attachmentName = attachmentNode.getAttribute("universalResourceIdentifier")
' Get the value of the fileIdentifier attribute
fileIdentifier = attachmentNode.getAttribute("fileIdentifier")
' Generate the final attachment text
attachmentName = fileIdentifier & "." & attachmentName
' Write the attachmentName to column A
Set attachmentCell = ws.Cells(rowNum, 1)
attachmentCell.Value = attachmentName
' Check if "File Purpose" attribute exists
On Error Resume Next
filePurpose = attachmentNode.SelectSingleNode("AdditionalAttributes/AdditionalAttribute[@name='File Purpose']").getAttribute("value")
' Write the filePurpose to column B
Set purposeCell = ws.Cells(rowNum, 2)
If filePurpose <> "" Then
purposeCell.Value = filePurpose
Else
purposeCell.Value = "" ' Default value if attribute is not present
End If
' Create hyperlink for the attachment
ws.Hyperlinks.Add anchor:=attachmentCell, Address:=xmladdress & "\" & attachmentName, TextToDisplay:=attachmentName
' Increment row number
rowNum = rowNum + 1
Next attachmentNode
' Increment row number for next item
rowNum = rowNum + 1
Next xmlNode
' Auto-adjust column width to fit content for both columns A and B
ws.Columns("A:B").AutoFit
ws.Columns("A:B").AutoFilter
' Display confirmation message
'MsgBox "PDX XML file successfully parsed and data displayed in Excel."
结束子