Beispiel #1
0
        public static void DetectHeaders(Document doc)
        {
            try {
                for (int i = 1; i < doc.Paragraphs.Count; i++)
                {
                    Paragraph paragraph = doc.Paragraphs[i];

                    Style  style     = paragraph.get_Style() as Style;
                    int    position  = paragraph.ParaID;
                    string styleName = style.NameLocal;
                    string text      = paragraph.Range.Text;

                    ConsoleC.Write(ConsoleColor.DarkCyan, styleName + "   ");
                    ConsoleC.Write(ConsoleColor.Cyan, position + "    ");
                    ConsoleC.WriteLine(ConsoleColor.Blue, StringMethods.TrimAndShorten(text, 20));
                    ////This checks the spacing after every paragraph.
                    //if (position == 360681186)
                    //{
                    //    ConsoleC.WriteLine(ConsoleColor.Cyan, "Left indent: "+paragraph.Format.LeftIndent);
                    //}

                    //This checks the heading size.
                    if (styleName == "Heading 1")
                    {
                        ConsoleC.WriteLine(ConsoleColor.Green, "Acceptable heading size.");

                        //// Check whether the first-level heading is followed by
                        //// either a second-level heading or a 3–4 lines of body text.
                        DetectParaAfterHeadingOne(doc, i);
                    }
                    else if (styleName == "Heading 2")
                    {
                        ConsoleC.WriteLine(ConsoleColor.Green, "Acceptable heading size.");
                    }
                    else if (styleName == "Heading 3")
                    {
                        ConsoleC.WriteLine(ConsoleColor.Green, "Acceptable heading size.");
                    }
                    else if (styleName == "Heading 4")
                    {
                        ConsoleC.WriteLine(ConsoleColor.Green, "Acceptable heading size.");
                    }
                    else if (styleName == "Heading 5" || styleName == "Heading 6")
                    {
                        ConsoleC.WriteLine(ConsoleColor.Red, "Header is too small.");
                        Comments.Add(doc, paragraph, "Heading level should be 1, 2, 3, or 4, but this is a " + styleName + ".");
                    }
                }
            }
            catch (Exception ex)
            {
                ConsoleC.WriteLine(ConsoleColor.Red, "Error in DetectHeaders() — " + ex.ToString());
            }
        }
Beispiel #2
0
        //// Add() is overloaded such that it will accept either a Document, Paragraph, and String,
        //// or a Document, int, and string. The string is coerced into an object to work with interop.
        //// If the second parameter is an int 'k', it is treated as referring to the 'k'th word in the Document.
        public static void Add(Document doc, Paragraph placeForComment, object comment)
        {
            try
            {
                ConsoleC.Write(ConsoleColor.White, "\nAdding a comment — ");
                ConsoleC.WriteLine(ConsoleColor.Blue, comment);

                doc.Comments.Add(placeForComment.Range, ref comment);
            }
            catch
            {
                ConsoleC.WriteLine(ConsoleColor.Red, "Failed to add a comment to paragraph!");
            }
        }
Beispiel #3
0
        public static void Add(Document doc, int k, object comment)
        {
            try
            {
                ConsoleC.Write(ConsoleColor.White, "\nAdding a comment of ");
                ConsoleC.Write(ConsoleColor.Blue, comment);
                ConsoleC.WriteLine(ConsoleColor.White, " to word #" + k + ".");

                doc.Comments.Add(doc.Words[k], ref comment);
            }

            catch
            {
                ConsoleC.WriteLine(ConsoleColor.Red, "Failed to add a comment to word #" + k + "!");
            }
        }
Beispiel #4
0
        public static void LanguageChecker(Document doc)
        {
            try
            {
                int count = doc.Words.Count;

                int countUKEnglish      = 0;
                int countUSEnglish      = 0;
                int countNotUKUSEnglish = 0;

                ConsoleC.WriteLine(ConsoleColor.White, "Checking the language of every word...");

                for (int k = 1; k <= count; k++)
                {
                    //// Write a marker of where we are in the document every kth word.
                    if (k % 50 == 0)
                    {
                        ConsoleC.Write(ConsoleColor.Black, ConsoleColor.Gray, " " + k + " / " + count + " ");
                    }

                    string text = doc.Words[k].Text;

                    //// Check language

                    if (doc.Words[k].LanguageID == WdLanguageID.wdEnglishUK)
                    {
                        ConsoleC.Write(ConsoleColor.Green, text);
                        countUKEnglish++;
                        // ConsoleC.WriteLine(ConsoleColor.Green, "\nThis is a UK/US English word.");
                    }
                    else if (doc.Words[k].LanguageID == WdLanguageID.wdEnglishUS)
                    {
                        ConsoleC.Write(ConsoleColor.Yellow, text);
                        countUSEnglish++;
                        if (countUSEnglish % 10 == 1)
                        {
                            Comments.Add(doc, k, "This is US English but should be UK English.");
                        }
                    }
                    else
                    {
                        ConsoleC.WriteLine(ConsoleColor.Red, "\n" + text);
                        ConsoleC.WriteLine(ConsoleColor.Red, "This is not a UK or US English word.");
                        countNotUKUSEnglish++;
                        if (countNotUKUSEnglish % 10 == 1)
                        {
                            Comments.Add(doc, k, "This is not UK English but should be.");
                        }
                    }
                }

                //// Give feedback after all the words have been checked.
                ConsoleC.WriteLine(ConsoleColor.White, "\nFinished checking language.");

                ConsoleC.WriteLine(ConsoleColor.Green, countUKEnglish + " words were UK English. This is good!");
                if (countUSEnglish > 0)
                {
                    ConsoleC.WriteLine(ConsoleColor.Yellow, countUSEnglish + " words were US English. Please change these to UK English.");
                }
                if (countNotUKUSEnglish > 0)
                {
                    ConsoleC.WriteLine(ConsoleColor.Red, countNotUKUSEnglish + " words were neither. Please change these to UK English.");
                }
            }
            catch (Exception ex)
            {
                ConsoleC.WriteLine(ConsoleColor.Red, ex.ToString());
            }
        }