本文将介绍如何使用spire.xls for .net在excel中添加和删除数字签名。
添加数字签名
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)
{
//创建workbook实例
workbook workbook = new workbook();
//加载excel文档
workbook.loadfromfile("sample.xlsx");
//添加数字签名
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);
//保存结果文档
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
添加数字签名后的文档截图:
删除数字签名
c#
using spire.xls;
namespace delete_digital_signature
{
class program
{
static void main(string[] args)
{
//创建workbook实例
workbook workbook = new workbook();
//加载excel文档
workbook.loadfromfile("adddigitalsignature.xlsx");
//删除文档中的数字签名
workbook.removealldigitalsignatures();
//保存结果文档
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
删除数字签名后的文档截图: