Skip to content

Commit 29d49ab

Browse files
Uploaded for 24.10.0
1 parent 64e6883 commit 29d49ab

File tree

4 files changed

+385
-0
lines changed

4 files changed

+385
-0
lines changed

FileFormat.Slides.Examples.Usage/Program.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,17 @@ static void Main (string[ ] args)
9797
//doubleArrowExamples.DrawNewDoubleArrowShapeInNewSlide(filename: "sample.pptx");
9898
//doubleArrowExamples.RemoveDoubleArrowShapeExistingSlide(filename: "sample.pptx");
9999

100+
//DoubleBracketExamples doubleBracketExamples = new DoubleBracketExamples();
101+
//doubleBracketExamples.DrawNewDoubleBracketShapeInNewSlide(filename: "sample.pptx");
102+
//doubleBracketExamples.RemoveDoubleBracketExistingSlide(filename: "sample.pptx");
103+
104+
//DoubleBraceExamples doubleBraceExamples = new DoubleBraceExamples();
105+
//doubleBraceExamples.DrawNewDoubleBraceShapeInNewSlide(filename: "sample.pptx");
106+
//doubleBraceExamples.RemoveDoubleBraceExistingSlide(filename: "sample.pptx");
107+
108+
//PentagonExamples pentagonExamples = new PentagonExamples();
109+
//pentagonExamples.DrawNewPentagonShapeInNewSlide(filename: "sample.pptx");
110+
//pentagonExamples.RemovePentagonShapeExistingSlide(filename: "sample.pptx");
100111
}
101112
}
102113
}
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
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 DoubleBrace 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 DoubleBraceExamples
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="DoubleBraceExamples"/> 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 DoubleBraceExamples()
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 DoubleBrace 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 DrawNewDoubleBraceShapeInNewSlide(string documentDirectory = newDocsDirectory, string filename = "test.pptx")
53+
{
54+
try
55+
{
56+
Presentation presentation = Presentation.Open($"{documentDirectory}/{filename}");
57+
// Create an instance of DoubleBrace
58+
59+
DoubleBrace DoubleBrace = new DoubleBrace();
60+
// Set height and width
61+
DoubleBrace.Width = 400.0;
62+
DoubleBrace.Height = 400.0;
63+
// Set Y position
64+
DoubleBrace.Y = 100.0;
65+
// First slide
66+
Slide slide = presentation.GetSlides()[1];
67+
// Add DoubleBrace shapes.
68+
slide.DrawDoubleBrace(DoubleBrace);
69+
// Save the PPT or PPTX
70+
presentation.Save();
71+
72+
}
73+
catch (System.Exception ex)
74+
{
75+
throw new FileFormat.Slides.Common.FileFormatException("An error occurred.", ex);
76+
}
77+
}
78+
/// <summary>
79+
/// This method Sets the background color of a DoubleBrace shape
80+
/// </summary>
81+
/// <param name="documentDirectory">Path of the presentation folder</param>
82+
/// <param name="filename">Presentation name</param>
83+
public void SetBackgroundColorOfDoubleBrace(string documentDirectory = newDocsDirectory, string filename = "test.pptx")
84+
{
85+
try
86+
{
87+
88+
Presentation presentation = Presentation.Open($"{documentDirectory}/{filename}");
89+
// Get the slides
90+
Slide slide = presentation.GetSlides()[1];
91+
// Get 1st DoubleBrace
92+
DoubleBrace DoubleBrace = slide.DoubleBraces[0];
93+
// Set background of the DoubleBrace
94+
DoubleBrace.BackgroundColor = "289876";
95+
96+
// Save the PPT or PPTX
97+
presentation.Save();
98+
99+
}
100+
catch (System.Exception ex)
101+
{
102+
throw new FileFormat.Slides.Common.FileFormatException("An error occurred.", ex);
103+
}
104+
}
105+
106+
/// <summary>
107+
/// Remove DoubleBrace shape from an existing slide
108+
/// </summary>
109+
/// <param name="documentDirectory">Path of the presentation folder</param>
110+
/// <param name="filename">Presentation name</param>
111+
public void RemoveDoubleBraceShapeExistingSlide(string documentDirectory = existingDocsDirectory, string filename = "test.pptx")
112+
{
113+
Presentation presentation = Presentation.Open($"{documentDirectory}/{filename}");
114+
// Get the slides
115+
Slide slide = presentation.GetSlides()[1];
116+
// Get 1st DoubleBrace
117+
DoubleBrace DoubleBrace = slide.DoubleBraces[0];
118+
// Remove DoubleBrace
119+
DoubleBrace.Remove();
120+
// Save the PPT or PPTX
121+
presentation.Save();
122+
123+
}
124+
}
125+
}
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
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 DoubleBracket 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 DoubleBracketExamples
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="DoubleBracketExamples"/> 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 DoubleBracketExamples()
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 DoubleBracket 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 DrawNewDoubleBracketShapeInNewSlide(string documentDirectory = newDocsDirectory, string filename = "test.pptx")
53+
{
54+
try
55+
{
56+
Presentation presentation = Presentation.Open($"{documentDirectory}/{filename}");
57+
// Create an instance of DoubleBracket
58+
59+
DoubleBracket DoubleBracket = new DoubleBracket();
60+
// Set height and width
61+
DoubleBracket.Width = 400.0;
62+
DoubleBracket.Height = 400.0;
63+
// Set Y position
64+
DoubleBracket.Y = 100.0;
65+
// First slide
66+
Slide slide = presentation.GetSlides()[1];
67+
// Add DoubleBracket shapes.
68+
slide.DrawDoubleBracket(DoubleBracket);
69+
// Save the PPT or PPTX
70+
presentation.Save();
71+
72+
}
73+
catch (System.Exception ex)
74+
{
75+
throw new FileFormat.Slides.Common.FileFormatException("An error occurred.", ex);
76+
}
77+
}
78+
/// <summary>
79+
/// This method Sets the background color of a DoubleBracket shape
80+
/// </summary>
81+
/// <param name="documentDirectory">Path of the presentation folder</param>
82+
/// <param name="filename">Presentation name</param>
83+
public void SetBackgroundColorOfDoubleBracket(string documentDirectory = newDocsDirectory, string filename = "test.pptx")
84+
{
85+
try
86+
{
87+
88+
Presentation presentation = Presentation.Open($"{documentDirectory}/{filename}");
89+
// Get the slides
90+
Slide slide = presentation.GetSlides()[1];
91+
// Get 1st DoubleBracket
92+
DoubleBracket DoubleBracket = slide.DoubleBrackets[0];
93+
// Set background of the DoubleBracket
94+
DoubleBracket.BackgroundColor = "289876";
95+
96+
// Save the PPT or PPTX
97+
presentation.Save();
98+
99+
}
100+
catch (System.Exception ex)
101+
{
102+
throw new FileFormat.Slides.Common.FileFormatException("An error occurred.", ex);
103+
}
104+
}
105+
106+
/// <summary>
107+
/// Remove DoubleBracket shape from an existing slide
108+
/// </summary>
109+
/// <param name="documentDirectory">Path of the presentation folder</param>
110+
/// <param name="filename">Presentation name</param>
111+
public void RemoveDoubleBracketShapeExistingSlide(string documentDirectory = existingDocsDirectory, string filename = "test.pptx")
112+
{
113+
Presentation presentation = Presentation.Open($"{documentDirectory}/{filename}");
114+
// Get the slides
115+
Slide slide = presentation.GetSlides()[1];
116+
// Get 1st DoubleBracket
117+
DoubleBracket DoubleBracket = slide.DoubleBrackets[0];
118+
// Remove DoubleBracket
119+
DoubleBracket.Remove();
120+
// Save the PPT or PPTX
121+
presentation.Save();
122+
123+
}
124+
}
125+
}
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 Pentagon 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 PentagonExamples
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="PentagonExamples"/> 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 PentagonExamples()
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 Pentagon 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 DrawNewPentagonShapeInNewSlide(string documentDirectory = newDocsDirectory, string filename = "test.pptx")
53+
{
54+
try
55+
{
56+
Presentation presentation = Presentation.Open($"{documentDirectory}/{filename}");
57+
// Create an instance of Pentagon
58+
Pentagon pentagon = new Pentagon();
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 Pentagon shapes.
67+
slide.DrawPentagon(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 Pentagon shape
79+
/// </summary>
80+
/// <param name="documentDirectory">Path of the presentation folder</param>
81+
/// <param name="filename">Presentation name</param>
82+
public void SetBackgroundColorOfPentagon(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+
Pentagon pentagon = slide.Pentagons[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 Pentagon 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 RemovePentagonShapeExistingSlide(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+
Pentagon pentagon = slide.Pentagons[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)