Skip to content

Commit

Permalink
Updated examples
Browse files Browse the repository at this point in the history
  • Loading branch information
vderyushev committed Apr 30, 2024
1 parent 3311077 commit f54b2dd
Show file tree
Hide file tree
Showing 13 changed files with 240 additions and 6 deletions.
3 changes: 2 additions & 1 deletion Examples/ApiExamples/ApiExamples/ApiExamples.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
<PackageReference Include="Aspose.BarCode" Version="24.3.0" />
<PackageReference Include="Aspose.Page" Version="24.3.3" />
<PackageReference Include="Aspose.PDF" Version="24.3.0" />
<PackageReference Include="Aspose.Words" Version="24.4.0" />
<PackageReference Include="Aspose.Words" Version="24.5.0" />
<PackageReference Include="Aspose.Words.Shaping.HarfBuzz" Version="24.4.0" />
<PackageReference Include="BouncyCastle.Cryptography" Version="2.3.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="8.0.0" />
Expand All @@ -138,6 +138,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="SkiaSharp" Version="2.88.8" />
<PackageReference Include="System.Data.OleDb" Version="8.0.0" />
<PackageReference Include="System.IO.Compression" Version="4.3.0" />
<PackageReference Include="System.Runtime.InteropServices.RuntimeInformation" Version="4.3.0" />
Expand Down
111 changes: 111 additions & 0 deletions Examples/ApiExamples/ApiExamples/ExCharts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1766,5 +1766,116 @@ public void ChartFormat()
Assert.AreEqual(Color.LightGoldenrodYellow.ToArgb(), chart.AxisX.Title.Format.Fill.Color.ToArgb());
Assert.AreEqual(Color.LightGoldenrodYellow.ToArgb(), chart.Legend.Format.Fill.Color.ToArgb());
}

[Test]
public void SecondaryAxis()
{
//ExStart:SecondaryAxis
//GistId:6e4482e7434754c31c6f2f6e4bf48bb1
//ExFor:ChartSeriesGroup
//ExFor:ChartSeriesGroup.AxisGroup
//ExFor:ChartSeriesGroup.AxisX
//ExFor:ChartSeriesGroup.AxisY
//ExFor:ChartSeriesGroup.Series
//ExFor:ChartSeriesGroupCollection.Add(ChartSeriesType)
//ExFor:AxisGroup
//ExSummary:Shows how to work with the secondary axis of chart.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

Shape shape = builder.InsertChart(ChartType.Line, 450, 250);
Chart chart = shape.Chart;
ChartSeriesCollection series = chart.Series;

// Delete default generated series.
series.Clear();

string[] categories = new string[] { "Category 1", "Category 2", "Category 3" };
series.Add("Series 1 of primary series group", categories, new double[] { 2, 3, 4 });
series.Add("Series 2 of primary series group", categories, new double[] { 5, 2, 3 });

// Create an additional series group, also of the line type.
ChartSeriesGroup newSeriesGroup = chart.SeriesGroups.Add(ChartSeriesType.Line);
// Specify the use of secondary axes for the new series group.
newSeriesGroup.AxisGroup = AxisGroup.Secondary;
// Hide the secondary X axis.
newSeriesGroup.AxisX.Hidden = true;
// Define title of the secondary Y axis.
newSeriesGroup.AxisY.Title.Show = true;
newSeriesGroup.AxisY.Title.Text = "Secondary Y axis";

// Add a series to the new series group.
ChartSeries series3 =
newSeriesGroup.Series.Add("Series of secondary series group", categories, new double[] { 13, 11, 16 });
series3.Format.Stroke.Weight = 3.5;

doc.Save(ArtifactsDir + "Charts.SecondaryAxis.docx");
//ExEnd:SecondaryAxis
}

