您当前的位置: 首页 >  .net

寒冰屋

暂无认证

  • 0浏览

    0关注

    2286博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

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

寒冰屋 发布时间:2022-09-29 20:00:00 ,浏览量:0

目录

Part1简介

Part2特点

Part3安装

Part4使用

文本生成

图片生成

列表生成

表格生成

Part5总结

 

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 一样(大小写敏感),系统会自动替换字串。

文本生成
  • 模板

  • 代码

标签值为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() { 
                ["title"] = "Hello MiniWord" ,
};
MiniSoftware.MiniWord.SaveAsByTemplate(outputPath, templatePath, value);
  • 生成

图片生成
  • 模板

  • 代码

标签值为 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() { 
["logo"] = new MiniWordPicture() { Path = @"E:\02_blibli\wenz\43_MiNiword\Template\logo.jpg", Width = 180, Height = 180 },
};
MiniSoftware.MiniWord.SaveAsByTemplate(outputPath, templatePath, value);
  • 生成

列表生成
  • 模板

  • 代码

标签值为 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() { 
 ["list"]=new string[] { "1","2","3"},
};
MiniSoftware.MiniWord.SaveAsByTemplate(outputPath, templatePath, value);
  • 生成

表格生成
  • 模板

  • 代码 标签值为 IEmerable类别

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() { 

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

Part5总结

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

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

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

关注
打赏
1665926880
查看更多评论
立即登录/注册

微信扫码登录

0.0478s