Effortlessly Remove Hyperlinks in Excel using C#/VB.NET - Free Tutorial!

Effortlessly Remove Hyperlinks in Excel using C#/VB.NET - Free Tutorial!

Excel is a widely used spreadsheet program that offers many features for managing data. One such feature is the ability to create hyperlinks within a worksheet. Although hyperlinks can be useful, they can also clutter up a worksheet and make it harder to read and analyze data. In this article, we will show you how to remove hyperlinks in Excel using C#/VB.NET.

Programming Environment

In this test, Free Spire.XLS for .NET is introduced into the program. The Spire.XLS.dll file can be referenced by:

Method 1: Download Free Spire.XLS for .NET locally, unzip it, and install it. After the installation is complete, find Spire.XLS.dll in the BIN folder under the installation path. Then open the "Solution Explorer" in Visual Studio, right-click "References", "Add Reference", and add a reference to the dll file in the BIN folder of the local path to the program.

Method 2: Install via NuGet. It can be installed by the following 2 methods:

(1) You can open the "Solution Explorer" in Visual Studio, right-click "References", "Manage NuGet Packages", then search for "Free Spire.XLS", and click "Install". Wait for the program installation to complete.

(2) Copy the following content to the PM console installation.

Install-Package FreeSpire.XLS -Version 12.7.0

The following steps demonstrate how to remove a specific hyperlink from an Excel file:

  • Initialize an instance of the Workbook class.

  • Load an Excel file using the Workbook.LoadFromFile() method.

  • Get a specific worksheet using the Workbook.Worksheets[int index] property.

  • Remove a specific hyperlink from the worksheet using the Worksheet.Hyperlinks.RemoveAt(int index) method.

  • Save the result file using the Workbook.SaveToFile() method.

Full Code:

C#

using Spire.Xls;

namespace RemoveHyperlinks
{
    internal class Program
    {
        static void Main(string[] args)
        {
            //Initialize an instance of the Workbook class
            Workbook workbook = new Workbook();
            //Load an Excel file
            workbook.LoadFromFile("Hyperlinks2.xlsx");

            //Get the first worksheet
            Worksheet sheet = workbook.Worksheets[0];

            //Remove the first hyperlink and keep its display text
            sheet.HyperLinks.RemoveAt(0);

            //Remove all content from the cell
            //sheet.Range["B2"].ClearAll();

            //Save the result file
            workbook.SaveToFile("RemoveHyperlink.xlsx", ExcelVersion.Version2013);
            workbook.Dispose();
        }
    }
}

VB.NET

Imports Spire.Xls

Namespace RemoveHyperlinks
    Friend Class Program
        Private Shared Sub Main(ByVal args As String())
            'Initialize an instance of the Workbook class
            Dim workbook As Workbook = New Workbook()
            'Load an Excel file
            workbook.LoadFromFile("Hyperlinks2.xlsx")

            'Get the first worksheet
            Dim sheet As Worksheet = workbook.Worksheets(0)

            'Remove the first hyperlink and keep its display text
            sheet.HyperLinks.RemoveAt(0)

            'Remove all content from the cell
            'sheet.Range["B2"].ClearAll();

            'Save the result file
            workbook.SaveToFile("RemoveHyperlink.xlsx", ExcelVersion.Version2013)
            workbook.Dispose()
        End Sub
    End Class
End Namespace

Effective Shot

Conclusion:

In addition to removing hyperlinks in Excel, Spire.XLS for .NET offers many other useful features. For example, you can use Spire.XLS to Add Hyperlinks to Excel, Protect or Unprotect Excel Documents. You can also use it to add images, text, and graphics to your Excel files. Additionally, Spire.XLS for .NET can be applied easily to Convert Excel to PDF, and Excel to HTML in high quality. In short, Spire.XLS for .NET is a useful tool to convert Excel to Various document formats. With the additional features it offers, it is a complete solution for all your Excel file needs.