Skip to content

Commit 1f1bcf7

Browse files
Publish linq-reporting category examples (#233)
1 parent 7736c4e commit 1f1bcf7

240 files changed

Lines changed: 10297 additions & 11079 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

linq-reporting/AGENTS.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2085,7 +2085,7 @@ Use the simplest workflow that satisfies the task.
20852085
## Build and run contract
20862086

20872087
- Target framework: `net8.0`
2088-
- Package: `Aspose.Words` `26.7.0`
2088+
- Package: `Aspose.Words` `26.8.0`
20892089
- Package: `Newtonsoft.Json`
20902090
- Package: `System.Text.Encoding.CodePages` `9.0.2`
20912091

@@ -2101,7 +2101,7 @@ cd ExampleProject
21012101
### Add required packages
21022102

21032103
```bash
2104-
dotnet add package Aspose.Words --version 26.7.0
2104+
dotnet add package Aspose.Words --version 26.8.0
21052105
dotnet add package Newtonsoft.Json
21062106
dotnet add package System.Text.Encoding.CodePages --version 9.0.2
21072107
```

linq-reporting/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# LINQ Reporting Examples for Aspose.Words for .NET
22

3-
This folder contains the live, publish-ready C# examples for the LINQ Reporting category. Each file is a standalone console example selected from the verified 26.7.0 run.
3+
This folder contains the live, publish-ready C# examples for the LINQ Reporting category. Each file is a standalone console example selected from the verified 26.8.0 run.
44

55
## Snapshot
66

77
- Category: LINQ Reporting
88
- Slug: linq-reporting
99
- Total examples: 403
1010
- Publish-ready successful examples: 403 / 403
11-
- Source run: 20260802_190455_803b68
11+
- Source run: 20260830_195242_46e1a9
1212
- LINQ Reporting Workflow examples: 403
1313

1414
## Category rules that shaped these examples
@@ -23,7 +23,7 @@ This folder contains the live, publish-ready C# examples for the LINQ Reporting
2323
## Prerequisites
2424

2525
- .NET SDK 8.0 or later
26-
- Aspose.Words 26.7.0
26+
- Aspose.Words 26.8.0
2727
- Newtonsoft.Json
2828
- System.Text.Encoding.CodePages 9.0.2
2929

@@ -34,7 +34,7 @@ Each file in this folder is a single, standalone `.cs` console example. To run o
3434
```bash
3535
dotnet new console -n ExampleProject --framework net8.0
3636
cd ExampleProject
37-
dotnet add package Aspose.Words --version 26.7.0
37+
dotnet add package Aspose.Words --version 26.8.0
3838
dotnet add package Newtonsoft.Json
3939
dotnet add package System.Text.Encoding.CodePages --version 9.0.2
4040

@@ -57,7 +57,7 @@ Example:
5757
# From the repository root
5858
dotnet new console -n ExampleProject --framework net8.0
5959
cd ExampleProject
60-
dotnet add package Aspose.Words --version 26.7.0
60+
dotnet add package Aspose.Words --version 26.8.0
6161
dotnet add package Newtonsoft.Json
6262
dotnet add package System.Text.Encoding.CodePages --version 9.0.2
6363

@@ -519,6 +519,6 @@ dotnet run --configuration Release --no-build
519519
520520
## Notes for maintainers
521521

522-
- This category is 100% publish-ready for the 26.7.0 run.
522+
- This category is 100% publish-ready for the 26.8.0 run.
523523
- Preserve file-to-task traceability when updating this folder.
524524
- Keep examples standalone and bootstrap local inputs inside the example whenever external sources are mentioned.

linq-reporting/access-static-members-of-system-math-inside-an-expression-to-compute-rounded-values-for-fi.cs

Lines changed: 25 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -3,81 +3,51 @@
33
using Aspose.Words;
44
using Aspose.Words.Reporting;
55

6-
public class Program
6+
public class InvoiceItem
77
{
8-
// Simple data model representing a financial record.
9-
public class FinancialRecord
10-
{
11-
public string Description { get; set; } = string.Empty;
12-
public double Amount { get; set; }
13-
}
8+
public string Description { get; set; } = string.Empty;
9+
public decimal Amount { get; set; }
10+
}
1411

15-
// Wrapper class that will be passed as the root data source.
16-
public class ReportModel
17-
{
18-
public List<FinancialRecord> Items { get; set; } = new();
19-
}
12+
public class ReportModel
13+
{
14+
public List<InvoiceItem> Items { get; set; } = new();
15+
}
2016

17+
public class Program
18+
{
2119
public static void Main()
2220
{
23-
// 1. Prepare sample data.
21+
// Prepare sample data.
2422
var model = new ReportModel
2523
{
26-
Items = new List<FinancialRecord>
24+
Items = new List<InvoiceItem>
2725
{
28-
new FinancialRecord { Description = "Consulting", Amount = 1234.5678 },
29-
new FinancialRecord { Description = "Software License", Amount = 9876.5432 },
30-
new FinancialRecord { Description = "Support", Amount = 250.125 }
26+
new InvoiceItem { Description = "Consulting", Amount = 1234.567m },
27+
new InvoiceItem { Description = "Software License", Amount = 2500.0m },
28+
new InvoiceItem { Description = "Support", Amount = 199.994m }
3129
}
3230
};
3331

34-
// 2. Create a template document programmatically.
35-
var templatePath = "Template.docx";
32+
// Create a template document in memory.
3633
var doc = new Document();
3734
var builder = new DocumentBuilder(doc);
3835

39-
// Header.
40-
builder.Writeln("Financial Report");
41-
builder.Writeln("-----------------");
42-
43-
// Table header (outside the foreach loop).
44-
var headerTable = builder.StartTable();
45-
builder.InsertCell();
46-
builder.Writeln("Description");
47-
builder.InsertCell();
48-
builder.Writeln("Amount (rounded to 2 decimals)");
49-
builder.EndRow();
50-
builder.EndTable();
51-
52-
// Data rows using LINQ Reporting tags.
53-
// The foreach block must enclose the entire table that repeats for each item.
36+
builder.Writeln("Invoice Report");
5437
builder.Writeln("<<foreach [item in Items]>>");
55-
var dataTable = builder.StartTable();
56-
builder.InsertCell();
57-
builder.Writeln("<<[item.Description]>>");
58-
builder.InsertCell();
59-
// Use System.Math.Round static method inside the expression.
60-
builder.Writeln("<<[Math.Round(item.Amount, 2)]>>");
61-
builder.EndRow();
62-
builder.EndTable();
38+
// Use System.Math static method to round the amount to 2 decimal places.
39+
builder.Writeln("Item: <<[item.Description]>> - Amount: $<<[Math.Round(item.Amount, 2)]>>");
6340
builder.Writeln("<</foreach>>");
6441

65-
// Save the template to disk.
66-
doc.Save(templatePath);
67-
68-
// 3. Load the template for reporting.
69-
var reportDoc = new Document(templatePath);
70-
71-
// 4. Configure the ReportingEngine.
42+
// Configure the reporting engine.
7243
var engine = new ReportingEngine();
73-
// Allow the engine to access static members of System.Math.
44+
// Register System.Math so its static members can be used in expressions.
7445
engine.KnownTypes.Add(typeof(Math));
7546

76-
// 5. Build the report.
77-
engine.BuildReport(reportDoc, model, "model");
47+
// Build the report using the model as the root data source named "model".
48+
engine.BuildReport(doc, model, "model");
7849

79-
// 6. Save the generated report.
80-
var outputPath = "Report.docx";
81-
reportDoc.Save(outputPath);
50+
// Save the generated report.
51+
doc.Save("InvoiceReport.docx");
8252
}
8353
}

linq-reporting/activate-reportbuildoptions-inlineerrormessages-and-capture-the-boolean-success-flag-from.cs

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,44 @@
22
using Aspose.Words;
33
using Aspose.Words.Reporting;
44

5-
public class Program
5+
namespace AsposeWordsLinqReportingExample
66
{
7-
public static void Main()
7+
// Simple data model used as the root object for the report.
8+
public class Person
89
{
9-
// Create a template document with a LINQ Reporting tag.
10-
Document doc = new Document();
11-
DocumentBuilder builder = new DocumentBuilder(doc);
12-
builder.Writeln("Hello <<[model.Name]>>!");
10+
public string Name { get; set; } = string.Empty;
11+
public int Age { get; set; }
12+
}
1313

14-
// Prepare the data model.
15-
var model = new ReportModel { Name = "World" };
14+
public class Program
15+
{
16+
public static void Main()
17+
{
18+
// Create a sample data object.
19+
var person = new Person
20+
{
21+
Name = "John Doe",
22+
Age = 30
23+
};
1624

17-
// Configure the reporting engine to inline error messages.
18-
ReportingEngine engine = new ReportingEngine();
19-
engine.Options = ReportBuildOptions.InlineErrorMessages;
25+
// Create a new blank document and insert a LINQ Reporting tag.
26+
var doc = new Document();
27+
var builder = new DocumentBuilder(doc);
28+
// The tag references the root object name "person".
29+
builder.Writeln("<<[person.Name]>> is <<[person.Age]>> years old.");
2030

21-
// Build the report and capture the success flag.
22-
bool success = engine.BuildReport(doc, model, "model");
31+
// Configure the reporting engine to inline error messages.
32+
var engine = new ReportingEngine();
33+
engine.Options = ReportBuildOptions.InlineErrorMessages;
2334

24-
// Save the generated report.
25-
doc.Save("ReportOutput.docx");
35+
// Build the report and capture the success flag.
36+
bool success = engine.BuildReport(doc, person, "person");
2637

27-
// Output the success flag.
28-
Console.WriteLine($"BuildReport success: {success}");
29-
}
38+
// Save the resulting document.
39+
doc.Save("ReportOutput.docx");
3040

31-
// Simple data model class used by the template.
32-
public class ReportModel
33-
{
34-
public string Name { get; set; } = "";
41+
// Output the success flag (no interactive input required).
42+
Console.WriteLine($"Report build success: {success}");
43+
}
3544
}
3645
}
Lines changed: 52 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,88 @@
11
using System;
22
using System.Collections.Generic;
33
using Aspose.Words;
4+
using Aspose.Words.Lists; // For ListTemplate
45
using Aspose.Words.Reporting;
6+
using Aspose.Words.Drawing;
7+
using Aspose.Words.Drawing.Charts; // For ChartType
58

69
public class Program
710
{
811
public static void Main()
912
{
10-
// Paths for the template and the generated report.
11-
const string templatePath = "Template.docx";
12-
const string outputPath = "Report.docx";
13+
// Prepare sample data.
14+
var model = new ReportModel
15+
{
16+
Items = new List<Item>
17+
{
18+
new Item { Title = "First item", BookmarkName = "bmFirst" },
19+
new Item { Title = "Second item", BookmarkName = "bmSecond" },
20+
new Item { Title = "Third item", BookmarkName = "bmThird" }
21+
}
22+
};
1323

14-
// -------------------------------------------------
15-
// 1. Create the LINQ Reporting template programmatically.
16-
// -------------------------------------------------
17-
Document templateDoc = new Document();
18-
DocumentBuilder builder = new DocumentBuilder(templateDoc);
24+
// -----------------------------------------------------------------
25+
// 1. Create the template document programmatically.
26+
// -----------------------------------------------------------------
27+
var template = new Document();
28+
var builder = new DocumentBuilder(template);
1929

20-
// Create a numbered list that will be used for the items.
21-
builder.ListFormat.List = templateDoc.Lists.Add(Aspose.Words.Lists.ListTemplate.NumberDefault);
30+
// Title paragraph.
31+
builder.Writeln("Report with bookmarks inside list items:");
2232

23-
// Write the foreach tag that iterates over the Items collection.
33+
// Start a numbered list.
34+
builder.ListFormat.List = template.Lists.Add(ListTemplate.NumberDefault);
35+
36+
// LINQ Reporting foreach block iterating over Items.
2437
builder.Writeln("<<foreach [item in Items]>>");
2538

26-
// Each iteration is a list paragraph. Insert a bookmark that wraps the item's title.
27-
// The bookmark name is taken from the data source (item.BookmarkName).
28-
builder.Writeln("<<bookmark [item.BookmarkName]>><<[item.Title]>><</bookmark>>");
39+
// Insert a bookmark that wraps the list item text.
40+
// The bookmark expression must return a non‑empty string.
41+
builder.Writeln("<<bookmark [item.BookmarkName]>>");
42+
builder.Writeln("<<[item.Title]>>");
43+
builder.Writeln("<</bookmark>>");
2944

30-
// End the foreach block.
45+
// End of foreach block.
3146
builder.Writeln("<</foreach>>");
3247

48+
// End the list.
49+
builder.ListFormat.RemoveNumbers();
50+
51+
// Insert a chart after the list – bookmarks are **not** placed inside the chart.
52+
builder.Writeln("\nSample chart:");
53+
builder.InsertChart(ChartType.Column, 400, 300);
54+
3355
// Save the template to disk.
34-
templateDoc.Save(templatePath);
56+
const string templatePath = "Template.docx";
57+
template.Save(templatePath);
3558

36-
// -------------------------------------------------
37-
// 2. Prepare the data model.
38-
// -------------------------------------------------
39-
ReportModel model = new ReportModel
59+
// -----------------------------------------------------------------
60+
// 2. Build the report using the LINQ Reporting engine.
61+
// -----------------------------------------------------------------
62+
var report = new Document(templatePath);
63+
var engine = new ReportingEngine
4064
{
41-
Items = new List<Item>
42-
{
43-
new Item { Title = "First item", BookmarkName = "bmFirst" },
44-
new Item { Title = "Second item", BookmarkName = "bmSecond" },
45-
new Item { Title = "Third item", BookmarkName = "bmThird" }
46-
}
65+
Options = ReportBuildOptions.None
4766
};
4867

49-
// -------------------------------------------------
50-
// 3. Load the template and build the report.
51-
// -------------------------------------------------
52-
Document doc = new Document(templatePath);
53-
ReportingEngine engine = new ReportingEngine();
68+
// The root object name used in the template is "model".
69+
engine.BuildReport(report, model, "model");
5470

55-
// Build the report using the model as the root object named "model".
56-
engine.BuildReport(doc, model, "model");
57-
58-
// -------------------------------------------------
59-
// 4. Save the generated report.
60-
// -------------------------------------------------
61-
doc.Save(outputPath);
71+
// Save the final report.
72+
report.Save("Report.docx");
6273
}
6374
}
6475

65-
// -------------------------------------------------
66-
// Data model classes.
67-
// -------------------------------------------------
76+
// ---------------------------------------------------------------------
77+
// Data model classes – must be public with public properties.
78+
// ---------------------------------------------------------------------
6879
public class ReportModel
6980
{
70-
// Collection of items to be listed.
7181
public List<Item> Items { get; set; } = new();
7282
}
7383

7484
public class Item
7585
{
76-
// Text displayed for the list item.
7786
public string Title { get; set; } = string.Empty;
78-
79-
// Name of the bookmark that will be placed around the title.
8087
public string BookmarkName { get; set; } = string.Empty;
8188
}

0 commit comments

Comments
 (0)