送分了。。。ASP.NET 打印并下载,服务器上一模版,然后复制模版并进行赋值,然后打印下载
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();
markName = "tdsyzmc";//土地申请人名称
bm = doc . Bookmarks . get_Item(ref markName);
bm . Range . Text = dr [ "tdsyzmc" ] . ToString();
object missingValue = Type . Missing;
Range range = printdoc . Content;
doc . Content . Copy();
object save = false;
range . Collapse(ref nullobj);
range . Paste();
doc . Close(ref save , ref nullobj , ref nullobj);
wordApp . Visible = true;//导出后显示word
printdoc . PrintPreview();//显示打印预览
string filenameS = pathfile + pfilename + ".doc";
File . Delete(filenameS);

