asp.net core Aspose Words for .Net v24.10.0 引用
一、文件附件
二、Aspose.Words.dll 引用
放置在:bin\Release\net9.0\

三、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");
}