Appendix C. Typical Templates

Data Source Objects

Every example given in this article is using one of the following data source objects:

  • manager, an instance of the Manager class
  • managers, an enumeration of instances of the Manager class
  • contracts, an enumeration of instances of the Contract class
  • clients, an enumeration of instances of the Client class

The Manager, Contract, and Client classes are defined as follows.

// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET
public class Manager
{
public String Name { get; set; }
public int Age { get; set; }
public byte[] Photo { get; set; }
public IEnumerable<Contract> Contracts { get; set; }
}
// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET
public class Contract
{
public Manager Manager { get; set; }
public Client Client { get; set; }
public float Price { get; set; }
public DateTime Date { get; set; }
}
// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET
public class Client
{
public String Name { get; set; }
public String Country { get; set; }
public String LocalAddress { get; set; }
}

Templates

Single-Row Template

Template Example

Single_Row_Template_Example-aspose-words-net Name: «[manager.Name]»
Age: «[manager.Age]»

You can download the template file of this example from here.

Report Example

Single_Row_Report_Example-aspose-words-net Name: John Smith
Age: 37
// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_LINQ();
string fileName = "SingleRow.doc";
// Load the template document.
Document doc = new Document(dataDir + fileName);
// Load the photo and read all bytes.
byte[] imgdata = System.IO.File.ReadAllBytes(dataDir + "photo.png");
// Create a Reporting Engine.
ReportingEngine engine = new ReportingEngine();
// Execute the build report.
engine.BuildReport(doc, Common.GetManager(), "manager");
dataDir = dataDir + RunExamples.GetOutputFilePath(fileName);
// Save the finished document to disk.
doc.Save(dataDir);

In-Paragraph List Template

Template Example

We provide support for the following clients: «foreach [in clients]»«[IndexOf() != 0 ? “, " : “"]»«[Name]»«/foreach»

Report Example

We provide support for the following clients: A Company, B Ltd., C & D, E Corp., F & Partners, G & Co., H Group, I & Sons, J Ent.
// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_LINQ();
string fileName = "InParagraphList.doc";
// Load the template document.
Document doc = new Document(dataDir + fileName);
// Create a Reporting Engine.
ReportingEngine engine = new ReportingEngine();
// Execute the build report.
engine.BuildReport(doc, Common.GetClients(), "clients");
dataDir = dataDir + RunExamples.GetOutputFilePath(fileName);
// Save the finished document to disk.
doc.Save(dataDir);

Bulleted List Template

Template Example

We provide support for the following clients:
    * <<foreach [in clients]>><<[Name]>>
<</foreach>>

You can download the template file of this example from here.

Report Example

We provide support for the following clients:
    * A Company
    * B Ltd.
    * C & D
    * E Corp.
    * F & Partners
    * G & Co.
    * H Group
    * I & Sons
    * J Ent.
// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_LINQ();
string fileName = "BulletedList.doc";
// Load the template document.
Document doc = new Document(dataDir + fileName);
// Create a Reporting Engine.
ReportingEngine engine = new ReportingEngine();
// Execute the build report.
engine.BuildReport(doc, Common.GetClients(), "clients");
dataDir = dataDir + RunExamples.GetOutputFilePath(fileName);
// Save the finished document to disk.
doc.Save(dataDir);

Numbered List Template

Template Example

We provide support for the following clients:
    1. <<foreach [in clients]>><<[Name]>>
<</foreach>>

You can download the template file of this example from here.

Report Example

We provide support for the following clients:
    1. A Company
    2. B Ltd.
    3. C & D
    4. E Corp.
    5. F & Partners
    6. G & Co.
    7. H Group
    8. I & Sons
    9. J Ent.
// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_LINQ();
string fileName = "NumberedList.doc";
// Load the template document.
Document doc = new Document(dataDir + fileName);
// Create a Reporting Engine.
ReportingEngine engine = new ReportingEngine();
// Execute the build report.
engine.BuildReport(doc, Common.GetClients(), "clients");
dataDir = dataDir + RunExamples.GetOutputFilePath(fileName);
// Save the finished document to disk.
doc.Save(dataDir);

Multicolored Numbered List Template

Template Example

We provide support for the following clients:

1. <<foreach [in clients]>><<if [IndexOf() % 2 == 0]>><<[Name]>>
2. <<else>><<[Name]>>
<</if>><</foreach>>

You can download the template file of this example from here.

Report Example

We provide support for the following clients:

1. A Company
2. B Ltd.
3. C & D
4. E Corp.
5. F & Partners
6. G & Co.
7. H Group
8. I & Sons
9. J Ent.
// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_LINQ();
string fileName = "MulticoloredNumberedList.doc";
// Load the template document.
Document doc = new Document(dataDir + fileName);
// Create a Reporting Engine.
ReportingEngine engine = new ReportingEngine();
// Execute the build report.
engine.BuildReport(doc, Common.GetClients(), "clients");
dataDir = dataDir + RunExamples.GetOutputFilePath(fileName);
// Save the finished document to disk.
doc.Save(dataDir);

Common List Template

Template Example

