c# 如何调用word模版,把数据放到相应的位置 如题 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 在word相应的位置插入书签,C#中添加word的引用,然后操作word,把数据放到word书签位置。就记得这么多,详细的网上搜搜 我来给楼上做下补充 嘿嘿 using Microsoft.Office.Interop.Word;然后在具体需要操作的地方Microsoft.Office.Interop.Word.ApplicationClass wordapp = new Microsoft.Office.Interop.Word.ApplicationClass();Microsoft.Office.Interop.Word.Document doc = null;object nothing = System.Reflection.Missing.Value;object filePath1 = modelPath; //模板的地址 doc1 = wordapp1.Documents.Open(ref filePath, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing); string bmn="book";//书签的名字doc.Books.get_Item(ref bmn).Range.Text=“你需要插入的内容”;object filePath2="你需要将此word保存的地址";doc.SaveAs(ref filePath2, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing);doc.Close(ref save, ref nothing, ref nothing);//关闭wordwordapp.Quit(ref nothing, ref nothing, ref nothing); http://blog.csdn.net/huyang77/article/details/7789987去看看希望对你有帮助 嗯 我觉得我的例子很全了啊 从打开ApplicationClass,到关闭它。设计word操作,如果仅仅是想book中插入东西的话,这点应该就很全了啊 我想说的,首先不推荐服务器端或程序中调用com来弄word,太容易假退出了,目前我的应用专门写了个杀word进程的小程序,来干掉服务器上超过一分钟还不退出的word.exe。其它的4楼的例子非常好,我就不多说了,要注意的是office2000,2003,2007,2010的调用接口函数的参数表都各有不同。 doc1 = wordapp1.Documents.Open(ref filePath, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing); 这个里面很可能多几项,少几项的,要注意自己服务器上的版本后上网查相关的介绍,或者自己在自己服务器上的word的vba中查看帮助,帮助中会说明当前版本的vba参数表的。 我知道这个是主要的代码,但不全,我想要个全的object filePath1 = modelPath; //模板的地址 doc1 = wordapp1.Documents.Open(ref filePath, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing); doc1是从哪来的 求教公司要开发财务管理系统,我选c#还是Java? 调用另一个窗体的方法 winform 中点击datagrid的列名选择该列 点击最左上角的地方 就会选择整个datagrid 就像EXECL 推荐使用Google拼音输入法 求一个C#读取数据库的问题 实例被析构问题 求帮忙写个Silverlight动画 请高手指点,马上给分 为什么c#的win form程序一运行就就4,5个线程. 图片放大失真问题 字符段的截取 数据源更新问题
就记得这么多,详细的网上搜搜
using Microsoft.Office.Interop.Word;然后在具体需要操作的地方Microsoft.Office.Interop.Word.ApplicationClass wordapp = new Microsoft.Office.Interop.Word.ApplicationClass();
Microsoft.Office.Interop.Word.Document doc = null;object nothing = System.Reflection.Missing.Value;
object filePath1 = modelPath; //模板的地址
doc1 = wordapp1.Documents.Open(ref filePath, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing); string bmn="book";//书签的名字doc.Books.get_Item(ref bmn).Range.Text=“你需要插入的内容”;object filePath2="你需要将此word保存的地址";
doc.SaveAs(ref filePath2, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing);doc.Close(ref save, ref nothing, ref nothing);//关闭word
wordapp.Quit(ref nothing, ref nothing, ref nothing);
设计word操作,如果仅仅是想book中插入东西的话,这点应该就很全了啊
我知道这个是主要的代码,但不全,我想要个全的object filePath1 = modelPath; //模板的地址
doc1 = wordapp1.Documents.Open(ref filePath, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing); doc1是从哪来的