[Test]
public void ConfigureGapOverlap()
{
//ExStart:ConfigureGapOverlap
//GistId:6e4482e7434754c31c6f2f6e4bf48bb1
//ExFor:ChartSeriesGroup.GapWidth
//ExFor:ChartSeriesGroup.Overlap
//ExSummary:Show how to configure gap width and overlap.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

Shape shape = builder.InsertChart(ChartType.Column, 450, 250);
ChartSeriesGroup seriesGroup = shape.Chart.SeriesGroups[0];

// Set column gap width and overlap.
seriesGroup.GapWidth = 450;
seriesGroup.Overlap = -75;

doc.Save(ArtifactsDir + "Charts.ConfigureGapOverlap.docx");
//ExEnd:ConfigureGapOverlap
}

[Test]
public void BubbleScale()
{
//ExStart:BubbleScale
//GistId:6e4482e7434754c31c6f2f6e4bf48bb1
//ExFor:ChartSeriesGroup.BubbleScale
//ExSummary:Show how to set size of the bubbles.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Insert a bubble 3D chart.
Shape shape = builder.InsertChart(ChartType.Bubble3D, 450, 250);
ChartSeriesGroup seriesGroup = shape.Chart.SeriesGroups[0];

// Set bubble scale to 200%.
seriesGroup.BubbleScale = 200;

doc.Save(ArtifactsDir + "Charts.BubbleScale.docx");
//ExEnd:BubbleScale
}

[Test]
public void RemoveSecondaryAxis()
{
//ExStart:RemoveSecondaryAxis
//GistId:6e4482e7434754c31c6f2f6e4bf48bb1
//ExFor:ChartSeriesGroupCollection.Count
//ExFor:ChartSeriesGroupCollection.Item(Int32)
//ExFor:ChartSeriesGroupCollection.RemoveAt(Int32)
//ExSummary:Show how to remove secondary axis.
Document doc = new Document(MyDir + "Combo chart.docx");

Shape shape = (Shape)doc.GetChild(NodeType.Shape, 0, true);
Chart chart = shape.Chart;
ChartSeriesGroupCollection seriesGroups = chart.SeriesGroups;

// Find secondary axis and remove from the collection.
for (int i = 0; i < seriesGroups.Count; i++)
if (seriesGroups[i].AxisGroup == AxisGroup.Secondary)
seriesGroups.RemoveAt(i);
//ExEnd:RemoveSecondaryAxis
}
}
}
12 changes: 12 additions & 0 deletions Examples/ApiExamples/ApiExamples/ExDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3092,5 +3092,17 @@ public void SaveDocumentToStream(SaveFormat saveFormat)
doc.Save(stream, saveFormat);
}
}

[Test]
public void HasMacros()
{
//ExStart:HasMacros
//GistId:6e4482e7434754c31c6f2f6e4bf48bb1
//ExFor:FileFormatInfo.HasMacros
//ExSummary:Shows how to check VBA macro presence without loading document.
FileFormatInfo fileFormatInfo = FileFormatUtil.DetectFileFormat(MyDir + "Macro.docm");
Assert.IsTrue(fileFormatInfo.HasMacros);
//ExEnd:HasMacros
}
}
}
2 changes: 1 addition & 1 deletion Examples/ApiExamples/ApiExamples/ExFieldOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ public void UseInvariantCultureNumberFormat()

// Sometimes, fields may not format their numbers correctly under certain cultures.
Assert.IsFalse(doc.FieldOptions.UseInvariantCultureNumberFormat);
Assert.AreEqual("$1234567,89 . ", field.Result);
Assert.AreEqual("$1.234.567,89 , ", field.Result);

// To fix this, we could change the culture for the entire thread.
// Another way to fix this is to set this flag,
Expand Down
1 change: 0 additions & 1 deletion Examples/ApiExamples/ApiExamples/ExFont.cs
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,6 @@ public void Bidi()

