Java (481)
A digital signature is an electronic signature with encrypted information that helps verify the authenticity of messages, software and digital documents. They are commonly used in software distribution, financial transactions, contract management software, and other situations that require forgery or tampering detection. When generating an Excel report, you may need to add a digital signature to make it look more authentic and official. In this article, you will learn how to add or delete digital signatures in Excel in Java using Spire.XLS for Java.
Install Spire.XLS for Java
First of all, you're required to add the Spire.Xls.jar file as a dependency in your Java program. The JAR file can be downloaded from this link. If you use Maven, you can easily import the JAR file in your application by adding the following code to your project's pom.xml file.
<repositories>
<repository>
<id>com.e-iceblue</id>
<name>e-iceblue</name>
<url>https://repo.e-iceblue.com/nexus/content/groups/public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>e-iceblue</groupId>
<artifactId>spire.xls</artifactId>
<version>15.12.15</version>
</dependency>
</dependencies>
Add a Digital Signature to Excel in Java
You can add a digital signature to protect the integrity of an Excel file. Once the digital signature is added, the file becomes read-only to discourage further editing. If someone makes changes to the file, the digital signature will become invalid immediately.
Spire.XLS for Java provides the addDigitalSignature method of Workbook class to add digital signatures to an Excel file. The detailed steps are as follows:
- Instantiate a Workbook instance.
- Load an Excel file using Workbook.loadFromFile() method.
- Instantiate a CertificateAndPrivateKey instance with the specified certificate (.pfx) file path and the password of the .pfx file.
- Add a digital signature to the file using Workbook.addDigitalSignature(CertificateAndPrivateKey, String, Date) method.
- Save the result file using Workbook.saveToFile() method.
- Java
import com.spire.xls.ExcelVersion;
import com.spire.xls.Workbook;
import com.spire.xls.digital.CertificateAndPrivateKey;
import java.util.Date;
public class AddDigitalSignature {
public static void main(String []args) throws Exception {
//Create a Workbook instance
Workbook workbook=new Workbook();
//Load an Excel file
workbook.loadFromFile("Sample.xlsx");
//Add a digital signature to the file
CertificateAndPrivateKey cap = new CertificateAndPrivateKey("Test.pfx","e-iceblue");
workbook.addDigitalSignature(cap, "e-iceblue",new Date());
//Save the result file
workbook.saveToFile("AddDigitalSignature.xlsx", ExcelVersion.Version2013);
}
}

Delete Digital Signature from Excel in Java
Spire.XLS for Java provides the removeAllDigitalSignatures method of Workbook class for developers to remove digital signatures from an Excel file. The detailed steps are as follows:
- Initialize an instance of the Workbook class.
- Load an Excel file using Workbook.loadFromFile() method.
- Remove all digital signatures from the file using Workbook.removeAllDigitalSignatures() method.
- Save the result file using Workbook.saveToFile() method.
- Java
import com.spire.xls.ExcelVersion;
import com.spire.xls.Workbook;
public class DeleteDigitalSignature {
public static void main(String []args) throws Exception {
//Create a Workbook instance
Workbook workbook = new Workbook();
//Load an Excel file
workbook.loadFromFile("AddDigitalSignature.xlsx");
//Remove all digital signatures in the file
workbook.removeAllDigitalSignatures();
//Save the result file
workbook.saveToFile("RemoveDigitalSignature.xlsx", ExcelVersion.Version2013);
}
}

Apply for a Temporary License
If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.
This article demonstrates how to horizontally and vertically align a table in a slide using Spire.Presentation for Java.
Below is a screenshot of the sample document.

import com.spire.presentation.FileFormat;
import com.spire.presentation.ITable;
import com.spire.presentation.Presentation;
import com.spire.presentation.ShapeAlignmentEnum;
public class AlignTable {
public static void main(String[] args) throws Exception {
//Create a Presentation object
Presentation presentation = new Presentation();
//Load the sample PowerPoint document contain
presentation.loadFromFile("C:\\Users\\Administrator\\Desktop\\sample.pptx");
//Declare a ITable variable
ITable table = null;
//Loop through the shapes in the first slide
for (Object shape: presentation.getSlides().get(0).getShapes()
) {
//Check if shape is an instance of ITable
if (shape instanceof ITable)
{
//Convert shape to table
table =(ITable)shape;
}
}
//Horizontally align table to center
table.setShapeAlignment(ShapeAlignmentEnum.ShapeAlignment.AlignCenter);
//Vertically align table to middle
table.setShapeAlignment(ShapeAlignmentEnum.ShapeAlignment.AlignMiddle);
//Save to file
presentation.saveToFile("AlignTable.pptx", FileFormat.PPTX_2013);
}
}

Suppose there are two PowerPoint documents, and you want to copy a certain slide from one document to a specified location of the other. Manual copying and pasting is an option, but the quicker and more efficient way is to use Java codes for automatic operation. This article will show you how to programmatically copy slides between two different PowerPoint documents using Spire.Presentation for Java.
Install Spire.Presentation for Java
First of all, you're required to add the Spire.Presentation.jar file as a dependency in your Java program. The JAR file can be downloaded from this link. If you use Maven, you can easily import the JAR file in your application by adding the following code to your project's pom.xml file.
<repositories>
<repository>
<id>com.e-iceblue</id>
<name>e-iceblue</name>
<url>https://repo.e-iceblue.com/nexus/content/groups/public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>e-iceblue</groupId>
<artifactId>spire.presentation</artifactId>
<version>11.1.1</version>
</dependency>
</dependencies>
Copy Slides Between Two PowerPoint Documents
The following are detailed steps to copy a slide from one PowerPoint document to a specified position or the end of the other document.
- Create a Presentation object and load one sample document using Presentation.loadFromFile() method.
- Create another Presentation object and load the other sample document using Presentation.loadFromFile() method.
- Get a specific slide of document one using Presentation.getSlides().get() method and insert its copy into the specified position of document two using Presentation.getSlides().insert() method.
- Get another specific slide of document one using Presentation.getSlides().get() method and add its copy to the end of document two using Presentation.getSlides().append() method.
- Save the document two to another file using Presentation.saveToFile() method.
- Java
import com.spire.presentation.FileFormat;
import com.spire.presentation.Presentation;
public class CopySlidesBetweenPPT {
public static void main(String[] args) throws Exception {
//Create a Presentation object to load one sample document
Presentation pptOne= new Presentation();
pptOne.loadFromFile("C:\\Users\\Test1\\Desktop\\sample1.pptx");
//Create another Presentation object to load the other sample document
Presentation pptTwo = new Presentation();
pptTwo.loadFromFile("C:\\Users\\Test1\\Desktop\\sample2.pptx");
//Insert the specific slide from document one into the specified position of document two
pptTwo.getSlides().insert(0,pptOne.getSlides().get(0));
//Append the specific slide of document one to the end of document two
pptTwo.getSlides().append(pptOne.getSlides().get(3));
//Save the document two to another file
pptTwo.saveToFile("output/CopySlidesBetweenPPT.pptx", FileFormat.PPTX_2013);
}
}

Apply for a Temporary License
If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.