-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added an example for a pilot article.
- Loading branch information
1 parent
c4ceb99
commit 8e2cbe7
Showing
5 changed files
with
101 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
Examples/ApiExamples/ApiExamples/LinqTemp/ExReportingEngine.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. | ||
// | ||
// This file is part of Aspose.Words. The source code in this file | ||
// is only intended as a supplement to the documentation, and is provided | ||
// "as is", without warranty of any kind, either expressed or implied. | ||
////////////////////////////////////////////////////////////////////////// | ||
|
||
using Aspose.Words; | ||
using Aspose.Words.Reporting; | ||
using NUnit.Framework; | ||
using System; | ||
using System.IO; | ||
|
||
namespace ApiExamples.LinqTemp | ||
{ | ||
[TestFixture] | ||
public class ExReportingEngine : ApiExampleBase | ||
{ | ||
[Test] | ||
public void BuildingColumnChart() | ||
{ | ||
//ExStart:BuildingColumnChart | ||
//GistId:a9bfce4e06620c7bb2f1f0af6d166f0e | ||
// Open the template document. | ||
Document doc = new Document(MyLinqDir + "Column Chart Template.docx"); | ||
|
||
// Open the data source file. | ||
JsonDataSource dataSource = new JsonDataSource(MyLinqDir + "Column Chart Data.json"); | ||
|
||
// Build a report. The name of the data source should match the one used in the template. | ||
ReportingEngine engine = new ReportingEngine(); | ||
engine.BuildReport(doc, dataSource, "items"); | ||
|
||
// Save the report. | ||
doc.Save(ArtifactsDir + "Column Chart Report.docx"); | ||
//ExEnd:BuildingColumnChart | ||
|
||
// Test the report. | ||
CompareDocs("Column Chart Report.docx", "Column Chart Report Gold.docx"); | ||
} | ||
|
||
/// <summary> | ||
/// A helper method asserting that two files are equal. | ||
/// </summary> | ||
/// <param name="artifactFileName">The name of a file within <see cref="ArtifactsDir"/>.</param> | ||
/// <param name="linqGoldFileName">The name of a file within <see cref="LinqGoldsDir"/>.</param> | ||
private static void CompareDocs(string artifactFileName, string linqGoldFileName) | ||
{ | ||
string artifactPath = ArtifactsDir + artifactFileName; | ||
string linqGoldPath = LinqGoldsDir + linqGoldFileName; | ||
|
||
if (!File.Exists(linqGoldPath)) | ||
File.Copy(artifactPath, linqGoldPath); | ||
else | ||
Assert.IsTrue(DocumentHelper.CompareDocs(artifactPath, linqGoldPath)); | ||
} | ||
|
||
/// <summary> | ||
/// Gets the path to the directory with template and data files used by this class. Ends with a back slash. | ||
/// </summary> | ||
private static string MyLinqDir { get; } | ||
|
||
/// <summary> | ||
/// Gets the path to the directory with previously generated reports used by this class. Ends with a back slash. | ||
/// </summary> | ||
private static string LinqGoldsDir { get; } | ||
|
||
static ExReportingEngine() | ||
{ | ||
MyLinqDir = new Uri(new Uri(MyDir), @"LINQ/").LocalPath; | ||
LinqGoldsDir = new Uri(new Uri(GoldsDir), @"LINQ/").LocalPath; | ||
} | ||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
[ | ||
{ | ||
"department": "Sales", | ||
"revenue": 50000, | ||
"expenses": 30000 | ||
}, | ||
{ | ||
"department": "Marketing", | ||
"revenue": 40000, | ||
"expenses": 25000 | ||
}, | ||
{ | ||
"department": "Finance", | ||
"revenue": 30000, | ||
"expenses": 20000 | ||
}, | ||
{ | ||
"department": "Operations", | ||
"revenue": 35000, | ||
"expenses": 22000 | ||
}, | ||
{ | ||
"department": "Human Resources", | ||
"revenue": 25000, | ||
"expenses": 15000 | ||
} | ||
] |
Binary file not shown.