diff --git a/Excel Shapes/Hide or Unhide Shape/.NET/Hide or Unhide Shape/Hide or Unhide Shape.sln b/Excel Shapes/Hide or Unhide Shape/.NET/Hide or Unhide Shape/Hide or Unhide Shape.sln new file mode 100644 index 00000000..1b1ffc54 --- /dev/null +++ b/Excel Shapes/Hide or Unhide Shape/.NET/Hide or Unhide Shape/Hide or Unhide Shape.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.12.35506.116 d17.12 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Hide or Unhide Shape", "Hide or Unhide Shape\Hide or Unhide Shape.csproj", "{0EEEEBAA-E5A2-4DF8-B362-0ACD365416E3}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {0EEEEBAA-E5A2-4DF8-B362-0ACD365416E3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0EEEEBAA-E5A2-4DF8-B362-0ACD365416E3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0EEEEBAA-E5A2-4DF8-B362-0ACD365416E3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0EEEEBAA-E5A2-4DF8-B362-0ACD365416E3}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Excel Shapes/Hide or Unhide Shape/.NET/Hide or Unhide Shape/Hide or Unhide Shape/Data/Input.xlsx b/Excel Shapes/Hide or Unhide Shape/.NET/Hide or Unhide Shape/Hide or Unhide Shape/Data/Input.xlsx new file mode 100644 index 00000000..1bd6fe95 Binary files /dev/null and b/Excel Shapes/Hide or Unhide Shape/.NET/Hide or Unhide Shape/Hide or Unhide Shape/Data/Input.xlsx differ diff --git a/Excel Shapes/Hide or Unhide Shape/.NET/Hide or Unhide Shape/Hide or Unhide Shape/Hide or Unhide Shape.csproj b/Excel Shapes/Hide or Unhide Shape/.NET/Hide or Unhide Shape/Hide or Unhide Shape/Hide or Unhide Shape.csproj new file mode 100644 index 00000000..38542346 --- /dev/null +++ b/Excel Shapes/Hide or Unhide Shape/.NET/Hide or Unhide Shape/Hide or Unhide Shape/Hide or Unhide Shape.csproj @@ -0,0 +1,21 @@ + + + + Exe + net8.0 + Hide_or_Unhide_Shape + enable + enable + + + + + + + + + Always + + + + diff --git a/Excel Shapes/Hide or Unhide Shape/.NET/Hide or Unhide Shape/Hide or Unhide Shape/Output/.gitkeep b/Excel Shapes/Hide or Unhide Shape/.NET/Hide or Unhide Shape/Hide or Unhide Shape/Output/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/Excel Shapes/Hide or Unhide Shape/.NET/Hide or Unhide Shape/Hide or Unhide Shape/Program.cs b/Excel Shapes/Hide or Unhide Shape/.NET/Hide or Unhide Shape/Hide or Unhide Shape/Program.cs new file mode 100644 index 00000000..67dcd856 --- /dev/null +++ b/Excel Shapes/Hide or Unhide Shape/.NET/Hide or Unhide Shape/Hide or Unhide Shape/Program.cs @@ -0,0 +1,42 @@ +using System; +using System.IO; +using Syncfusion.XlsIO; +using Syncfusion.XlsIO.Implementation.Shapes; + +namespace Hide_Unhide_Shapes +{ + class Program + { + static void Main(string[] args) + { + using (ExcelEngine excelEngine = new ExcelEngine()) + { + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Xlsx; + + FileStream inputStream = new FileStream("Data/Input.xlsx", FileMode.Open, FileAccess.Read); + IWorkbook workbook = application.Workbooks.Open(inputStream); + IWorksheet worksheet = workbook.Worksheets[0]; + + IShapes shapes = worksheet.Shapes; + AutoShapeImpl shape1 = shapes[0] as AutoShapeImpl; + + //Set shape1 to be hidden + shape1.IsHidden = true; + + AutoShapeImpl shape2 = shapes[1] as AutoShapeImpl; + + //Set shape2 to be visible + shape2.IsHidden = false; + + //Saving the workbook as stream + FileStream outputStream = new FileStream("Output/Output.xlsx", FileMode.Create, FileAccess.Write); + workbook.SaveAs(outputStream); + outputStream.Dispose(); + inputStream.Dispose(); + } + + } + + } +} diff --git a/Excel Shapes/Hide or Unhide Shape/.NET/Hide or Unhide Shape/README.md b/Excel Shapes/Hide or Unhide Shape/.NET/Hide or Unhide Shape/README.md new file mode 100644 index 00000000..d5e51a55 --- /dev/null +++ b/Excel Shapes/Hide or Unhide Shape/.NET/Hide or Unhide Shape/README.md @@ -0,0 +1,46 @@ +# How to hide or un-hide a shape in Excel using C#? + +Step 1: Create a New C# Console Application Project. + +Step 2: Name the Project. + +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). + +Step 4: Include the following namespaces in the **Program.cs** file. + +```csharp +using System; +using System.IO; +using Syncfusion.XlsIO; +using Syncfusion.XlsIO.Implementation.Shapes; +``` + +Step 5: Include the below code snippet in **Program.cs** to hide or un-hide a shape in Excel using C#. +```csharp +using (ExcelEngine excelEngine = new ExcelEngine()) +{ + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Xlsx; + + FileStream inputStream = new FileStream("Data/Input.xlsx", FileMode.Open, FileAccess.Read); + IWorkbook workbook = application.Workbooks.Open(inputStream); + IWorksheet worksheet = workbook.Worksheets[0]; + + IShapes shapes = worksheet.Shapes; + AutoShapeImpl shape1 = shapes[0] as AutoShapeImpl; + + //Set shape1 to be hidden + shape1.IsHidden = true; + + AutoShapeImpl shape2 = shapes[1] as AutoShapeImpl; + + //Set shape2 to be visible + shape2.IsHidden = false; + + //Saving the workbook as stream + FileStream outputStream = new FileStream("Output/Output.xlsx", FileMode.Create, FileAccess.Write); + workbook.SaveAs(outputStream); + outputStream.Dispose(); + inputStream.Dispose(); +} +``` \ No newline at end of file