目录
Part1简介
Part2特点
Part3安装
Part4使用
文本生成
图片生成
列表生成
表格生成
Part5总结
Part1简介
MiniWord 是.NET Word模板引擎,由Word模板和数据,简单、快速生成文件。
Part2特点
Part3安装
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<string, object>() {
["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<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);
列表生成
标签值为 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);
表格生成
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);
Part5总结
目前来说MiniWord功能还比较少,达不到商用的程度,但是我相信 在不久的将来,MiniWord会越来越好! 如果对MiniWord感兴趣的可以去Gitee或者Github点个Star。
gitee:https://gitee.com/dotnetchina/MiniWord
github:https://github.com/mini-software/MiniWord/