none
How to xml file data comaire and mitchmatch data show in excel file RRS feed

  • Question

  • hi to all,

    I want to How to two xml files data comaire and mitchmatch data  show in excel file.

    i am using this code


      private void btnCompaire_Click(object sender, RoutedEventArgs e)
            {
                List<string> fileslist = new List<string>();
                var list = new List<KeyValuePair<string, string>>();
                //string[] finaltxtfiledata;
                // KeyValuePair<string, string> finallist = new KeyValuePair<string, string>();
                if (File.Exists(txtpath))
                {
                    string[] LinesinText = File.ReadAllLines(txtpath);
                    fileslist.Add(LinesinText[0]);
                    fileslist.Add(LinesinText[1]);
                }
                string[] Linesin1 = File.ReadAllLines(fileslist[0]);
                string[] Linesin2 = File.ReadAllLines(fileslist[1]);
                bool areEqual = Linesin1pcfg.SequenceEqual(Linesin2pcfg);
                int onecount = Linesin1.Count();
                int twocount = Linesin2.Count();
                int finalcount;
                if (onecount > twocount)
                {
                    finalcount = onecount;
                }
                else
                {
                    finalcount = twocount;
                }

                if (!areEqual)
                {
                    for (int i = 0; i < finalcount; i++)
                    {
                        try
                        {
                            if (Linesin1pcfg[i] != null && Linesin2[i] != null)
                            {
                                if (Linesin1pcfg[i].Equals(Linesin2[i]))
                                {
                                    //.Application oExcel = new Microsoft.Office.Interop.Excel.Application();
                                    //Excel._Workbook oWorkBook;
                                    //Excel._Worksheet oSheet;  
                                    Microsoft.Office.Interop.Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application();

                                    if (xlApp != null)
                                    {
                                       // xlApp.Visible = true;
                                        
                                        string workbookPath = Linesin1[i];
                                        Microsoft.Office.Interop.Excel.Application excelApp = new Microsoft.Office.Interop.Excel.Application();
                                        Microsoft.Office.Interop.Excel.Workbook excelWorkbook = excelApp.Workbooks.Open(workbookPath);
                                        Microsoft.Office.Interop.Excel.Worksheet sheet = excelWorkbook.Sheets["Sheet1"] as      Microsoft.Office.Interop.Excel.Worksheet;

                                        if (sheet == null) return;
                                        Microsoft.Office.Interop.Excel.Range range = sheet.get_Range("A1", Missing.Value);
                                        var yourValue = range.Text;
                                    }

                                }
                                else
                                {
                                    list.Add(new KeyValuePair<string, string>(Linesin1[i], Linesin2[i]));

                                }
                            }
                        }
                        catch (Exception)
                        {

                            continue;
                        }

                    }
                }
            }

    In this code i am getting value :

    xaml file path in TextFile  : like C:\Desktop\abc.xml

                                                  C:\Desktop\xyz.xml

    In Both files contaion some data like abc.xml file contaion 150 lines  & xyz.xml file contain 200 lines of xml code.

    Getting data of both files

      string[] Linesin1 = File.ReadAllLines(fileslist[0]);
      string[] Linesin2 = File.ReadAllLines(fileslist[1]);

    Now i want to how to compaire data of both files and show in a EXCEL file.

    Mismatch  xml data show on EXCEL file.

    Thanks.

    Wednesday, November 15, 2017 6:08 AM

All replies

  • Hi,

    >>Now i want to how to compaire data of both files and show in a EXCEL file.

    Base on your description, Do you mean that you want to compare every line of content in array named Linesin1 and  Linesin2, if so, you could loop the array and compare the content of every line, if they are different, you could insert them into excel.

    Because your code is not completed, I am not sure what is the issue on your code.

    If i misunderstand, please describe it detailed and feel free let me know.

    Best regards,

    Cole Wu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, November 16, 2017 5:10 AM
    Moderator