企業面臨資訊分散、難以搜尋與合規的挑戰。Office 2007 引入的文件資訊面板 (Document Information Panel, DIP),結合 InfoPath 表單、內容控件、Quick Parts 與 OpenXML 格式,提供了一套完整的文件級中繼資料管理解決方案。本文深入剖析 DIP 架構、程式碼操作、與檢查清單管理應用的完整實作。
Office 2007 文件本質是 ZIP 套件,解壓後可見:
_rels/.rels:關係檔,指向 docProps/core.xml(標準屬性)、docProps/app.xml(擴充屬性)、docProps/custom.xml(自訂屬性)、customXml/itemN.xml(InfoPath 表單資料)。itemPropsN.xml) 標註 schemaRef 指向 InfoPath 結構描述,並可宣告為「自訂文件資訊面板」(customDocumentInformationPanel)。BuiltInDocumentProperties 與 CustomXMLParts' 透過 BuiltInDocumentProperties
Dim props As DocumentProperties = DirectCast(Globals.ThisDocument.BuiltInDocumentProperties, DocumentProperties)
Dim prop As DocumentProperty = props.Item("Category")
prop.Value = "Modified Checklist"
' 透過 CustomXMLParts (XPath 操作 core.xml)
Dim xmlParts As CustomXMLParts = Globals.ThisDocument.CustomXMLParts
xmlParts.Item(1).SelectSingleNode("//*[local-name()='category']").Text = "modified category"
' 讀取 InfoPath 表單欄位
Dim ipXml As New XmlDocument()
ipXml.LoadXml(Globals.ThisDocument.CustomXMLParts.Item(4).XML)
Dim projName = ipXml.SelectSingleNode("//*[local-name()='ProjectName']").InnerText
' 寫入需配合 InfoPath 結構描述,建議透過 DIP UI 或表單邏輯維護
CustomDocumentProperties)' 讀取/寫入
Dim cProps = DirectCast(Globals.ThisDocument.CustomDocumentProperties, DocumentProperties)
Dim clientProp = cProps.Item("Client")
clientProp.Value = "Microsoft"
' 新增屬性
cProps.Add("ChecklistVersion", False, MsoDocProperties.msoPropertyTypeNumber, "1.1")
ChecklistMetadata.xsn 為自訂 DIP,預設檢視設為表單檢視。Private Sub ShowHideDIP_Click(sender As Object, e As RibbonControlEventArgs) Handles ShowHideDIP.Click
Globals.ThisDocument.Application.DisplayDocumentInformationPanel = Not Globals.ThisDocument.Application.DisplayDocumentInformationPanel
End Sub
ChecklistsQuickPartsTemplate.dotm,將各分類檢查清單存為 Quick Part,分類名稱前綴「CL - 」。AttachedTemplate 指向該範本。ChCategory 欄位 → 篩選範本中對應分類的所有 Quick Part → 逐一插入為內容控件,每個換頁。' 繫結至 InfoPath 欄位 ProjectName (CustomXMLParts 第 4 項)
Globals.ThisDocument.ContentControls(1).XMLMapping.SetMapping("//*[local-name()='ProjectName']", , Globals.ThisDocument.CustomXMLParts.Item(4))
' 繫結至標準屬性 Category (CustomXMLParts 第 1 項 core.xml)
Globals.ThisDocument.ContentControls(2).XMLMapping.SetMapping("//*[local-name()='category']", , Globals.ThisDocument.CustomXMLParts.Item(1))
繫結後,DIP 中修改欄位值即時反映於文件內容控件,反之亦然,實現「單一資料源,多處呈現」。
功能區「插入」→「Quick Part」→「文件屬性」,可插入作者、標題等標準屬性,與 DIP 雙向同步。
DIP + InfoPath + 內容控件 + Quick Parts + OpenXML,構成了 Office 2007 文件中繼資料管理與內容自動化的完整生態。廣泛採用標準化結構化中繼資料,將極大提升企業搜尋、合規、流程自動化的效能。