asp.net core Aspose Words for .Net v24.10.0 引用

浪淘沙1年前后端222

一、文件附件

Aspose.Words.rar


二、Aspose.Words.dll 引用

放置在:bin\Release\net9.0\

image.png


三、Aspose.Total.NET.lic 放置在根目录 


四、使用

 public IActionResult OnGet()
 {
     ViewData["Description"] = _systemService.GetDescription();

     string templatePath = FileHelper.absolutPath("wwwroot/mb/kh.docx"); //模板文件路径
                                                                         
     new Aspose.Words.License().SetLicense("Aspose.Total.NET.lic");//注册码
                                                                 
     var template = new Document(templatePath); 

     // 创建合并文档
     var combinedDocument = new Document();
     combinedDocument.RemoveAllChildren();
     // 生成多个副本并合并
     for (int i = 0; i < 20; i++)
     {



         #region 替换占位符
         var tempDocument = template.Clone();
         var placeholders = new Dictionary<string, string>
         {
                 {"{title}","title"+i.ToString() },
         };

         foreach (var placeholder in placeholders)
         {
             tempDocument.Range.Replace(placeholder.Key, placeholder.Value, new Aspose.Words.Replacing.FindReplaceOptions());
         }
         #endregion
         // 合并到目标文档
         combinedDocument.AppendDocument(tempDocument, ImportFormatMode.KeepSourceFormatting);
     }
     var stream = new MemoryStream();
     combinedDocument.Save(stream, SaveFormat.Docx);
     stream.Position = 0;

     // 返回文件时不使用 using,避免释放 Stream
     return File(stream, "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "评定表.docx");

 }


相关文章

_LayoutAdmin.cshtml 取得url,调用ViewComponent 视图

_LayoutAdmin.cshtml 取得url,调用ViewComponent 视图

<body id="watermark-parent"> @{ var name = Furion.App.HttpC...

asp.net core弹出对话框最佳实践

 public void OnGet()  {         ...

asp.net core razor 远程请求 认证Basic auth 模式 body传递 json

private readonly HttpClient _httpClient;    public RemoteReq...

asp.net core Razor 部门视图Partial Views 用法

1、在/Pages/Shared/目录下创建设视图文件 _top.cshtml2、在razor页面中进行引用@await Html.PartialAsync("_top&...

wangeditor编辑器

<!--编辑器--> <link href="/wangeditor/style.css" rel="stylesheet&quo...

asp.net core 图片转正

在 ASP.NET Core 中将图片旋转为正向,通常你需要处理图片的 EXIF 信息,因为一些相机和手机拍摄的照片会包含方向信息,表示照片应该如何旋转才能显示为正确的方向。可以使用一个图像处理库来实...

发表评论    

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。