Skip to content

Commit

Permalink
Updated API examples
Browse files Browse the repository at this point in the history
  • Loading branch information
vderyushev committed Oct 4, 2024
1 parent 1fda0ef commit 20a23f8
Show file tree
Hide file tree
Showing 4 changed files with 156 additions and 1 deletion.
55 changes: 55 additions & 0 deletions Examples/ApiExamples/ApiExamples/ExCharts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2243,5 +2243,60 @@ public void TickLabelsOrientationRotation()
doc.Save(ArtifactsDir + "Charts.TickLabelsOrientationRotation.docx");
//ExEnd:TickLabelsOrientationRotation
}

[Test]
public void DoughnutChart()
{
//ExStart:DoughnutChart
//GistId:bb594993b5fe48692541e16f4d354ac2
//ExFor:ChartSeriesGroup.DoughnutHoleSize
//ExFor:ChartSeriesGroup.FirstSliceAngle
//ExSummary:Shows how to create and format Doughnut chart.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

Shape shape = builder.InsertChart(ChartType.Doughnut, 400, 400);
Chart chart = shape.Chart;
// Delete the default generated series.
chart.Series.Clear();

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

// Format the Doughnut chart.
ChartSeriesGroup seriesGroup = chart.SeriesGroups[0];
seriesGroup.DoughnutHoleSize = 10;
seriesGroup.FirstSliceAngle = 270;

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

[Test]
public void PieOfPieChart()
{
//ExStart:PieOfPieChart
//GistId:bb594993b5fe48692541e16f4d354ac2
//ExFor:ChartSeriesGroup.SecondSectionSize
//ExSummary:Shows how to create and format pie of Pie chart.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

Shape shape = builder.InsertChart(ChartType.PieOfPie, 440, 300);
Chart chart = shape.Chart;
// Delete the default generated series.
chart.Series.Clear();

string[] categories = new string[] { "Category 1", "Category 2", "Category 3", "Category 4" };
chart.Series.Add("Series 1", categories, new double[] { 11, 8, 4, 3 });

// Format the Pie of Pie chart.
ChartSeriesGroup seriesGroup = chart.SeriesGroups[0];
seriesGroup.GapWidth = 10;
seriesGroup.SecondSectionSize = 77;

doc.Save(ArtifactsDir + "Charts.PieOfPieChart.docx");
//ExEnd:PieOfPieChart
}
}
}
36 changes: 36 additions & 0 deletions Examples/ApiExamples/ApiExamples/ExMarkdownSaveOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,42 @@ public void LinkExportMode()
string outDocContents = File.ReadAllText(ArtifactsDir + "MarkdownSaveOptions.LinkExportMode.Inline.md");
Assert.AreEqual("![](MarkdownSaveOptions.LinkExportMode.Inline.001.png)", outDocContents.Trim());
}

[Test]
public void ExportTableAsHtml()
{
//ExStart:ExportTableAsHtml
//GistId:bb594993b5fe48692541e16f4d354ac2
//ExFor:MarkdownExportAsHtml
//ExFor:MarkdownSaveOptions.ExportAsHtml
//ExSummary:Shows how to export a table to Markdown as raw HTML.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

builder.Writeln("Sample table:");

// Create table.
builder.InsertCell();
builder.ParagraphFormat.Alignment = ParagraphAlignment.Right;
builder.Write("Cell1");
builder.InsertCell();
builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;
builder.Write("Cell2");

MarkdownSaveOptions saveOptions = new MarkdownSaveOptions();
saveOptions.ExportAsHtml = MarkdownExportAsHtml.Tables;

doc.Save(ArtifactsDir + "MarkdownSaveOptions.ExportTableAsHtml.md", saveOptions);
//ExEnd:ExportTableAsHtml

string outDocContents = File.ReadAllText(ArtifactsDir + "MarkdownSaveOptions.ExportTableAsHtml.md");
Assert.AreEqual("Sample table:\r\n<table cellspacing=\"0\" cellpadding=\"0\" style=\"width:100%; border:0.75pt solid #000000; border-collapse:collapse\">" +
"<tr><td style=\"border-right-style:solid; border-right-width:0.75pt; padding-right:5.03pt; padding-left:5.03pt; vertical-align:top\">" +
"<p style=\"margin-top:0pt; margin-bottom:0pt; text-align:right; font-size:12pt\"><span style=\"font-family:'Times New Roman'\">Cell1</span></p>" +
"</td><td style=\"border-left-style:solid; border-left-width:0.75pt; padding-right:5.03pt; padding-left:5.03pt; vertical-align:top\">" +
"<p style=\"margin-top:0pt; margin-bottom:0pt; text-align:center; font-size:12pt\"><span style=\"font-family:'Times New Roman'\">Cell2</span></p>" +
"</td></tr></table>", outDocContents.Trim());
}
}
}

