Ejemplo n.º 1
0
        //本科论文页眉页脚检测
        private void detectUnderHeaderFooter(WordprocessingDocument docx)
        {
            Body body = docx.MainDocumentPart.Document.Body;
            IEnumerable <Paragraph>  paras  = body.Elements <Paragraph>();
            SectionProperties        scetpr = body.GetFirstChild <SectionProperties>();
            MainDocumentPart         Mpart  = docx.MainDocumentPart;
            List <SectionProperties> list   = secPrList(body);

            list.Add(scetpr);
            //List<int> intlist = secPrListInt(body);     //节的位置

            string docname = getChineseTitleOfDocx(paras, indexOfChineseTitleOfDocx);  //论文中文题目


            if (list.Count == 0)
            {
                return;
            }

            for (int i = 2; i <= list.Count <SectionProperties>(); i++)
            {
                SectionProperties             s      = list[i - 1];
                IEnumerable <HeaderReference> headrs = s.Elements <HeaderReference>();

                foreach (HeaderReference headr in headrs)
                {
                    #region 页眉
                    if (headr != null && headr.Type == HeaderFooterValues.Default)
                    {
                        string     ID     = headr.Id.ToString();
                        HeaderPart hp     = (HeaderPart)Mpart.GetPartById(ID);
                        Header     header = hp.Header;

                        if (header.InnerText.Trim() != "")
                        {
                            Paragraph p          = header.GetFirstChild <Paragraph>();
                            string    headername = header.InnerText.Trim();
                            if (Util.correctfonts(p, docx, CNheaderFonts, ENHeaderFonts) == false)
                            {
                                PaperFormatDetection.Tools.Util.printError("第" + i + "节" + "页眉字体错误,应为:" + CNheaderFonts);
                            }

                            if (Util.correctsize(p, docx, headerFontsize) == false)
                            {
                                PaperFormatDetection.Tools.Util.printError("第" + i + "节" + "页眉字号错误,应为:" + headerFontsize);
                            }
                            if (Util.correctJustification(p, docx, headerJustification) == false)
                            {
                                PaperFormatDetection.Tools.Util.printError("第" + i + "节" + "页眉对齐错误,应为:" + headerJustification);
                            }
                            if (headername != docname)
                            {
                                PaperFormatDetection.Tools.Util.printError("第" + i + "节" + "页眉内容错误,应为:" + docname);
                            }
                        }
                    }
                    #endregion
                }

                IEnumerable <FooterReference> footrs = s.Elements <FooterReference>();
                foreach (FooterReference footr in footrs)
                {
                    if (footr != null)
                    {
                        string     ID     = footr.Id.ToString();
                        FooterPart fp     = (FooterPart)Mpart.GetPartById(ID);
                        Footer     footer = fp.Footer;
                        Paragraph  p      = footer.GetFirstChild <Paragraph>();

                        if (footer.InnerText != null && footer.InnerText.Trim() != "")
                        {
                            if (Util.correctfonts(p, docx, CNFooterFonts, ENFooterFonts) == false)
                            {
                                Util.printError("第" + i + "节" + "页脚字体错误,应为:" + CNFooterFonts);
                            }

                            if (Util.correctsize(p, docx, footerFontsize) == false)
                            {
                                PaperFormatDetection.Tools.Util.printError("第" + i + "节" + "页脚字号错误,应为:" + footerFontsize);
                            }
                            if (Util.correctJustification(p, docx, footerJustification) == false)
                            {
                                PaperFormatDetection.Tools.Util.printError("第" + i + "节" + "页脚对齐错误,应为:" + footerJustification);
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        protected void detectHeaderFooter(WordprocessingDocument docx)
        {
            Body body = docx.MainDocumentPart.Document.Body;
            IEnumerable <Paragraph>  paras = body.Elements <Paragraph>();
            MainDocumentPart         Mpart = docx.MainDocumentPart;
            List <SectionProperties> list  = secPrList(body);
            List <int>        intlist      = secPrListInt(body);
            SectionProperties scetpr       = body.GetFirstChild <SectionProperties>();
            //list.Add(scetpr);
            //intlist.Add(body.ChildElements.Count() - 1);
            SectionProperties s = null;

            for (int i = 2; i <= list.Count <SectionProperties>(); i++)
            {
                s = list[i - 1];
                string chapter = null;
                if (intlist[i - 1] < body.ChildElements.Count)
                {
                    chapter = getPicMassage(intlist[i - 1], body) + "---所在章的";
                }

                //页眉
                IEnumerable <HeaderReference> headrs = s.Elements <HeaderReference>();

                foreach (HeaderReference headr in headrs)
                {
                    string headertype = null;
                    if (headr.Type == HeaderFooterValues.Default)
                    {
                        headertype = "奇数页";
                    }
                    if (headr.Type == HeaderFooterValues.Even)
                    {
                        headertype = "偶数页";
                    }
                    string     ID     = headr.Id.ToString();
                    HeaderPart hp     = (HeaderPart)Mpart.GetPartById(ID);
                    Header     header = hp.Header;
                    Paragraph  p      = header.GetFirstChild <Paragraph>();
                    if (header.InnerText != null)
                    {
                        if (Util.correctfonts(p, docx, CNheaderFonts, ENHeaderFonts) == false)
                        {
                            PaperFormatDetection.Tools.Util.printError("页眉字体错误,应为:" + CNheaderFonts + "----" + chapter + headertype);
                        }
                        if (Util.correctsize(p, docx, headerFontsize) == false)
                        {
                            PaperFormatDetection.Tools.Util.printError("页眉字号错误,应为:" + headerFontsize + "----" + headertype);
                        }
                        if (JustificationCenter(p, Mpart) == false)
                        {
                            PaperFormatDetection.Tools.Util.printError("页眉未居中" + "----" + chapter + headertype);
                        }
                    }
                }
                //页脚
                IEnumerable <FooterReference> footrs = s.Elements <FooterReference>();
                foreach (FooterReference footr in footrs)
                {
                    string type = null;
                    if (footr.Type == HeaderFooterValues.Default)
                    {
                        type = "奇数页";
                    }
                    if (footr.Type == HeaderFooterValues.Even)
                    {
                        type = "偶数页";
                    }
                    string     ID     = footr.Id.ToString();
                    FooterPart fp     = (FooterPart)Mpart.GetPartById(ID);
                    Footer     footer = fp.Footer;
                    Paragraph  p      = footer.GetFirstChild <Paragraph>();

                    if (footer.InnerText.Trim() != "")
                    {
                        if (Util.correctfonts(p, docx, CNFooterFonts, ENFooterFonts) == false)
                        {
                            Util.printError("页脚字体错误,应为:" + CNFooterFonts + "----" + chapter + type);
                        }
                        if (Util.correctsize(p, docx, footerFontsize) == false)
                        {
                            Util.printError("页脚字号错误,应为:" + footerFontsize + "----" + chapter + type);
                        }
                        if (JustificationCenter(p, Mpart) == false)
                        {
                            Util.printError("页脚未居中" + "----" + chapter + type);
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
        //判断偶数页
        protected void detectEven(WordprocessingDocument docx)
        {
            Body body = docx.MainDocumentPart.Document.Body;
            IEnumerable <Paragraph>  paras  = body.Elements <Paragraph>();
            MainDocumentPart         Mpart  = docx.MainDocumentPart;
            List <SectionProperties> list   = secPrList(body);
            SectionProperties        scetpr = body.GetFirstChild <SectionProperties>();

            list.Add(scetpr);


            HeaderReference headereven = null;
            FooterReference footereven = null;

            if (list.Count == 0)
            {
                return;
            }
            bool[] flag   = { false, false, false, false }; //终止循环
            bool[] flagyj = { false, false, false };        //终止循环
            for (int i = 2; i <= list.Count <SectionProperties>(); i++)
            {
                SectionProperties             s      = list[i - 1];
                IEnumerable <HeaderReference> headrs = s.Elements <HeaderReference>();

                foreach (HeaderReference headr in headrs)
                {
                    if (headr.Type == HeaderFooterValues.Even)
                    {
                        headereven = headr;
                    }
                }

                if (headereven != null)
                {
                    string     ID     = headereven.Id.ToString();
                    HeaderPart hp     = (HeaderPart)Mpart.GetPartById(ID);
                    Header     header = hp.Header;
                    Paragraph  p      = header.GetFirstChild <Paragraph>();

                    if (header.InnerText != null)
                    {
                        string headername = header.InnerText.Trim();
                        if (flag[0] == false && Util.correctfonts(p, docx, CNheaderFonts, ENHeaderFonts) == false)
                        {
                            PaperFormatDetection.Tools.Util.printError("偶数页页眉字体错误,应为:" + CNheaderFonts);
                            flag[0] = true;
                        }

                        if (flag[1] == false && Util.correctsize(p, docx, headerFontsize) == false)
                        {
                            PaperFormatDetection.Tools.Util.printError("偶数页页眉字号错误,应为:" + headerFontsize);
                            flag[1] = true;
                        }
                        if (flag[2] == false && JustificationCenter(p, Mpart) == false)
                        {
                            PaperFormatDetection.Tools.Util.printError("偶数页页眉未居中");
                            flag[2] = true;
                        }
                        if (flag[3] == false && headername != evenHeaderText)
                        {
                            PaperFormatDetection.Tools.Util.printError("偶数页页眉内容错误,应为:" + evenHeaderText);
                            flag[3] = true;
                        }
                    }
                }
                //页脚
                IEnumerable <FooterReference> footrs = s.Elements <FooterReference>();
                foreach (FooterReference footr in footrs)
                {
                    if (footr.Type == HeaderFooterValues.Default)
                    {
                        footereven = footr;
                    }
                }
                if (footereven != null)
                {
                    string     ID     = footereven.Id.ToString();
                    FooterPart fp     = (FooterPart)Mpart.GetPartById(ID);
                    Footer     footer = fp.Footer;
                    Paragraph  p      = footer.GetFirstChild <Paragraph>();

                    if (footer.InnerText != null)
                    {
                        if (flagyj[0] == false && Util.correctfonts(p, docx, CNFooterFonts, ENFooterFonts) == false)
                        {
                            PaperFormatDetection.Tools.Util.printError("偶数页页脚字体错误,应为" + CNFooterFonts);
                            flagyj[0] = true;
                        }

                        if (flagyj[1] == false && Util.correctsize(p, docx, footerFontsize) == false)
                        {
                            PaperFormatDetection.Tools.Util.printError("偶数页页脚字号错误,应为:" + footerFontsize);
                            flagyj[1] = true;
                        }
                        if (flagyj[2] == false && JustificationCenter(p, Mpart) == false)
                        {
                            PaperFormatDetection.Tools.Util.printError("偶数页页脚未居中");
                            flagyj[2] = true;
                        }
                    }
                }
            }
        }