Exemple #1
0
        //第一位
        public string[] readList2()
        {
            string fileName = @"D:\Program Files\VS2017_workplace\test4\file_test4\students_answer\1001_张三.docx";

            using (WordprocessingDocument wordprocessingDocument =
                       WordprocessingDocument.Open(fileName, false))
            {
                // Create a Body object.
                DocumentFormat.OpenXml.Wordprocessing.Body body =
                    wordprocessingDocument.MainDocumentPart.Document.Body;

                List <string> list2 = new List <string>();
                foreach (var g in body.Elements())
                {
                    list2.Add(g.InnerText);
                }
                //初始化一个字符数组
                char[] chArr = new char[list2.Count];
                //将list转化为字符串数组
                string[] str = list2.ToArray();
                //调用函数转化为字符数组
                Change CH = new Change();
                chArr = CH.changeCh(str, list2.Count);
                //再转换为string[]
                string[] s = new string[chArr.Length];
                //调用函数
                s = CH.changeStr(chArr);
                return(s);
            }
        }
Exemple #2
0
        //第一篇
        public string[] readList1()
        {
            string fileName = @"F:\国考_标准答案1.docx";

            using (WordprocessingDocument wordprocessingDocument =
                       WordprocessingDocument.Open(fileName, false))
            {
                // Create a Body object.
                DocumentFormat.OpenXml.Wordprocessing.Body body =
                    wordprocessingDocument.MainDocumentPart.Document.Body;

                List <string> list1 = new List <string>();
                foreach (var g in body.Elements())
                {
                    list1.Add(g.InnerText);
                }
                //初始化一个字符数组
                char[] chArr = new char[list1.Count];
                //将list转化为字符串数组
                string[] str = list1.ToArray();
                //调用函数转化为字符数组
                Change CH = new Change();
                chArr = CH.changeCh(str, list1.Count);
                //再转换为string[]
                string[] s = new string[chArr.Length];
                //调用函数
                s = CH.changeStr(chArr);
                return(s);
            }
        }
Exemple #3
0
        //第二篇
        public string[] ReadList2()
        {
            string fileName = @"C:\Users\Administrator.MICROSO-IJAJHM4\Desktop\github\C#_work\CSharp\test3\国考_标准答案2.docx";

            using (WordprocessingDocument wordprocessingDocument = WordprocessingDocument.Open(fileName, false))
            {
                // Create a Body object.
                DocumentFormat.OpenXml.Wordprocessing.Body body = wordprocessingDocument.MainDocumentPart.Document.Body;

                List <string> list2 = new List <string>();
                foreach (var g in body.Elements())
                {
                    list2.Add(g.InnerText);
                }
                //初始化一个字符数组
                char[] ch = new char[list2.Count];
                //将list转化为字符串数组
                string[] str = list2.ToArray();
                //调用函数转化为字符数组
                Operation CH = new Operation();
                ch = CH.OperationCh(str, list2.Count);
                //再转换为string[]
                string[] s = new string[ch.Length];
                //调用函数
                s = CH.changeStr(ch);
                return(s);
            }
        }
Exemple #4
0
        //第三位
        public string[] readList4()
        {
            string fileName = @"C:\Users\lenovo\Desktop\18wang\CSharp\test4\file_test4\students_answer\1003_王五.docx";

            using (WordprocessingDocument wordprocessingDocument =
                       WordprocessingDocument.Open(fileName, false))
            {
                // Create a Body object.
                DocumentFormat.OpenXml.Wordprocessing.Body body =
                    wordprocessingDocument.MainDocumentPart.Document.Body;

                List <string> list4 = new List <string>();
                foreach (var g in body.Elements())
                {
                    list4.Add(g.InnerText);
                }
                //初始化一个字符数组
                char[] chArr = new char[list4.Count];
                //将list转化为字符串数组
                string[] str = list4.ToArray();
                //调用函数转化为字符数组
                Change CH = new Change();
                chArr = CH.changeCh(str, list4.Count);
                //再转换为string[]
                string[] s = new string[chArr.Length];
                //调用函数
                s = CH.changeStr(chArr);
                return(s);
            }
        }
Exemple #5
0
        public ReadWord(string filename)
        {
            try
            {
                using (WordprocessingDocument wordprocessingDocument =
                           WordprocessingDocument.Open(filename, true))
                {
                    // 获取主体
                    DocumentFormat.OpenXml.Wordprocessing.Body body = wordprocessingDocument.MainDocumentPart.Document.Body;

                    // 获取所有元素
                    IEnumerable <DocumentFormat.OpenXml.OpenXmlElement> elements = body.Elements <DocumentFormat.OpenXml.OpenXmlElement>();
                    //遍历元素列表,输出内容
                    foreach (DocumentFormat.OpenXml.OpenXmlElement element in elements)
                    {
                        //Text += element.InnerText+ "\r\n";
                        //Console.WriteLine(element.InnerText);
                        strList += element.InnerText.ToString();
                        TextList.Add(element.InnerText);
                    }
                }
            }
            catch
            {
                Console.WriteLine("没有找到文件");
                Console.ReadKey();
            }
        }
Exemple #6
0
        public void read()
        {
            string fileName = @"D:\Program Files\VS2017_workplace\C#_Git_Work\CSharp\test2\科研细则.docx";

            using (WordprocessingDocument wordprocessingDocument =
                       WordprocessingDocument.Open(fileName, false))
            {
                // Create a Body object.
                DocumentFormat.OpenXml.Wordprocessing.Body body =
                    wordprocessingDocument.MainDocumentPart.Document.Body;

                // Get the Run elements after the specified element.
                Console.WriteLine("Run elements after the first child are: ");
                foreach (var paragraph in body.Elements())
                {
                    Console.WriteLine(paragraph.InnerText);
                }
                Console.ReadKey();
            }
        }