Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active March 5, 2020 16:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-com-gists/4f0e741d863333a8ea3874eadaf34372 to your computer and use it in GitHub Desktop.
Save aspose-com-gists/4f0e741d863333a8ea3874eadaf34372 to your computer and use it in GitHub Desktop.
Generate Word from Template in C#
John Doe 30 1989-04-01 4:00:00 pm
Jane Doe 27 1992-01-31 07:00:00 am
John Smith 51 1968-03-08 1:00:00 pm
[
{
Name: "John Smith",
Contract:
[
{
Client:
{
Name: "A Company"
},
Price: 1200000
},
{
Client:
{
Name: "B Ltd."
},
Price: 750000
},
{
Client:
{
Name: "C & D"
},
Price: 350000
}
]
},
{
Name: "Tony Anderson",
Contract:
[
{
Client:
{
Name: "E Corp."
},
Price: 650000
},
{
Client:
{
Name: "F & Partners"
},
Price: 550000
}
]
},
]
<Persons>
<Person>
<Name>John Doe</Name>
<Age>30</Age>
<Birth>1989-04-01 4:00:00 pm</Birth>
</Person>
<Person>
<Name>Jane Doe</Name>
<Age>27</Age>
<Birth>1992-01-31 07:00:00 am</Birth>
</Person>
<Person>
<Name>John Smith</Name>
<Age>51</Age>
<Birth>1968-03-08 1:00:00 pm</Birth>
</Person>
</Persons>
Document doc = new Document("template.docx");
CsvDataSource dataSource = new CsvDataSource("datasource.csv");
ReportingEngine engine = new ReportingEngine();
engine.BuildReport(doc, dataSource, "persons");
doc.Save("word.docx");
Document doc = new Document("template.docx");
JsonDataSource dataSource = new JsonDataSource("datasource.json");
ReportingEngine engine = new ReportingEngine();
engine.BuildReport(doc, dataSource, "managers");
doc.Save("word.docx");
Document doc = new Document("template.docx");
Sender sender = new Sender("LINQ Reporting Engine", "Hello World");
ReportingEngine engine = new ReportingEngine();
engine.BuildReport(doc, sender, "sender");
doc.Save("word.docx");
Document doc = new Document("template.docx");
XmlDataSource dataSource = new XmlDataSource("datasource.xml");
ReportingEngine engine = new ReportingEngine();
engine.BuildReport(doc, dataSource, "persons");
doc.Save("word.docx");
public class Sender
{
public string Name { get; set; }
public string Message { get; set; }
public Sender (string _name, string _message)
{
Name = _name;
Message = _message;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment