Remove Excel Hyperlinks in C#, VB.NET

Hyperlink is very convenient for helping people easily reach the webpage in a few seconds. While sometimes, it disturbs people since it may be clicked by accident and the page will automatically open. Especially, when there are many hyperlinks in excel, it is really a trouble that many web pages opened one by one just because your light clicks. In such a case, it is a good choice to remove hyperlinks. Now let us look at how to remove Excel hyperlink with C#/VB.NET by using Spire.XLS.

Spire.XLS Offers 2 solutions to remove Excel hyperlink via C#/VB.NET. The image below shows an Excel sample with different links. Now, we will use Spire.XLS to remove some of them.

Remove Excel Hyperlink

Step 1: Create Project

Create a C#/VB.NET project in your visual studio. Add Spire.XLS.dll as reference. The default setting of Spire.Xls.dll is placed under "C:\Program Files\e-iceblue\Spire.Xls\Bin". Select assembly Spire.Xls.dll and click OK to add it to the project.

[C#]
using Spire.Xls;

namespace remove_hyperlink
{
    class Program
    {
        static void Main(string[] args)
        {
        }
    }
}
[VB.NET]
Imports Spire.Xls

Namespace remove_hyperlink
	Class Program
		Private Shared Sub Main(args As String())
          End Sub
    End Class
End Namespace

Step 2: Load Excel File

Use the code below to load Excel file which we will remove links.

[C#]
            //Create a new workbook;
            Workbook workbook = new Workbook();
            workbook.LoadFromFile(@"E:\test1.xlsx");
            Worksheet sheet = workbook.Worksheets[0];
[VB.NET]
           ‘Create a new workbook
          Dim workbook As New Workbook()

 

Step 3: Remove Excel Hyperlink

Remove All Link Content

Select the cell range which we want to remove all link content. Use the code below to remove them.

[C#]
            sheet.Range["B5"].ClearAll();
            sheet.Range["B11"].ClearAll();
[VB.NET]
sheet.Range("B5").ClearAll()
sheet.Range("B11").ClearAll()

Remove Hyperlink Effect and Keep Link Text

Sometimes we just need remove the link effect and keep the link text content. Spire.XLS offers sheet.HyperLinks.RemoveAt(0); method for users to remove only link effect and keep the link content. The default setting of this method means removing links one by one. If we want to remove 3 links, we can use 3 sentences of the code. If we want to remove 5 links, then just write 5 sentences.

[C#]
             sheet.HyperLinks.RemoveAt(0);
              sheet.HyperLinks.RemoveAt(0);
              sheet.HyperLinks.RemoveAt(0);
              sheet.HyperLinks.RemoveAt(0);
              sheet.HyperLinks.RemoveAt(0);
[VB.NET]
             sheet.HyperLinks.RemoveAt(0)
              sheet.HyperLinks.RemoveAt(0)
              sheet.HyperLinks.RemoveAt(0)
              sheet.HyperLinks.RemoveAt(0)
              sheet.HyperLinks.RemoveAt(0)

Step 4: Preview

Use the code below to preview output Excel file.

 

[C#]
            // Save the project
            workbook.SaveToFile("sample.xls", ExcelVersion.Version97to2003);
            System.Diagnostics.Process.Start(workbook.FileName);
[VB.NET]
            // Save the project
            workbook.SaveToFile("sample.xls", ExcelVersion.Version97to2003)
            System.Diagnostics.Process.Start(workbook.FileName)

Effective Screeshot:

Remove Excel Hyperlink