Skip to content

Latest commit

 

History

History
49 lines (39 loc) · 1.31 KB

README.md

File metadata and controls

49 lines (39 loc) · 1.31 KB

WordReport

Generate report from Word document. Not required MS Office to generate documents.

NuGet

Get it

PM> Install-Package WordReport

Step 1: Provide word template file

NOTE: template is Scriban, please see usage there.
NOTE2: You need to open selection pane to get or set image name to replace

image

Step 2: Provide data models & images (optional)

var data = new
{
    teacher = "Ben",
    author = "John Doe",
    students = new[]
    {
        new {name = "Foo", age = 15},
        new {name = "Bar", age = 16},
    }
};
var images = new Dictionary<string, byte[]>
{
    ["signature_pic"] = File.ReadAllBytes("signature.png")
};

Step 3: Load template (NOTE: you can reuse template to generate multiple output)

var reporter = WordTemplate.FromFile("Template.docx");

Step 4: Generate output

var mem = new MemoryStream();
reporter.Render(mem, data, images);
File.WriteAllBytes("Output.docx", mem.ToArray());

image