C#/VB.NET 给Excel添加、删除数字签名

1. 添加数字签名

C#

using Spire.Xls;using Spire.Xls.Core.MergeSpreadsheet.Interfaces;using System;using System.Security.Cryptography.X509Certificates;namespace DigitalSignature_XLS

{

    class Program

    {

        staticvoidMain(string[] args)

        {

            //创建Workbook实例Workbook workbook =new Workbook();

            //加载Excel文档workbook.LoadFromFile("sample.xlsx");

            //添加数字签名X509Certificate2 cert =newX509Certificate2("gary.pfx","123456");

            DateTime certtime =newDateTime(2020,7,1,7,10,36);

            IDigitalSignatures signature = workbook.AddDigitalSignature(cert,"Manager", certtime);

            //保存文档workbook.SaveToFile("AddDigitalSignature.xlsx", FileFormat.Version2013);

            System.Diagnostics.Process.Start("AddDigitalSignature.xlsx");

        }

    }

}

VB.NET

Imports Spire.XlsImports Spire.Xls.Core.MergeSpreadsheet.InterfacesImports System.Security.Cryptography.X509CertificatesNamespace DigitalSignature_XLS

    Class Program

        PrivateSharedSubMain(argsAsString())

            '创建Workbook实例DimworkbookAsNew Workbook()

            '加载Excel文档workbook.LoadFromFile("sample.xlsx")

            '添加数字签名DimcertAsNewX509Certificate2("gary.pfx","123456")

            DimcerttimeAsNewDateTime(2020,7,1,7,10,36)

            DimsignatureAsIDigitalSignatures = workbook.AddDigitalSignature(cert,"Manager", certtime)

            '保存文档workbook.SaveToFile("AddDigitalSignature.xlsx", FileFormat.Version2013)

            System.Diagnostics.Process.Start("AddDigitalSignature.xlsx")

        End SubEnd ClassEnd Namespace

数字签名添加效果:

正在上传... 取消

2. 删除Excel中的数字签名

C#

正在上传... 取消

using Spire.Xls;namespace RemoveSignature

{

    class Program

    {

        staticvoidMain(string[] args)

        {

            //加载Excel文档Workbook workbook =new Workbook();

            workbook.LoadFromFile("AddDigitalSignature.xlsx");

            //删除文档中的数字签名            workbook.RemoveAllDigitalSignatures();

            //保存文档workbook.SaveToFile("RemoveDigitalSignature.xlsx", FileFormat.Version2013);

            System.Diagnostics.Process.Start("RemoveDigitalSignature.xlsx");

        }

    }

}

正在上传... 取消

VB.NET

正在上传... 取消

Imports Spire.XlsNamespace RemoveSignature

    Class Program

        PrivateSharedSubMain(argsAsString())

            '加载Excel文档DimworkbookAsNew Workbook()

            workbook.LoadFromFile("AddDigitalSignature.xlsx")

            '删除文档中的数字签名            workbook.RemoveAllDigitalSignatures()

            '保存文档workbook.SaveToFile("RemoveDigitalSignature.xlsx", FileFormat.Version2013)

            System.Diagnostics.Process.Start("RemoveDigitalSignature.xlsx")

        End SubEnd ClassEnd Namespace

龙华大道1号 http://www.kinghill.cn/Dynamics/2106.html

你可能感兴趣的:(C#/VB.NET 给Excel添加、删除数字签名)