日期:2014-05-17 浏览次数:20469 次
string pfile = "模版2.doc";
string pathfile=System . Configuration . ConfigurationManager . AppSettings [ "FilePath" ] . ToString();//通过配置文件获取路劲
string pfilename=Guid . NewGuid() . ToString();
Object file = pathfile + "TXT\\" + pfile;//此处为绝对路径,也可以设置相对路径
Object filename = pathfile + pfilename + ".doc";
ApplicationClass wordApp = new ApplicationClass();
wordApp . Visible = false;
Document doc = new Document();
Document docname = new Document();
Document printdoc = new Document();
String id_ = Request [ "id" ] . ToString();
String uid = Request [ "bid" ] . ToString();
DAO_YW_tddjsq tddj = new DAO_YW_tddjsq();
dao_yw_yj yj=new dao_yw_yj();
DataRow dar=yj . GetsqxxByID(uid) . Rows [ 0 ];
DataRow dr = tddj . GetsqxxByID(id_) . Rows [ 0 ];
File . Copy(file . ToString() , filename . ToString());
object nullobj = System . Reflection . Missing . Value;
doc = wordApp . Documents . Open(ref file , ref nullobj , ref nullobj , ref nullobj , ref nullobj , ref nullobj , ref nullobj , ref nullobj , ref nullobj , ref nullobj , ref nullobj , ref nullobj , ref nullobj , ref nullobj , ref nullobj , ref nullobj);
object markName = "id";//id
Bookmark bm = doc . Bookmarks . get_Item(ref markName);
bm . Range . Text = dr [ "ID_" ] . ToString();
markName = "ywlx";//登记类型
bm = doc . Bookmarks . get_Item(ref markName);
bm . Range . Text = dr [ "ywlx" ] . ToString