亚洲乱色熟女一区二区三区丝袜,天堂√中文最新版在线,亚洲精品乱码久久久久久蜜桃图片,香蕉久久久久久av成人,欧美丰满熟妇bbb久久久

LOGO OA教程 ERP教程 模切知識(shí)交流 PMS教程 CRM教程 開發(fā)文檔 其他文檔  
 
網(wǎng)站管理員

【C#】免費(fèi)開源 Word 模板引擎 MiniWord .NET

admin
2024年7月16日 18:24 本文熱度 2867

介紹

MiniWord .NET Word模板引擎,藉由Word模板和數(shù)據(jù)簡(jiǎn)單、快速生成文件。

Getting Started

安裝

快速入門

模板遵循“所見即所得”的設(shè)計(jì),模板和標(biāo)簽的樣式會(huì)被完全保留

var value = new Dictionary<string, object>(){["title"] = "Hello MiniWord"};

MiniSoftware.MiniWord.SaveAsByTemplate(outputPath, templatePath, value);

輸入、輸出

  • 輸入系統(tǒng)支持模版路徑或是Byte[]

  • 輸出支持文件路徑、Byte[]、Stream

SaveAsByTemplate(string path, string templatePath, Dictionary<string, object> value)

SaveAsByTemplate(string path, byte[] templateBytes, Dictionary<string, object> value)

SaveAsByTemplate(this Stream stream, string templatePath, Dictionary<string, object> value)

SaveAsByTemplate(this Stream stream, byte[] templateBytes, Dictionary<string, object> value)

標(biāo)簽

MiniWord 使用類似 Vue, React 的模版字串 {{tag}},只需要確保 tag 與 value 參數(shù)的 key 一樣(大小寫敏感),系統(tǒng)會(huì)自動(dòng)替換字串。

文本

{{tag}}
代碼例子

var value = new Dictionary<string, object>()