2 changes: 1 addition & 1 deletion Examples/ApiExamples/ApiExamples/ExPdfSaveOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ public void UsePdfDocumentForCompliance(PdfCompliance pdfCompliance)
Assert.AreEqual("2.0", pdfDocument.Version);
break;
case PdfCompliance.PdfA4:
Assert.AreEqual(PdfFormat.v_2_0, pdfDocument.PdfFormat);
Assert.AreEqual(PdfFormat.PDF_A_4, pdfDocument.PdfFormat);
Assert.AreEqual("2.0", pdfDocument.Version);
break;
case PdfCompliance.PdfA4Ua2:
Expand Down
64 changes: 64 additions & 0 deletions Examples/ApiExamples/ApiExamples/ExShape.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3400,5 +3400,69 @@ public void InsertGroupShape()
doc.Save(ArtifactsDir + "Shape.InsertGroupShape.docx");
//ExEnd:InsertGroupShape
}

[Test]
public void CombineGroupShape()
{
//ExStart:CombineGroupShape
//GistId:bb594993b5fe48692541e16f4d354ac2
//ExFor:DocumentBuilder.InsertGroupShape(Shape[])
//ExSummary:Shows how to combine group shape with the shape.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

Shape shape1 = builder.InsertShape(ShapeType.Rectangle, 200, 250);
shape1.Left = 20;
shape1.Top = 20;
shape1.Stroke.Color = Color.Red;

Shape shape2 = builder.InsertShape(ShapeType.Ellipse, 150, 200);
shape2.Left = 40;
shape2.Top = 50;
shape2.Stroke.Color = Color.Green;

// Combine shapes into a GroupShape node which is inserted into the specified position.
GroupShape groupShape1 = builder.InsertGroupShape(shape1, shape2);

// Combine Shape and GroupShape nodes.
Shape shape3 = (Shape)shape1.Clone(true);
GroupShape groupShape2 = builder.InsertGroupShape(groupShape1, shape3);

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

[Test]
public void InsertCommandButton()
{
//ExStart:InsertCommandButton
//GistId:bb594993b5fe48692541e16f4d354ac2
//ExFor:CommandButtonControl
//ExFor:DocumentBuilder.InsertForms2OleControl(Forms2OleControl)
//ExSummary:Shows how to insert ActiveX control.
DocumentBuilder builder = new DocumentBuilder();

CommandButtonControl button1 = new CommandButtonControl();
Shape shape = builder.InsertForms2OleControl(button1);
Assert.AreEqual(Forms2OleControlType.CommandButton, ((Forms2OleControl)shape.OleFormat.OleControl).Type);
//ExEnd:InsertCommandButton
}

[Test]
public void Hidden()
{
//ExStart:Hidden
//GistId:bb594993b5fe48692541e16f4d354ac2
//ExFor:ShapeBase.Hidden
//ExSummary:Shows how to hide the shape.
Document doc = new Document(MyDir + "Shadow color.docx");

Shape shape = (Shape)doc.GetChild(NodeType.Shape, 0, true);
if (!shape.Hidden)
shape.Hidden = true;

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

0 comments on commit 20a23f8

Please sign in to comment.