static void Main()
    {
        Console.WriteLine("Enter a string to spell-check:");
        string stringToSpellCheck = Console.ReadLine();
        string spellingResults;
        int    errors = 0;

        if (stringToSpellCheck.Length == 0)
        {
            spellingResults = "No string to check";
        }
        else
        {
            Microsoft.Office.Interop.Word.Application app = new Microsoft.Office.Interop.Word.Application();
            Console.WriteLine("\nChecking the string for misspellings ...");
            app.Visible = false;

            Microsoft.Office.Interop.Word._Document tempDoc = app.Documents.Add();

            tempDoc.Words.First.InsertBefore(stringToSpellCheck);
            Microsoft.Office.Interop.Word.ProofreadingErrors spellErrorsColl = tempDoc.SpellingErrors;
            errors = spellErrorsColl.Count;

            // 1. Without using optional parameters
            // object ignoreCase    = true;
            // object alwaysSuggest = false;
            // object optional      = Missing.Value;
            // tempDoc.CheckSpelling( ref optional, ref ignoreCase, ref alwaysSuggest,
            //     ref optional, ref optional, ref optional, ref optional, ref optional,
            //     ref optional, ref optional, ref optional, ref optional );

            //2. Using the "omit ref" feature
            object optional = Missing.Value;
            tempDoc.CheckSpelling(optional, true, false, optional, optional, optional, optional, optional, optional, optional, optional, optional);

            //3. Using "omit ref" and optional parameters tempDoc.CheckSpelling( Missing.Value, true, false );
            app.Quit(false);
            spellingResults = errors + " errors found";
        }

        Console.WriteLine(spellingResults);
        Console.WriteLine("\nPress <Enter> to exit program.");
        Console.ReadLine();
    }
Example #2
0
    /*-------------------------word转化----------------------------------------------------------*/
    private static void WordToHtmlFile(string WordFilePath)
    {
        Microsoft.Office.Interop.Word.Application newApp = new Microsoft.Office.Interop.Word.Application();
        // 指定原文件和目标文件
        object Source       = WordFilePath;
        string SaveHtmlPath = WordFilePath.Substring(0, WordFilePath.Length - 3) + "html";
        object Target       = SaveHtmlPath;

        // 缺省参数
        object Unknown = Type.Missing;

        //为了保险,只读方式打开
        object readOnly = true;

        // 打开doc文件
        Microsoft.Office.Interop.Word.Document doc = newApp.Documents.Open(ref Source, ref Unknown,
                                                                           ref readOnly, ref Unknown, ref Unknown,
                                                                           ref Unknown, ref Unknown, ref Unknown,
                                                                           ref Unknown, ref Unknown, ref Unknown,
                                                                           ref Unknown, ref Unknown, ref Unknown,
                                                                           ref Unknown, ref Unknown);

        // 指定另存为格式(rtf)
        object format = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatHTML;

        // 转换格式
        doc.SaveAs(ref Target, ref format,
                   ref Unknown, ref Unknown, ref Unknown,
                   ref Unknown, ref Unknown, ref Unknown,
                   ref Unknown, ref Unknown, ref Unknown,
                   ref Unknown, ref Unknown, ref Unknown,
                   ref Unknown, ref Unknown);

        // 关闭文档和Word程序
        doc.Close(ref Unknown, ref Unknown, ref Unknown);
        newApp.Quit(ref Unknown, ref Unknown, ref Unknown);
    }