Skip to content

Commit 3182fff

Browse files
Updated examples as per 24.11.0
1 parent 29d49ab commit 3182fff

File tree

6 files changed

+389
-1
lines changed

6 files changed

+389
-1
lines changed

FileFormat.Slides.Examples.Usage/FileFormat.Slides.Examples.Usage.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
<Optimize>True</Optimize>
1313
</PropertyGroup>
1414

15+
<ItemGroup>
16+
<PackageReference Include="FileFormat.Slides" Version="24.11.0" />
17+
</ItemGroup>
18+
1519

1620

1721
<ItemGroup>

FileFormat.Slides.Examples.Usage/Program.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,18 @@ static void Main (string[ ] args)
108108
//PentagonExamples pentagonExamples = new PentagonExamples();
109109
//pentagonExamples.DrawNewPentagonShapeInNewSlide(filename: "sample.pptx");
110110
//pentagonExamples.RemovePentagonShapeExistingSlide(filename: "sample.pptx");
111+
112+
//HexagonExamples hexagonExamples = new HexagonExamples();
113+
//hexagonExamples.DrawNewHexagonShapeInNewSlide(filename: "sample.pptx");
114+
//hexagonExamples.RemoveHexagonShapeExistingSlide(filename: "sample.pptx");
115+
116+
//TrapezoidExamples trapezoidExamples = new TrapezoidExamples();
117+
//trapezoidExamples.DrawNewTrapezoidShapeInNewSlide(filename: "sample.pptx");
118+
//trapezoidExamples.RemoveTrapezoidShapeExistingSlide(filename: "sample.pptx");
119+
120+
//PieExamples pieExamples = new PieExamples();
121+
//pieExamples.DrawNewPieShapeInNewSlide(filename: "sample.pptx");
122+
//pieExamples.RemovePieShapeExistingSlide(filename: "sample.pptx");
111123
}
112124
}
113125
}

FileFormat.Slides.Examples/FileFormat.Slides.Examples.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
</PropertyGroup>
1111

1212
<ItemGroup>
13-
<PackageReference Include="FileFormat.Slides" Version="24.4.0" />
13+
<PackageReference Include="FileFormat.Slides" Version="24.11.0" />
1414
</ItemGroup>
1515

