Skip to content

Commit 64e6883

Browse files
Update for 24.9.0
1 parent 218d6fb commit 64e6883

File tree

5 files changed

+515
-1
lines changed

5 files changed

+515
-1
lines changed

FileFormat.Slides.Examples.Usage/Program.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,26 @@ static void Main (string[ ] args)
7676
//triangleExamples.RemoveTriangleShapeExistingSlide(filename: "sample.pptx");
7777
//triangleExamples.SetBackgroundColorOfTriangle(filename: "sample.pptx");
7878

79-
//TriangleExamples diamondExamples = new DiamondExamples();
79+
//DiamondExamples diamondExamples = new DiamondExamples();
8080
//diamondExamples.DrawNewDiamondShapeInNewSlide(filename: "sample.pptx");
8181
//diamondExamples.RemoveDiamondShapeExistingSlide(filename: "sample.pptx");
8282
//diamondExamples.SetBackgroundColorOfDiamond(filename: "sample.pptx");
8383

84+
//LineExamples lineExamples = new LineExamples();
85+
//lineExamples.DrawNewLineShapeInNewSlide(filename: "sample.pptx");
86+
//lineExamples.RemoveLineShapeExistingSlide(filename: "sample.pptx");
87+
88+
//CurvedLineExamples curvedlineExamples = new CurvedLineExamples();
89+
//curvedlineExamples.DrawNewCurvedLineShapeInNewSlide(filename: "sample.pptx");
90+
//curvedlineExamples.RemoveCurvedLineShapeExistingSlide(filename: "sample.pptx");
91+
92+
//ArrowExamples curvedlineExamples = new ArrowExamples();
93+
//arrowExamples.DrawNewArrowShapeInNewSlide(filename: "sample.pptx");
94+
//arrowExamples.RemoveArrowShapeExistingSlide(filename: "sample.pptx");
95+
96+
//DoubleArrowExamples doubleArrowExamples = new DoubleArrowExamples();
97+
//doubleArrowExamples.DrawNewDoubleArrowShapeInNewSlide(filename: "sample.pptx");
98+
//doubleArrowExamples.RemoveDoubleArrowShapeExistingSlide(filename: "sample.pptx");
8499

85100
}
86101
}
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 Arrow 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 ArrowExamples
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="ArrowExamples"/> 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 ArrowExamples()
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 Arrow 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 DrawNewArrowShapeInNewSlide(string documentDirectory = newDocsDirectory, string filename = "test.pptx")
53+
{
54+
try
55+
{
56+
Presentation presentation = Presentation.Open($"{documentDirectory}/{filename}");
57+
// Create an instance of Arrow
58+
59+
Arrow Arrow = new Arrow();
60+
// Set height and width
61+
Arrow.Width = 400.0;
62+
Arrow.Height = 400.0;
63+
// Set Y position
64+
Arrow.Y = 100.0;
65+
// First slide
66+
Slide slide = presentation.GetSlides()[1];
67+
// Add Arrow shapes.
68+
slide.DrawArrow(Arrow);
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 Arrow shape
80+
/// </summary>
81+
/// <param name="documentDirectory">Path of the presentation folder</param>
82+
/// <param name="filename">Presentation name</param>
83+
public void SetBackgroundColorOfArrow(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 Arrow
92+
Arrow Arrow = slide.Arrows[0];
93+
// Set background of the Arrow
94+
Arrow.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 Arrow 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 RemoveArrowShapeExistingSlide(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 Arrow
117+
Arrow Arrow = slide.Arrows[0];
118+
// Remove Arrow
119+
Arrow.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 CurvedLine 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 CurvedLineExamples
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="CurvedLineExamples"/> 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 CurvedLineExamples()
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 CurvedLine 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 DrawNewCurvedLineShapeInNewSlide(string documentDirectory = newDocsDirectory, string filename = "test.pptx")
53+
{
54+
try
55+
{
56+
Presentation presentation = Presentation.Open($"{documentDirectory}/{filename}");
57+
// Create an instance of CurvedLine
58+
CurvedLine CurvedLine = new CurvedLine();
59+
// Set height and width
60+
CurvedLine.Width = 400.0;
61+
CurvedLine.Height = 400.0;
62+
// Set Y position
63+
CurvedLine.Y = 100.0;
64+
// First slide
65+
Slide slide = presentation.GetSlides()[1];
66+
// Add CurvedLine shapes.
67+
slide.DrawCurvedLine(CurvedLine);
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 CurvedLine shape
79+
/// </summary>
80+
/// <param name="documentDirectory">Path of the presentation folder</param>
81+
/// <param name="filename">Presentation name</param>
82+
public void SetBackgroundColorOfCurvedLine(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 CurvedLine
91+
CurvedLine CurvedLine = slide.CurvedLines[0];
92+
// Set background of the CurvedLine
93+
CurvedLine.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 CurvedLine 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 RemoveCurvedLineShapeExistingSlide(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 CurvedLine
116+
CurvedLine CurvedLine = slide.CurvedLines[0];
117+
// Remove CurvedLine
118+
CurvedLine.Remove();
119+
// Save the PPT or PPTX
120+
presentation.Save();
121+
122+
}
123+
}
124+
}

0 commit comments

Comments
 (0)