This example shows how to sign only the VBA project of the document. See SignResult
Signaturesignature=newSignature(excelFilePath);try{// create digital signature options without a digital certificate
DigitalSignOptionssignOptions=newDigitalSignOptions();// add extension for signing VBA project digitally
DigitalVBAdigitalVBA=newDigitalVBA(certificatePath,password);// set to true only for signing VBA project
digitalVBA.setSignOnlyVBAProject(true);digitalVBA.setComments("VBA Comment");signOptions.getExtensions().add(digitalVBA);// sign document to file
SignResultsignResult=signature.sign(outputFilePath,signOptions);}finally{signature.dispose();}
To sign both the spreadsheet and its VBA project, create the options with the certificate and do not call setSignOnlyVBAProject(true):
Signaturesignature=newSignature(excelFilePath);try{// digital signature options for the document itself
DigitalSignOptionssignOptions=newDigitalSignOptions(certificatePath);signOptions.setPassword(password);signOptions.getSignature().setComments("Comment");// add extension for signing VBA project digitally
DigitalVBAdigitalVBA=newDigitalVBA(certificatePath,password);digitalVBA.setComments("VBA Comment");signOptions.getExtensions().add(digitalVBA);// sign document to file
SignResultsignResult=signature.sign(outputFilePath,signOptions);}finally{signature.dispose();}
More resources
GitHub Examples
You may easily run the code above and see the feature in action in our GitHub examples: