WorkbookBase.AfterXmlExport 事件

在 Microsoft Office Excel 保存工作簿的数据或将数据从工作簿导出到 XML 数据文件后发生。

命名空间:  Microsoft.Office.Tools.Excel
程序集:  Microsoft.Office.Tools.Excel.v4.0.Utilities(在 Microsoft.Office.Tools.Excel.v4.0.Utilities.dll 中)

语法

声明
Public Event AfterXmlExport As WorkbookEvents_AfterXmlExportEventHandler
public event WorkbookEvents_AfterXmlExportEventHandler AfterXmlExport

示例

下面的代码示例演示如何从工作簿中导出 XML 数据。 该示例将 XML 数据从 DataSet 导入到当前工作簿的 XmlMap 中。 然后,该示例调用 SaveAsXMLData 方法将数据从 XmlMap 导出到 XML 文件中。 调用 SaveAsXMLData 方法时,BeforeXmlExport 事件处理程序报告正在导出 XML,并且 AfterXmlExport 事件处理程序报告是否已成功导出 XML。

此示例针对的是文档级自定义项。

Private Sub WorkbookXmlExportEvents()

    ' Create a new DataTable.
    Dim ds As New DataSet()
    Dim dt As DataTable = ds.Tables.Add("Customers")
    dt.Columns.Add(New DataColumn("LastName"))
    dt.Columns.Add(New DataColumn("FirstName"))

    ' Add a new row to the DataTable.
    Dim dr As DataRow = dt.NewRow()
    dr("LastName") = "Chan"
    dr("FirstName") = "Gareth"
    dt.Rows.Add(dr)

    ' Add a new XML map.
    Dim xmlMap1 As Excel.XmlMap = Me.XmlMaps.Add( _
        ds.GetXmlSchema())

    ' Import the data into Sheet1. 
    Dim range1 As Excel.Range = Globals.Sheet1.Range("A1")
    Me.XmlImportXml(ds.GetXml(), xmlMap1, True, _
        range1)

    If xmlMap1.IsExportable Then
        Me.SaveAsXMLData(Me.Name & ".xml", xmlMap1)
    End If
End Sub

Sub ThisWorkbook_BeforeXmlExport(ByVal Map As Excel.XmlMap, _
    ByVal Url As String, ByRef Cancel As Boolean) _
    Handles Me.BeforeXmlExport

    MsgBox("Microsoft Excel is exporting XML from " & _
        "the XmlMap.")
End Sub

Sub ThisWorkbook_AfterXmlExport(ByVal Map As Excel.XmlMap, _
    ByVal Url As String, ByVal Result As Excel.XlXmlExportResult) _
    Handles Me.AfterXmlExport

    If Result = Excel.XlXmlExportResult.xlXmlExportSuccess Then
        MsgBox("XML export succeeded.")
    Else
        MsgBox("XML export failed.")
    End If
End Sub
private void WorkbookXmlExportEvents()
{
    this.BeforeXmlExport +=
        new Excel.WorkbookEvents_BeforeXmlExportEventHandler(
        ThisWorkbook_BeforeXmlExport);

    this.AfterXmlExport +=
        new Excel.WorkbookEvents_AfterXmlExportEventHandler(
        ThisWorkbook_AfterXmlExport);

    // Create a new DataTable.
    DataSet ds = new DataSet();
    DataTable dt = ds.Tables.Add("Customers");
    dt.Columns.Add(new DataColumn("LastName"));
    dt.Columns.Add(new DataColumn("FirstName"));

    // Add a new row to the DataTable.
    DataRow dr = dt.NewRow();
    dr["LastName"] = "Chan";
    dr["FirstName"] = "Gareth";
    dt.Rows.Add(dr);

    // Add a new XML map.
    Excel.XmlMap xmlMap1 = this.XmlMaps.Add(
        ds.GetXmlSchema(), missing);

    // Import the data into Sheet1. 
    Excel.Range range1 = Globals.Sheet1.Range["A1", missing];
    this.XmlImportXml(ds.GetXml(), out xmlMap1, true,
       range1);

    // Export the data.
    if (xmlMap1.IsExportable)
    {
        this.SaveAsXMLData(this.Name + ".xml", xmlMap1);
    }
}

void ThisWorkbook_BeforeXmlExport(Excel.XmlMap Map, string Url,
    ref bool Cancel)
{
    MessageBox.Show("Microsoft Excel is exporting XML from " +
        "the XmlMap.");
}

void ThisWorkbook_AfterXmlExport(Excel.XmlMap Map, string Url,
    Excel.XlXmlExportResult Result)
{
    if (Result == Excel.XlXmlExportResult.xlXmlExportSuccess)
    {
        MessageBox.Show("XML export succeeded.");
    }
    else
    {
        MessageBox.Show("XML export failed.");
    }
}

.NET Framework 安全性

请参见

参考

WorkbookBase 类

Microsoft.Office.Tools.Excel 命名空间