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 資料從活頁簿中匯出。範例會從 DataSet 匯入 XML 資料至目前活頁簿的 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());
// Import the data into Sheet1.
Excel.Range range1 = Globals.Sheet1.Range["A1"];
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 安全性
- 完全信任立即呼叫者。這個成員無法供部分信任的程式碼使用。如需詳細資訊,請參閱從部分受信任程式碼使用程式庫。