Skip to content

Commit 10c51cf

Browse files
authored
Merge pull request #173 from SyncfusionExamples/261508-HideOrUnhideShapeExample
261508-How to hide or un-hide a shape in Excel using XlsIO?
2 parents 1b2c963 + d3717bc commit 10c51cf

File tree

6 files changed

+131
-0
lines changed

6 files changed

+131
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.12.35506.116 d17.12
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Hide or Unhide Shape", "Hide or Unhide Shape\Hide or Unhide Shape.csproj", "{0EEEEBAA-E5A2-4DF8-B362-0ACD365416E3}"
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+
{0EEEEBAA-E5A2-4DF8-B362-0ACD365416E3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{0EEEEBAA-E5A2-4DF8-B362-0ACD365416E3}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{0EEEEBAA-E5A2-4DF8-B362-0ACD365416E3}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{0EEEEBAA-E5A2-4DF8-B362-0ACD365416E3}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal
Binary file not shown.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<RootNamespace>Hide_or_Unhide_Shape</RootNamespace>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<Nullable>enable</Nullable>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="Syncfusion.XlsIO.Net.Core" Version="*" />
13+
</ItemGroup>
14+
15+
<ItemGroup>
16+
<None Update="Output\*">
17+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
18+
</None>
19+
</ItemGroup>
20+
21+
</Project>

Excel Shapes/Hide or Unhide Shape/.NET/Hide or Unhide Shape/Hide or Unhide Shape/Output/.gitkeep

Whitespace-only changes.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using System;
2+
using System.IO;
3+
using Syncfusion.XlsIO;
4+
using Syncfusion.XlsIO.Implementation.Shapes;
5+
6+
namespace Hide_Unhide_Shapes
7+
{
8+
class Program
9+
{
10+
static void Main(string[] args)
11+
{
12+
using (ExcelEngine excelEngine = new ExcelEngine())
13+
{
14+
IApplication application = excelEngine.Excel;
15+
application.DefaultVersion = ExcelVersion.Xlsx;
16+
17+
FileStream inputStream = new FileStream("Data/Input.xlsx", FileMode.Open, FileAccess.Read);
18+
IWorkbook workbook = application.Workbooks.Open(inputStream);
19+
IWorksheet worksheet = workbook.Worksheets[0];
20+
21+
IShapes shapes = worksheet.Shapes;
22+
AutoShapeImpl shape1 = shapes[0] as AutoShapeImpl;
23+
24+
//Set shape1 to be hidden
25+
shape1.IsHidden = true;
26+
27+
AutoShapeImpl shape2 = shapes[1] as AutoShapeImpl;
28+
29+
//Set shape2 to be visible
30+
shape2.IsHidden = false;
31+
32+
//Saving the workbook as stream
33+
FileStream outputStream = new FileStream("Output/Output.xlsx", FileMode.Create, FileAccess.Write);
34+
workbook.SaveAs(outputStream);
35+
outputStream.Dispose();
36+
inputStream.Dispose();
37+
}
38+
39+
}
40+
41+
}
42+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# How to hide or un-hide a shape in Excel using C#?
2+
3+
Step 1: Create a New C# Console Application Project.
4+
5+
Step 2: Name the Project.
6+
7+
Step 3: Install the [Syncfusion.XlsIO.Net.Core](https://www.nuget.org/packages/Syncfusion.XlsIO.Net.Core) NuGet package as reference to your .NET Standard applications from [NuGet.org](https://www.nuget.org).
8+
9+
Step 4: Include the following namespaces in the **Program.cs** file.
10+
11+
```csharp
12+
using System;
13+
using System.IO;
14+
using Syncfusion.XlsIO;
15+
using Syncfusion.XlsIO.Implementation.Shapes;
16+
```
17+
18+
Step 5: Include the below code snippet in **Program.cs** to hide or un-hide a shape in Excel using C#.
19+
```csharp
20+
using (ExcelEngine excelEngine = new ExcelEngine())
21+
{
22+
IApplication application = excelEngine.Excel;
23+
application.DefaultVersion = ExcelVersion.Xlsx;
24+
25+
FileStream inputStream = new FileStream("Data/Input.xlsx", FileMode.Open, FileAccess.Read);
26+
IWorkbook workbook = application.Workbooks.Open(inputStream);
27+
IWorksheet worksheet = workbook.Worksheets[0];
28+
29+
IShapes shapes = worksheet.Shapes;
30+
AutoShapeImpl shape1 = shapes[0] as AutoShapeImpl;
31+
32+
//Set shape1 to be hidden
33+
shape1.IsHidden = true;
34+
35+
AutoShapeImpl shape2 = shapes[1] as AutoShapeImpl;
36+
37+
//Set shape2 to be visible
38+
shape2.IsHidden = false;
39+
40+
//Saving the workbook as stream
41+
FileStream outputStream = new FileStream("Output/Output.xlsx", FileMode.Create, FileAccess.Write);
42+
workbook.SaveAs(outputStream);
43+
outputStream.Dispose();
44+
inputStream.Dispose();
45+
}
46+
```

0 commit comments

Comments
 (0)