C#word拼写检查对话框,如何不打开word
我在c#中使用一个单词引用,我需要知道如何使它在使用拼写检查对话框时不会打开office,下面是代码C#word拼写检查对话框,如何不打开word,c#,C#,我在c#中使用一个单词引用,我需要知道如何使它在使用拼写检查对话框时不会打开office,下面是代码 private void metroButton8_Click(object sender, EventArgs e) { Word.Application app = new Word.Application(); int errors = 0; if (richTextBox1.Text.Length > 0) { app.Visibl
private void metroButton8_Click(object sender, EventArgs e)
{
Word.Application app = new Word.Application();
int errors = 0;
if (richTextBox1.Text.Length > 0)
{
app.Visible = false;
// Setting these variables is comparable to passing null to the function.
// This is necessary because the C# null cannot be passed by reference.
object template = Missing.Value;
object newTemplate = Missing.Value;
object documentType = Missing.Value;
object visible = true;
Word._Document doc1 = app.Documents.Add(ref template, ref newTemplate, ref documentType, ref visible);
doc1.Words.First.InsertBefore(richTextBox1.Text);
Word.ProofreadingErrors spellErrorsColl = doc1.SpellingErrors;
errors = spellErrorsColl.Count;
object optional = Missing.Value;
doc1.CheckSpelling(
ref optional, ref optional, ref optional, ref optional, ref optional, ref optional,
ref optional, ref optional, ref optional, ref optional, ref optional, ref optional);
object first = 0;
object last = doc1.Characters.Count - 1;
richTextBox1.Text = doc1.Range(ref first, ref last).Text;
}
}
如果您知道如何提供帮助,请执行在“如果文档或范围包含错误,此方法将显示拼写和语法对话框”中明确指出。因此,请改用app.CheckSpelling()。它在“如果文档或区域包含错误,此方法将显示拼写和语法对话框”中有明确说明。因此,请改用app.CheckSpelling()。