«foreach [in managers]»
Common_List_Template_Example2-aspose-words-net
«[Name()]»
<</foreach>>

You can download the template file of this example from here.

Report Example

Single_Row_Report_Example1-aspose-words-net
John Smith
Single_Row_Report_Example-aspose-words-net
Tony Anderson
Single_Row_Report_Example-aspose-words-net
July James
// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_LINQ();
string fileName = "CommonList.doc";
// Load the template document.
Document doc = new Document(dataDir + fileName);
// Create a Reporting Engine.
ReportingEngine engine = new ReportingEngine();
// Execute the build report.
engine.BuildReport(doc, Common.GetManagers(), "managers");
dataDir = dataDir + RunExamples.GetOutputFilePath(fileName);
// Save the finished document to disk.
doc.Save(dataDir);

In-Table List Template

Template Example

Manager Contract Price
 <<foreach [in managers]>><<[Name()]>> 
 <<[Contracts().sum(c => c.Price())]>><</foreach>> 
 Total: 
 <<[sum(m => m.Contracts().sum(c => c.Price()))]>> 

You can download the template file of this example from here.

Report Example

Manager Contract Price
 John Smith 
 2300000 
 Tony Anderson 
 1200000 
 July James 
 800000 
 Total: 
 4300000 
// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_LINQ();
string fileName = "InTableList.doc";
// Load the template document.
Document doc = new Document(dataDir + fileName);
// Create a Reporting Engine.
ReportingEngine engine = new ReportingEngine();
// Execute the build report.
engine.BuildReport(doc, Common.GetManagers(), "managers");
dataDir = dataDir + RunExamples.GetOutputFilePath(fileName);
// Save the finished document to disk.
doc.Save(dataDir);

In-Table List Template with Running (Progressive) Total

Template Example

<<var [total = 0.0]>>

Client Total Contract Price
<<foreach [in contracts]>><<[getClient().getName()]>> <<var [total = total + getPrice()]>><<[total]>><</foreach>>

Report Example

Client Total Contract Price
A Company 1200000
B Ltd. 1950000
C & D 2300000
E Corp. 2950000
F & Partners 3500000
G & Co. 3850000
H Group 4100000
I & Sons 4200000
J Ent. 4300000

In-Table List Template with Highlighted Rows

Template Example

Client Contract Price
<<foreach [in contracts]>><<if [Price() >= 1000000]>><<[Client().Name()]>> <<[Price()]>>
<<else>><<[Client().Name()]>> <<[Price()]>><</if>><</foreach>>
Total: <<[sum(c => c.Price())]>>

Report Example

Client Contract Price
A Company 1200000
B Ltd. 750000
C & D 350000
E Corp. 650000
F & Partners 550000
G & Co. 350000
H Group 250000
I & Sons 100000
J Ent. 100000
Total: 4300000

In-Table List Template with Alternate Content

Template Example

Client Contract Price
«if [!Any()]»No data
«else»«foreach [in contracts]»«[Client.Name]» «[Price]»«/foreach»
Total: «[Sum(c => c.Price)]»«/if»

You can download the template file of this example from here.

Report Example 1

Client Contract Price
No data

Report Example 2

Client Contract Price
A Company 1200000
B Ltd. 750000
C & D 350000
E Corp. 650000
F & Partners 550000
G & Co. 350000
H Group 250000
I & Sons 100000
J Ent. 100000
Total: 4300000
// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_LINQ();
string fileName = "InTableAlternateContent.doc";
// Load the template document.
Document doc = new Document(dataDir + fileName);
// Create a Reporting Engine.
ReportingEngine engine = new ReportingEngine();
// Execute the build report.
engine.BuildReport(doc, Common.GetContracts(), "contracts");
dataDir = dataDir + RunExamples.GetOutputFilePath(fileName);
// Save the finished document to disk.
doc.Save(dataDir);

Common Master-Detail Template

Template Example

«foreach [in managers]»
Common_List_Template_Example2-aspose-words-net
«[Name()]»
Clients: «foreach [in Contracts() ]»«[indexOf() != 0 ? “, " : “"]»«[Client().Name()]»«/foreach»
<</foreach>>

You can download the template file of this example from here.

Report Example

Single_Row_Report_Example-aspose-words-net
John Smith
Clients: A Company, B Ltd., C & D
Single_Row_Report_Example-aspose-words-net
Tony Anderson
Clients: E Corp., F & Partners
Single_Row_Report_Example-aspose-words-net
July James
Clients: G & Co., H Group, I & Sons, J Ent.
// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_LINQ();
string fileName = "CommonMasterDetail.doc";
// Load the template document.
Document doc = new Document(dataDir + fileName);
// Create a Reporting Engine.
ReportingEngine engine = new ReportingEngine();
// Execute the build report.
engine.BuildReport(doc, Common.GetManagers(), "managers");
dataDir = dataDir + RunExamples.GetOutputFilePath(fileName);
// Save the finished document to disk.
doc.Save(dataDir);

In-Table Master-Detail Template

Template Example