1616
</Project>
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
using FileFormat.Slides;
2+
using FileFormat.Slides.Common;
3+
using System;
4+
using System.Collections.Generic;
5+
6+
7+
8+
namespace FileFormat.Slides.Examples
9+
{
10+
/// <summary>
11+
/// Provides C# code examples for creating, reading, and modifying Hexagon segments or shapes in a Presentation
12+
/// using the <a href="https://www.nuget.org/packages/FileFormat.Slides">FileFormat.Slides</a> library.
13+
/// </summary>
14+
public class HexagonExamples
15+
{
16+
private const string newDocsDirectory = "../../../Presentations/New";
17+
private const string existingDocsDirectory = "../../../Presentations/Existing";
18+
19+
/// <summary>
20+
/// Initializes a new instance of the <see cref="HexagonExamples"/> class.
21+
/// Prepares the directory 'Presentations/New' for storing or loading PowerPoint(PPT or PPTX) presentations
22+
/// at the root of the project.
23+
/// If the directory doesn't exist, it is created. If it already exists,
24+
/// existing files are deleted, and the directory is cleaned up.
25+
/// </summary>
26+
public HexagonExamples()
27+
{
28+
if (!System.IO.Directory.Exists(newDocsDirectory))
29+
{
30+
// If it doesn't exist, create the directory
31+
System.IO.Directory.CreateDirectory(newDocsDirectory);
32+
System.Console.WriteLine($"Directory '{System.IO.Path.GetFullPath(newDocsDirectory)}' " +
33+
$"created successfully.");
34+
}
35+
else
36+
{
37+
var files = System.IO.Directory.GetFiles(System.IO.Path.GetFullPath(newDocsDirectory));
38+
foreach (var file in files)
39+
{
40+
System.IO.File.Delete(file);
41+
System.Console.WriteLine($"File deleted: {file}");
42+
}
43+
System.Console.WriteLine($"Directory '{System.IO.Path.GetFullPath(newDocsDirectory)}' " +
44+
$"cleaned up.");
45+
}
46+
}
47+
/// <summary>
48+
/// This method adds Hexagon segment or shape in the silde of a new PowerPoint presentation.
49+
/// </summary>
50+
/// <param name="documentDirectory">Path of the presentation folder</param>
51+
/// <param name="filename">Presentation name</param>
52+
public void DrawNewHexagonShapeInNewSlide(string documentDirectory = newDocsDirectory, string filename = "test.pptx")
53+
{
54+
try
55+
{
56+
Presentation presentation = Presentation.Open($"{documentDirectory}/{filename}");
57+
// Create an instance of Hexagon
58+
Hexagon pentagon = new Hexagon();
59+
// Set height and width
60+
pentagon.Width = 400.0;
61+
pentagon.Height = 400.0;
62+
// Set Y position
63+
pentagon.Y = 100.0;
64+
// First slide
65+
Slide slide = presentation.GetSlides()[1];
66+
// Add Hexagon shapes.
67+
slide.DrawHexagon(pentagon);
68+
// Save the PPT or PPTX
69+
presentation.Save();
70+
71+
}
72+
catch (System.Exception ex)
73+
{
74+
throw new FileFormat.Slides.Common.FileFormatException("An error occurred.", ex);
75+
}
76+
}
77+
/// <summary>
78+
/// This method Sets the background color of a Hexagon shape
79+
/// </summary>
80+
/// <param name="documentDirectory">Path of the presentation folder</param>
81+
/// <param name="filename">Presentation name</param>
82+
public void SetBackgroundColorOfHexagon(string documentDirectory = newDocsDirectory, string filename = "test.pptx")
83+
{
84+
try
85+
{
86+
87+
Presentation presentation = Presentation.Open($"{documentDirectory}/{filename}");
88+
// Get the slides
89+
Slide slide = presentation.GetSlides()[1];
90+
// Get 1st pentagon
91+
Hexagon pentagon = slide.Hexagons[0];
92+
// Set background of the pentagon
93+
pentagon.BackgroundColor = "289876";
94+
95+
// Save the PPT or PPTX
96+
presentation.Save();
97+
98+
}
99+
catch (System.Exception ex)
100+
{
101+
throw new FileFormat.Slides.Common.FileFormatException("An error occurred.", ex);
102+
}
103+
}
104+
105+
/// <summary>
106+
/// Remove Hexagon shape from an existing slide
107+
/// </summary>
108+
/// <param name="documentDirectory">Path of the presentation folder</param>
109+
/// <param name="filename">Presentation name</param>
110+
public void RemoveHexagonShapeExistingSlide(string documentDirectory = existingDocsDirectory, string filename = "test.pptx")
111+
{
112+
Presentation presentation = Presentation.Open($"{documentDirectory}/{filename}");
113+
// Get the slides
114+
Slide slide = presentation.GetSlides()[1];
115+
// Get 1st pentagon
116+
Hexagon pentagon = slide.Hexagons[0];
117+
// Remove pentagon
118+
pentagon.Remove();
119+
// Save the PPT or PPTX
120+
presentation.Save();
121+
122+
}
123+
}
124+
}
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
using FileFormat.Slides;
2+
using FileFormat.Slides.Common;
3+
using System;
4+
using System.Collections.Generic;
5+
6+
7+
8+
namespace FileFormat.Slides.Examples
9+
{
10+
/// <summary>
11+
/// Provides C# code examples for creating, reading, and modifying Pie segments or shapes in a Presentation
12+
/// using the <a href="https://www.nuget.org/packages/FileFormat.Slides">FileFormat.Slides</a> library.
13+
/// </summary>
14+
public class PieExamples
15+
{
16+
private const string newDocsDirectory = "../../../Presentations/New";
17+
private const string existingDocsDirectory = "../../../Presentations/Existing";
18+
19+
/// <summary>
20+
/// Initializes a new instance of the <see cref="PieExamples"/> class.
21+
/// Prepares the directory 'Presentations/New' for storing or loading PowerPoint(PPT or PPTX) presentations
22+
/// at the root of the project.
23+
/// If the directory doesn't exist, it is created. If it already exists,
24+
/// existing files are deleted, and the directory is cleaned up.
25+
/// </summary>
26+
public PieExamples()
27+
{
28+
if (!System.IO.Directory.Exists(newDocsDirectory))
29+
{
30+
// If it doesn't exist, create the directory
31+
System.IO.Directory.CreateDirectory(newDocsDirectory);
32+
System.Console.WriteLine($"Directory '{System.IO.Path.GetFullPath(newDocsDirectory)}' " +
33+
$"created successfully.");
34+
}
35+
else
36+
{
37+
var files = System.IO.Directory.GetFiles(System.IO.Path.GetFullPath(newDocsDirectory));
38+
foreach (var file in files)
39+
{
40+
System.IO.File.Delete(file);
41+
System.Console.WriteLine($"File deleted: {file}");
42+
}
43+
System.Console.WriteLine($"Directory '{System.IO.Path.GetFullPath(newDocsDirectory)}' " +
44+
$"cleaned up.");
45+
}
46+
}
47+
/// <summary>
48+
/// This method adds Pie segment or shape in the silde of a new PowerPoint presentation.
49+
/// </summary>
50+
/// <param name="documentDirectory">Path of the presentation folder</param>
51+
/// <param name="filename">Presentation name</param>
52+
public void DrawNewPieShapeInNewSlide(string documentDirectory = newDocsDirectory, string filename = "test.pptx")
53+
{
54+
try
55+
{
56+
Presentation presentation = Presentation.Open($"{documentDirectory}/{filename}");
57+
// Create an instance of Pie
58+
Pie pentagon = new Pie();
59+
// Set height and width
60+
pentagon.Width = 400.0;
61+
pentagon.Height = 400.0;
62+
// Set Y position
63+
pentagon.Y = 100.0;
64+
// First slide
65+
Slide slide = presentation.GetSlides()[1];
66+
// Add Pie shapes.
67+
slide.DrawPie(pentagon);
68+
// Save the PPT or PPTX
69+
presentation.Save();
70+
71+
}
72+
catch (System.Exception ex)
73+
{
74+
throw new FileFormat.Slides.Common.FileFormatException("An error occurred.", ex);
75+
}
76+
}
77+
/// <summary>
78+
/// This method Sets the background color of a Pie shape
79+
/// </summary>
80+
/// <param name="documentDirectory">Path of the presentation folder</param>
81+
/// <param name="filename">Presentation name</param>
82+
public void SetBackgroundColorOfPie(string documentDirectory = newDocsDirectory, string filename = "test.pptx")
83+
{
84+
try
85+
{
86+
87+
Presentation presentation = Presentation.Open($"{documentDirectory}/{filename}");
88+
// Get the slides
89+
Slide slide = presentation.GetSlides()[1];
90+
// Get 1st pentagon
91+
Pie pentagon = slide.Pies[0];
92+
// Set background of the pentagon
93+
pentagon.BackgroundColor = "289876";
94+
95+
// Save the PPT or PPTX
96+
presentation.Save();
97+
98+
}
99+
catch (System.Exception ex)
100+
{
101+
throw new FileFormat.Slides.Common.FileFormatException("An error occurred.", ex);
102+
}
103+
}
104+
105+
/// <summary>
106+
/// Remove Pie shape from an existing slide
107+
/// </summary>
108+
/// <param name="documentDirectory">Path of the presentation folder</param>
109+
/// <param name="filename">Presentation name</param>
110+
public void RemovePieShapeExistingSlide(string documentDirectory = existingDocsDirectory, string filename = "test.pptx")
111+
{
112+
Presentation presentation = Presentation.Open($"{documentDirectory}/{filename}");
113+
// Get the slides
114+
Slide slide = presentation.GetSlides()[1];
115+
// Get 1st pentagon
116+
Pie pentagon = slide.Pies[0];
117+
// Remove pentagon
118+
pentagon.Remove();
119+
// Save the PPT or PPTX
120+
presentation.Save();
121+
122+
}
123+
}
124+
}

0 commit comments

Comments
 (0)