Skip to content

Commit

Permalink
Updated examples
Browse files Browse the repository at this point in the history
  • Loading branch information
falleretic committed Feb 1, 2024
1 parent 8d9b057 commit e86868d
Show file tree
Hide file tree
Showing 12 changed files with 318 additions and 8 deletions.
5 changes: 3 additions & 2 deletions Examples/ApiExamples/ApiExamples/ApiExamples.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
<Content Include="ExMailMerge.cs" />
<Content Include="ExMailMergeCustom.cs" />
<Content Include="ExMailMergeEvent.cs" />
<Content Include="ExMarkdownLoadOptions.cs" />
<Content Include="ExMarkdownSaveOptions.cs" />
<Content Include="ExMetered.cs" />
<Content Include="ExMossDoc2Pdf.cs" />
Expand Down Expand Up @@ -127,8 +128,8 @@
<PackageReference Include="Aspose.BarCode" Version="23.12.0" />
<PackageReference Include="Aspose.Page" Version="23.12.0" />
<PackageReference Include="Aspose.PDF" Version="23.12.0" />
<PackageReference Include="Aspose.Words" Version="24.1.0" />
<PackageReference Include="Aspose.Words.Shaping.HarfBuzz" Version="24.1.0" />
<PackageReference Include="Aspose.Words" Version="24.2.0" />
<PackageReference Include="Aspose.Words.Shaping.HarfBuzz" Version="24.2.0" />
<PackageReference Include="BouncyCastle.Cryptography" Version="2.2.1" />
<PackageReference Include="Microsoft.Extensions.Http" Version="8.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
Expand Down
49 changes: 43 additions & 6 deletions Examples/ApiExamples/ApiExamples/ExCharts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,15 @@ public void AxisProperties()
//ExFor:ChartAxis.MinorTickMark
//ExFor:ChartAxis.MajorUnit
//ExFor:ChartAxis.MinorUnit
//ExFor:ChartAxis.TickLabelOffset
//ExFor:ChartAxis.TickLabelPosition
//ExFor:ChartAxis.TickLabelSpacingIsAuto
//ExFor:AxisTickLabels.Offset
//ExFor:AxisTickLabels.Position
//ExFor:AxisTickLabels.IsAutoSpacing
//ExFor:ChartAxis.TickMarkSpacing
//ExFor:Charts.AxisCategoryType
//ExFor:Charts.AxisCrosses
//ExFor:Charts.Chart.AxisX
//ExFor:Charts.Chart.AxisY
//ExFor:Charts.Chart.AxisZ
//ExFor:Chart.AxisX
//ExFor:Chart.AxisY
//ExFor:Chart.AxisZ
//ExSummary:Shows how to insert a chart and modify the appearance of its axes.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Expand Down Expand Up @@ -1627,5 +1627,42 @@ public void ResetDataPointFill()
doc.Save(ArtifactsDir + "Charts.ResetDataPointFill.docx");
//ExEnd:ResetDataPointFill
}

[Test]
public void DataTable()
{
//ExStart:DataTable
//GistId:a775441ecb396eea917a2717cb9e8f8f
//ExFor:ChartDataTable
//ExFor:ChartDataTable.Show
//ExSummary:Shows how to show data table with chart series data.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

Shape shape = builder.InsertChart(ChartType.Column, 432, 252);
Chart chart = shape.Chart;

ChartSeriesCollection series = chart.Series;
series.Clear();
double[] xValues = new double[] { 2020, 2021, 2022, 2023 };
series.Add("Series1", xValues, new double[] { 5, 11, 2, 7 });
series.Add("Series2", xValues, new double[] { 6, 5.5, 7, 7.8 });
series.Add("Series3", xValues, new double[] { 10, 8, 7, 9 });

ChartDataTable dataTable = chart.DataTable;
dataTable.Show = true;

dataTable.HasLegendKeys = false;
dataTable.HasHorizontalBorder = false;
dataTable.HasVerticalBorder = false;

dataTable.Font.Italic = true;
dataTable.Format.Stroke.Weight = 1;
dataTable.Format.Stroke.DashStyle = DashStyle.ShortDot;
dataTable.Format.Stroke.Color = Color.DarkBlue;

doc.Save(ArtifactsDir + "Charts.DataTable.docx");
//ExEnd:DataTable
}
}
}
18 changes: 18 additions & 0 deletions Examples/ApiExamples/ApiExamples/ExInlineStory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -623,5 +623,23 @@ public void DeleteShapes()
Assert.AreEqual(0, doc.GetChildNodes(NodeType.Shape, true).Count);
//ExEnd
}