Manager/Client Contract Price
 <<foreach [in managers]>><<[Name()]>> 
 <<[Contracts().sum(c => c.Price())]>> 
 <<foreach [in Contracts()]>> <<[Client().Name()]>> 
 <<[Price()]>><</foreach>><</foreach>> 
 Total: 
 <<[sum(m => m.Contracts().sum(c => c.Price()))]>> 

You can download the template file of this example from here.

Report Example

Manager/Client Contract Price
 John Smith 
 2300000 
 A Company 
 1200000 
 B Ltd. 
 750000</p><p>
 C & D 
 350000</p><p>
 Tony Anderson 
 1200000</p><p>
 E Corp. 
 650000</p><p>
 F & Partners 
 550000</p><p>
 July James 
 800000</p><p>
 G & Co. 
 350000</p><p>
 H Group 
 250000</p><p>
 I & Sons 
 100000</p><p>
 J Ent. 
 100000</p><p>
 Total: 
 4300000</p><p>
// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_LINQ();
string fileName = "InTableMasterDetail.doc";
// Load the template document.
Document doc = new Document(dataDir + fileName);
// Create a Reporting Engine.
ReportingEngine engine = new ReportingEngine();
// Execute the build report.
engine.BuildReport(doc, Common.GetManagers(), "managers");
dataDir = dataDir + RunExamples.GetOutputFilePath(fileName);
// Save the finished document to disk.
doc.Save(dataDir);

Pie Chart Template

You can download the template file of this example from here.

Template Example

Pie_Chart_Template_Example2-aspose-words-net

Initial Chart Series Data

Pie_Chart_Series_Data2-aspose-words-net

Report Example

Pie_Chart_Report_Example-aspose-words-net

// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_LINQ();
string fileName = "PieChart.docx";
// Load the template document.
Document doc = new Document(dataDir + fileName);
// Create a Reporting Engine.
ReportingEngine engine = new ReportingEngine();
// Execute the build report.
engine.BuildReport(doc, Common.GetManagers(), "managers");
dataDir = dataDir + RunExamples.GetOutputFilePath(fileName);
// Save the finished document to disk.
doc.Save(dataDir);

Scatter Chart Template

You can download the template file of this example from here.

Template Example

Scatter_Chart_Template_Example2-aspose-words-net

Initial Chart Series Data

Scatter_Chart_Series_Data2-aspose-words-net

Report Example

Scatter_Chart_Report_Example-aspose-words-net

// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_LINQ();
string fileName = "ScatterChart.docx";
// Load the template document.
Document doc = new Document(dataDir + fileName);
// Create a Reporting Engine.
ReportingEngine engine = new ReportingEngine();
// Execute the build report.
engine.BuildReport(doc, Common.GetContracts(), "contracts");
dataDir = dataDir + RunExamples.GetOutputFilePath(fileName);
// Save the finished document to disk.
doc.Save(dataDir);

Bubble Chart Template

You can download the template file of this example from here.

Template Example

Bubble_Chart_Template_Example2-aspose-words-net

Initial Chart Series Data

Bubble_Chart_Series_Data2-aspose-words-net

Report Example

Bubble_Chart_Report_Example-aspose-words-net

// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_LINQ();
string fileName = "BubbleChart.docx";
// Load the template document.
Document doc = new Document(dataDir + fileName);
// Create a Reporting Engine.
ReportingEngine engine = new ReportingEngine();
// Execute the build report.
engine.BuildReport(doc, Common.GetContracts(), "contracts");
dataDir = dataDir + RunExamples.GetOutputFilePath(fileName);
// Save the finished document to disk.
doc.Save(dataDir);

In-Table Template with Filtering, Grouping, and Ordering

You can download the template file of this example from here.

Template Example

Manager Contract Price
 <<foreach [in contracts
.Where(c => c.Date().Year() == 2015)
.GroupBy(c => c.Manager())
.OrderBy(g => g.key.Name())]>>
<<[key.Name()]>> 
«[sum(c => c.Price())]»«/foreach»

Report Example

Manager Contract Price
John Smith 2300000
July James 800000
Tony Anderson 1200000
// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_LINQ();
string fileName = "InTableWithFilteringGroupingSorting.doc";
// Load the template document.
Document doc = new Document(dataDir + fileName);
// Create a Reporting Engine.
ReportingEngine engine = new ReportingEngine();
// Execute the build report.
engine.BuildReport(doc, Common.GetContracts(), "contracts");
dataDir = dataDir + RunExamples.GetOutputFilePath(fileName);
// Save the finished document to disk.
doc.Save(dataDir);

Chart Template with Filtering, Grouping, and Ordering

You can download the template file of this example from here.

Template Example

Chart_Template_Example2-aspose-words-net

Report Example

Chart_Report_Example-aspose-words-net

// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_LINQ();
string fileName = "ChartWithFilteringGroupingOrdering.docx";
// Load the template document.
Document doc = new Document(dataDir + fileName);
// Create a Reporting Engine.
ReportingEngine engine = new ReportingEngine();
// Execute the build report.
engine.BuildReport(doc, Common.GetContracts(), "contracts");
dataDir = dataDir + RunExamples.GetOutputFilePath(fileName);
// Save the finished document to disk.
doc.Save(dataDir);