Skip to content

Commit e033c07

Browse files
Updated v24.4.0
1 parent ac5d113 commit e033c07

File tree

5 files changed

+256
-2
lines changed

5 files changed

+256
-2
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
55
<TargetFramework>netcoreapp3.1</TargetFramework>
6+
<StartupObject>FileFormat.Slides.Examples.Usage.Program</StartupObject>
7+
<GenerateDocumentationFile>True</GenerateDocumentationFile>
68
</PropertyGroup>
79

810
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
911
<DocumentationFile>D:\Local_Repos\FileFormat.Examples\FileFormat.Slides-for-.NET\FileFormat.Slides.Examples\FileFormat.Slides.Examples.Usage\FileFormat.Slides.Examples.Usage.xml</DocumentationFile>
12+
<Optimize>True</Optimize>
1013
</PropertyGroup>
1114

15+
16+
1217
<ItemGroup>
1318
<ProjectReference Include="..\FileFormat.Slides.Examples\FileFormat.Slides.Examples.csproj" />
1419
</ItemGroup>

FileFormat.Slides.Examples.Usage/Program.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,15 @@ static void Main (string[ ] args)
4646
//tableExamples.CreateTableWithThemeInASlide(filename: "sample.pptx");
4747
//tableExamples.AddRowInAnExistingTableInASlide(filename: "sample.pptx");
4848
//tableExamples.AddColumnWithCellValuesInAnExistingTableInASlide(filename: "sample.pptx");
49+
50+
//CommentExamples commentExamples = new CommentExamples();
51+
//commentExamples.CreateCommentInASlide(filename: "sample.pptx");
52+
//commentExamples.RemoveACommentFromASlide(filename: "sample.pptx");
53+
//commentExamples.AddCommentWithExistingCommentAuthor(filename: "sample.pptx");
54+
55+
//CommentAuthorExamples authorExamples = new CommentAuthorExamples();
56+
//authorExamples.AddCommentAuthor(filename: "sample.pptx");
57+
//authorExamples.RemoveCommentAuthor(filename: "sample.pptx");
4958
}
5059
}
5160
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
using DocumentFormat.OpenXml.Presentation;
2+
using FileFormat.Slides.Common;
3+
using FileFormat.Slides.Common.Enumerations;
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Text;
7+
8+
namespace FileFormat.Slides.Examples
9+
{
10+
public class CommentAuthorExamples
11+
{
12+
private const string newDocsDirectory = "../../../Presentations/New";
13+
private const string existingDocsDirectory = "../../../Presentations/Existing";
14+
/// <summary>
15+
/// Initializes a new instance of the <see cref="CommentExamples"/> class.
16+
/// Prepares the directory 'Presentations/New' for storing or loading PowerPoint(PPT or PPTX) presentations
17+
/// at the root of the project.
18+
/// If the directory doesn't exist, it is created. If it already exists,
19+
/// existing files are deleted, and the directory is cleaned up.
20+
/// </summary>
21+
public CommentAuthorExamples()
22+
{
23+
if (!System.IO.Directory.Exists(newDocsDirectory))
24+
{
25+
// If it doesn't exist, create the directory
26+
System.IO.Directory.CreateDirectory(newDocsDirectory);
27+
System.Console.WriteLine($"Directory '{System.IO.Path.GetFullPath(newDocsDirectory)}' " +
28+
$"created successfully.");
29+
}
30+
else
31+
{
32+
var files = System.IO.Directory.GetFiles(System.IO.Path.GetFullPath(newDocsDirectory));
33+
foreach (var file in files)
34+
{
35+
System.IO.File.Delete(file);
36+
System.Console.WriteLine($"File deleted: {file}");
37+
}
38+
System.Console.WriteLine($"Directory '{System.IO.Path.GetFullPath(newDocsDirectory)}' " +
39+
$"cleaned up.");
40+
}
41+
}
42+
/// <summary>
43+
/// Method to add new comment author.
44+
/// </summary>
45+
/// <param name="documentDirectory">The directory where the PowerPoint presentation is located. Default is 'Presentations/Existing'.</param>
46+
/// <param name="filename">The name of the PowerPoint file. Default is 'test.pptx'.</param>
47+
48+
public void AddCommentAuthor(string documentDirectory = existingDocsDirectory, string filename = "test.pptx")
49+
{
50+
try
51+
{
52+
// Create an instance of new presentation
53+
Presentation presentation = Presentation.Create($"{documentDirectory}/{filename}");
54+
// Create new comment author
55+
CommentAuthor author = new CommentAuthor();
56+
author.Name = "hp";
57+
author.InitialLetter = "h";
58+
author.ColorIndex = 2;
59+
author.Id = 1;
60+
presentation.CreateAuthor(author);
61+
// Save presentation
62+
presentation.Save();
63+
64+
65+
}
66+
catch (System.Exception ex)
67+
{
68+
throw new FileFormat.Slides.Common.FileFormatException("An error occurred.", ex);
69+
}
70+
}
71+
/// <summary>
72+
/// Method to remove comment authors.
73+
/// </summary>
74+
/// <param name="documentDirectory">The directory where the PowerPoint presentation is located. Default is 'Presentations/Existing'.</param>
75+
/// <param name="filename">The name of the PowerPoint file. Default is 'test.pptx'.</param>
76+
77+
public void RemoveCommentAuthor(string documentDirectory = existingDocsDirectory, string filename = "test.pptx")
78+
{
79+
try
80+
{
81+
// Create an instance of new presentation
82+
Presentation presentation = Presentation.Create($"{documentDirectory}/{filename}");
83+
// Get existing comment authors
84+
List<CommentAuthor> authors = presentation.GetCommentAuthors();
85+
// Remove comment authors
86+
foreach (CommentAuthor author in authors)
87+
{
88+
presentation.RemoveCommentAuthor(author);
89+
}
90+
91+
presentation.Save();
92+
}
93+
catch (System.Exception ex)
94+
{
95+
throw new FileFormat.Slides.Common.FileFormatException("An error occurred.", ex);
96+
}
97+
}
98+
99+
}
100+
}
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
using DocumentFormat.OpenXml.Presentation;
2+
using FileFormat.Slides.Common;
3+
using FileFormat.Slides.Common.Enumerations;
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Text;
7+
8+
9+
namespace FileFormat.Slides.Examples
10+
{
11+
public class CommentExamples
12+
{
13+
private const string newDocsDirectory = "../../../Presentations/New";
14+
private const string existingDocsDirectory = "../../../Presentations/Existing";
15+
/// <summary>
16+
/// Initializes a new instance of the <see cref="CommentExamples"/> class.
17+
/// Prepares the directory 'Presentations/New' for storing or loading PowerPoint(PPT or PPTX) presentations
18+
/// at the root of the project.
19+
/// If the directory doesn't exist, it is created. If it already exists,
20+
/// existing files are deleted, and the directory is cleaned up.
21+
/// </summary>
22+
public CommentExamples()
23+
{
24+
if (!System.IO.Directory.Exists(newDocsDirectory))
25+
{
26+
// If it doesn't exist, create the directory
27+
System.IO.Directory.CreateDirectory(newDocsDirectory);
28+
System.Console.WriteLine($"Directory '{System.IO.Path.GetFullPath(newDocsDirectory)}' " +
29+
$"created successfully.");
30+
}
31+
else
32+
{
33+
var files = System.IO.Directory.GetFiles(System.IO.Path.GetFullPath(newDocsDirectory));
34+
foreach (var file in files)
35+
{
36+
System.IO.File.Delete(file);
37+
System.Console.WriteLine($"File deleted: {file}");
38+
}
39+
System.Console.WriteLine($"Directory '{System.IO.Path.GetFullPath(newDocsDirectory)}' " +
40+
$"cleaned up.");
41+
}
42+
}
43+
/// <summary>
44+
/// Creates comment in a slide of a PowerPoint presentation.
45+
/// </summary>
46+
/// <param name="documentDirectory">The directory where the PowerPoint presentation is located. Default is 'Presentations/Existing'.</param>
47+
/// <param name="filename">The name of the PowerPoint file. Default is 'test.pptx'.</param>
48+
49+
public void CreateCommentInASlide(string documentDirectory = existingDocsDirectory, string filename = "test.pptx")
50+
{
51+
try
52+
{
53+
// Create instance of presentation
54+
Presentation presentation = Presentation.Open($"{documentDirectory}/{filename}");
55+
// Get 1st slide
56+
Slide slide = presentation.GetSlides()[0];
57+
// Create comment
58+
Comment comment1 = new Comment();
59+
// Set comment author
60+
comment1.AuthorId = 1;
61+
// Add comment content
62+
comment1.Text = "2nd Programmatic comment in an existing presentation";
63+
// Set comment time
64+
comment1.InsertedAt = DateTime.Now;
65+
// Add comment to slide
66+
slide.AddComment(comment1);
67+
// Save presentation
68+
presentation.Save();
69+
70+
}
71+
catch (System.Exception ex)
72+
{
73+
throw new FileFormat.Slides.Common.FileFormatException("An error occurred.", ex);
74+
}
75+
}
76+
/// <summary>
77+
/// Remove a comment from a slide.
78+
/// </summary>
79+
/// <param name="documentDirectory">The directory where the PowerPoint presentation is located. Default is 'Presentations/Existing'.</param>
80+
/// <param name="filename">The name of the PowerPoint file. Default is 'test.pptx'.</param>
81+
82+
public void RemoveACommentFromASlide(string documentDirectory = existingDocsDirectory, string filename = "test.pptx")
83+
{
84+
try
85+
{
86+
// Create instance of presentation
87+
Presentation presentation = Presentation.Open($"{documentDirectory}/{filename}");
88+
// Get 1st slide
89+
Slide slide = presentation.GetSlides()[0];
90+
// Get comments of a slide
91+
var comments = slide.GetComments();
92+
// Remove 1st comment
93+
comments[0].Remove();
94+
// Save presentation
95+
presentation.Save();
96+
97+
}
98+
catch (System.Exception ex)
99+
{
100+
throw new FileFormat.Slides.Common.FileFormatException("An error occurred.", ex);
101+
}
102+
}
103+
/// <summary>
104+
/// Add comment with new comment author.
105+
/// </summary>
106+
/// <param name="documentDirectory">The directory where the PowerPoint presentation is located. Default is 'Presentations/Existing'.</param>
107+
/// <param name="filename">The name of the PowerPoint file. Default is 'test.pptx'.</param>
108+
109+
public void AddCommentWithExistingCommentAuthor(string documentDirectory = existingDocsDirectory, string filename = "test.pptx")
110+
{
111+
try
112+
{
113+
// Create instance of presentation
114+
Presentation presentation = Presentation.Open($"{documentDirectory}/{filename}");
115+
// Get 1st slide
116+
Slide slide = presentation.GetSlides()[0];
117+
// Create comment
118+
Comment comment1 = new Comment();
119+
// Get existing saved comment author
120+
CommentAuthor author = presentation.GetCommentAuthors()[0];
121+
// Set authorId
122+
comment1.AuthorId = author.Id;
123+
// Add comment content
124+
comment1.Text = "2nd Programmatic comment in an existing presentation";
125+
// Set comment time
126+
comment1.InsertedAt = DateTime.Now;
127+
// Add comment to slide
128+
slide.AddComment(comment1);
129+
// Save presentation
130+
presentation.Save();
131+
132+
}
133+
catch (System.Exception ex)
134+
{
135+
throw new FileFormat.Slides.Common.FileFormatException("An error occurred.", ex);
136+
}
137+
}
138+
}
139+
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22

33
<PropertyGroup>
44
<TargetFramework>netcoreapp3.1</TargetFramework>
5+
<GenerateDocumentationFile>True</GenerateDocumentationFile>
56
</PropertyGroup>
67

78
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
89
<DocumentationFile>D:\Local_Repos\FileFormat.Examples\FileFormat.Slides-for-.NET\FileFormat.Slides.Examples\FileFormat.Slides.Examples\FileFormat.Slides.Examples.xml</DocumentationFile>
910
</PropertyGroup>
1011

1112
<ItemGroup>
12-
<PackageReference Include="FileFormat.Slides" Version="23.12.1" />
13+
<PackageReference Include="FileFormat.Slides" Version="24.4.0" />
1314
</ItemGroup>
1415

1516
</Project>

0 commit comments

Comments
 (0)