مشاركة عبر


WorkbookBase.XmlImportXml أسلوب

قم باستيراد دفق بيانات XML التي تم تم تحميله مسبقاً في ذاكرة.

مساحة الاسم:  Microsoft.Office.Tools.Excel
التجميع:  Microsoft.Office.Tools.Excel.v4.0.Utilities (في Microsoft.Office.Tools.Excel.v4.0.Utilities.dll)

بناء الجملة

'إقرار
Public Function XmlImportXml ( _
    data As String, _
    <OutAttribute> ByRef importMap As XmlMap, _
    overwrite As Object, _
    destination As Object _
) As XlXmlImportResult
public XlXmlImportResult XmlImportXml(
    string data,
    out XmlMap importMap,
    Object overwrite,
    Object destination
)

المعلمات

  • data
    النوع: System.String
    بيانات إلى استيراد.
  • overwrite
    النوع: System.Object
    إذا كانت القيمة هو غير محدد ل Destinationمعلمة، ثم th هو تعين معلمة أو عدم الكتابة فوق بيانات التي يتم تعيين إلى مخطط المخطط المحدد في ImportMapمعلمة.التعيين إلى trueالكتابة فوق البيانات موجود أو falseلإلحاق بيانات جديدة إلى البيانات موجود.القيمة الافتراضية هي true.إذا كانت القيمة هو المحددة ل Destinationمعلمة، ثم th هو تعين معلمة أو عدم الكتابة فوق بيانات exهوting.قم بتعيين trueالكتابة فوق بيانات موجود أو falseإلى إلغاء الأمر استيراد إذا قد تتم الكتابة فوق بيانات.القيمة الافتراضية هي true.
  • destination
    النوع: System.Object
    سيتم استيراد بيانات إلى قائمة XML جديد في Rangeالمحدد.

القيمة المُرجعة

النوع: Microsoft.Office.Interop.Excel.XlXmlImportResult
واحد XlXmlImportResultقيم.

ملاحظات

لا تقم بتحديد القيمة ل Destinationمعلمة إذا كنت تريد في استيراد البيانات في في موجودة التعيين.

الشروط التالية سيؤدي هذا الأسلوب إلى إنشاء أخطاء وقت التشغيل:

  • بيانات XML المحدد يحتوي على أخطاء في بناء الجملة.

  • تم الإلغاء عملية استيراد بسبب تعذر احتواء بيانات المحددة في ورقة عمل.

استخدام XmlImportأسلوب إلى استيراد ملف بيانات XML في إلى مصنف الحالي.

المعلمات الإختيارية

ل معلومات تشغيل معلمات اختيارية، راجع يفتقد المتغير و "المعلمات الاختيارية" في حلول Office.

أمثلة

يوضح مثال التعليمة البرمجية التالية كيفية استيراد بيانات XML في مصنف. ينشئ المثال DataSetمن العميل أسماء وإضافة XmlMapاستناداً إلى مخطط XML DataSet XmlMapsمجموعة في مصنف الحالي. المثال ثم استدعاء XmlImportXmlأسلوب في استيراد بيانات الموجودة في في ورقة Sheet1. عند XmlImportXmlأسلوب هو تسمى، BeforeXmlImportمعالج الأحداث بمطالبة مستخدم بمتابعة أو إلغاء الأمر استيراد XML، و AfterXmlImportمعالج حدث تقرير ما إذا كان تم بنجاح استيراد XML.

Th هو المثال هو لتخصيص المستوى مستند.

Private Sub WorkbookXmlImportEvents()

    ' 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 to the collection.
    Dim xmlMap1 As Excel.XmlMap = Me.XmlMaps.Add(ds.GetXmlSchema(), _
        "NewDataSet")

    ' Import the data stream if the XmlMap was successfully created.
    If Not (xmlMap1 Is Nothing) Then

        ' This will raise the BeforeXmlImport and AfterXmlImport events.
        Dim range1 As Excel.Range = Globals.Sheet1.Range("A1")
        Me.XmlImportXml(ds.GetXml(), xmlMap1, True, _
            range1)
    Else
        MsgBox("The XmlMap could not be created")
    End If
End Sub

Sub ThisWorkbook_BeforeXmlImport(ByVal Map As Excel.XmlMap, _
    ByVal Url As String, ByVal IsRefresh As Boolean, _
    ByRef Cancel As Boolean) Handles Me.BeforeXmlImport

    If DialogResult.No = MessageBox.Show("Microsoft Excel is about" & _
        " to import XML into the workbook. Continue with importing?", _
        "Custom XML Import Dialog", MessageBoxButtons.YesNo) Then
        Cancel = True
    End If
End Sub

Sub ThisWorkbook_AfterXmlImport(ByVal Map As Excel.XmlMap, _
    ByVal IsRefresh As Boolean, ByVal Result As Excel.XlXmlImportResult) _
    Handles Me.AfterXmlImport

    If Result = Excel.XlXmlImportResult.xlXmlImportSuccess Then
        MsgBox("XML import succeeded.")
    Else
        MsgBox("XML import failed.")
    End If
End Sub
private void WorkbookXmlImportEvents()
{
    this.BeforeXmlImport +=
        new Excel.WorkbookEvents_BeforeXmlImportEventHandler(
        ThisWorkbook_BeforeXmlImport);

    this.AfterXmlImport += new
        Excel.WorkbookEvents_AfterXmlImportEventHandler(
        ThisWorkbook_AfterXmlImport);

    // 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 to the collection.
    Excel.XmlMap xmlMap1 = this.XmlMaps.Add(ds.GetXmlSchema(),
        "NewDataSet");

    // Import the data stream if the XmlMap was successfully created.
    if (xmlMap1 != null)
    {
        // This will raise the BeforeXmlImport and AfterXmlImport events.
        Excel.Range range1 = Globals.Sheet1.Range["A1", missing];
        this.XmlImportXml(ds.GetXml(), out xmlMap1, true,
            range1);
    }
    else
    {
        MessageBox.Show("The XmlMap could not be created");
    }
}

void ThisWorkbook_BeforeXmlImport(Excel.XmlMap Map,
    string Url, bool IsRefresh, ref bool Cancel)
{
    if (DialogResult.No == MessageBox.Show("Microsoft Excel is about" +
        " to import XML into the workbook. Continue with importing?",
        "Custom XML Import Dialog", MessageBoxButtons.YesNo))
    {
        Cancel = true;
    }
}

void ThisWorkbook_AfterXmlImport(Excel.XmlMap Map, bool IsRefresh,
    Excel.XlXmlImportResult Result)
{
    if (Result == Excel.XlXmlImportResult.xlXmlImportSuccess)
    {
        MessageBox.Show("XML import succeeded.");
    }
    else
    {
        MessageBox.Show("XML import failed.");
    }
}

أمن NET Framework.

راجع أيضًَا

المرجع

WorkbookBase الفئة

WorkbookBase الأعضاء

Microsoft.Office.Tools.Excel مساحة الاسم