分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 网页技术

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

发布时间:2023-09-06 02:26责任编辑:顾先生关键词:MVC

controller

 ???????/// <summary> ???????/// 导入Word 文档 ???????/// </summary> ???????/// <param name="PaperId"></param> ???????/// <returns></returns> ???????public ActionResult GetWord(int Id) ???????{ ???????????try ???????????{ ???????????????var __data = _App.GetWord(Id); ???????????????string tempPath = Server.MapPath("~/Template/试卷导出模版.docx"); ???????????????string outputPath = Server.MapPath("~/Resources/Output/试卷导出模版_temp.doc"); ???????????????//载入模板 ???????????????var doc = new Document(tempPath); ???????????????//提供数据源 ???????????????String[] fieldNames = new String[] { "PaperName", "PaperTypeName", "SingleChoiceCount", "SingleChoiceScore", "SingleChoiceContent", ???????????????"MultipleChoiceCount", "MultipleChoiceScore", "MultipleChoiceContent", "TrueFalseCount", "TrueFalseScore", "TrueFalseContent" }; ???????????????Object[] fieldValues = new Object[] { __data.PaperName, __data.PaperTypeName, __data.SingleChoiceCount, __data.SingleChoiceScore, __data.SingleChoiceContent, ???????????????__data.MultipleChoiceCount, __data.MultipleChoiceScore, __data.MultipleChoiceContent, __data.TrueFalseCount, __data.TrueFalseScore, __data.TrueFalseContent }; ???????????????//合并模版,相当于页面的渲染 ???????????????doc.MailMerge.Execute(fieldNames, fieldValues); ???????????????//保存合并后的文档 ???????????????doc.Save(outputPath);//在MVC中采用,保存文档到流中,使用base.File输出该文件 ???????????????var docStream = new MemoryStream(); ???????????????doc.Save(docStream, SaveOptions.CreateSaveOptions(SaveFormat.Doc)); ???????????????return base.File(docStream.ToArray(), "application/msword", "试卷" + __data.PaperName + ".doc"); ???????????} ???????????catch (Exception ex) ???????????{ ???????????????return Error(ex.Message); ???????????} ???????}
GetWordController

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

原文地址:https://www.cnblogs.com/WNpursue/p/10137038.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved