目录
Part1简介
Part2特点
Part3安装
Part4使用
文本生成
图片生成
列表生成
表格生成
Part5总结
Part1简介
MiniWord 是.NET Word模板引擎,由Word模板和数据,简单、快速生成文件。
Part2特点-
.NET Word(docx) 模版导出引擎不需要安装 Office COM+
-
支持 Linux 和 Mac
-
支持生成文本、图片、列表、表格
-
nuget link : https://www.nuget.org/packages/MiniWord
-
.NET CLI : dotnet add package MiniWord --version 0.4.0
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);
-
生成
目前来说MiniWord功能还比较少,达不到商用的程度,但是我相信 在不久的将来,MiniWord会越来越好! 如果对MiniWord感兴趣的可以去Gitee或者Github点个Star。
gitee:https://gitee.com/dotnetchina/MiniWord
github:https://github.com/mini-software/MiniWord/