C# word 拼写 语法
来源:互联网 发布:电脑网络参数在哪里 编辑:程序博客网 时间:2024/05/01 23:27
1.引用word库
2.1
try
{
object oMissing = System.Reflection.Missing.Value;
//创建Word对象和临时文档
Microsoft.Office.Interop.Word._Application wdApp = new Microsoft.Office.Interop.Word.Application();
Microsoft.Office.Interop.Word._Document wdDoc = wdApp.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing);
//声明IDataObject存放从剪贴板返回的数据
IDataObject iData;
//定位Word窗口,使之不可见
wdApp.WindowState = 0;
wdApp.Top = -3000;
//复制输入框的文字到剪贴板
Clipboard.SetDataObject(txtWord.Text);
//对临时文档进行拼写或者语法检查
wdDoc.Content.Paste();
wdDoc.Activate();
object ignoreUppercase = true;
object alwaysSuggest = true;
object o = false;
if (blnSpellOnly)
{
wdDoc.CheckSpelling(ref oMissing, ref ignoreUppercase, ref alwaysSuggest, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref
oMissing, ref oMissing);
}
else
{
wdDoc.SpellingChecked = true;
wdDoc.CheckGrammar();
}
//在拼写检查或者语法检查后,如果用户进行了修改,
//利用剪贴板把修改后的数据返回给文本输入框
wdDoc.Content.Copy();
iData = Clipboard.GetDataObject();
if(iData.GetDataPresent(DataFormats.Text))
{
txtWord.Text = (string)(iData.GetData(DataFormats.Text));
}
wdDoc.Saved = true;
wdDoc.Close(ref o, ref oMissing, ref oMissing);
wdApp.Quit(ref o, ref oMissing, ref oMissing);
//MessageBox.Show("拼写检查已经完成!", "拼写检查", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (System.Runtime.InteropServices.COMException COMExcep)
{
MessageBox.Show("必须安装Microsoft Word才能进行拼写或者语法检查。", "拼写检查", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
catch (Exception Excep)
{
MessageBox.Show("错误:" + Excep.Message, "拼写检查", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
2.2
object oMissing = System.Reflection.Missing.Value;
object timeOut = Type.Missing;
object o = false;
Microsoft.Office.Interop.Word._Application wdApp = new Microsoft.Office.Interop.Word.Application();
wdApp.Visible = false;
Microsoft.Office.Interop.Word._Document wdDoc = wdApp.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing);
wdApp.Selection.Text = txtWord.Text;
int iCount = wdApp.Dialogs[WdWordDialog.wdDialogToolsSpellingAndGrammar].Show(ref timeOut); //A.无法判断他的忽略,B.Cancel 与 Replace 、Replace All 都返回-1 对话框是返回0
if (iCount != 0)
{
MessageBox.Show("The spelling check is complete.", "Title", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
txtWord.Text = wdApp.Selection.Text;
wdDoc.Saved = true;
wdDoc.Close(ref o, ref oMissing, ref oMissing);
wdDoc = null;
//Marshal.ReleaseComObject(wd);
wdApp.Quit(ref o, ref oMissing, ref oMissing);
wdApp = null;
第一种情况不能同时检查拼写与语法。
同时这两种情况都不无做成与word一样的效果(指提示信息),A.无法判断他的忽略,B.Cancl 与 Replace 、Replace All 都返回-1 对话框是返回0
C.正确与以前就忽略的情况不需要弹出对话框???
- C# word 拼写 语法
- word 2007 取消拼写/语法检查
- C#调用Word拼写检查功能
- Word 2010 取消拼写/语法检查,隐藏红线/绿线
- Word 2010 取消拼写/语法检查,隐藏红线/绿线
- 关闭、开启Wrod拼写与语法检查
- word2007禁用自动拼写和语法检查
- VIM 启用拼写和语法检查
- 怎么取消word 的拼写检查怎么取消word 的拼写检查
- 拼写检查C#类库调用示例
- 使用ASP和Word进行服务器端拼写检查
- Word如何取消自动拼写检查、自动句首字母大写
- Word 关闭拼写检查 (去掉Word中拼写检查的所有红色和绿色的浪线)
- 在.NET应用程序中添加拼写和语法检查功能
- mysql分组(group by)多表统计(count)拼写语法
- 对TexStudio配置拼写和语法检查LanguageTool功能
- c# word
- c#语法
- Shell控制结构--循环控制
- STM32下CMA3000的SPI驱动程序
- linux 下切换用户
- 爱情的退路
- 散列表问题
- C# word 拼写 语法
- uml建模之时序图
- 约瑟夫环问题数学解法
- struts2自定义404错误页面
- jquery-autocomplete 使用手册
- android 屏幕截图
- vxworks6.6 license问题
- UILable控件
- 半角全角互转