Assert.AreEqual(1033, run.Font.LocaleId);
Assert.AreEqual(16, run.Font.Size);
Assert.AreEqual("Courier New", run.Font.Name);
Assert.False(run.Font.Italic);
Assert.False(run.Font.Bold);
Assert.AreEqual(1025, run.Font.LocaleIdBi);
Expand Down
2 changes: 1 addition & 1 deletion Examples/ApiExamples/ApiExamples/ExHtmlSaveOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,7 @@ public void HtmlVersions(HtmlVersion htmlVersion)
case HtmlVersion.Html5:
Assert.True(outDocContents.Contains("<a id=\"_Toc76372689\"></a>"));
Assert.True(outDocContents.Contains("<a id=\"_Toc76372689\"></a>"));
Assert.True(outDocContents.Contains("<table style=\"-aw-border-insideh:0.5pt single #000000; -aw-border-insidev:0.5pt single #000000; border-collapse:collapse\">"));
Assert.True(outDocContents.Contains("<table style=\"padding:0pt; -aw-border-insideh:0.5pt single #000000; -aw-border-insidev:0.5pt single #000000; border-collapse:collapse\">"));
break;
case HtmlVersion.Xhtml:
Assert.True(outDocContents.Contains("<a name=\"_Toc76372689\"></a>"));
Expand Down
23 changes: 23 additions & 0 deletions Examples/ApiExamples/ApiExamples/ExReportingEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,29 @@ public void InsertDocumentDynamicallyTrimLastParagraph()
Assert.AreEqual(1, template.FirstSection.Body.Paragraphs.Count);
}

[Test]
public void SourseListNumbering()
{
//ExStart:SourseListNumbering
//GistId:6e4482e7434754c31c6f2f6e4bf48bb1
//ExFor:ReportingEngine.BuildReport(Document, Object[], String[])
//ExSummary:Shows how to keep inserted numbering as is.
// By default, numbered lists from a template document are continued when their identifiers match those from a document being inserted.
// With "-sourceNumbering" numbering should be separated and kept as is.
Document template = DocumentHelper.CreateSimpleDocument("<<doc [src.Document]>>" + Environment.NewLine + "<<doc [src.Document] -sourceNumbering>>");

DocumentTestClass doc = new DocumentTestBuilder()
.WithDocument(new Document(MyDir + "List item.docx")).Build();

ReportingEngine engine = new ReportingEngine() { Options = ReportBuildOptions.RemoveEmptyParagraphs };
engine.BuildReport(template, new object[] { doc }, new[] { "src" });

template.Save(ArtifactsDir + "ReportingEngine.SourseListNumbering.docx");
//ExEnd:SourseListNumbering

Assert.IsTrue(DocumentHelper.CompareDocs(ArtifactsDir + "ReportingEngine.SourseListNumbering.docx", GoldsDir + "ReportingEngine.SourseListNumbering Gold.docx"));
}

