-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathShapesAndImagesSample.cs
246 lines (214 loc) · 12.1 KB
/
ShapesAndImagesSample.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
/*************************************************************************************************
Required Notice: Copyright (C) EPPlus Software AB.
This software is licensed under PolyForm Noncommercial License 1.0.0
and may only be used for noncommercial purposes
https://polyformproject.org/licenses/noncommercial/1.0.0/
A commercial license to use this software can be purchased at https://epplussoftware.com
*************************************************************************************************
Date Author Change
*************************************************************************************************
01/27/2020 EPPlus Software AB Initial release EPPlus 5
*************************************************************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using OfficeOpenXml;
using System.Drawing;
using OfficeOpenXml.Style;
using OfficeOpenXml.Drawing;
namespace EPPlusSamples.EncryptionAndProtection
{
public static class ShapesAndImagesSample
{
public static void Run()
{
//The output package
var outputFile = FileUtil.GetCleanFileInfo("14-ShapesAndImages.xlsx");
//Create the template...
using (ExcelPackage package = new ExcelPackage(outputFile))
{
FillAndColorSamples(package);
EffectSamples(package);
ThreeDSamples(package);
PictureSample(package);
package.Save();
}
}
private static void PictureSample(ExcelPackage package)
{
var ws = package.Workbook.Worksheets.Add("Picture");
//Add an jpg image and apply some effects.
var pic = ws.Drawings.AddPicture("Landscape", FileUtil.GetFileInfo("14-ShapesAndImages", "LandscapeView.jpg"));
pic.SetPosition(2, 0, 1, 0);
pic.Effect.SetPresetShadow(ePresetExcelShadowType.OuterBottomRight);
pic.Effect.OuterShadow.Distance = 10;
pic.Effect.SetPresetSoftEdges(ePresetExcelSoftEdgesType.SoftEdge5Pt);
//Add the same image, but with 25 percent of the size. Let the position be absolute.
pic = ws.Drawings.AddPicture("LandscapeSmall", FileUtil.GetFileInfo("14-ShapesAndImages", "LandscapeView.jpg"));
pic.SetPosition(2, 0, 16, 0);
pic.SetSize(25); //25%
pic.ChangeCellAnchor(eEditAs.Absolute);
//Add the same image again, but let the picture move and resize when rows and colums are resized.
pic = ws.Drawings.AddPicture("LandscapeMoveAndResize", FileUtil.GetFileInfo("14-ShapesAndImages", "LandscapeView.jpg"));
pic.SetPosition(30, 0, 16, 0);
pic.ChangeCellAnchor(eEditAs.TwoCell);
//Add the image overlapping the first image, but make sure it is behind
pic = ws.Drawings.AddPicture("LandscapeSendToBack", FileUtil.GetFileInfo("14-ShapesAndImages", "LandscapeView.jpg"));
pic.SetPosition(8, 0, 8, 0);
pic.SetSize(25); //25%
pic.SendToBack();
}
private static void FillAndColorSamples(ExcelPackage package)
{
var ws = package.Workbook.Worksheets.Add("Fills And Colors");
//Drawing with a Solid fill
var drawing = ws.Drawings.AddShape("SolidFill", eShapeStyle.RoundRect);
drawing.SetPosition(0, 5, 0, 5);
drawing.SetSize(250, 250);
drawing.Fill.Style = eFillStyle.SolidFill;
drawing.Fill.SolidFill.Color.SetSchemeColor(eSchemeColor.Accent6);
drawing.Text = "RoundRect With Solid Fill";
//Drawing with a pattern fill
drawing = ws.Drawings.AddShape("PatternFill", eShapeStyle.SmileyFace);
drawing.SetPosition(0, 5, 4, 5);
drawing.SetSize(250, 250);
drawing.Fill.Style = eFillStyle.PatternFill;
drawing.Fill.PatternFill.PatternType = eFillPatternStyle.DiagBrick;
drawing.Fill.PatternFill.BackgroundColor.SetPresetColor(ePresetColor.Yellow);
drawing.Fill.PatternFill.ForegroundColor.SetSystemColor(eSystemColor.GrayText);
drawing.Border.Width = 2;
drawing.Border.Fill.Style = eFillStyle.SolidFill;
drawing.Border.Fill.SolidFill.Color.SetHslColor(90, 50, 25);
drawing.Font.Fill.Color = Color.Black;
drawing.Font.Bold = true;
drawing.Text = "Smiley With Pattern Fill";
//Drawing with a Gradient fill
drawing = ws.Drawings.AddShape("GradientFill", eShapeStyle.Heart);
drawing.SetPosition(0, 5, 8, 5);
drawing.SetSize(250, 250);
drawing.Fill.Style = eFillStyle.GradientFill;
drawing.Fill.GradientFill.Colors.AddRgb(0, Color.DarkRed);
drawing.Fill.GradientFill.Colors.AddRgb(30, Color.Red);
drawing.Fill.GradientFill.Colors.AddRgbPercentage(65, 100, 0, 0);
drawing.Fill.GradientFill.Colors[2].Color.Transforms.AddAlpha(75);
drawing.Text = "Heart with Gradient";
//Drawing with a blip fill
drawing = ws.Drawings.AddShape("BlipFill", eShapeStyle.Bevel);
drawing.SetPosition(0, 5, 12, 5);
drawing.SetSize(250, 250);
drawing.Fill.Style = eFillStyle.BlipFill;
drawing.Fill.BlipFill.Image.SetImage(FileUtil.GetFileInfo("14-ShapesAndImages", "EPPlusLogo.jpg"));
drawing.Fill.BlipFill.Stretch = true;
drawing.Text = "Blip Fill";
}
private static void EffectSamples(ExcelPackage package)
{
var ws=package.Workbook.Worksheets.Add("Effects");
/**** Shadow effects ****/
var drawing = ws.Drawings.AddShape("OuterShadow", eShapeStyle.RoundRect);
drawing.Effect.SetPresetShadow(ePresetExcelShadowType.OuterBottomRight);
drawing.SetPosition(0, 5, 0, 5);
drawing.SetSize(250, 250);
drawing.Text = "Outer Shadow - Bottom Right";
drawing = ws.Drawings.AddShape("InnerShadow", eShapeStyle.RoundRect);
drawing.Effect.SetPresetShadow(ePresetExcelShadowType.InnerTopLeft);
drawing.SetPosition(0, 5, 4, 5);
drawing.SetSize(250, 250);
drawing.Text = "Inner Shadow - Top Left";
drawing = ws.Drawings.AddShape("PerspectiveBelowShadow", eShapeStyle.RoundRect);
drawing.Effect.SetPresetShadow(ePresetExcelShadowType.PerspectiveBelow);
drawing.SetPosition(0, 5, 8, 5);
drawing.SetSize(250, 250);
drawing.Text = "Perspective Shadow - Below";
/**** Glow effects ****/
drawing = ws.Drawings.AddShape("Glow Accent1 5pt", eShapeStyle.RoundRect);
drawing.Effect.SetPresetGlow(ePresetExcelGlowType.Accent1_5Pt);
drawing.SetPosition(20, 5, 0, 5);
drawing.SetSize(250, 250);
drawing.Text = "Glow - Accent1 - 5pt";
drawing = ws.Drawings.AddShape("Glow Accent2 8pt", eShapeStyle.RoundRect);
drawing.Effect.SetPresetGlow(ePresetExcelGlowType.Accent2_8Pt);
drawing.SetPosition(20, 5, 4, 5);
drawing.SetSize(250, 250);
drawing.Text = "Glow - Accent2 - 8pt";
drawing = ws.Drawings.AddShape("Glow Accent4 11pt", eShapeStyle.RoundRect);
drawing.Effect.SetPresetGlow(ePresetExcelGlowType.Accent4_11Pt);
drawing.SetPosition(20, 5, 8, 5);
drawing.SetSize(250, 250);
drawing.Text = "Glow - Accent4 - 11pt";
drawing = ws.Drawings.AddShape("Glow Accent5 18pt", eShapeStyle.RoundRect);
drawing.Effect.SetPresetGlow(ePresetExcelGlowType.Accent5_18Pt);
drawing.SetPosition(20, 5, 12, 5);
drawing.SetSize(250, 250);
drawing.Text = "Glow - Accent5 - 18pt";
/**** Reflection effects ****/
drawing = ws.Drawings.AddShape("Full Reflection", eShapeStyle.RoundRect);
drawing.Effect.SetPresetReflection(ePresetExcelReflectionType.Full4Pt);
drawing.SetPosition(40, 5, 0, 5);
drawing.SetSize(250, 250);
drawing.Text = "Reflection - Full 4Pt";
drawing = ws.Drawings.AddShape("Half Reflection", eShapeStyle.RoundRect);
drawing.Effect.SetPresetReflection(ePresetExcelReflectionType.Half8Pt);
drawing.SetPosition(40, 5, 4, 5);
drawing.SetSize(250, 250);
drawing.Text = "Reflection - Half 8Pt";
drawing = ws.Drawings.AddShape("Tight Touching Reflection", eShapeStyle.RoundRect);
drawing.Effect.SetPresetReflection(ePresetExcelReflectionType.TightTouching);
drawing.SetPosition(40, 5, 8, 5);
drawing.SetSize(250, 250);
drawing.Text = "Reflection - Tight Touching Reflection";
drawing = ws.Drawings.AddShape("Soft Edges 10Pt", eShapeStyle.RoundRect);
drawing.Effect.SetPresetSoftEdges(ePresetExcelSoftEdgesType.SoftEdge10Pt);
drawing.SetPosition(70, 0, 0, 0);
drawing.SetSize(250, 250);
drawing.Text = "Soft Edges - 10Pt";
}
private static void ThreeDSamples(ExcelPackage package)
{
var ws = package.Workbook.Worksheets.Add("3D");
//Create a shape with 3D - TopBevel - Round
var drawing = ws.Drawings.AddShape("3D - TopBevel - Round", eShapeStyle.RoundRect);
drawing.ThreeD.TopBevel.BevelType = eBevelPresetType.Circle;
//Default height and width is 6, but we can alter it.
drawing.ThreeD.TopBevel.Height = 5;
drawing.ThreeD.TopBevel.Width = 5;
drawing.SetPosition(0, 5, 0, 5);
drawing.SetSize(250, 250);
drawing.Text = "3D - TopBevel - Angle";
//Create a shape with 3D - TopBevel - ArtDeco and change the 3D camera
drawing = ws.Drawings.AddShape("3D - TopBevel - ArtDeco", eShapeStyle.RoundRect);
drawing.ThreeD.TopBevel.BevelType = eBevelPresetType.ArtDeco;
drawing.ThreeD.Scene.Camera.CameraType = ePresetCameraType.PerspectiveLeft;
drawing.ThreeD.MaterialType = ePresetMaterialType.TranslucentPowder;
drawing.SetPosition(0, 5, 5, 5);
drawing.SetSize(250, 250);
drawing.Text = "3D - TopBevel - ArtDeco";
//Create a shape with 3D Camera PerspectiveRelaxedModerately, alter the beveltype and Lightrig
drawing = ws.Drawings.AddShape("3D Camera PerspectiveRelaxedModerately", eShapeStyle.RoundRect);
drawing.ThreeD.MaterialType=ePresetMaterialType.Metal;
drawing.ThreeD.Scene.Camera.CameraType=ePresetCameraType.PerspectiveRelaxedModerately;
drawing.ThreeD.TopBevel.BevelType = eBevelPresetType.HardEdge;
drawing.ThreeD.Scene.LightRig.RigType=eRigPresetType.Sunrise;
drawing.SetPosition(0, 5, 10, 5);
drawing.SetSize(250, 250);
drawing.Text = "3D - Camera - PerspectiveRelaxedModerately - Metal";
//Create a shape with 3D Camera With Extrusion Color & Contour Color
drawing = ws.Drawings.AddShape("3D Camera With Extr & Contour", eShapeStyle.RoundRect);
drawing.ThreeD.MaterialType = ePresetMaterialType.Plastic;
drawing.ThreeD.Scene.Camera.CameraType = ePresetCameraType.IsometricOffAxis2Right;
drawing.ThreeD.TopBevel.BevelType = eBevelPresetType.Convex;
drawing.ThreeD.TopBevel.BevelType = eBevelPresetType.Circle;
drawing.ThreeD.Scene.LightRig.RigType = eRigPresetType.BrightRoom;
drawing.ThreeD.ExtrusionColor.SetRgbColor(Color.Red);
drawing.ThreeD.ExtrusionHeight = 6;
drawing.ThreeD.ContourColor.SetHslColor(240, 32, 27); //Dark blue
drawing.ThreeD.ContourWidth = 3;
drawing.ThreeD.Scene.LightRig.RigType = eRigPresetType.BrightRoom;
drawing.SetPosition(0, 5, 15, 5);
drawing.SetSize(250, 250);
drawing.Text = "3D Camera With Extrusion & Contour";
}
}
}