共用方式為


WorkbookBase.CustomXMLParts 屬性

取得活頁簿中自訂 XML 組件的集合。

命名空間:  Microsoft.Office.Tools.Excel
組件:  Microsoft.Office.Tools.Excel.v4.0.Utilities (在 Microsoft.Office.Tools.Excel.v4.0.Utilities.dll 中)

語法

'宣告
Public ReadOnly Property CustomXMLParts As CustomXMLParts
public CustomXMLParts CustomXMLParts { get; }

屬性值

型別:Microsoft.Office.Core.CustomXMLParts
Microsoft.Office.Core.CustomXMLParts 集合,含有活頁簿中的自訂 XML 組件。

備註

如需自訂 XML 組件的詳細資訊,請參閱自訂 XML 組件概觀

範例

下列程式碼範例會藉由在 Microsoft.Office.Core.CustomXMLParts 集合中插入新的 Microsoft.Office.Core.CustomXMLPart,將員工資料加入至文件。範例會接著從 XML 組件擷取員工資料,並將員工姓名和雇用日期顯示在 Sheet1 上。

這是示範文件層級自訂的範例。

Private Sub AddCustomXMLPart()
    Dim xmlString As String = _
        "<?xml version=""1.0"" encoding=""utf-8"" ?>" _
        + "<employees>" _
        + "<employee>" _
        + "<name>Karina Leal</name>" _
        + "<hireDate>1999-04-01</hireDate>" _
        + "</employee>" _
        + "</employees>"
    Dim employeeXMLPart As Office.CustomXMLPart = _
        Me.CustomXMLParts.Add(xmlString)

    Globals.Sheet1.Range("A1").Value2 = employeeXMLPart.SelectSingleNode( _
        "/employees[1]/employee[1]/name[1]").Text
    Globals.Sheet1.Range("A2").Value2 = employeeXMLPart.SelectSingleNode( _
                "/employees[1]/employee[1]/hireDate[1]").Text
End Sub
private void AddCustomXMLPart()
{
    string xmlString =
        "<?xml version=\"1.0\" encoding=\"utf-8\" ?>"
        + "<employees>"
        + "<employee>"
        + "<name>Karina Leal</name>"
        + "<hireDate>1999-04-01</hireDate>"
        + "</employee>"
        + "</employees>";
    Office.CustomXMLPart employeeXMLPart =
        this.CustomXMLParts.Add(xmlString);

    Globals.Sheet1.Range["A1"].Value2 = employeeXMLPart.SelectSingleNode(
        "/employees[1]/employee[1]/name[1]").Text;
    Globals.Sheet1.Range["A2"].Value2 = employeeXMLPart.SelectSingleNode(
                "/employees[1]/employee[1]/hireDate[1]").Text;
}

.NET Framework 安全性

請參閱

參考

WorkbookBase 類別

Microsoft.Office.Tools.Excel 命名空間