C# 如何在已存在的WORD文档的特定位置插入数据呢

test126 2008-07-14 11:26:54
我想在WORD文档的特定位置,插入数据,比如:在第6行,第3列(6,3);插入:合格,
下面是从网上找的一段代码:

Word.Application thisApplication = new Word.ApplicationClass();
thisApplication.Visible = true;
thisApplication.Caption = "";
thisApplication.Options.CheckSpellingAsYouType = false;
thisApplication.Options.CheckGrammarAsYouType = false;

Object filename = "h:\\q.doc";
Object ConfirmConversions = false;
Object ReadOnly = true;
Object AddToRecentFiles = false;

Object PasswordDocument = System.Type.Missing;
Object PasswordTemplate = System.Type.Missing;
Object Revert = System.Type.Missing;
Object WritePasswordDocument = System.Type.Missing;
Object WritePasswordTemplate = System.Type.Missing;
Object Format = System.Type.Missing;
Object Encoding = System.Type.Missing;
Object Visible = System.Type.Missing;
Object OpenAndRepair = System.Type.Missing;
Object DocumentDirection = System.Type.Missing;
Object NoEncodingDialog = System.Type.Missing;
Object XMLTransform = System.Type.Missing;

try
{
Word.Document wordDoc =
thisApplication.Documents.Open(ref filename, ref ConfirmConversions,
ref ReadOnly, ref AddToRecentFiles, ref PasswordDocument, ref PasswordTemplate,
ref Revert, ref WritePasswordDocument, ref WritePasswordTemplate, ref Format,
ref Encoding, ref Visible, ref OpenAndRepair, ref DocumentDirection,
ref NoEncodingDialog, ref XMLTransform);


thisApplication.Selection.SetRange(20,20);//这个方法只能控制插入到第多少个字符,现在是第20个字符
//thisApplication.Selection.Select();

thisApplication.Selection.TypeText("合格");//要插入的内容
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}



thisApplication.Selection.SetRange(20,20);这个方法太麻烦了,有没有直接控制行列的插入点呢,或者更好的方法.
...全文
190 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
test126 2008-07-14
  • 打赏
  • 举报
回复
1楼的兄弟,可否说的详细些,小弟愚笨啊.
GhostAdai 2008-07-14
  • 打赏
  • 举报
回复
不会操作office文档,帮顶!
yilanwuyu123 2008-07-14
  • 打赏
  • 举报
回复
定义文档的段落 在段落之间操作

110,010

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