[Test]
public void InsertDocumentDynamicallyByStream()
{
Expand Down
70 changes: 70 additions & 0 deletions Examples/ApiExamples/ApiExamples/ExShape.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
using HorizontalAlignment = Aspose.Words.Drawing.HorizontalAlignment;
using TextBox = Aspose.Words.Drawing.TextBox;
using Aspose.Words.Themes;
using Aspose.Words.Model.Drawing;

namespace ApiExamples
{
Expand Down Expand Up @@ -3180,5 +3181,74 @@ public void Reflection()
Assert.AreEqual(0, shape.Reflection.Distance);
//ExEnd:Reflection
}

[Test]
public void SoftEdge()
{
//ExStart:SoftEdge
//GistId:6e4482e7434754c31c6f2f6e4bf48bb1
//ExFor:ShapeBase.SoftEdge
//ExFor:SoftEdgeFormat.Radius
//ExFor:SoftEdgeFormat.Remove
//ExSummary:Shows how to work with soft edge formatting.
DocumentBuilder builder = new DocumentBuilder();
Shape shape = builder.InsertShape(ShapeType.Rectangle, 200, 200);

// Apply soft edge to the shape.
shape.SoftEdge.Radius = 30;

builder.Document.Save(ArtifactsDir + "Shape.SoftEdge.docx");

// Load document with rectangle shape with soft edge.
Document doc = new Document(ArtifactsDir + "Shape.SoftEdge.docx");
shape = (Shape)doc.GetChild(NodeType.Shape, 0, true);

// Check soft edge radius.
Assert.AreEqual(30, shape.SoftEdge.Radius);

// Remove soft edge from the shape.
shape.SoftEdge.Remove();

// Check radius of the removed soft edge.
Assert.AreEqual(0, shape.SoftEdge.Radius);
//ExEnd:SoftEdge
}

[Test]
public void Adjustments()
{
//ExStart:Adjustments
//GistId:6e4482e7434754c31c6f2f6e4bf48bb1
//ExFor:Shape.Adjustments
//ExFor:AdjustmentCollection
//ExFor:Adjustment
//ExFor:Adjustment.Name
//ExFor:Adjustment.Value
//ExSummary:Shows how to work with adjustment raw values.
Document doc = new Document(MyDir + "Rounded rectangle shape.docx");
Shape shape = (Shape)doc.GetChild(NodeType.Shape, 0, true);

AdjustmentCollection adjustments = shape.Adjustments;
Assert.AreEqual(1, adjustments.Count);

Adjustment adjustment = adjustments[0];
Assert.AreEqual("adj", adjustment.Name);
Assert.AreEqual(16667, adjustment.Value);

adjustment.Value = 30000;

doc.Save(ArtifactsDir + "Shape.Adjustments.docx");
//ExEnd:Adjustments

doc = new Document(ArtifactsDir + "Shape.Adjustments.docx");
shape = (Shape)doc.GetChild(NodeType.Shape, 0, true);

adjustments = shape.Adjustments;
Assert.AreEqual(1, adjustments.Count);

adjustment = adjustments[0];
Assert.AreEqual("adj", adjustment.Name);
Assert.AreEqual(30000, adjustment.Value);
}
}
}
18 changes: 18 additions & 0 deletions Examples/ApiExamples/ApiExamples/ExSvgSaveOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,5 +101,23 @@ public void SaveOfficeMath()
math.GetMathRenderer().Save(ArtifactsDir + "SvgSaveOptions.Output.svg", options);
//ExEnd:SaveOfficeMath
}

[Test]
public void MaxImageResolution()
{
//ExStart:MaxImageResolution
//GistId:6e4482e7434754c31c6f2f6e4bf48bb1
//ExFor:ShapeBase.SoftEdge
//ExFor:SoftEdgeFormat.Radius
//ExFor:SoftEdgeFormat.Remove
//ExSummary:Shows how to set limit for image resolution.
Document doc = new Document(MyDir + "Rendering.docx");

SvgSaveOptions saveOptions = new SvgSaveOptions();
saveOptions.MaxImageResolution = 72;

doc.Save(ArtifactsDir + "SvgSaveOptions.MaxImageResolution.svg", saveOptions);
//ExEnd:MaxImageResolution
}
}
}
Binary file added Examples/Data/Combo chart.docx
Binary file not shown.
Binary file not shown.
Binary file added Examples/Data/Rounded rectangle shape.docx
Binary file not shown.
4 changes: 2 additions & 2 deletions Examples/DocsExamples/DocsExamples/DocsExamples.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@
<ItemGroup>
<PackageReference Include="Aspose.BarCode" Version="24.3.0" />
<PackageReference Include="Aspose.Email" Version="24.3.0" />
<PackageReference Include="Aspose.Words" Version="24.4.0" />
<PackageReference Include="Aspose.Words.Shaping.HarfBuzz" Version="24.4.0" />
<PackageReference Include="Aspose.Words" Version="24.5.0" />
<PackageReference Include="Aspose.Words.Shaping.HarfBuzz" Version="24.5.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="NUnit" Version="3.14.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
Expand Down

0 comments on commit f54b2dd

Please sign in to comment.