本篇内容主要讲解“C#操作Word书签的方法”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“C#操作Word书签的方法”吧!
C#操作Word书签是如何实现的呢?让我们来看看实例的操作:
Word.Application app = new Word.Application(); //模板文件 //C#操作Word书签string TemplateFile = @"D:\lin\Invoice.doc"; //生成的具有模板样式的新文件 //C#操作Word书签string FileName = @"D:\lin\" + DateTime.Now.ToString("yyyyMMddHHmmssfffffff") + ".doc"; string Fname = DateTime.Now.ToString( "yyyyMMddHHmmssfffffff") + ".doc"; //FileName = Server.MapPath("~/UpLoad/TestWord/" + Fname ); //模板文件拷贝到新文件 File.Copy(TemplateFile, FileName); Word.Document doc = new Word.Document(); object Obj_FileName = FileName; object Visible = false; object ReadOnly = false; object missing = System.Reflection.Missing.Value; //C#操作Word书签//打开文件 doc = app.Documents.Open(ref Obj_FileName, ref missing, ref ReadOnly, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref Visible, ref missing, ref missing, ref missing, ref missing); doc.Activate(); //C#操作Word书签 foreach (Word.Bookmark bm in doc.Bookmarks) { if (bm.Name == "BookMark_Date") { bm.Select(); bm.Range.Text = "2008";//ViewState["FK_ProdurcePlanID"].ToString(); } //else if (bm.Name == "class") //{ //bm.Select(); //bm.Range.Text = ViewState["_class"].ToString(); //} } //C#操作Word书签object IsSave = true; doc.Close(ref IsSave, ref missing, ref missing); Response.Write( "﹤script language='javascript'﹥alert('生成word成功!'); ﹤/script﹥");
到此,相信大家对“C#操作Word书签的方法”有了更深的了解,不妨来实际操作一番吧!这里是亿速云网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。