This article is designed to teach how to add digital signature in Excel using C#. It provides the conceptual steps to write a program for adding an electronic signature to an Excel document using C# such that first steps are provided and then a working sample code is shared to test this feature. Information is also shared to customize the signing of the Excel document like an XLSX using the PFX certificate.
Steps to Insert Electronic Signature in Excel using C#
- Configure the environment to use Aspose.Cells for .NET into your project
- Load an existing workbook or create a new workbook with sample data in it using the Workbook object
- Instantiate a collection of digital signatures
- Load a certificate using the certificate file name and the password
- Create a digital signature using the loaded certificate, comments, and signing date
- Add this signature to the collection that is further added to the workbook
- Save the signed workbook
Here the process to put digital signature in excel using c# is described in the form of easy-to-follow steps where first the configuration resources are shared and then a step-by-step procedure is explained that contains all the classes, methods, and their usage in sequence. You need a PFX certificate file, its password, and a workbook if the digital signatures are to be added to an existing workbook otherwise create a simple new workbook for testing the feature as demonstrated in the sample code below. The final workbook with a digital signature can be saved in any of the supported formats like XLSX, XLS, XLSM, etc.
Code to Digitally Sign an Excel Document using C#
This code demonstrates how to add digital signature to Excel using C# where the X509Certificate2 class object is used to load the certificate file. Note that there are more than 15 different overloaded constructors for this class that can be used to load a certificate file. Also while creating a digital signature with the help of this certificate file, you can also use the array of bytes containing the certificate instead of a file on the disk.
This tutorial has taught us to electronically sign an Excel document using C#. If you want to learn the process to open password-protected spreadsheets, refer to the article on how to open password protected Excel file in C#.