[Test]
public void UpdateActualReferenceMarks()
{
//ExStart:UpdateActualReferenceMarks
//GistId:a775441ecb396eea917a2717cb9e8f8f
//ExFor:Document.UpdateActualReferenceMarks
//ExFor:Footnote.ActualReferenceMark
//ExSummary:Shows how to get actual footnote reference mark.
Document doc = new Document(MyDir + "Footnotes and endnotes.docx");

Footnote footnote = (Footnote)doc.GetChild(NodeType.Footnote, 1, true);
doc.UpdateFields();
doc.UpdateActualReferenceMarks();

Assert.AreEqual("1", footnote.ActualReferenceMark);
//ExEnd:UpdateActualReferenceMarks
}
}
}
31 changes: 31 additions & 0 deletions Examples/ApiExamples/ApiExamples/ExMarkdownLoadOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;
using System.IO;
using System.Text;
using ApiExamples;
using Aspose.Words.Loading;
using NUnit.Framework;

namespace Aspose.Words.ApiExamples
{
class ExMarkdownLoadOptions : ApiExampleBase
{
[Test]
public void PreserveEmptyLines()
{
//ExStart:PreserveEmptyLines
//GistId:a775441ecb396eea917a2717cb9e8f8f
//ExFor:MarkdownLoadOptions
//ExFor:MarkdownLoadOptions.PreserveEmptyLines
//ExSummary:Shows how to preserve empty line while load a document.
string mdText = $"{Environment.NewLine}Line1{Environment.NewLine}{Environment.NewLine}Line2{Environment.NewLine}{Environment.NewLine}";
using (MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(mdText)))
{
MarkdownLoadOptions loadOptions = new MarkdownLoadOptions() { PreserveEmptyLines = true };
Document doc = new Document(stream, loadOptions);

Assert.AreEqual("\rLine1\r\rLine2\r\f", doc.GetText());
}
//ExEnd:PreserveEmptyLines
}
}
}
17 changes: 17 additions & 0 deletions Examples/ApiExamples/ApiExamples/ExReportingEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1242,6 +1242,23 @@ public void RestrictedTypes()
//ExEnd:RestrictedTypes
}

[Test]
public void Word2016Charts()
{
//ExStart:Word2016Charts
//GistId:a775441ecb396eea917a2717cb9e8f8f
//ExFor:ReportingEngine.BuildReport(Document, Object[], String[])
//ExSummary:Shows how to work with charts from word 2016.
Document doc = new Document(MyDir + "Reporting engine template - Word 2016 Charts.docx");

ReportingEngine engine = new ReportingEngine();
engine.BuildReport(doc, new object[] { Common.GetShares(), Common.GetShareQuotes() },
new string[] { "shares", "quotes" });

doc.Save(ArtifactsDir + "ReportingEngine.Word2016Charts.docx");
//ExEnd:Word2016Charts
}

private static void BuildReport(Document document, object dataSource, ReportBuildOptions reportBuildOptions)
{
ReportingEngine engine = new ReportingEngine { Options = reportBuildOptions };
Expand Down
17 changes: 17 additions & 0 deletions Examples/ApiExamples/ApiExamples/ExStructuredDocumentTag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1312,5 +1312,22 @@ public void RemoveSelfOnly()
Assert.AreEqual(0, sdts.Count());
//ExEnd:RemoveSelfOnly
}

[Test]
public void Appearance()
{
//ExStart:Appearance
//GistId:a775441ecb396eea917a2717cb9e8f8f
//ExFor:SdtAppearance
//ExFor:StructuredDocumentTagRangeStart.Appearance
//ExSummary:Shows how to show tag around content.
Document doc = new Document(MyDir + "Multi-section structured document tags.docx");
StructuredDocumentTagRangeStart tag =
doc.GetChild(NodeType.StructuredDocumentTagRangeStart, 0, true) as StructuredDocumentTagRangeStart;

if (tag.Appearance == SdtAppearance.Hidden)
tag.Appearance = SdtAppearance.Tags;
//ExEnd:Appearance
}
}
}
25 changes: 25 additions & 0 deletions Examples/ApiExamples/ApiExamples/ExStyles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -372,5 +372,30 @@ public void LockStyle()
doc = new Document(ArtifactsDir + "Styles.LockStyle.docx");
Assert.IsTrue(doc.Styles[StyleIdentifier.Heading1].Locked);
}

