C# 通过word模板创建新文件

本文档介绍如何使用C#编程语言,通过已有的Word模板来创建新的Word文档,并在文档的书签位置插入指定内容。首先,通过`ApplicationClass`实例化Word应用程序并打开模板文件。然后,保存新生成的文件到指定路径。最后,在书签处插入值,确保书签存在后,使用`TypeText`方法插入文本。此外,还包括一个辅助方法用于关闭并结束所有运行的WinWord进程。
摘要由CSDN通过智能技术生成

   
       ///
       /// 通过模板创建新文档
       ///
       /// 模板文件
       public void CreateNewDocument(stringfilePath)
       {
          killWinWordProcess();
           wordApp =new ApplicationClass();
          wordApp.DisplayAlerts = WdAlertLevel.wdAlertsNone;
          wordApp.Visible = false;
           objectmissing = System.Reflection.Missing.Value;
           objecttemplateName = filePath;
           wordDoc =wordApp.Documents.Open(ref templateName, ref missing,
              ref missing, ref missing, refmissing, ref missing, ref missing,
              ref missing, ref missing, refmis
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值