Skip to content

Commit b463333

Browse files
Release v24.7.0
1 parent 88c82c8 commit b463333

File tree

3 files changed

+258
-0
lines changed

3 files changed

+258
-0
lines changed

FileFormat.Slides.Examples.Usage/Program.cs

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

0 commit comments

Comments
 (0)