[Test]
public void StylePriority()
{
//ExStart:StylePriority
//GistId:a775441ecb396eea917a2717cb9e8f8f
//ExFor:Style.Priority
//ExFor:Style.UnhideWhenUsed
//ExFor:Style.SemiHidden
//ExSummary:Shows how to prioritize and hide a style.
Document doc = new Document();
Style styleTitle = doc.Styles[StyleIdentifier.Subtitle];

if (styleTitle.Priority == 9)
styleTitle.Priority = 10;

if (!styleTitle.UnhideWhenUsed)
styleTitle.UnhideWhenUsed = true;

if (styleTitle.SemiHidden)
styleTitle.SemiHidden = true;

doc.Save(ArtifactsDir + "Styles.StylePriority.docx");
//ExEnd:StylePriority
}
}
}
19 changes: 19 additions & 0 deletions Examples/ApiExamples/ApiExamples/ExSvgSaveOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System;
using System.IO;
using Aspose.Words;
using Aspose.Words.Math;
using Aspose.Words.Saving;
using NUnit.Framework;

Expand Down Expand Up @@ -82,5 +83,23 @@ void IResourceSavingCallback.ResourceSaving(ResourceSavingArgs args)
private int mSavedResourceCount;
}
//ExEnd

[Test]
public void SaveOfficeMath()
{
//ExStart:SaveOfficeMath
//GistId:a775441ecb396eea917a2717cb9e8f8f
//ExFor:NodeRendererBase.Save(String, SvgSaveOptions)
//ExSummary:Shows how to pass save options when rendering office math.
Document doc = new Document(MyDir + "Office math.docx");

OfficeMath math = (OfficeMath)doc.GetChild(NodeType.OfficeMath, 0, true);

SvgSaveOptions options = new SvgSaveOptions();
options.TextOutputMode = SvgTextOutputMode.UsePlacedGlyphs;

math.GetMathRenderer().Save(ArtifactsDir + "SvgSaveOptions.Output.svg", options);
//ExEnd:SaveOfficeMath
}
}
}
32 changes: 32 additions & 0 deletions Examples/ApiExamples/ApiExamples/TestData/Common.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using ApiExamples.TestData.TestClasses;
using Aspose.Words.ApiExamples.HelperClasses.TestClasses;

namespace ApiExamples.TestData
{
Expand Down Expand Up @@ -173,5 +174,36 @@ public static IEnumerable<ContractTestClass> GetContracts()
yield return contract;
}
}

public static ShareTestClass[] GetShares()
{
return new ShareTestClass[]
{
new ShareTestClass("Technology", "Consumer Electronics", "AAPL", 6.602835, -0.0054),
new ShareTestClass("Technology", "Software - Infrastructure", "MSFT", 5.832072, -0.005),
new ShareTestClass("Technology", "Software - Infrastructure", "ADBE", 0.562561, -0.0274),
new ShareTestClass("Technology", "Semiconductors", "NVDA", 1.335994, -0.0074),
new ShareTestClass("Technology", "Semiconductors", "QCOM", 0.462198, 0.0248),
new ShareTestClass("Communication Services", "Internet Content & Information", "GOOG", 3.771651, 0.011),
new ShareTestClass("Communication Services", "Entertainment", "DIS", 0.575768, 0.0102),
new ShareTestClass("Communication Services", "Entertainment", "WBD", 0.116579, -0.0165),
new ShareTestClass("Consumer Cyclical", "Internet Retail", "AMZN", 3.011482, 0.044),
new ShareTestClass("Consumer Cyclical", "Auto Manufactures", "TSLA", 1.816734, -0.0018),
new ShareTestClass("Consumer Cyclical", "Auto Manufactures", "GM", 0.160205, 0.0026),
new ShareTestClass("Financial", "Credit Services", "V", 1.1, 0.005)
};
}

public static ShareQuoteTestClass[] GetShareQuotes()
{
return new ShareQuoteTestClass[]
{
new ShareQuoteTestClass(45131, 15232450, 171.32, 172.50, 170.69, 171.98),
new ShareQuoteTestClass(45132, 13962990, 172.20, 172.70, 171.40, 171.86),
new ShareQuoteTestClass(45133, 14902060, 171.86, 171.93, 170.31, 171.35),
new ShareQuoteTestClass(45134, 16962540, 171.64, 173.10, 171.35, 172.00),
new ShareQuoteTestClass(45135, 15588280, 171.98, 172.40, 170.00, 171.44)
};
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Aspose.Words.ApiExamples.HelperClasses.TestClasses
{
public class ShareQuoteTestClass
{
internal ShareQuoteTestClass(int date, int volume, double open, double high, double low, double close)
{
this.Date = date;
this.Volume = volume;
this.Open = open;
this.High = high;
this.Low = low;
this.Close = close;
}

public string Color()
{
return (Open < Close) ? "#1B9629" : "#96002C";
}

public int Date;
public int Volume;
public double Open;
public double High;
public double Low;
public double Close;
}
}
Loading

0 comments on commit e86868d

Please sign in to comment.