当前位置: 移动技术网 > IT编程>开发语言>.net > .net MVC使用Aspose.Words 获取文本域获取文档

.net MVC使用Aspose.Words 获取文本域获取文档

2018年12月19日  | 移动技术网IT编程  | 我要评论

安义县人民政府网,iphonex预定,永生小说下载

 

 

controller

 1 using aspose.words;
 2 using aspose.words.saving;
 3 using system.io;
 4 
 5 
 6         /// <summary>
 7         /// 获取导入word 文档
 8         /// </summary>
 9         /// <param name="paperid"></param>
10         /// <returns></returns>
11         public actionresult getword(int paperid)
12         {
13             try
14             {
15                 var __data = _paperapp.getword(paperid);
16                 string temppath = server.mappath("~/template/导出模版.docx");
17                 string outputpath = server.mappath("~/resources/output/模版_temp.doc");
18                 //载入模板
19                 var doc = new document(temppath);
20                 //提供数据源
21                 string[] fieldnames = new string[] { "papername", "papertypename", "singlechoicecount", "singlechoicescore", "singlechoicecontent",
22                 "multiplechoicecount", "multiplechoicescore", "multiplechoicecontent", "truefalsecount", "truefalsescore", "truefalsecontent" };
23                 object[] fieldvalues = new object[] { __data.papername, __data.papertypename, __data.singlechoicecount, __data.singlechoicescore, __data.singlechoicecontent,
24                 __data.multiplechoicecount, __data.multiplechoicescore, __data.multiplechoicecontent, __data.truefalsecount, __data.truefalsescore, __data.truefalsecontent };
25                 //合并模版,相当于页面的渲染
26                 doc.mailmerge.execute(fieldnames, fieldvalues);
27                 //保存合并后的文档
28                 doc.save(outputpath);//在mvc中采用,保存文档到流中,使用base.file输出该文件
29                 var docstream = new memorystream();
30                 doc.save(docstream, saveoptions.createsaveoptions(saveformat.doc));
31                 return base.file(docstream.toarray(), "application/msword", "试卷" + __data.papername + ".doc");
32             }
33             catch (exception ex)
34             {
35                 return error(ex.message);
36             }
37         }

 

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网