{

    ["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);

模版

導(dǎo)出

圖片

標(biāo)簽值為 MiniWordPicture 類別

代碼例子

var value = new Dictionary<string, object>()

{

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

};

MiniWord.SaveAsByTemplate(path, templatePath, value);

模版

導(dǎo)出

列表

標(biāo)簽值為 string[] 或是 IList<string>類別

代碼例子

var value = new Dictionary<string, object>(){

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

    ["employees"] = new[] { "Mike","Henry"},};MiniWord.SaveAsByTemplate(path, templatePath, value);

模版

導(dǎo)出

表格

標(biāo)簽值為 IEmerable<Dictionary<string,object>>類別

代碼例子

var value = new Dictionary<string, object>()

{

    ["TripHs"] = new List<Dictionary<string, object>>

    {

        new Dictionary<string, object>

        {

            { "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<string, object>

        {

            { "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);

模版

導(dǎo)出

二級(jí)列表

Tag 是 IEnumerable<MiniWordForeach> 類別. 使用方式{{foreach 和 endforeach}}.

Example

var value = new Dictionary<string, object>()

{

    ["TripHs"] = new List<Dictionary<string, object>>

    {

        new Dictionary<string, object>

        {

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

                {

                    new MiniWordForeach()

                    {

                        Value = new Dictionary<string, object>()

                        {

                            {"Text", "Air"},

                            {"Value", "Airplane"}

                        },

                        Separator = " | "

                    },

                    new MiniWordForeach()

                    {

                        Value = new Dictionary<string, object>()

                        {

                            {"Text", "Parking"},

                            {"Value", "Car"}

                        },

                        Separator = " / "

                    }

                }

            }

        }

    }

};

MiniWord.SaveAsByTemplate(path, templatePath, value);

Template

Result

條件判斷

@if 和 @endif tags .

Example

var value = new Dictionary<string, object>()

{

    ["Name"] = new List<MiniWordHyperLink>(){

        new MiniWordHyperLink(){

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

            Text = "測(cè)試連結(jié)22!!"

        },

        new MiniWordHyperLink(){

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

            Text = "測(cè)試連結(jié)11!!"

        }

    },

    ["Company_Name"] = "MiniSofteware",

    ["CreateDate"] = new DateTime(2021, 01, 01),

    ["VIP"] = true,

    ["Points"] = 123,

    ["APP"] = "Demo APP",

};

MiniWord.SaveAsByTemplate(path, templatePath, value);

Template

Result

多彩字體

代碼例子

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(2021, 01, 01).ToString(),

        HighlightColor = "#eb70AB",

        FontColor = "#ffffff",

    },

    VIP = true,

    Points = 123,

    APP = "Demo APP",

};

MiniWord.SaveAsByTemplate(path, templatePath, value);

其他

POCO or dynamic 參數(shù)

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(2021, 01, 01).ToString(), HighlightColor = "#eb70AB", FontColor = "#ffffff" },

    VIP = true,

    Points = 123,

    APP = "Demo APP",

};

HyperLink

我們可以嘗試使用 MiniWodrHyperLink 類,用模板測(cè)試替換為超鏈接。

MiniWordHyperLink 提供了兩個(gè)主要參數(shù)。

  • Url: HyperLink URI 目標(biāo)路徑

  • 文字:超鏈接文字

var value = new 

{

    ["Name"] = new MiniWordHyperLink(){

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

        Text = "測(cè)試連結(jié)!!"

    },

    ["Company_Name"] = "MiniSofteware",

    ["CreateDate"] = new DateTime(2021, 01, 01),

    ["VIP"] = true,

    ["Points"] = 123,

    ["APP"] = "Demo APP",

};

MiniWord.SaveAsByTemplate(path, templatePath, value);

例子

ASP.NET Core 3.1 API Export

using Microsoft.AspNetCore.Builder;

using Microsoft.AspNetCore.Hosting;

using Microsoft.AspNetCore.Mvc;

using Microsoft.Extensions.DependencyInjection;

using Microsoft.Extensions.Hosting;

using System;

using System.Collections.Generic;

using System.IO;

using System.Net;

using MiniSoftware;


public class Program

{

    public static void Main(string[] args) => CreateHostBuilder(args).Build().Run();


    public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args).ConfigureWebHostDefaults(webBuilder => webBuilder.UseStartup<Startup>());

}


public class Startup

{

    public void ConfigureServices(IServiceCollection services) => services.AddMvc();

    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)

    {

        app.UseStaticFiles();

        app.UseRouting();

        app.UseEndpoints(endpoints =>

        {

            endpoints.MapControllerRoute(

                name: "default",

                pattern: "{controller=api}/{action=Index}/{id?}");

        });

    }

}


public class ApiController : Controller

{

    public IActionResult Index()

    {

        return new ContentResult

        {

            ContentType = "text/html",

            StatusCode = (int)HttpStatusCode.OK,

            Content = @"<html><body>

<a href='api/DownloadWordFromTemplatePath'>DownloadWordFromTemplatePath</a><br>

<a href='api/DownloadWordFromTemplateBytes'>DownloadWordFromTemplateBytes</a><br>

</body></html>"

        };

    }


    static Dictionary<string, object> defaultValue = new Dictionary<string, object>()

    {

        ["title"] = "FooCompany",

        ["managers"] = new List<Dictionary<string, object>> {

            new Dictionary<string, object>{{"name","Jack"},{ "department", "HR" } },

            new Dictionary<string, object> {{ "name", "Loan"},{ "department", "IT" } }

        },

        ["employees"] = new List<Dictionary<string, object>> {

            new Dictionary<string, object>{{ "name", "Wade" },{ "department", "HR" } },

            new Dictionary<string, object> {{ "name", "Felix" },{ "department", "HR" } },

            new Dictionary<string, object>{{ "name", "Eric" },{ "department", "IT" } },

            new Dictionary<string, object> {{ "name", "Keaton" },{ "department", "IT" } }

        }

    };


    public IActionResult DownloadWordFromTemplatePath()

    {

        string templatePath = "TestTemplateComplex.docx";


        Dictionary<string, object> value = defaultValue;


        MemoryStream memoryStream = new MemoryStream();

        MiniWord.SaveAsByTemplate(memoryStream, templatePath, value);

        memoryStream.Seek(0, SeekOrigin.Begin);

        return new FileStreamResult(memoryStream, "application/vnd.openxmlformats-officedocument.wordprocessingml.document")

        {

            FileDownloadName = "demo.docx"

        };

    }


    private static Dictionary<string, Byte[]> TemplateBytesCache = new Dictionary<string, byte[]>();


    static ApiController()

    {

        string templatePath = "TestTemplateComplex.docx";

        byte[] bytes = System.IO.File.ReadAllBytes(templatePath);

        TemplateBytesCache.Add(templatePath, bytes);

    }


    public IActionResult DownloadWordFromTemplateBytes()

    {

        byte[] bytes = TemplateBytesCache["TestTemplateComplex.docx"];


        Dictionary<string, object> value = defaultValue;


        MemoryStream memoryStream = new MemoryStream();

        MiniWord.SaveAsByTemplate(memoryStream, bytes, value);

        memoryStream.Seek(0, SeekOrigin.Begin);

        return new FileStreamResult(memoryStream, "application/vnd.openxmlformats-officedocument.wordprocessingml.document")

        {

            FileDownloadName = "demo.docx"

        };

    }

}


該文章在 2024/7/16 18:38:03 編輯過
關(guān)鍵字查詢
相關(guān)文章
正在查詢...
點(diǎn)晴ERP是一款針對(duì)中小制造業(yè)的專業(yè)生產(chǎn)管理軟件系統(tǒng),系統(tǒng)成熟度和易用性得到了國內(nèi)大量中小企業(yè)的青睞。
點(diǎn)晴PMS碼頭管理系統(tǒng)主要針對(duì)港口碼頭集裝箱與散貨日常運(yùn)作、調(diào)度、堆場(chǎng)、車隊(duì)、財(cái)務(wù)費(fèi)用、相關(guān)報(bào)表等業(yè)務(wù)管理,結(jié)合碼頭的業(yè)務(wù)特點(diǎn),圍繞調(diào)度、堆場(chǎng)作業(yè)而開發(fā)的。集技術(shù)的先進(jìn)性、管理的有效性于一體,是物流碼頭及其他港口類企業(yè)的高效ERP管理信息系統(tǒng)。
點(diǎn)晴WMS倉儲(chǔ)管理系統(tǒng)提供了貨物產(chǎn)品管理,銷售管理,采購管理,倉儲(chǔ)管理,倉庫管理,保質(zhì)期管理,貨位管理,庫位管理,生產(chǎn)管理,WMS管理系統(tǒng),標(biāo)簽打印,條形碼,二維碼管理,批號(hào)管理軟件。
點(diǎn)晴免費(fèi)OA是一款軟件和通用服務(wù)都免費(fèi),不限功能、不限時(shí)間、不限用戶的免費(fèi)OA協(xié)同辦公管理系統(tǒng)。
Copyright 2010-2025 ClickSun All Rights Reserved