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

test126 test126 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我想在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);这个方法太麻烦了,有没有直接控制行列的插入点呢,或者更好的方法.
...全文
评论 3
收藏 已收藏
分享
返回顶部
test126
C# 111,129 成员 642,539 内容