支持对Excel XP以来的高级保护设置

Contents
[ ]

Aspose.Cells 提供了支持使用 XAdES 签名对工作簿进行签名。为此,API 提供了 DigitalSignature 类和 XAdESType 枚举。

以下代码段演示了使用 DigitalSignature 类 签署 source 工作簿。

示例代码

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// directories
String sourceDir = Utils.Get_SourceDirectory();
String outputDir = Utils.Get_OutputDirectory();
Workbook workbook = new Workbook(sourceDir + "sourceFile.xlsx");
String password = "pfxPassword";
String pfx = "pfxFile";
// Load the certificate into an instance of InputStream
InputStream inStream = new FileInputStream(pfx);
// Create an instance of KeyStore with PKCS12 cryptography
java.security.KeyStore inputKeyStore = java.security.KeyStore.getInstance("PKCS12");
// Use the KeyStore.load method to load the certificate stream and its password
inputKeyStore.load(inStream, password.toCharArray());
DigitalSignature signature = new DigitalSignature(inputKeyStore, password, "testXAdES", com.aspose.cells.DateTime.getNow());
signature.setXAdESType(XAdESType.X_AD_ES);
DigitalSignatureCollection dsCollection = new DigitalSignatureCollection();
dsCollection.add(signature);
workbook.setDigitalSignature(dsCollection);
workbook.save(outputDir + "XAdESSignatureSupport_out.xlsx");