diff --git a/FAQ/Hyperlinks/.NET/Delete Hyperlinks/Delete Hyperlinks.sln b/FAQ/Hyperlinks/.NET/Delete Hyperlinks/Delete Hyperlinks.sln new file mode 100644 index 00000000..38082bea --- /dev/null +++ b/FAQ/Hyperlinks/.NET/Delete Hyperlinks/Delete Hyperlinks.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}") = "Delete Hyperlinks", "Delete Hyperlinks\Delete Hyperlinks.csproj", "{5BF46923-4F9F-4CFC-BF1A-336E40153917}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {5BF46923-4F9F-4CFC-BF1A-336E40153917}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5BF46923-4F9F-4CFC-BF1A-336E40153917}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5BF46923-4F9F-4CFC-BF1A-336E40153917}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5BF46923-4F9F-4CFC-BF1A-336E40153917}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/FAQ/Hyperlinks/.NET/Delete Hyperlinks/Delete Hyperlinks/Data/InputTemplate.xlsx b/FAQ/Hyperlinks/.NET/Delete Hyperlinks/Delete Hyperlinks/Data/InputTemplate.xlsx new file mode 100644 index 00000000..f375f0fc Binary files /dev/null and b/FAQ/Hyperlinks/.NET/Delete Hyperlinks/Delete Hyperlinks/Data/InputTemplate.xlsx differ diff --git a/FAQ/Hyperlinks/.NET/Delete Hyperlinks/Delete Hyperlinks/Delete Hyperlinks.csproj b/FAQ/Hyperlinks/.NET/Delete Hyperlinks/Delete Hyperlinks/Delete Hyperlinks.csproj new file mode 100644 index 00000000..d77c5f84 --- /dev/null +++ b/FAQ/Hyperlinks/.NET/Delete Hyperlinks/Delete Hyperlinks/Delete Hyperlinks.csproj @@ -0,0 +1,20 @@ + + + + Exe + net8.0 + Delete_Hyperlinks + enable + enable + + + + + + + + + Always + + + diff --git a/FAQ/Hyperlinks/.NET/Delete Hyperlinks/Delete Hyperlinks/Output/.gitkeep b/FAQ/Hyperlinks/.NET/Delete Hyperlinks/Delete Hyperlinks/Output/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/FAQ/Hyperlinks/.NET/Delete Hyperlinks/Delete Hyperlinks/Program.cs b/FAQ/Hyperlinks/.NET/Delete Hyperlinks/Delete Hyperlinks/Program.cs new file mode 100644 index 00000000..096bedf7 --- /dev/null +++ b/FAQ/Hyperlinks/.NET/Delete Hyperlinks/Delete Hyperlinks/Program.cs @@ -0,0 +1,35 @@ +using System; +using System.IO; +using Syncfusion.XlsIO; +using Syncfusion.XlsIO.Implementation; +using Syncfusion.XlsIO.Implementation.Collections; + +namespace Delete_Hyperlinks +{ + 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/InputTemplate.xlsx", FileMode.Open, FileAccess.Read); + IWorkbook workbook = application.Workbooks.Open(inputStream); + IWorksheet worksheet = workbook.Worksheets[0]; + + // Remove first hyperlink without affecting cell styles + HyperLinksCollection hyperlink = worksheet.HyperLinks as HyperLinksCollection; + hyperlink.Remove(hyperlink[0] as HyperLinkImpl); + + //Saving the workbook as stream + FileStream outputStream = new FileStream("Output/Output.xlsx", FileMode.Create, FileAccess.Write); + workbook.SaveAs(outputStream); + workbook.Close(); + excelEngine.Dispose(); + } + } + + } +} + diff --git a/FAQ/Hyperlinks/.NET/Delete Hyperlinks/README.md b/FAQ/Hyperlinks/.NET/Delete Hyperlinks/README.md new file mode 100644 index 00000000..b0bd892e --- /dev/null +++ b/FAQ/Hyperlinks/.NET/Delete Hyperlinks/README.md @@ -0,0 +1,41 @@ +# How to delete hyperlinks from worksheet without affecting the cell styles? + +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; +using Syncfusion.XlsIO.Implementation.Collections; +``` + +Step 5: Include the below code snippet in **Program.cs** to delete hyperlinks from worksheet without affecting the cell styles. + +```csharp +using (ExcelEngine excelEngine = new ExcelEngine()) +{ + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Xlsx; + FileStream inputStream = new FileStream("Data/InputTemplate.xlsx", FileMode.Open, FileAccess.Read); + IWorkbook workbook = application.Workbooks.Open(inputStream); + IWorksheet worksheet = workbook.Worksheets[0]; + + // Remove first hyperlink without affecting cell styles + HyperLinksCollection hyperlink = worksheet.HyperLinks as HyperLinksCollection; + hyperlink.Remove(hyperlink[0] as HyperLinkImpl); + + //Saving the workbook as stream + FileStream outputStream = new FileStream("Output/Output.xlsx", FileMode.Create, FileAccess.Write); + workbook.SaveAs(outputStream); + workbook.Close(); + excelEngine.Dispose(); +} +``` +