.NET Word模板引擎--MiniWord,继MiniExcel后又一开源作品!

Part1简介

MiniWord 是.NET Word模板引擎,由Word模板和数据,简单、快速生成文件。

Part2特点

  • .NET Word(docx) 模版导出引擎不需要安装 Office COM+

  • 支持 Linux 和 Mac

  • 支持生成文本、图片、列表、表格

Part3安装

  • nuget link : https://www.nuget.org/packages/MiniWord

  • .NET CLI : dotnet add package MiniWord --version 0.4.0

Part4使用

MiniWord 使用类似 Vue, React 的模版字串 {{tag}},只需要确保 tag 与 value 参数的 key 一样(大小写敏感),系统会自动替换字串。

文本生成

  • 模板

91ed406e9bb970915cba7df37e18d1fc.png

  • 代码

标签值为string类别

string templatePath = @"E:\02_blibli\wenz\43_MiNiword\Template\Test.docx";
string outputPath = @"E:\02_blibli\wenz\43_MiNiword\OutPut\TestOutPut.docx";
var value = new Dictionary<string, object>() { 
                ["title"] = "Hello MiniWord" ,
};
MiniSoftware.MiniWord.SaveAsByTemplate(outputPath, templatePath, value);
  • 生成

32645d22db183bd83f71a6fe53c596e3.png

图片生成

  • 模板

94f2f5192b38281ae5de8fae3700c818.png

  • 代码

标签值为 MiniWordPicture 类别

string templatePath = @"E:\02_blibli\wenz\43_MiNiword\Template\Test.docx";
string outputPath = @"E:\02_blibli\wenz\43_MiNiword\OutPut\TestOutPut.docx";
var value = new Dictionary<string, object>() { 
["logo"] = new MiniWordPicture() { Path = @"E:\02_blibli\wenz\43_MiNiword\Template\logo.jpg", Width = 180, Height = 180 },
};
MiniSoftware.MiniWord.SaveAsByTemplate(outputPath, templatePath, value);
  • 生成

473622de952c89dbf30cdf1f1bcd9f71.png

列表生成

  • 模板

74a11a054c16faf57c8e35f93ca6c2a5.png

  • 代码

标签值为 string[] 或是 IList类别

string templatePath = @"E:\02_blibli\wenz\43_MiNiword\Template\Test.docx";
string outputPath = @"E:\02_blibli\wenz\43_MiNiword\OutPut\TestOutPut.docx";
var value = new Dictionary<string, object>() { 
 ["list"]=new string[] { "1","2","3"},
};
MiniSoftware.MiniWord.SaveAsByTemplate(outputPath, templatePath, value);
  • 生成

4c1af2c0e2bedcd632e617863783acec.png

表格生成

  • 模板

b885879181c62ead28620bd3f459753b.png

  • 代码 标签值为 IEmerable<Dictionary<string,object>>类别

string templatePath = @"E:\02_blibli\wenz\43_MiNiword\Template\Test.docx";
 string outputPath = @"E:\02_blibli\wenz\43_MiNiword\OutPut\TestOutPut.docx";
var value = new Dictionary<string, object>() { 

                ["person"] = new List<Dictionary<string, object>> {
                    new Dictionary<string, object>{{ "name", "Wade" },{ "age", "HR" } },
                    new Dictionary<string, object> {{ "name", "Felix" },{ "age", "HR" } },
                    new Dictionary<string, object>{{ "name", "Eric" },{ "age", "IT" } },
                    new Dictionary<string, object> {{ "name", "Keaton" },{ "age", "IT" } }
                }
 };
 MiniSoftware.MiniWord.SaveAsByTemplate(outputPath, templatePath, value);
  • 生成

3e1e09355a40d46a2c0d89c12d73de13.png

Part5总结

目前来说MiniWord功能还比较少,达不到商用的程度,但是我相信   在不久的将来,MiniWord会越来越好! 如果对MiniWord感兴趣的可以去Gitee或者Github点个Star。

gitee:https://gitee.com/dotnetchina/MiniWord

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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值