首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >开源免费, .NET 又一个 Word 处理神器

开源免费, .NET 又一个 Word 处理神器

作者头像
郑子铭
发布2024-11-23 13:38:03
发布2024-11-23 13:38:03
7570
举报

MiniWord

推荐一个 .NET 开源的免费 Word 处理神器 MiniWord。这是一个非常简单有效的 .NET Word 模板库,甚至可以使用一行代码处理 Word,非常方便。并且不需要安装微软 Word,无需 COM+ 和互操作支持 Linux 和 Mac,轻量级 Word 处理神器。

快速使用

模板遵循“所见即所得”设计,模板标签样式完整保留。 var value = new Dictionary<string, object>(){["title"] = "Hello MiniWord"}; MiniSoftware.MiniWord.SaveAsByTemplate(outputPath, templatePath, value);

MiniWord 模板格式字符串如 Vue、React {{tag}} ,用户只需确保 tag 和 value 参数 key 相同,系统会自动替换它们。 var value = new Dictionary<string, object>() { ["Name"] = "Jack", ["Department"] = "IT Department", ["Purpose"] = "Shanghai site needs a new system to control HR system.", ["StartDate"] = DateTime.Parse("2022-09-07 08:30:00"), ["EndDate"] = DateTime.Parse("2022-09-15 15:30:00"), ["Approved"] = true, ["Total_Amount"] = 123456, }; MiniWord.SaveAsByTemplate(path, templatePath, value); 模板

结果

.NET Core 使用

public IActionResult DownloadWordFromTemplatePath() { string templatePath = "TestTemplateComplex.docx"; Dictionary<string, object> value = defaultValue; MemoryStream memoryStream = new MemoryStream(); MiniWord.SaveAsByTemplate(memoryStream, templatePath, value); memoryStream.Seek(0, SeekOrigin.Begin); return new FileStreamResult(memoryStream, "application/vnd.openxmlformats-officedocument.wordprocessingml.document") { FileDownloadName = "demo.docx" }; } public IActionResult DownloadWordFromTemplateBytes() { byte[] bytes = TemplateBytesCache["TestTemplateComplex.docx"]; Dictionary<string, object> value = defaultValue; MemoryStream memoryStream = new MemoryStream(); MiniWord.SaveAsByTemplate(memoryStream, bytes, value); memoryStream.Seek(0, SeekOrigin.Begin); return new FileStreamResult(memoryStream, "application/vnd.openxmlformats-officedocument.wordprocessingml.document") { FileDownloadName = "demo.docx" }; } MiniWord 的更多功能,等待您去发现!

项目地址

https://github.com/mini-software/MiniWord

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2024-11-22,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 DotNet NB 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • MiniWord
  • 推荐一个 .NET 开源的免费 Word 处理神器 MiniWord。这是一个非常简单有效的 .NET Word 模板库,甚至可以使用一行代码处理 Word,非常方便。并且不需要安装微软 Word,无需 COM+ 和互操作支持 Linux 和 Mac,轻量级 Word 处理神器。
  • 快速使用
  • 模板遵循“所见即所得”设计,模板标签样式完整保留。 var value = new Dictionary<string, object>(){["title"] = "Hello MiniWord"}; MiniSoftware.MiniWord.SaveAsByTemplate(outputPath, templatePath, value);
  • .NET Core 使用
  • public IActionResult DownloadWordFromTemplatePath() { string templatePath = "TestTemplateComplex.docx"; Dictionary<string, object> value = defaultValue; MemoryStream memoryStream = new MemoryStream(); MiniWord.SaveAsByTemplate(memoryStream, templatePath, value); memoryStream.Seek(0, SeekOrigin.Begin); return new FileStreamResult(memoryStream, "application/vnd.openxmlformats-officedocument.wordprocessingml.document") { FileDownloadName = "demo.docx" }; } public IActionResult DownloadWordFromTemplateBytes() { byte[] bytes = TemplateBytesCache["TestTemplateComplex.docx"]; Dictionary<string, object> value = defaultValue; MemoryStream memoryStream = new MemoryStream(); MiniWord.SaveAsByTemplate(memoryStream, bytes, value); memoryStream.Seek(0, SeekOrigin.Begin); return new FileStreamResult(memoryStream, "application/vnd.openxmlformats-officedocument.wordprocessingml.document") { FileDownloadName = "demo.docx" }; } MiniWord 的更多功能,等待您去发现!
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档