Skip to content

Commit 218d6fb

Browse files
Release 24.8.0
1 parent b463333 commit 218d6fb

File tree

3 files changed

+266
-8
lines changed

3 files changed

+266
-8
lines changed

FileFormat.Slides.Examples.Usage/Program.cs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class Program
88
static void Main (string[ ] args)
99
{
1010
//SlideExamples slideExamples = new SlideExamples();
11-
11+
1212
//slideExamples.CreateNewSlideInNewPresentation();
1313

1414
//slideExamples.CreateNewSlideInExistingPresentation(filename:"test.pptx");
@@ -18,23 +18,23 @@ static void Main (string[ ] args)
1818
//slideExamples.AddBackgroundColorToAnExistingSlide(filename: "sample.pptx");
1919

2020
//TextExamples textExamples = new TextExamples();
21-
21+
2222
//textExamples.CreateNewTextShapeInNewSlide();
23-
23+
2424
//textExamples.AddNewTextShapeExistingSlide(filename: "sample.pptx");
2525

2626
//ImageExamples imageExamples = new ImageExamples();
27-
27+
2828
//imageExamples.AddImageInASlide(imagename:"sample.jpg");
29-
29+
3030
//imageExamples.UpdateImageInExistingSlide(filename: "sample.pptx", xAxis: 300.0, yAxis: 200.0);
3131

3232
//StyledListExamples styledListExamples = new StyledListExamples();
33-
33+
3434
//styledListExamples.CreateBulletedListInASlide();
35-
35+
3636
//styledListExamples.AddListItemsInAnExistingList(filename: "test.pptx");
37-
37+
3838
//styledListExamples.RemoveListItemsInAnExistingList(filename: "test.pptx");
3939

4040
//TableExamples tableExamples= new TableExamples();
@@ -71,6 +71,16 @@ static void Main (string[ ] args)
7171
//circleExamples.SetBackgroundColorOfCircle(filename: "sample.pptx");
7272
//circleExamples.RemoveCircleShapeExistingSlide(filename: "sample.pptx");
7373

74+
//TriangleExamples triangleExamples = new TriangleExamples();
75+
//triangleExamples.DrawNewTriangleShapeInNewSlide(filename: "sample.pptx");
76+
//triangleExamples.RemoveTriangleShapeExistingSlide(filename: "sample.pptx");
77+
//triangleExamples.SetBackgroundColorOfTriangle(filename: "sample.pptx");
78+
79+
//TriangleExamples diamondExamples = new DiamondExamples();
80+
//diamondExamples.DrawNewDiamondShapeInNewSlide(filename: "sample.pptx");
81+
//diamondExamples.RemoveDiamondShapeExistingSlide(filename: "sample.pptx");
82+
//diamondExamples.SetBackgroundColorOfDiamond(filename: "sample.pptx");
83+
7484

7585
}
7686
}
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 Diamond 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 DiamondExamples
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="DiamondExamples"/> 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 DiamondExamples()
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 Diamond 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 DrawNewDiamondShapeInNewSlide(string documentDirectory = newDocsDirectory, string filename = "test.pptx")
53+
{
54+
try
55+
{
56+
Presentation presentation = Presentation.Open($"{documentDirectory}/{filename}");
57+
// Create an instance of Diamond
58+
Diamond Diamond = new Diamond();
59+
// Set height and width
60+
Diamond.Width = 400.0;
61+
Diamond.Height = 400.0;
62+
// Set Y position
63+
Diamond.Y = 100.0;
64+
// First slide
65+
Slide slide = presentation.GetSlides()[1];
66+
// Add Diamond shapes.
67+
slide.DrawDiamond(Diamond);
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 Diamond shape
79+
/// </summary>
80+
/// <param name="documentDirectory">Path of the presentation folder</param>
81+
/// <param name="filename">Presentation name</param>
82+
public void SetBackgroundColorOfDiamond(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 Diamond
91+
Diamond Diamond = slide.Diamonds[0];
92+
// Set background of the Diamond
93+
Diamond.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 Diamond 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 RemoveDiamondShapeExistingSlide(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 Diamond
116+
Diamond Diamond = slide.Diamonds[0];
117+
// Remove Diamond
118+
Diamond.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 Triangle 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 TriangleExamples
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="TriangleExamples"/> 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 TriangleExamples()
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 Triangle 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 DrawNewTriangleShapeInNewSlide(string documentDirectory = newDocsDirectory, string filename = "test.pptx")
53+
{
54+
try
55+
{
56+
Presentation presentation = Presentation.Open($"{documentDirectory}/{filename}");
57+
// Create an instance of Triangle
58+
Triangle Triangle = new Triangle();
59+
// Set height and width
60+
Triangle.Width = 400.0;
61+
Triangle.Height = 400.0;
62+
// Set Y position
63+
Triangle.Y = 100.0;
64+
// First slide
65+
Slide slide = presentation.GetSlides()[1];
66+
// Add Triangle shapes.
67+
slide.DrawTriangle(Triangle);
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 Triangle shape
79+
/// </summary>
80+
/// <param name="documentDirectory">Path of the presentation folder</param>
81+
/// <param name="filename">Presentation name</param>
82+
public void SetBackgroundColorOfTriangle(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 Triangle
91+
Triangle Triangle = slide.Triangles[0];
92+
// Set background of the Triangle
93+
Triangle.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 Triangle 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 RemoveTriangleShapeExistingSlide(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 Triangle
116+
Triangle Triangle = slide.Triangles[0];
117+
// Remove Triangle
118+
Triangle.Remove();
119+
// Save the PPT or PPTX
120+
presentation.Save();
121+
122+
}
123+
}
124+
}

0 commit comments

Comments
 (0)