抖音粉丝群1
『7x24小时有问必答』

AI浪潮下的计算机行业——从业者现状与未来展望
MiniWord .NET Word介绍
MiniWord .NET Word模板引擎,藉由Word模板和数据简单、快速生成文件。
image
Getting Started安装
• nuget link : https://www.nuget.org/packages/MiniWord
快速入门
模板遵循“所见即所得”的设计,模板和标签的样式会被完全保留
var value = new Dictionary<stringobject>(){["title"] = "Hello MiniWord"};

MiniSoftware.MiniWord.SaveAsByTemplate(outputPath, templatePath, value);
image
输入、输出
• 输入系统支持模版路径或是Byte[]
• 输出支持文件路径、Byte[]、Stream
SaveAsByTemplate(string path, string templatePath, Dictionary<stringobjectvalue)

SaveAsByTemplate(string path, byte[] templateBytes, Dictionary<stringobjectvalue)

SaveAsByTemplate(this Stream stream, string templatePath, Dictionary<stringobjectvalue)

SaveAsByTemplate(this Stream stream, byte[] templateBytes, Dictionary<stringobjectvalue)
标签
MiniWord 使用类似 Vue, React 的模版字串 
{{tag}}
,只需要确保 tag 与 value 参数的 key 一样
(大小写敏感)
,系统会自动替换字串。
文本
{{tag}}
代码例子
var value = new Dictionary<stringobject>()

{

    ["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);
模版
image
导出
image
图片
标签值为 
MiniWordPicture
 类别
代码例子
var value = new Dictionary<stringobject>()

{

    ["Logo"] = new MiniWordPicture() { Path= PathHelper.GetFile("DemoLogo.png"), Width= 180, Height= 180 }

};

MiniWord.SaveAsByTemplate(path, templatePath, value);
模版
image
导出
image
列表
标签值为 
string[]
 或是 
IList
类别
代码例子
var value = new Dictionary<stringobject>()

{

    ["managers"] = new[] { "Jack" ,"Alan"},

    ["employees"] = new[] { "Mike" ,"Henry"},

};

MiniWord.SaveAsByTemplate(path, templatePath, value);
模版
image
导出
image
表格
标签值为 
IEmerable>
类别
代码例子
var value = new Dictionary<stringobject>()

{

    ["TripHs"] = new Liststring[ span], object[="" span]="">>

    {

        new Dictionary<stringobject>

        {

            { "sDate",DateTime.Parse("2022-09-08 08:30:00")},

            { "eDate",DateTime.Parse("2022-09-08 15:00:00")},

            { "How","Discussion requirement part1"},

            { "Photo",new MiniWordPicture() { Path = PathHelper.GetFile("DemoExpenseMeeting02.png"), Width = 160, Height = 90 }},

        },

        new Dictionary<stringobject>

        {

            { "sDate",DateTime.Parse("2022-09-09 08:30:00")},

            { "eDate",DateTime.Parse("2022-09-09 17:00:00")},

            { "How","Discussion requirement part2 and development"},

            { "Photo",new MiniWordPicture() { Path = PathHelper.GetFile("DemoExpenseMeeting01.png"), Width = 160, Height = 90 }},

        },

    }

};

MiniWord.SaveAsByTemplate(path, templatePath, value);
模版
image
导出
image
二级列表
Tag 是 
IEnumerable
 类别. 使用方式
{{foreach
 和 
endforeach}}
.
Example
var value = new Dictionary<stringobject>()

{

    ["TripHs"] = new Liststring[ span], object[="" span]="">>

    {

        new Dictionary<stringobject>

        {

            { "sDate", DateTime.Parse("2022-09-08 08:30:00") },

            { "eDate", DateTime.Parse("2022-09-08 15:00:00") },

            { "How""Discussion requirement part1" },

            {

                "Details"new List()

                {

                    new MiniWordForeach()

                    {

                        Value = new Dictionary<stringobject>()

                        {

                            {"Text""Air"},

                            {"Value""Airplane"}

                        },

                        Separator = " | "

                    },

                    new MiniWordForeach()

                    {

                        Value = new Dictionary<stringobject>()

                        {

                            {"Text""Parking"},

                            {"Value""Car"}

                        },

                        Separator = " / "

                    }

                }

            }

        }

    }

};

MiniWord.SaveAsByTemplate(path, templatePath, value);
Template
before_foreach
Result
after_foreach
条件判断
@if
 和 
@endif
 tags .
Example
var value = new Dictionary<stringobject>()

{

    ["Name"] = new List(){

        new MiniWordHyperLink(){

            Url = "https://google.com",

            Text = "測試連結22!!"

        },

        new MiniWordHyperLink(){

            Url = "https://google1.com",

            Text = "測試連結11!!"

        }

    },

    ["Company_Name"] = "MiniSofteware",

    ["CreateDate"] = new DateTime(20210101),

    ["VIP"] = true,

    ["Points"] = 123,

    ["APP"] = "Demo APP",

};

MiniWord.SaveAsByTemplate(path, templatePath, value);
Template
before_if
Result
after_if
多彩字体代码例子
var value = new

{

    Company_Name = new MiniWordColorText { Text = "MiniSofteware", FontColor = "#eb70AB", },

    Name = new[] {

        new MiniWordColorText { Text = "Ja", HighlightColor = "#eb70AB" },

        new MiniWordColorText { Text = "ck", HighlightColor = "#a56abe" }

    },

    CreateDate = new MiniWordColorText

    {

        Text = new DateTime(20210101).ToString(),

        HighlightColor = "#eb70AB",

        FontColor = "#ffffff",

    },

    VIP = true,

    Points = 123,

    APP = "Demo APP",

};

MiniWord.SaveAsByTemplate(path, templatePath, value);
其他POCO or dynamic 参数
v0.5.0 支持 POCO 或 dynamic parameter
var value = new { title = "Hello MiniWord" };

MiniWord.SaveAsByTemplate(outputPath, templatePath, value);
字体FontColor和HighlightColor
var value = new

{

    Company_Name = new MiniWordColorText { Text = "MiniSofteware", FontColor = "#eb70AB" },

    Name = new MiniWordColorText { Text = "Jack", HighlightColor = "#eb70AB" },

    CreateDate = new MiniWordColorText { Text = new DateTime(20210101).ToString(), HighlightColor = "#eb70AB", FontColor = "#ffffff" },

    VIP = true,

    Points = 123,

    APP = "Demo APP",

};
HyperLink
我们可以尝试使用 
MiniWodrHyperLink
 类,用模板测试替换为超链接。
MiniWordHyperLink
 提供了两个主要参数。
• Url: HyperLink URI 目标路径
• 文字:超链接文字
var value = new 

{

    ["Name"] = new MiniWordHyperLink(){

        Url = "https://google.com",

        Text = "測試連結!!"

    },

    ["Company_Name"] = "MiniSofteware",

    ["CreateDate"] = new DateTime(20210101),

    ["VIP"] = true,

    ["Points"] = 123,

    ["APP"] = "Demo APP",

};

MiniWord.SaveAsByTemplate(path, templatePath, value);
项目地址
文档地址:https://github.com/mini-software/MiniWord
推荐阅读
欢迎关注我的公众号“Net分享”,技术文章第一时间推送,随缘更新 , 分享一些你可能注意不到的细节。

string[>string[>
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

上一主题上一主题         下一主题下一主题
QQ手机版小黑屋粤ICP备17165530号

Copyright 2010-2015. All rights reserved. 

微信公众号二维码 抖音二维码 百家号二维码 今日头条二维码哔哩哔哩二维码