Add and Delete Digital Signature in Excel in C#, VB.NET

This article demonstrates how to add and delete digital signature in an Excel file using Spire.XLS for .NET.

Add digital signature

C#
using System;
using System.Security.Cryptography.X509Certificates;
using Spire.Xls;
using Spire.Xls.Core.MergeSpreadsheet.Interfaces;

namespace Add_Digital_Signature
{
    class Program
    {
        static void Main(string[] args)
        {
            //Create a Workbook instance
            Workbook workbook = new Workbook();
            //Load an Excel file
            workbook.LoadFromFile("Sample.xlsx");

            //Add digital signature to the file
            X509Certificate2 cert = new X509Certificate2("gary.pfx", "e-iceblue");
            DateTime certtime = new DateTime(2020, 7, 1, 7, 10, 36);
            IDigitalSignatures signature = workbook.AddDigitalSignature(cert, "e-iceblue", certtime);
            
            //Save the result file
            workbook.SaveToFile("AddDigitalSignature.xlsx", FileFormat.Version2013);
        }
    }
}
VB.NET
Imports System
Imports System.Security.Cryptography.X509Certificates
Imports Spire.Xls
Imports Spire.Xls.Core.MergeSpreadsheet.Interfaces

Namespace Add_Digital_Signature
    Class Program
        Private Shared Sub Main(ByVal args As String())
            Dim workbook As Workbook = New Workbook()
            workbook.LoadFromFile("Sample.xlsx")
            Dim cert As X509Certificate2 = New X509Certificate2("gary.pfx", "e-iceblue")
            Dim certtime As DateTime = New DateTime(2020, 7, 1, 7, 10, 36)
            Dim signature As IDigitalSignatures = workbook.AddDigitalSignature(cert, "e-iceblue", certtime)
            workbook.SaveToFile("AddDigitalSignature.xlsx", FileFormat.Version2013)
        End Sub
    End Class
End Namespace

 

Add and Delete Digital Signature in Excel in C#, VB.NET

Delete digital signature

C#
using Spire.Xls;

namespace Delete_Digital_Signature
{
    class Program
    {
        static void Main(string[] args)
        {
            //Create a Workbook instance
            Workbook workbook = new Workbook();
            //Load an Excel file
            workbook.LoadFromFile("AddDigitalSignature.xlsx");

            //Remove all the digital signatures in the file
            workbook.RemoveAllDigitalSignatures();

            //Save the result file
            workbook.SaveToFile("RemoveDigitalSignature.xlsx", FileFormat.Version2013);
        }
    }
}
VB.NET
Imports Spire.Xls

Namespace Delete_Digital_Signature
    Class Program
        Private Shared Sub Main(ByVal args As String())
            Dim workbook As Workbook = New Workbook()
            workbook.LoadFromFile("AddDigitalSignature.xlsx")
            workbook.RemoveAllDigitalSignatures()
            workbook.SaveToFile("RemoveDigitalSignature.xlsx", FileFormat.Version2013)
        End Sub
    End Class
End Namespace

The output Excel file after deleting digital signature:

Add and Delete Digital Signature in Excel in C#, VB.NET