Skip to content

Commit 4a71624

Browse files
Merge pull request #116 from DharanyaSakthivel-SF4210/master
ES-946307- Add the sample Iterate-slide-elements
2 parents 87b9478 + 9641e53 commit 4a71624

File tree

5 files changed

+218
-0
lines changed

5 files changed

+218
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.31911.196
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Iterate-slide-elements", "Iterate-slide-elements\Iterate-slide-elements.csproj", "{38FB99D1-DB4A-4A3F-B90B-7135724337EF}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{38FB99D1-DB4A-4A3F-B90B-7135724337EF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{38FB99D1-DB4A-4A3F-B90B-7135724337EF}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{38FB99D1-DB4A-4A3F-B90B-7135724337EF}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{38FB99D1-DB4A-4A3F-B90B-7135724337EF}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {B75368E1-9546-4CD5-BE4C-5C905E8D16C2}
24+
EndGlobalSection
25+
EndGlobal
Binary file not shown.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<RootNamespace>Iterate_slide_elements</RootNamespace>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Syncfusion.Presentation.NET" Version="*" />
11+
</ItemGroup>
12+
13+
<ItemGroup>
14+
<None Update="Data\Template.pptx">
15+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
16+
</None>
17+
<None Update="Output\.gitkeep">
18+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
19+
</None>
20+
</ItemGroup>
21+
22+
</Project>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
using Syncfusion.Presentation;
2+
using Syncfusion.OfficeChart;
3+
using System.IO;
4+
5+
class Program
6+
{
7+
public static void Main(string[] args)
8+
{
9+
// Load or open a PowerPoint presentation
10+
using (FileStream inputStream = new(Path.GetFullPath(@"Data/Template.pptx"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
11+
{
12+
using (IPresentation presentation = Presentation.Open(inputStream))
13+
{
14+
// Iterate through each slide in the presentation
15+
foreach (ISlide slide in presentation.Slides)
16+
{
17+
// Iterate through each shape in the master slide shapes.
18+
foreach (IShape shape in slide.LayoutSlide.MasterSlide.Shapes)
19+
{
20+
// Modify the shape properties (text, size, hyperlinks, etc.)
21+
ModifySlideElements(shape);
22+
}
23+
// Iterate through each shape in the layout slide shapes.
24+
foreach (IShape shape in slide.LayoutSlide.Shapes)
25+
{
26+
// Modify the shape properties (text, size, hyperlinks, etc.)
27+
ModifySlideElements(shape);
28+
}
29+
// Iterate through each shape in the slide
30+
foreach (IShape shape in slide.Shapes)
31+
{
32+
// Modify the shape properties (text, size, hyperlinks, etc.)
33+
ModifySlideElements(shape);
34+
}
35+
}
36+
37+
// Save the modified presentation to an output file
38+
using (FileStream outputStream = new(Path.GetFullPath(@"Output/Result.pptx"), FileMode.Create, FileAccess.ReadWrite))
39+
{
40+
presentation.Save(outputStream);
41+
}
42+
}
43+
}
44+
}
45+
46+
/// <summary>
47+
/// Modifies slide elements based on their type.
48+
/// </summary>
49+
private static void ModifySlideElements(IShape shape )
50+
{
51+
switch (shape.SlideItemType)
52+
{
53+
case SlideItemType.AutoShape:
54+
{
55+
// Modify text if present in the shape
56+
if (!string.IsNullOrEmpty(shape.TextBody.Text))
57+
{
58+
ModifyTextPart(shape.TextBody);
59+
}
60+
// If shape is a rectangle, add a hyperlink
61+
else if (shape.AutoShapeType == AutoShapeType.Rectangle)
62+
{
63+
shape.SetHyperlink("www.google.com");
64+
}
65+
break;
66+
}
67+
68+
case SlideItemType.ConnectionShape:
69+
{
70+
IConnector connector = shape as IConnector;
71+
// Modify the arrowhead style at the beginning of the connector line
72+
connector.LineFormat.BeginArrowheadStyle = ArrowheadStyle.ArrowDiamond;
73+
break;
74+
}
75+
76+
case SlideItemType.Placeholder:
77+
{
78+
// Modify text if present in the placeholder
79+
if (!string.IsNullOrEmpty(shape.TextBody.Text))
80+
{
81+
ModifyTextPart(shape.TextBody);
82+
}
83+
break;
84+
}
85+
86+
case SlideItemType.Picture:
87+
{
88+
// Resize the picture
89+
IPicture picture = shape as IPicture;
90+
picture.Height = 160;
91+
picture.Width = 130;
92+
break;
93+
}
94+
95+
case SlideItemType.Table:
96+
{
97+
// Get the table shape
98+
ITable table = shape as ITable;
99+
100+
// Iterate through rows and modify text in each cell
101+
foreach (IRow row in table.Rows)
102+
{
103+
foreach (ICell cell in row.Cells)
104+
{
105+
ModifyTextPart(cell.TextBody);
106+
}
107+
}
108+
break;
109+
}
110+
111+
case SlideItemType.GroupShape:
112+
{
113+
// Get the group shape and iterate through child shapes
114+
IGroupShape groupShape = shape as IGroupShape;
115+
foreach (IShape childShape in groupShape.Shapes)
116+
{
117+
ModifySlideElements(childShape);
118+
}
119+
break;
120+
}
121+
122+
case SlideItemType.Chart:
123+
{
124+
// Modify chart properties
125+
IPresentationChart chart = shape as IPresentationChart;
126+
chart.ChartTitle = "Purchase Details";
127+
chart.ChartTitleArea.Bold = true;
128+
chart.ChartTitleArea.Color = OfficeKnownColors.Red;
129+
chart.ChartTitleArea.Size = 20;
130+
break;
131+
}
132+
133+
case SlideItemType.SmartArt:
134+
{
135+
// Modify SmartArt content
136+
ISmartArt smartArt = shape as ISmartArt;
137+
//Traverse through all nodes inside SmartArt
138+
foreach (ISmartArtNode node in smartArt.Nodes)
139+
{
140+
ModifyTextPart(node.TextBody);
141+
}
142+
break;
143+
}
144+
145+
case SlideItemType.OleObject:
146+
{
147+
// Modify OLE object size
148+
IOleObject oleObject = shape as IOleObject;
149+
oleObject.Width = 300;
150+
break;
151+
}
152+
}
153+
}
154+
155+
/// <summary>
156+
/// Modifies the text content within a text body.
157+
/// </summary>
158+
private static void ModifyTextPart(ITextBody textBody)
159+
{
160+
// Iterate through paragraphs in the text body
161+
foreach (IParagraph paragraph in textBody.Paragraphs)
162+
{
163+
// Iterate through text parts and modify the text
164+
foreach (ITextPart textPart in paragraph.TextParts)
165+
{
166+
textPart.Text = "Adventure Works";
167+
}
168+
}
169+
}
170+
}

0 commit comments

Comments
 (0)