如何在excel文件中显示xml文件数据comaire和mitchmatch数据 [英] How to xml file data comaire and mitchmatch data show in excel file

查看:82
本文介绍了如何在excel文件中显示xml文件数据comaire和mitchmatch数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我想如何将两个xml文件数据comaire和mitchmatch数据 在excel文件中显示。


我正在使用此代码





  private void btnCompaire_Click(object sender,RoutedEventArgs e)

        {

           列表与LT;串GT; fileslist = new List< string>();

            VAR列表=新列表与LT; KeyValuePair<串,串>>();

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; // string [] finaltxtfiledata;

            // KeyValuePair< string,string> finallist =新KeyValuePair<串,串>();

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; if(File.Exists(txtpath))

            {

               串[] LinesinText = File.ReadAllLines(txtpath);

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; fileslist.Add(LinesinText [0]);

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; fileslist.Add(LinesinText [1]);

            }
           串[] Linesin1 = File.ReadAllLines(fileslist [0]);

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;串[] Linesin2 = File.ReadAllLines(fileslist [1]);

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;布尔areEqual = Linesin1pcfg.SequenceEqual(Linesin2pcfg);

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; int onecount = Linesin1.Count();

            int twocount = Linesin2.Count();

            int finalcount;

            if(onecount> twocount)

            {

                finalcount = onecount;

            }
           否则为
            {

                finalcount = twocount;

            }


            if(!areEqual)

            {

               对(INT I = 0; I< finalcount;我++)

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; &NBSP; {

                   尝试

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; {

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;如果(Linesin1pcfg [I] = NULL&安培;!&安培; Linesin2 [I]!= NULL)

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; {

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;如果(Linesin1pcfg [I] .Equals(Linesin2 [I]))

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; {

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; //.Application oExcel =新Microsoft.Office.Interop.Excel.Application();

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; //Excel._Workbook oWorkBook;

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; //Excel._Worksheet oSheet; &NBSP;

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; Microsoft.Office.Interop.Excel.Application xlApp =新Microsoft.Office.Interop.Excel.Application();



&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;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&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; Microsoft.Office.Interop.Excel.Application excelApp
=新Microsoft.Office.Interop.Excel.Application();

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; Microsoft.Office.Interop.Excel.Workbook excelWorkbook
= excelApp.Workbooks.Open(workbookPath);

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; &NBSP; Microsoft.Office.Interop.Excel.Worksheet sheet
= excelWorkbook.Sheets [" Sheet1"] as      Microsoft.Office.Interop.Excel.Worksheet;



&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;如果(片== NULL)回报;

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBS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&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; list.Add(新KeyValuePair<串,串>(Linesin1 [I],Linesin2 [I]));



&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; }

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP; }
                    }
                   赶上(例外)

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; {



&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;继续;

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; }


                }
            }
        }






在这段代码中我得到了价值:


TextFile中的xaml文件路径  :像C:\Desktop\abc.xml


&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;
C:\Desktop\xyz.xml



在这两个文件,容像abc.xml文件,容一些数据150线&NBSP ; &安培; xyz.xml文件包含200行xml代码。


获取两个文件的数据


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

 串[] Linesin2 = File.ReadAllLines(fileslist [1]);



立即我想如何compaire两者的数据文件并显示在EXCEL文件中。


不匹配  xml数据显示在EXCEL文件中。



谢谢。






解决方案

您好,


>> 现在我想如何比较两个文件的数据并在EXCEL文件中显示。


根据您的描述,你的意思是你要比较名为  Linesin1和 的数组中的每一行内容。 Linesin2,如果是这样,你可以循环数组并比较每一行的内容,如果它们不同,你可以将它们插入到
excel中。


由于您的代码未完成,我不确定您的代码有什么问题。


如果我误解了,请详细说明请随时告诉我。


祝你好运,


Cole Wu


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.

解决方案

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


这篇关于如何在excel文件中显示xml文件数据comaire和mitchmatch数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