c# Aspose.Words,MiniWord记录
Aspose.Words 商业版要付费(会有水印)
官方文档
.NET 格式的 Aspose.Words
官方代码
Word Processing API for .NET
MiniWord 开源
https://gitee.com/dotnetchina/MiniWord
public async Task<IActionResult> Exporttest(string id) { var templatePath = @"\Template\模板.docx"; var value = new Dictionary<string, object>() { ["test1"] = "test", ["test2"] = "test", ["test3"] = "test", ["test4"] = DateTime.Now.ToString("yyyy-MM-dd"), }; MemoryStream memoryStream = new(); MiniWord.SaveAsByTemplate(memoryStream, templatePath, value); memoryStream.Seek(0, SeekOrigin.Begin); return new FileStreamResult(memoryStream, "application/vnd.openxmlformats-officedocument.wordprocessingml.document") { FileDownloadName = "登记表.docx" }; }
模板.docx 格式如下图
导出效果
word转pdf(要安装office 或 WPS)