一、程序环境
以下内容通过C#及VB.NET代介绍如何给Excel文档添加数字签名,以及删除Excel文档中已有的数字签名。工具使用最近发布的Spire.XLS for .NET 版本10.11.2,可在官网下载包,或者通过Nuget搜索下载;编辑代码前,注意先将Spire.XLS.dll添加引用到VS,并添加相应using指令,如下添加引用效果:
二、C# / VB示例代码
1. 添加数字签名
C#
using Spire.Xls;
using Spire.Xls.Core.MergeSpreadsheet.Interfaces;
using System;
using System.Security.Cryptography.X509Certificates;
namespace DigitalSignature_XLS
{
class Program
{
static void Main(string[] args)
{
//创建Workbook实例
Workbook workbook = new Workbook();
//加载Excel文档
workbook.LoadFromFile("sample.xlsx");
//添加数字签名
X509Certificate2 cert = new X509Certificate2("gary.pfx", "123456");
DateTime certtime = new DateTime(2020, 7, 1, 7, 10, 36);